mirror of https://github.com/GNOME/gimp.git
introduced macros to set a single pixel in a Cairo surface without having
2007-11-05 Sven Neumann <sven@gimp.org> * app/widgets/gimpcairo-utils.h: introduced macros to set a single pixel in a Cairo surface without having to worry about endianness. * app/widgets/gimpcairo-utils.c * app/widgets/gimpviewrenderer.c * app/widgets/gimpviewrenderergradient.c * app/widgets/gimpviewrendererpalette.c: use the new macros. svn path=/trunk/; revision=24065
This commit is contained in:
parent
f164d4bad3
commit
c197362e9d
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
2007-11-05 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* app/widgets/gimpcairo-utils.h: introduced macros to set a single
|
||||
pixel in a Cairo surface without having to worry about endianness.
|
||||
|
||||
* app/widgets/gimpcairo-utils.c
|
||||
* app/widgets/gimpviewrenderer.c
|
||||
* app/widgets/gimpviewrenderergradient.c
|
||||
* app/widgets/gimpviewrendererpalette.c: use the new macros.
|
||||
|
||||
2007-11-05 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
* app/widgets/gimpcurveview.c (gimp_curve_view_expose): port to
|
||||
|
|
|
@ -104,15 +104,7 @@ gimp_cairo_create_surface_from_pixbuf (GdkPixbuf *pixbuf)
|
|||
|
||||
while (w--)
|
||||
{
|
||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||
d[0] = s[2];
|
||||
d[1] = s[1];
|
||||
d[2] = s[0];
|
||||
#else
|
||||
d[1] = s[0];
|
||||
d[2] = s[1];
|
||||
d[3] = s[2];
|
||||
#endif
|
||||
GIMP_CAIRO_RGB24_SET_PIXEL (d, s[0], s[1], s[2]);
|
||||
|
||||
s += 3;
|
||||
d += 4;
|
||||
|
@ -129,30 +121,15 @@ gimp_cairo_create_surface_from_pixbuf (GdkPixbuf *pixbuf)
|
|||
const guchar *s = src;
|
||||
guchar *d = dest;
|
||||
gint w = width;
|
||||
guint t1, t2, t3;
|
||||
|
||||
#define MULT(d,c,a,t) \
|
||||
G_STMT_START { t = c * a + 0x7f; d = ((t >> 8) + t) >> 8; } G_STMT_END
|
||||
|
||||
while (w--)
|
||||
{
|
||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||
MULT (d[0], s[2], s[3], t1);
|
||||
MULT (d[1], s[1], s[3], t2);
|
||||
MULT (d[2], s[0], s[3], t3);
|
||||
d[3] = s[3];
|
||||
#else
|
||||
d[0] = s[3];
|
||||
MULT (d[1], s[0], s[3], t1);
|
||||
MULT (d[2], s[1], s[3], t2);
|
||||
MULT (d[3], s[2], s[3], t3);
|
||||
#endif
|
||||
GIMP_CAIRO_ARGB32_SET_PIXEL (d, s[0], s[1], s[2], s[3]);
|
||||
|
||||
s += 4;
|
||||
d += 4;
|
||||
}
|
||||
|
||||
#undef MULT
|
||||
|
||||
src += src_stride;
|
||||
dest += dest_stride;
|
||||
}
|
||||
|
|
|
@ -28,4 +28,58 @@ void gimp_cairo_set_source_color (cairo_t *cr,
|
|||
cairo_surface_t * gimp_cairo_create_surface_from_pixbuf (GdkPixbuf *pixbuf);
|
||||
|
||||
|
||||
#define INT_MULT(a,b,t) ((t) = (a) * (b) + 0x80, ((((t) >> 8) + (t)) >> 8))
|
||||
|
||||
|
||||
/* some useful macros for writing directly to a Cairo surface */
|
||||
|
||||
/**
|
||||
* GIMP_CAIRO_RGB24_SET_PIXEL:
|
||||
* @d: pointer to the destination buffer
|
||||
* @r: red component
|
||||
* @g: green component
|
||||
* @b: blue component
|
||||
*
|
||||
* Sets a single pixel in an Cairo image surface in %CAIRO_FORMAT_RGB24.
|
||||
**/
|
||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||
#define GIMP_CAIRO_RGB24_SET_PIXEL(d, r, g, b) \
|
||||
G_STMT_START { d[0] = (b); d[1] = (g); d[2] = (r); } G_STMT_END
|
||||
#else
|
||||
#define GIMP_CAIRO_RGB24_SET_PIXEL(d, r, g, b) \
|
||||
G_STMT_START { d[1] = (r); d[2] = (g); d[3] = (b); } G_STMT_END
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* GIMP_CAIRO_ARGB32_SET_PIXEL:
|
||||
* @d: pointer to the destination buffer
|
||||
* @r: red component, not pre-multiplied
|
||||
* @g: green component, not pre-multiplied
|
||||
* @b: blue component, not pre-multiplied
|
||||
* @a: alpha component
|
||||
*
|
||||
* Sets a single pixel in an Cairo image surface in %CAIRO_FORMAT_ARGB32.
|
||||
**/
|
||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||
#define GIMP_CAIRO_ARGB32_SET_PIXEL(d, r, g, b, a) \
|
||||
G_STMT_START { \
|
||||
guint t1, t2, t3; \
|
||||
d[0] = INT_MULT ((b), (a), t1); \
|
||||
d[1] = INT_MULT ((g), (a), t2); \
|
||||
d[2] = INT_MULT ((r), (a), t3); \
|
||||
d[3] = (a); \
|
||||
} G_STMT_END
|
||||
#else
|
||||
#define GIMP_CAIRO_ARGB32_SET_PIXEL(d, r, g, b, a) \
|
||||
G_STMT_START { \
|
||||
guint t1, t2, t3; \
|
||||
d[0] = (a); \
|
||||
d[1] = INT_MULT ((r), (a), t1); \
|
||||
d[2] = INT_MULT ((g), (a), t2); \
|
||||
d[3] = INT_MULT ((b), (a), t3); \
|
||||
} G_STMT_END
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* __GIMP_CAIRO_UTILS_H__ */
|
||||
|
|
|
@ -995,15 +995,7 @@ gimp_view_render_to_surface (TempBuf *temp_buf,
|
|||
/* Handle the leading transparency */
|
||||
for (j = 0; j < x1; j++, d += 4, cb += 3)
|
||||
{
|
||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||
d[0] = cb[2];
|
||||
d[1] = cb[1];
|
||||
d[2] = cb[0];
|
||||
#else
|
||||
d[1] = cb[0];
|
||||
d[2] = cb[1];
|
||||
d[3] = cb[2];
|
||||
#endif
|
||||
GIMP_CAIRO_RGB24_SET_PIXEL (d, cb[0], cb[1], cb[2]);
|
||||
}
|
||||
|
||||
/* The stuff in the middle */
|
||||
|
@ -1017,68 +1009,40 @@ gimp_view_render_to_surface (TempBuf *temp_buf,
|
|||
{
|
||||
if ((j + offset) & 0x4)
|
||||
{
|
||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||
d[0] = gimp_render_blend_dark_check [(a | s[blue_component])];
|
||||
d[1] = gimp_render_blend_dark_check [(a | s[green_component])];
|
||||
d[2] = gimp_render_blend_dark_check [(a | s[red_component])];
|
||||
#else
|
||||
d[1] = gimp_render_blend_dark_check [(a | s[red_component])];
|
||||
d[2] = gimp_render_blend_dark_check [(a | s[green_component])];
|
||||
d[3] = gimp_render_blend_dark_check [(a | s[blue_component])];
|
||||
#endif
|
||||
GIMP_CAIRO_RGB24_SET_PIXEL (d,
|
||||
gimp_render_blend_dark_check [a | s[red_component]],
|
||||
gimp_render_blend_dark_check [a | s[green_component]],
|
||||
gimp_render_blend_dark_check [a | s[blue_component]]);
|
||||
}
|
||||
else
|
||||
{
|
||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||
d[0] = gimp_render_blend_light_check [(a | s[blue_component])];
|
||||
d[1] = gimp_render_blend_light_check [(a | s[green_component])];
|
||||
d[2] = gimp_render_blend_light_check [(a | s[red_component])];
|
||||
#else
|
||||
d[1] = gimp_render_blend_light_check [(a | s[red_component])];
|
||||
d[2] = gimp_render_blend_light_check [(a | s[green_component])];
|
||||
d[3] = gimp_render_blend_light_check [(a | s[blue_component])];
|
||||
#endif
|
||||
GIMP_CAIRO_RGB24_SET_PIXEL (d,
|
||||
gimp_render_blend_light_check [a | s[red_component]],
|
||||
gimp_render_blend_light_check [a | s[green_component]],
|
||||
gimp_render_blend_light_check [a | s[blue_component]]);
|
||||
}
|
||||
}
|
||||
else /* GIMP_VIEW_BG_WHITE */
|
||||
{
|
||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||
d[0] = gimp_render_blend_white [(a | s[blue_component])];
|
||||
d[1] = gimp_render_blend_white [(a | s[green_component])];
|
||||
d[2] = gimp_render_blend_white [(a | s[red_component])];
|
||||
#else
|
||||
d[1] = gimp_render_blend_white [(a | s[red_component])];
|
||||
d[2] = gimp_render_blend_white [(a | s[green_component])];
|
||||
d[3] = gimp_render_blend_white [(a | s[blue_component])];
|
||||
#endif
|
||||
GIMP_CAIRO_RGB24_SET_PIXEL (d,
|
||||
gimp_render_blend_white [a | s[red_component]],
|
||||
gimp_render_blend_white [a | s[green_component]],
|
||||
gimp_render_blend_white [a | s[blue_component]]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||
d[0] = s[blue_component];
|
||||
d[1] = s[green_component];
|
||||
d[2] = s[red_component];
|
||||
#else
|
||||
d[1] = s[red_component];
|
||||
d[2] = s[green_component];
|
||||
d[3] = s[blue_component];
|
||||
#endif
|
||||
GIMP_CAIRO_RGB24_SET_PIXEL (d,
|
||||
s[red_component],
|
||||
s[green_component],
|
||||
s[blue_component]);
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle the trailing transparency */
|
||||
for (j = x2; j < dest_width; j++, d+= 4, cb += 3)
|
||||
{
|
||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||
d[0] = cb[2];
|
||||
d[1] = cb[1];
|
||||
d[2] = cb[0];
|
||||
#else
|
||||
d[1] = cb[0];
|
||||
d[2] = cb[1];
|
||||
d[3] = cb[2];
|
||||
#endif
|
||||
GIMP_CAIRO_RGB24_SET_PIXEL (d, cb[0], cb[1], cb[2]);
|
||||
}
|
||||
|
||||
src += rowstride;
|
||||
|
@ -1087,15 +1051,7 @@ gimp_view_render_to_surface (TempBuf *temp_buf,
|
|||
{
|
||||
for (j = 0; j < dest_width; j++, d+= 4, cb += 3)
|
||||
{
|
||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||
d[0] = cb[2];
|
||||
d[1] = cb[1];
|
||||
d[2] = cb[0];
|
||||
#else
|
||||
d[1] = cb[0];
|
||||
d[2] = cb[1];
|
||||
d[3] = cb[2];
|
||||
#endif
|
||||
GIMP_CAIRO_RGB24_SET_PIXEL (d, cb[0], cb[1], cb[2]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "core/gimpgradient.h"
|
||||
|
||||
#include "gimpcairo-utils.h"
|
||||
#include "gimprender.h"
|
||||
#include "gimpviewrenderergradient.h"
|
||||
|
||||
|
@ -227,47 +228,25 @@ gimp_view_renderer_gradient_render (GimpViewRenderer *renderer,
|
|||
|
||||
if (x & 0x4)
|
||||
{
|
||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||
even[0] = gimp_render_blend_dark_check[(a << 8) | b];
|
||||
even[1] = gimp_render_blend_dark_check[(a << 8) | g];
|
||||
even[2] = gimp_render_blend_dark_check[(a << 8) | r];
|
||||
#else
|
||||
even[1] = gimp_render_blend_dark_check[(a << 8) | r];
|
||||
even[2] = gimp_render_blend_dark_check[(a << 8) | g];
|
||||
even[3] = gimp_render_blend_dark_check[(a << 8) | b];
|
||||
#endif
|
||||
|
||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||
odd[0] = gimp_render_blend_light_check[(a << 8) | b];
|
||||
odd[1] = gimp_render_blend_light_check[(a << 8) | g];
|
||||
odd[2] = gimp_render_blend_light_check[(a << 8) | r];
|
||||
#else
|
||||
odd[1] = gimp_render_blend_light_check[(a << 8) | r];
|
||||
odd[2] = gimp_render_blend_light_check[(a << 8) | g];
|
||||
odd[3] = gimp_render_blend_light_check[(a << 8) | b];
|
||||
#endif
|
||||
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
|
||||
{
|
||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||
even[0] = gimp_render_blend_light_check[(a << 8) | b];
|
||||
even[1] = gimp_render_blend_light_check[(a << 8) | g];
|
||||
even[2] = gimp_render_blend_light_check[(a << 8) | r];
|
||||
#else
|
||||
even[1] = gimp_render_blend_light_check[(a << 8) | r];
|
||||
even[2] = gimp_render_blend_light_check[(a << 8) | g];
|
||||
even[3] = gimp_render_blend_light_check[(a << 8) | b];
|
||||
#endif
|
||||
|
||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||
odd[0] = gimp_render_blend_dark_check[(a << 8) | b];
|
||||
odd[1] = gimp_render_blend_dark_check[(a << 8) | g];
|
||||
odd[2] = gimp_render_blend_dark_check[(a << 8) | r];
|
||||
#else
|
||||
odd[1] = gimp_render_blend_dark_check[(a << 8) | r];
|
||||
odd[2] = gimp_render_blend_dark_check[(a << 8) | g];
|
||||
odd[3] = gimp_render_blend_dark_check[(a << 8) | b];
|
||||
#endif
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "core/gimppalette.h"
|
||||
|
||||
#include "gimpcairo-utils.h"
|
||||
#include "gimpviewrendererpalette.h"
|
||||
|
||||
|
||||
|
@ -178,27 +179,11 @@ gimp_view_renderer_palette_render (GimpViewRenderer *renderer,
|
|||
|
||||
if (renderpal->draw_grid && (x % renderpal->cell_width) == 0)
|
||||
{
|
||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||
d[0] = 0;
|
||||
d[1] = 0;
|
||||
d[2] = 0;
|
||||
#else
|
||||
d[1] = 0;
|
||||
d[2] = 0;
|
||||
d[3] = 0;
|
||||
#endif
|
||||
GIMP_CAIRO_RGB24_SET_PIXEL (d, 0, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||
d[0] = b;
|
||||
d[1] = g;
|
||||
d[2] = r;
|
||||
#else
|
||||
d[1] = r;
|
||||
d[2] = g;
|
||||
d[3] = b;
|
||||
#endif
|
||||
GIMP_CAIRO_RGB24_SET_PIXEL (d, r, g, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue