static void gimp_view_renderer_buffer_render (GimpViewRenderer *renderer, GtkWidget *widget) { gint buffer_width; gint buffer_height; gint view_width; gint view_height; gboolean scaling_up; GimpTempBuf *render_buf = NULL; gimp_viewable_get_size (renderer->viewable, &buffer_width, &buffer_height); gimp_viewable_calc_preview_size (buffer_width, buffer_height, renderer->width, renderer->height, TRUE, 1.0, 1.0, &view_width, &view_height, &scaling_up); if (scaling_up) { GimpTempBuf *temp_buf; temp_buf = gimp_viewable_get_new_preview (renderer->viewable, renderer->context, buffer_width, buffer_height); if (temp_buf) { render_buf = gimp_temp_buf_scale (temp_buf, view_width, view_height); gimp_temp_buf_unref (temp_buf); } } else { render_buf = gimp_viewable_get_new_preview (renderer->viewable, renderer->context, view_width, view_height); } if (render_buf) { gimp_view_renderer_render_temp_buf_simple (renderer, render_buf); gimp_temp_buf_unref (render_buf); } else /* no preview available */ { const gchar *icon_name; icon_name = gimp_viewable_get_icon_name (renderer->viewable); gimp_view_renderer_render_icon (renderer, widget, icon_name); } }
static GeglBuffer * gimp_ink_get_paint_buffer (GimpPaintCore *paint_core, GimpDrawable *drawable, GimpPaintOptions *paint_options, const GimpCoords *coords, gint *paint_buffer_x, gint *paint_buffer_y) { GimpInk *ink = GIMP_INK (paint_core); gint x, y; gint width, height; gint dwidth, dheight; gint x1, y1, x2, y2; gimp_blob_bounds (ink->cur_blob, &x, &y, &width, &height); dwidth = gimp_item_get_width (GIMP_ITEM (drawable)); dheight = gimp_item_get_height (GIMP_ITEM (drawable)); x1 = CLAMP (x / SUBSAMPLE - 1, 0, dwidth); y1 = CLAMP (y / SUBSAMPLE - 1, 0, dheight); x2 = CLAMP ((x + width) / SUBSAMPLE + 2, 0, dwidth); y2 = CLAMP ((y + height) / SUBSAMPLE + 2, 0, dheight); /* configure the canvas buffer */ if ((x2 - x1) && (y2 - y1)) { GimpTempBuf *temp_buf; const Babl *format; if (gimp_drawable_get_linear (drawable)) format = babl_format ("RGBA float"); else format = babl_format ("R'G'B'A float"); temp_buf = gimp_temp_buf_new ((x2 - x1), (y2 - y1), format); *paint_buffer_x = x1; *paint_buffer_y = y1; if (paint_core->paint_buffer) g_object_unref (paint_core->paint_buffer); paint_core->paint_buffer = gimp_temp_buf_create_buffer (temp_buf); gimp_temp_buf_unref (temp_buf); return paint_core->paint_buffer; } return NULL; }
static void gimp_pattern_finalize (GObject *object) { GimpPattern *pattern = GIMP_PATTERN (object); if (pattern->mask) { gimp_temp_buf_unref (pattern->mask); pattern->mask = NULL; } G_OBJECT_CLASS (parent_class)->finalize (object); }
void gimp_undo_refresh_preview (GimpUndo *undo, GimpContext *context) { g_return_if_fail (GIMP_IS_UNDO (undo)); g_return_if_fail (context == NULL || GIMP_IS_CONTEXT (context)); if (undo->preview_idle_id) return; if (undo->preview) { gimp_temp_buf_unref (undo->preview); undo->preview = NULL; gimp_undo_create_preview (undo, context, FALSE); } }
static void gimp_undo_finalize (GObject *object) { GimpUndo *undo = GIMP_UNDO (object); if (undo->preview_idle_id) { g_source_remove (undo->preview_idle_id); undo->preview_idle_id = 0; } if (undo->preview) { gimp_temp_buf_unref (undo->preview); undo->preview = NULL; } G_OBJECT_CLASS (parent_class)->finalize (object); }
static void gimp_brush_generated_dirty (GimpData *data) { GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (data); GimpBrush *gbrush = GIMP_BRUSH (brush); if (gbrush->priv->mask) gimp_temp_buf_unref (gbrush->priv->mask); gbrush->priv->mask = gimp_brush_generated_calc (brush, brush->shape, brush->radius, brush->spikes, brush->hardness, brush->aspect_ratio, brush->angle, &gbrush->priv->x_axis, &gbrush->priv->y_axis); GIMP_DATA_CLASS (parent_class)->dirty (data); }
static void gimp_pattern_clipboard_buffer_changed (Gimp *gimp, GimpPattern *pattern) { if (pattern->mask) { gimp_temp_buf_unref (pattern->mask); pattern->mask = NULL; } if (gimp->global_buffer) { GimpBuffer *buffer = gimp->global_buffer; gint width; gint height; width = MIN (gimp_buffer_get_width (buffer), 2048); height = MIN (gimp_buffer_get_height (buffer), 2048); pattern->mask = gimp_temp_buf_new (width, height, gimp_buffer_get_format (buffer)); gegl_buffer_get (gimp_buffer_get_buffer (buffer), GEGL_RECTANGLE (0, 0, width, height), 1.0, NULL, gimp_temp_buf_get_data (pattern->mask), GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE); } else { pattern->mask = gimp_temp_buf_new (16, 16, babl_format ("R'G'B' u8")); memset (gimp_temp_buf_get_data (pattern->mask), 255, 16 * 16 * 3); } gimp_data_dirty (GIMP_DATA (pattern)); }
static GdkPixbuf * gimp_buffer_get_new_pixbuf (GimpViewable *viewable, GimpContext *context, gint width, gint height) { GimpBuffer *buffer = GIMP_BUFFER (viewable); GdkPixbuf *pixbuf; gdouble scale; pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height); scale = MIN ((gdouble) width / (gdouble) gimp_buffer_get_width (buffer), (gdouble) height / (gdouble) gimp_buffer_get_height (buffer)); if (buffer->color_profile) { GimpColorProfile *srgb_profile; GimpTempBuf *temp_buf; GeglBuffer *src_buf; GeglBuffer *dest_buf; srgb_profile = gimp_color_profile_new_rgb_srgb (); temp_buf = gimp_temp_buf_new (width, height, gimp_buffer_get_format (buffer)); gegl_buffer_get (buffer->buffer, GEGL_RECTANGLE (0, 0, width, height), scale, gimp_temp_buf_get_format (temp_buf), gimp_temp_buf_get_data (temp_buf), GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_CLAMP); src_buf = gimp_temp_buf_create_buffer (temp_buf); dest_buf = gimp_pixbuf_create_buffer (pixbuf); gimp_temp_buf_unref (temp_buf); gimp_gegl_convert_color_profile (src_buf, GEGL_RECTANGLE (0, 0, width, height), buffer->color_profile, dest_buf, GEGL_RECTANGLE (0, 0, 0, 0), srgb_profile, GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL, TRUE, NULL); g_object_unref (src_buf); g_object_unref (dest_buf); g_object_unref (srgb_profile); } else { gegl_buffer_get (buffer->buffer, GEGL_RECTANGLE (0, 0, width, height), scale, gimp_pixbuf_get_format (pixbuf), gdk_pixbuf_get_pixels (pixbuf), gdk_pixbuf_get_rowstride (pixbuf), GEGL_ABYSS_CLAMP); } return pixbuf; }
static void gimp_brush_clipboard_buffer_changed (Gimp *gimp, GimpBrush *brush) { gint width; gint height; if (brush->mask) { gimp_temp_buf_unref (brush->mask); brush->mask = NULL; } if (brush->pixmap) { gimp_temp_buf_unref (brush->pixmap); brush->pixmap = NULL; } if (gimp->global_buffer) { GeglBuffer *buffer = gimp_buffer_get_buffer (gimp->global_buffer); const Babl *format = gegl_buffer_get_format (buffer); GeglBuffer *dest_buffer; width = MIN (gimp_buffer_get_width (gimp->global_buffer), 512); height = MIN (gimp_buffer_get_height (gimp->global_buffer), 512); brush->mask = gimp_temp_buf_new (width, height, babl_format ("Y u8")); brush->pixmap = gimp_temp_buf_new (width, height, babl_format ("R'G'B' u8")); /* copy the alpha channel into the brush's mask */ if (babl_format_has_alpha (format)) { dest_buffer = gimp_temp_buf_create_buffer (brush->mask); gegl_buffer_set_format (dest_buffer, babl_format ("A u8")); gegl_buffer_copy (buffer, NULL, dest_buffer, NULL); g_object_unref (dest_buffer); } else { memset (gimp_temp_buf_get_data (brush->mask), 255, width * height); } /* copy the color channels into the brush's pixmap */ dest_buffer = gimp_temp_buf_create_buffer (brush->pixmap); gegl_buffer_copy (buffer, NULL, dest_buffer, NULL); g_object_unref (dest_buffer); } else { width = 17; height = 17; brush->mask = gimp_temp_buf_new (width, height, babl_format ("Y u8")); gimp_temp_buf_data_clear (brush->mask); } 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)); }
GdkPixbuf * gimp_drawable_get_sub_pixbuf (GimpDrawable *drawable, gint src_x, gint src_y, gint src_width, gint src_height, gint dest_width, gint dest_height) { GimpItem *item; GimpImage *image; GeglBuffer *buffer; GdkPixbuf *pixbuf; gdouble scale; gint scaled_x; gint scaled_y; GimpColorTransform *transform; g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL); g_return_val_if_fail (src_x >= 0, NULL); g_return_val_if_fail (src_y >= 0, NULL); g_return_val_if_fail (src_width > 0, NULL); g_return_val_if_fail (src_height > 0, NULL); g_return_val_if_fail (dest_width > 0, NULL); g_return_val_if_fail (dest_height > 0, NULL); item = GIMP_ITEM (drawable); g_return_val_if_fail ((src_x + src_width) <= gimp_item_get_width (item), NULL); g_return_val_if_fail ((src_y + src_height) <= gimp_item_get_height (item), NULL); image = gimp_item_get_image (item); if (! image->gimp->config->layer_previews) return NULL; buffer = gimp_drawable_get_buffer (drawable); pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, dest_width, dest_height); scale = MIN ((gdouble) dest_width / (gdouble) src_width, (gdouble) dest_height / (gdouble) src_height); scaled_x = RINT ((gdouble) src_x * scale); scaled_y = RINT ((gdouble) src_y * scale); transform = gimp_image_get_color_transform_to_srgb_u8 (image); if (transform) { GimpTempBuf *temp_buf; GeglBuffer *src_buf; GeglBuffer *dest_buf; temp_buf = gimp_temp_buf_new (dest_width, dest_height, gimp_drawable_get_format (drawable)); gegl_buffer_get (buffer, GEGL_RECTANGLE (scaled_x, scaled_y, dest_width, dest_height), scale, gimp_temp_buf_get_format (temp_buf), gimp_temp_buf_get_data (temp_buf), GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_CLAMP); src_buf = gimp_temp_buf_create_buffer (temp_buf); dest_buf = gimp_pixbuf_create_buffer (pixbuf); gimp_temp_buf_unref (temp_buf); gimp_color_transform_process_buffer (transform, src_buf, GEGL_RECTANGLE (0, 0, dest_width, dest_height), dest_buf, GEGL_RECTANGLE (0, 0, 0, 0)); g_object_unref (src_buf); g_object_unref (dest_buf); } else { gegl_buffer_get (buffer, GEGL_RECTANGLE (scaled_x, scaled_y, dest_width, dest_height), scale, gimp_pixbuf_get_format (pixbuf), gdk_pixbuf_get_pixels (pixbuf), gdk_pixbuf_get_rowstride (pixbuf), GEGL_ABYSS_CLAMP); } return pixbuf; }
static void gimp_convolve_motion (GimpPaintCore *paint_core, GimpDrawable *drawable, GimpPaintOptions *paint_options, const GimpCoords *coords) { GimpConvolve *convolve = GIMP_CONVOLVE (paint_core); GimpBrushCore *brush_core = GIMP_BRUSH_CORE (paint_core); GimpConvolveOptions *options = GIMP_CONVOLVE_OPTIONS (paint_options); GimpContext *context = GIMP_CONTEXT (paint_options); GimpDynamics *dynamics = GIMP_BRUSH_CORE (paint_core)->dynamics; GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable)); GeglBuffer *paint_buffer; gint paint_buffer_x; gint paint_buffer_y; GimpTempBuf *temp_buf; GeglBuffer *convolve_buffer; gdouble fade_point; gdouble opacity; gdouble rate; fade_point = gimp_paint_options_get_fade (paint_options, image, paint_core->pixel_dist); opacity = gimp_dynamics_get_linear_value (dynamics, GIMP_DYNAMICS_OUTPUT_OPACITY, coords, paint_options, fade_point); if (opacity == 0.0) return; paint_buffer = gimp_paint_core_get_paint_buffer (paint_core, drawable, paint_options, coords, &paint_buffer_x, &paint_buffer_y); if (! paint_buffer) return; rate = (options->rate * gimp_dynamics_get_linear_value (dynamics, GIMP_DYNAMICS_OUTPUT_RATE, coords, paint_options, fade_point)); gimp_convolve_calculate_matrix (convolve, options->type, gimp_brush_get_width (brush_core->brush) / 2, gimp_brush_get_height (brush_core->brush) / 2, rate); /* need a linear buffer for gimp_gegl_convolve() */ temp_buf = gimp_temp_buf_new (gegl_buffer_get_width (paint_buffer), gegl_buffer_get_height (paint_buffer), gegl_buffer_get_format (paint_buffer)); convolve_buffer = gimp_temp_buf_create_buffer (temp_buf); gimp_temp_buf_unref (temp_buf); gegl_buffer_copy (gimp_drawable_get_buffer (drawable), GEGL_RECTANGLE (paint_buffer_x, paint_buffer_y, gegl_buffer_get_width (paint_buffer), gegl_buffer_get_height (paint_buffer)), convolve_buffer, GEGL_RECTANGLE (0, 0, 0, 0)); gimp_gegl_convolve (convolve_buffer, GEGL_RECTANGLE (0, 0, gegl_buffer_get_width (convolve_buffer), gegl_buffer_get_height (convolve_buffer)), paint_buffer, GEGL_RECTANGLE (0, 0, gegl_buffer_get_width (paint_buffer), gegl_buffer_get_height (paint_buffer)), convolve->matrix, 3, convolve->matrix_divisor, GIMP_NORMAL_CONVOL, TRUE); g_object_unref (convolve_buffer); gimp_brush_core_replace_canvas (brush_core, drawable, coords, MIN (opacity, GIMP_OPACITY_OPAQUE), gimp_context_get_opacity (context), gimp_paint_options_get_brush_mode (paint_options), 1.0, GIMP_PAINT_INCREMENTAL); }
GdkPixbuf * gimp_image_get_new_pixbuf (GimpViewable *viewable, GimpContext *context, gint width, gint height) { GimpImage *image = GIMP_IMAGE (viewable); GdkPixbuf *pixbuf; gdouble scale_x; gdouble scale_y; GimpColorTransform *transform; scale_x = (gdouble) width / (gdouble) gimp_image_get_width (image); scale_y = (gdouble) height / (gdouble) gimp_image_get_height (image); pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height); transform = gimp_image_get_color_transform_to_srgb_u8 (image); if (transform) { GimpTempBuf *temp_buf; GeglBuffer *src_buf; GeglBuffer *dest_buf; temp_buf = gimp_temp_buf_new (width, height, gimp_pickable_get_format (GIMP_PICKABLE (image))); gegl_buffer_get (gimp_pickable_get_buffer (GIMP_PICKABLE (image)), GEGL_RECTANGLE (0, 0, width, height), MIN (scale_x, scale_y), gimp_temp_buf_get_format (temp_buf), gimp_temp_buf_get_data (temp_buf), GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_CLAMP); src_buf = gimp_temp_buf_create_buffer (temp_buf); dest_buf = gimp_pixbuf_create_buffer (pixbuf); gimp_temp_buf_unref (temp_buf); gimp_color_transform_process_buffer (transform, src_buf, GEGL_RECTANGLE (0, 0, width, height), dest_buf, GEGL_RECTANGLE (0, 0, 0, 0)); g_object_unref (src_buf); g_object_unref (dest_buf); } else { gegl_buffer_get (gimp_pickable_get_buffer (GIMP_PICKABLE (image)), GEGL_RECTANGLE (0, 0, width, height), MIN (scale_x, scale_y), gimp_pixbuf_get_format (pixbuf), gdk_pixbuf_get_pixels (pixbuf), gdk_pixbuf_get_rowstride (pixbuf), GEGL_ABYSS_CLAMP); } return pixbuf; }
static void gimp_view_renderer_image_render (GimpViewRenderer *renderer, GtkWidget *widget) { GimpViewRendererImage *rendererimage = GIMP_VIEW_RENDERER_IMAGE (renderer); GimpImage *image = GIMP_IMAGE (renderer->viewable); const gchar *icon_name; /* The conditions checked here are mostly a hack to hide the fact that * we are creating the channel preview from the image preview and turning * off visibility of a channel has the side-effect of painting the channel * preview all black. See bug #459518 for details. */ if (rendererimage->channel == -1 || (gimp_image_get_component_visible (image, rendererimage->channel) && gimp_image_get_component_visible (image, GIMP_ALPHA_CHANNEL))) { gint view_width; gint view_height; gdouble xres; gdouble yres; gboolean scaling_up; GimpTempBuf *render_buf = NULL; gimp_image_get_resolution (image, &xres, &yres); gimp_viewable_calc_preview_size (gimp_image_get_width (image), gimp_image_get_height (image), renderer->width, renderer->height, renderer->dot_for_dot, xres, yres, &view_width, &view_height, &scaling_up); if (scaling_up) { GimpTempBuf *temp_buf; temp_buf = gimp_viewable_get_new_preview (renderer->viewable, renderer->context, gimp_image_get_width (image), gimp_image_get_height (image)); if (temp_buf) { render_buf = gimp_temp_buf_scale (temp_buf, view_width, view_height); gimp_temp_buf_unref (temp_buf); } } else { render_buf = gimp_viewable_get_new_preview (renderer->viewable, renderer->context, view_width, view_height); } if (render_buf) { gint render_buf_x = 0; gint render_buf_y = 0; gint component_index = -1; /* xresolution != yresolution */ if (view_width > renderer->width || view_height > renderer->height) { GimpTempBuf *temp_buf; temp_buf = gimp_temp_buf_scale (render_buf, renderer->width, renderer->height); gimp_temp_buf_unref (render_buf); render_buf = temp_buf; } if (view_width < renderer->width) render_buf_x = (renderer->width - view_width) / 2; if (view_height < renderer->height) render_buf_y = (renderer->height - view_height) / 2; if (rendererimage->channel != -1) component_index = gimp_image_get_component_index (image, rendererimage->channel); gimp_view_renderer_render_temp_buf (renderer, widget, render_buf, render_buf_x, render_buf_y, component_index, GIMP_VIEW_BG_CHECKS, GIMP_VIEW_BG_WHITE); gimp_temp_buf_unref (render_buf); return; } } switch (rendererimage->channel) { case GIMP_RED_CHANNEL: icon_name = GIMP_STOCK_CHANNEL_RED; break; case GIMP_GREEN_CHANNEL: icon_name = GIMP_STOCK_CHANNEL_GREEN; break; case GIMP_BLUE_CHANNEL: icon_name = GIMP_STOCK_CHANNEL_BLUE; break; case GIMP_GRAY_CHANNEL: icon_name = GIMP_STOCK_CHANNEL_GRAY; break; case GIMP_INDEXED_CHANNEL: icon_name = GIMP_STOCK_CHANNEL_INDEXED; break; case GIMP_ALPHA_CHANNEL: icon_name = GIMP_STOCK_CHANNEL_ALPHA; break; default: icon_name = gimp_viewable_get_icon_name (renderer->viewable); break; } gimp_view_renderer_render_icon (renderer, widget, icon_name); }