From f97ebdf72dbb1b1d43a78d85a378edf15fef3fee Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Fri, 28 Dec 2007 17:17:10 +0000 Subject: [PATCH] if the surface has CAIRO_CONTENT_COLOR_ALPHA, render it on a checkerboard 2007-12-28 Sven Neumann * app/widgets/gimpviewrenderer.c (gimp_view_renderer_real_draw): if the surface has CAIRO_CONTENT_COLOR_ALPHA, render it on a checkerboard background. * app/widgets/gimpviewrenderergradient.[ch]: just draw the gradient with alpha-transparency instead of doing the blend on the checkerboard here. * app/widgets/gimpcolormapeditor.c: formatting. svn path=/trunk/; revision=24446 --- ChangeLog | 12 ++++ app/widgets/gimpcolormapeditor.c | 7 ++- app/widgets/gimpviewrenderer.c | 27 +++++--- app/widgets/gimpviewrenderergradient.c | 87 +++----------------------- app/widgets/gimpviewrenderergradient.h | 4 -- 5 files changed, 44 insertions(+), 93 deletions(-) diff --git a/ChangeLog b/ChangeLog index 49527d3877..58e2c2e719 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2007-12-28 Sven Neumann + + * app/widgets/gimpviewrenderer.c (gimp_view_renderer_real_draw): + if the surface has CAIRO_CONTENT_COLOR_ALPHA, render it on a + checkerboard background. + + * app/widgets/gimpviewrenderergradient.[ch]: just draw the + gradient with alpha-transparency instead of doing the blend on the + checkerboard here. + + * app/widgets/gimpcolormapeditor.c: formatting. + 2007-12-27 Michael Natterer * app/tools/gimpcolorbalancetool.c: remove the same cruft here. diff --git a/app/widgets/gimpcolormapeditor.c b/app/widgets/gimpcolormapeditor.c index 5edabd39f2..c470628e03 100644 --- a/app/widgets/gimpcolormapeditor.c +++ b/app/widgets/gimpcolormapeditor.c @@ -510,7 +510,8 @@ gimp_colormap_editor_draw (GimpColormapEditor *editor) row[l * 3 + b] = (((((i * cellsize + k) & 0x4) ? (l) : (l + 0x4)) & 0x4) ? - gimp_render_light_check : gimp_render_dark_check); + gimp_render_light_check : + gimp_render_dark_check); gtk_preview_draw_row (GTK_PREVIEW (editor->preview), row, 0, i * cellsize + k, @@ -751,7 +752,7 @@ gimp_colormap_preview_drag_color (GtkWidget *widget, gpointer data) { GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (data); - GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image; + GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image; if (HAVE_COLORMAP (image)) gimp_image_get_colormap_entry (image, editor->dnd_col_index, color); @@ -765,7 +766,7 @@ gimp_colormap_preview_drop_color (GtkWidget *widget, gpointer data) { GimpColormapEditor *editor = GIMP_COLORMAP_EDITOR (data); - GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image; + GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image; if (HAVE_COLORMAP (image) && gimp_image_get_colormap_size (image) < 256) { diff --git a/app/widgets/gimpviewrenderer.c b/app/widgets/gimpviewrenderer.c index dfcd7ef8c5..8ed29c3fec 100644 --- a/app/widgets/gimpviewrenderer.c +++ b/app/widgets/gimpviewrenderer.c @@ -713,15 +713,28 @@ gimp_view_renderer_real_draw (GimpViewRenderer *renderer, } else if (renderer->surface) { - gint width = renderer->width; - gint height = renderer->height; - gint x, y; + cairo_content_t content = cairo_surface_get_content (renderer->surface); + gint width = renderer->width; + gint height = renderer->height; - x = area->x + (area->width - width) / 2; - y = area->y + (area->height - height) / 2; + cairo_translate (cr, + area->x + (area->width - width) / 2, + area->y + (area->height - height) / 2); - cairo_set_source_surface (cr, renderer->surface, x, y); - cairo_rectangle (cr, x, y, width, height); + cairo_rectangle (cr, 0, 0, width, height); + + if (content == CAIRO_CONTENT_COLOR_ALPHA) + { + cairo_pattern_t *pattern; + + pattern = gimp_cairo_checkerboard_create (cr, GIMP_CHECK_SIZE_SM); + + cairo_set_source (cr, pattern); + cairo_pattern_destroy (pattern); + cairo_fill_preserve (cr); + } + + cairo_set_source_surface (cr, renderer->surface, 0, 0); cairo_fill (cr); } } diff --git a/app/widgets/gimpviewrenderergradient.c b/app/widgets/gimpviewrenderergradient.c index c31b04ae0f..563c04de53 100644 --- a/app/widgets/gimpviewrenderergradient.c +++ b/app/widgets/gimpviewrenderergradient.c @@ -25,6 +25,7 @@ #include +#include "libgimpbase/gimpbase.h" #include "libgimpcolor/gimpcolor.h" #include "libgimpmath/gimpmath.h" #include "libgimpwidgets/gimpwidgets.h" @@ -33,12 +34,9 @@ #include "core/gimpgradient.h" -#include "gimprender.h" #include "gimpviewrenderergradient.h" -static void gimp_view_renderer_gradient_finalize (GObject *object); - static void gimp_view_renderer_gradient_set_context (GimpViewRenderer *renderer, GimpContext *context); static void gimp_view_renderer_gradient_invalidate (GimpViewRenderer *renderer); @@ -55,11 +53,8 @@ G_DEFINE_TYPE (GimpViewRendererGradient, gimp_view_renderer_gradient, static void gimp_view_renderer_gradient_class_init (GimpViewRendererGradientClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); GimpViewRendererClass *renderer_class = GIMP_VIEW_RENDERER_CLASS (klass); - object_class->finalize = gimp_view_renderer_gradient_finalize; - renderer_class->set_context = gimp_view_renderer_gradient_set_context; renderer_class->invalidate = gimp_view_renderer_gradient_invalidate; renderer_class->render = gimp_view_renderer_gradient_render; @@ -68,34 +63,11 @@ gimp_view_renderer_gradient_class_init (GimpViewRendererGradientClass *klass) static void gimp_view_renderer_gradient_init (GimpViewRendererGradient *renderer) { - renderer->even = NULL; - renderer->odd = NULL; - renderer->width = -1; renderer->left = 0.0; renderer->right = 1.0; renderer->reverse = FALSE; } -static void -gimp_view_renderer_gradient_finalize (GObject *object) -{ - GimpViewRendererGradient *renderer = GIMP_VIEW_RENDERER_GRADIENT (object); - - if (renderer->even) - { - g_free (renderer->even); - renderer->even = NULL; - } - - if (renderer->odd) - { - g_free (renderer->odd); - renderer->odd = NULL; - } - - G_OBJECT_CLASS (parent_class)->finalize (object); -} - static void gimp_view_renderer_gradient_fg_bg_changed (GimpContext *context, const GimpRGB *color, @@ -187,8 +159,7 @@ gimp_view_renderer_gradient_render (GimpViewRenderer *renderer, GimpViewRendererGradient *rendergrad = GIMP_VIEW_RENDERER_GRADIENT (renderer); GimpGradient *gradient = GIMP_GRADIENT (renderer->viewable); GimpGradientSegment *seg = NULL; - guchar *even; - guchar *odd; + guchar *buf; guchar *dest; gint dest_stride; gint x; @@ -196,27 +167,11 @@ gimp_view_renderer_gradient_render (GimpViewRenderer *renderer, gdouble dx, cur_x; GimpRGB color; - if (renderer->width != rendergrad->width) - { - if (rendergrad->even) - g_free (rendergrad->even); - - if (rendergrad->odd) - g_free (rendergrad->odd); - - rendergrad->even = g_new (guchar, 4 * renderer->width); - rendergrad->odd = g_new (guchar, 4 * renderer->width); - - rendergrad->width = renderer->width; - } - - even = rendergrad->even; - odd = rendergrad->odd; - + buf = g_alloca (4 * renderer->width); dx = (rendergrad->right - rendergrad->left) / (renderer->width - 1); cur_x = rendergrad->left; - for (x = 0; x < renderer->width; x++, even += 4, odd += 4) + for (x = 0, dest = buf; x < renderer->width; x++, dest += 4) { guchar r, g, b, a; @@ -226,46 +181,20 @@ gimp_view_renderer_gradient_render (GimpViewRenderer *renderer, gimp_rgba_get_uchar (&color, &r, &g, &b, &a); - if (x & 0x4) - { - GIMP_CAIRO_RGB24_SET_PIXEL (even, - gimp_render_blend_dark_check[(a << 8) | r], - gimp_render_blend_dark_check[(a << 8) | g], - gimp_render_blend_dark_check[(a << 8) | b]); - GIMP_CAIRO_RGB24_SET_PIXEL (odd, - gimp_render_blend_light_check[(a << 8) | r], - gimp_render_blend_light_check[(a << 8) | g], - gimp_render_blend_light_check[(a << 8) | b]); - } - else - { - GIMP_CAIRO_RGB24_SET_PIXEL (even, - gimp_render_blend_light_check[(a << 8) | r], - gimp_render_blend_light_check[(a << 8) | g], - gimp_render_blend_light_check[(a << 8) | b]); - GIMP_CAIRO_RGB24_SET_PIXEL (odd, - gimp_render_blend_dark_check[(a << 8) | r], - gimp_render_blend_dark_check[(a << 8) | g], - gimp_render_blend_dark_check[(a << 8) | b]); - } + GIMP_CAIRO_ARGB32_SET_PIXEL (dest, r, g, b, a); } if (! renderer->surface) - renderer->surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, + renderer->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, renderer->width, renderer->height); dest = cairo_image_surface_get_data (renderer->surface); dest_stride = cairo_image_surface_get_stride (renderer->surface); - for (y = 0; y < renderer->height; y++) + for (y = 0; y < renderer->height; y++, dest += dest_stride) { - if (y & 0x4) - memcpy (dest, rendergrad->even, renderer->width * 4); - else - memcpy (dest, rendergrad->odd, renderer->width * 4); - - dest += dest_stride; + memcpy (dest, buf, renderer->width * 4); } renderer->needs_render = FALSE; diff --git a/app/widgets/gimpviewrenderergradient.h b/app/widgets/gimpviewrenderergradient.h index 7f8b678e2f..7d8810a637 100644 --- a/app/widgets/gimpviewrenderergradient.h +++ b/app/widgets/gimpviewrenderergradient.h @@ -38,12 +38,8 @@ struct _GimpViewRendererGradient { GimpViewRenderer parent_instance; - guchar *even; - guchar *odd; - gint width; gdouble left; gdouble right; - gboolean reverse; gboolean has_fg_bg_segments; };