示例#1
0
static TempBuf *
gimp_undo_get_new_preview (GimpViewable *viewable,
                           GimpContext  *context,
                           gint          width,
                           gint          height)
{
  GimpUndo *undo = GIMP_UNDO (viewable);

  if (undo->preview)
    {
      gint preview_width;
      gint preview_height;

      gimp_viewable_calc_preview_size (undo->preview->width,
                                       undo->preview->height,
                                       width,
                                       height,
                                       TRUE, 1.0, 1.0,
                                       &preview_width,
                                       &preview_height,
                                       NULL);

      if (preview_width  < undo->preview->width &&
          preview_height < undo->preview->height)
        {
          return temp_buf_scale (undo->preview, preview_width, preview_height);
        }

      return temp_buf_copy (undo->preview, NULL);
    }

  return NULL;
}
示例#2
0
static void
gimp_brush_clipboard_buffer_changed (Gimp      *gimp,
                                     GimpBrush *brush)
{
  gint width;
  gint height;

  if (brush->mask)
    {
      temp_buf_free (brush->mask);
      brush->mask = NULL;
    }

  if (brush->pixmap)
    {
      temp_buf_free (brush->pixmap);
      brush->pixmap = NULL;
    }

  if (gimp->global_buffer)
    {
      TileManager   *tiles = gimp_buffer_get_tiles (gimp->global_buffer);
      GimpImageType  type  = gimp_buffer_get_image_type (gimp->global_buffer);

      width  = MIN (gimp_buffer_get_width  (gimp->global_buffer), 1024);
      height = MIN (gimp_buffer_get_height (gimp->global_buffer), 1024);

      brush->mask   = temp_buf_new (width, height, 1, 0, 0, NULL);
      brush->pixmap = temp_buf_new (width, height, 3, 0, 0, NULL);

      /*  copy the alpha channel into the brush's mask  */
      if (GIMP_IMAGE_TYPE_HAS_ALPHA (type))
        {
          PixelRegion bufferPR;
          PixelRegion maskPR;

          pixel_region_init (&bufferPR, tiles,
                             0, 0, width, height, FALSE);
          pixel_region_init_temp_buf (&maskPR, brush->mask,
                                      0, 0, width, height);

          extract_alpha_region (&bufferPR, NULL, &maskPR);
        }
      else
        {
          PixelRegion maskPR;
          guchar      opaque = OPAQUE_OPACITY;

          pixel_region_init_temp_buf (&maskPR, brush->mask,
                                      0, 0, width, height);
          color_region (&maskPR, &opaque);
        }

      /*  copy the color channels into the brush's pixmap  */
      if (GIMP_IMAGE_TYPE_IS_RGB (type))
        {
          PixelRegion bufferPR;
          PixelRegion pixmapPR;

          pixel_region_init (&bufferPR, tiles,
                             0, 0, width, height, FALSE);
          pixel_region_init_temp_buf (&pixmapPR, brush->pixmap,
                                      0, 0, width, height);

          if (GIMP_IMAGE_TYPE_HAS_ALPHA (type))
            copy_color (&bufferPR, &pixmapPR);
          else
            copy_region (&bufferPR, &pixmapPR);
        }
      else
        {
          PixelRegion  bufferPR;
          PixelRegion  tempPR;
          TempBuf     *temp = temp_buf_new (width, height, 1, 0, 0, NULL);

          pixel_region_init (&bufferPR, tiles,
                             0, 0, width, height, FALSE);
          pixel_region_init_temp_buf (&tempPR, temp,
                                      0, 0, width, height);

          if (GIMP_IMAGE_TYPE_HAS_ALPHA (type))
            copy_component (&bufferPR, &tempPR, 0);
          else
            copy_region (&bufferPR, &tempPR);

          temp_buf_copy (temp, brush->pixmap);
          temp_buf_free (temp);
        }
    }
  else
    {
      guchar color = 0;

      width  = 17;
      height = 17;

      brush->mask = temp_buf_new (width, height, 1, 0, 0, &color);
    }

  brush->x_axis.x = width / 2;
  brush->x_axis.y = 0;
  brush->y_axis.x = 0;
  brush->y_axis.y = height / 2;

  gimp_data_dirty (GIMP_DATA (brush));
}