*/
/* For more information on GdkRgb, see http://www.levien.com/gdkrgb/
-
+
Raph Levien <raph@acm.org>
- */
+*/
#include <math.h>
#include <stdio.h>
{
GdkVisual *visual;
GdkColormap *cmap;
-
+
gulong *color_pixels;
gulong *gray_pixels;
gulong *reserved_pixels;
-
+
guint nred_shades;
guint ngreen_shades;
guint nblue_shades;
guint ngray_shades;
guint nreserved;
-
+
guint bpp;
gint cmap_alloced;
gdouble gamma;
-
+
/* Generally, the stage buffer is used to convert 32bit RGB, gray,
and indexed images into 24 bit packed RGB. */
guchar *stage_buf;
-
+
GdkRgbCmap *gray_cmap;
-
+
gboolean dith_default;
-
+
/* Convert functions */
GdkRgbConvFunc conv;
GdkRgbConvFunc conv_d;
-
+
GdkRgbConvFunc conv_32;
GdkRgbConvFunc conv_32_d;
-
+
GdkRgbConvFunc conv_gray;
GdkRgbConvFunc conv_gray_d;
-
+
GdkRgbConvFunc conv_indexed;
GdkRgbConvFunc conv_indexed_d;
};
gulong free_pixels[256];
gint n_free;
gint i;
-
+
#ifdef VERBOSE
- g_print ("%s", msg);
+ g_message ("%s", msg);
#endif
n_free = 0;
for (i = 0; i < 256; i++)
{
guchar rt[16], gt[16], bt[16];
gint i;
-
+
colorcube = g_new (guchar, 4096);
for (i = 0; i < 16; i++)
{
gt[i] = nb * ((i * 17 * (ng - 1) + 128) >> 8);
bt[i] = ((i * 17 * (nb - 1) + 128) >> 8);
}
-
+
for (i = 0; i < 4096; i++)
{
colorcube[i] = pixels[rt[i >> 8] + gt[(i >> 4) & 0x0f] + bt[i & 0x0f]];
#ifdef VERBOSE
- g_print ("%03x %02x %x %x %x\n", i, colorcube[i], rt[i >> 8], gt[(i >> 4) & 0x0f], bt[i & 0x0f]);
+ g_message ("%03x %02x %x %x %x", i, colorcube[i], rt[i >> 8], gt[(i >> 4) & 0x0f], bt[i & 0x0f]);
#endif
}
}
{
gint r, g, b;
gint i;
-
+
colorcube_d = g_new (guchar, 512);
for (i = 0; i < 512; i++)
{
gint colors_needed;
gint idx;
gint best[256];
-
+
if (nr * ng * nb < gdk_rgb_min_colors)
return FALSE;
-
+
if (image_info->cmap_alloced)
cmap = image_info->cmap;
else
cmap = gdk_colormap_get_system ();
-
+
colors_needed = nr * ng * nb;
for (i = 0; i < 256; i++)
{
best[i] = 192;
pixels[i] = 256;
}
-
+
#ifndef GAMMA
if (!gdk_rgb_install_cmap)
- /* find color cube colors that are already present */
- for (i = 0; i < MIN (256, cmap->size); i++)
- {
- r = cmap->colors[i].red >> 8;
- g = cmap->colors[i].green >> 8;
- b = cmap->colors[i].blue >> 8;
- ri = (r * (nr - 1) + 128) >> 8;
- gi = (g * (ng - 1) + 128) >> 8;
- bi = (b * (nb - 1) + 128) >> 8;
- r0 = ri * 255 / (nr - 1);
- g0 = gi * 255 / (ng - 1);
- b0 = bi * 255 / (nb - 1);
- idx = ((ri * nr) + gi) * nb + bi;
- d2 = (r - r0) * (r - r0) + (g - g0) * (g - g0) + (b - b0) * (b - b0);
- if (d2 < best[idx]) {
- if (pixels[idx] < 256)
- gdk_colors_free (cmap, pixels + idx, 1, 0);
- else
- colors_needed--;
- color = cmap->colors[i];
- if (!gdk_color_alloc (cmap, &color))
- return gdk_rgb_cmap_fail ("error allocating system color\n",
- cmap, pixels);
- pixels[idx] = color.pixel; /* which is almost certainly i */
- best[idx] = d2;
+ /* find color cube colors that are already present */
+ for (i = 0; i < MIN (256, cmap->size); i++)
+ {
+ r = cmap->colors[i].red >> 8;
+ g = cmap->colors[i].green >> 8;
+ b = cmap->colors[i].blue >> 8;
+ ri = (r * (nr - 1) + 128) >> 8;
+ gi = (g * (ng - 1) + 128) >> 8;
+ bi = (b * (nb - 1) + 128) >> 8;
+ r0 = ri * 255 / (nr - 1);
+ g0 = gi * 255 / (ng - 1);
+ b0 = bi * 255 / (nb - 1);
+ idx = ((ri * nr) + gi) * nb + bi;
+ d2 = (r - r0) * (r - r0) + (g - g0) * (g - g0) + (b - b0) * (b - b0);
+ if (d2 < best[idx]) {
+ if (pixels[idx] < 256)
+ gdk_colors_free (cmap, pixels + idx, 1, 0);
+ else
+ colors_needed--;
+ color = cmap->colors[i];
+ if (!gdk_color_alloc (cmap, &color))
+ return gdk_rgb_cmap_fail ("error allocating system color",
+ cmap, pixels);
+ pixels[idx] = color.pixel; /* which is almost certainly i */
+ best[idx] = d2;
+ }
}
- }
#endif
-
+
if (colors_needed)
{
if (!gdk_colors_alloc (cmap, 0, NULL, 0, junk, colors_needed))
char tmp_str[80];
sprintf (tmp_str,
- "%d %d %d colormap failed (in gdk_colors_alloc)\n",
+ "%d %d %d colormap failed (in gdk_colors_alloc)",
nr, ng, nb);
return gdk_rgb_cmap_fail (tmp_str, cmap, pixels);
}
-
+
gdk_colors_free (cmap, junk, colors_needed, 0);
}
-
+
for (r = 0, i = 0; r < nr; r++)
for (g = 0; g < ng; g++)
for (b = 0; b < nb; b++, i++)
color.red = r * 65535 / (nr - 1);
color.green = g * 65535 / (ng - 1);
color.blue = b * 65535 / (nb - 1);
-
+
#ifdef GAMMA
color.red = 65535 * pow (color.red / 65535.0, 0.5);
color.green = 65535 * pow (color.green / 65535.0, 0.5);
color.blue = 65535 * pow (color.blue / 65535.0, 0.5);
#endif
-
+
if (!gdk_color_alloc (cmap, &color))
{
char tmp_str[80];
-
- sprintf (tmp_str, "%d %d %d colormap failed\n",
+
+ sprintf (tmp_str, "%d %d %d colormap failed",
nr, ng, nb);
return gdk_rgb_cmap_fail (tmp_str,
cmap, pixels);
pixels[i] = color.pixel;
}
#ifdef VERBOSE
- g_print ("%d: %lx\n", i, pixels[i]);
+ g_message ("%d: %lx", i, pixels[i]);
#endif
}
-
+
image_info->nred_shades = nr;
image_info->ngreen_shades = ng;
image_info->nblue_shades = nb;
gdk_rgb_do_colormaps (void)
{
const gint sizes[][3] = {
- /* { 6, 7, 6 }, */
+ /* { 6, 7, 6 }, */
{ 6, 6, 6 },
{ 6, 6, 5 },
{ 6, 6, 4 },
};
const gint n_sizes = sizeof(sizes) / (3 * sizeof(gint));
gint i;
-
+
for (i = 0; i < n_sizes; i++)
if (gdk_rgb_try_colormap (sizes[i][0], sizes[i][1], sizes[i][2]))
return TRUE;
}
/* Return a "score" based on the following criteria (in hex):
-
+
x000 is the quality - 1 is 1bpp, 2 is 4bpp,
- 4 is 8bpp,
- 7 is 15bpp truecolor, 8 is 16bpp truecolor,
- 9 is 24bpp truecolor.
+ 4 is 8bpp,
+ 7 is 15bpp truecolor, 8 is 16bpp truecolor,
+ 9 is 24bpp truecolor.
0x00 is the speed - 1 is the normal case,
- 2 means faster than normal
+ 2 means faster than normal
00x0 gets a point for being the system visual
000x gets a point for being pseudocolor
-
+
A caveat: in the 8bpp modes, being the system visual seems to be
quite important. Thus, all of the 8bpp modes should be ranked at
the same speed.
"true color",
"direct color",
};
-
-
+
+
quality = 0;
speed = 1;
sys = 0;
else if (visual->depth == 1)
quality = 1;
}
-
+
if (quality == 0)
return 0;
-
+
sys = (visual == gdk_visual_get_system ());
-
+
pseudo = (visual->type == GDK_VISUAL_PSEUDO_COLOR);
-
+
if (gdk_rgb_verbose)
- g_print ("Visual 0x%x, type = %s, depth = %d, %x:%x:%x%s; score=%x\n",
- (gint)(((GdkVisualPrivate *)visual)->xvisual->visualid),
- visual_names[visual->type],
- visual->depth,
- visual->red_mask,
- visual->green_mask,
- visual->blue_mask,
- sys ? " (system)" : "",
- (quality << 12) | (speed << 8) | (sys << 4) | pseudo);
-
+ g_message ("Visual 0x%x, type = %s, depth = %d, %x:%x:%x%s; score=%x",
+ (gint)(((GdkVisualPrivate *)visual)->xvisual->visualid),
+ visual_names[visual->type],
+ visual->depth,
+ visual->red_mask,
+ visual->green_mask,
+ visual->blue_mask,
+ sys ? " (system)" : "",
+ (quality << 12) | (speed << 8) | (sys << 4) | pseudo);
+
return (quality << 12) | (speed << 8) | (sys << 4) | pseudo;
}
GList *visuals;
guint32 score, best_score;
GdkVisual *visual, *best_visual;
-
+
visuals = gdk_list_visuals ();
-
+
best_visual = visuals->data;
best_score = gdk_rgb_score_visual (best_visual);
visuals = visuals->next;
}
visuals = visuals->next;
}
-
+
image_info->visual = best_visual;
}
gint status;
gulong pixels[256];
gint r, g, b, gray;
-
+
for (i = 0; i < 256; i++)
{
color.pixel = i;
status = gdk_color_alloc (cmap, &color);
pixels[i] = color.pixel;
#ifdef VERBOSE
- g_print ("allocating pixel %d, %x %x %x, result %d\n",
- color.pixel, color.red, color.green, color.blue, status);
+ g_message ("allocating pixel %d, %x %x %x, result %d",
+ color.pixel, color.red, color.green, color.blue, status);
#endif
}
-
+
/* Now, we make fake colorcubes - we ultimately just use the pseudocolor
methods. */
-
+
colorcube = g_new (guchar, 4096);
-
+
for (i = 0; i < 4096; i++)
{
r = (i >> 4) & 0xf0;
{
gint i;
gint byte_order[1] = { 1 };
-
+
/* check endian sanity */
#ifdef WORDS_BIGENDIAN
if (((char *)byte_order)[0] == 1)
if (((char *)byte_order)[0] != 1)
g_error ("gdk_rgb_init: WORDS_BIGENDIAN is not defined, but this is a little endian machine.\n\n");
#endif
-
+
if (image_info == NULL)
{
image_info = g_new0 (GdkRgbInfo, 1);
-
+
image_info->visual = NULL;
image_info->cmap = NULL;
-
+
image_info->color_pixels = NULL;
image_info->gray_pixels = NULL;
image_info->reserved_pixels = NULL;
-
+
image_info->nred_shades = 6;
image_info->ngreen_shades = 6;
image_info->nblue_shades = 4;
image_info->ngray_shades = 24;
image_info->nreserved = 0;
-
+
image_info->bpp = 0;
image_info->cmap_alloced = FALSE;
image_info->gamma = 1.0;
-
+
image_info->stage_buf = NULL;
-
+
gdk_rgb_choose_visual ();
-
+
if (image_info->visual->type == GDK_VISUAL_PSEUDO_COLOR)
{
if (gdk_rgb_install_cmap ||
gdk_rgb_do_colormaps ();
}
if (gdk_rgb_verbose)
- g_print ("color cube: %d x %d x %d\n",
- image_info->nred_shades,
- image_info->ngreen_shades,
- image_info->nblue_shades);
-
+ g_message ("color cube: %d x %d x %d",
+ image_info->nred_shades,
+ image_info->ngreen_shades,
+ image_info->nblue_shades);
+
if (!image_info->cmap_alloced)
- image_info->cmap = gdk_colormap_get_system ();
+ image_info->cmap = gdk_colormap_get_system ();
}
#ifdef ENABLE_GRAYSCALE
else if (image_info->visual->type == GDK_VISUAL_GRAYSCALE)
image_info->cmap = gdk_colormap_new (image_info->visual, FALSE);
gdk_rgb_set_gray_cmap (image_info->cmap);
image_info->cmap_alloced = TRUE;
- }
+ }
#endif
else
{
image_info->cmap_alloced = TRUE;
}
}
-
+
for (i = 0; i < N_IMAGES; i++)
static_image[i] = gdk_image_new (GDK_IMAGE_FASTEST,
image_info->visual,
IMAGE_WIDTH, IMAGE_HEIGHT);
-
+
image_info->bpp = static_image[0]->bpp;
-
+
gdk_rgb_select_conv (static_image[0]);
-
+
}
}
gdk_rgb_xpixel_from_rgb (guint32 rgb)
{
gulong pixel;
-
+
if (image_info->visual->type == GDK_VISUAL_PSEUDO_COLOR)
pixel = colorcube[((rgb & 0xf00000) >> 12) |
((rgb & 0xf000) >> 8) |
((rgb & 0xf0) >> 4)];
- else
- {
+ else
+ {
#ifdef VERBOSE
- g_print ("shift, prec: r %d %d g %d %d b %d %d\n",
+ g_message ("shift, prec: r %d %d g %d %d b %d %d",
image_info->visual->red_shift,
image_info->visual->red_prec,
image_info->visual->green_shift,
image_info->visual->blue_shift,
image_info->visual->blue_prec);
#endif
-
- pixel = (((((rgb & 0xff0000) >> 16) >>
- (8 - image_info->visual->red_prec)) <<
- image_info->visual->red_shift) +
- ((((rgb & 0xff00) >> 8) >>
- (8 - image_info->visual->green_prec)) <<
- image_info->visual->green_shift) +
- (((rgb & 0xff) >>
- (8 - image_info->visual->blue_prec)) <<
- image_info->visual->blue_shift));
-
- ;
- }
-
+
+ pixel = (((((rgb & 0xff0000) >> 16) >>
+ (8 - image_info->visual->red_prec)) <<
+ image_info->visual->red_shift) +
+ ((((rgb & 0xff00) >> 8) >>
+ (8 - image_info->visual->green_prec)) <<
+ image_info->visual->green_shift) +
+ (((rgb & 0xff) >>
+ (8 - image_info->visual->blue_prec)) <<
+ image_info->visual->blue_shift));
+
+ ;
+ }
+
return pixel;
}
gdk_rgb_gc_set_foreground (GdkGC *gc, guint32 rgb)
{
GdkColor color;
-
+
color.pixel = gdk_rgb_xpixel_from_rgb (rgb);
gdk_gc_set_foreground (gc, &color);
}
gdk_rgb_gc_set_background (GdkGC *gc, guint32 rgb)
{
GdkColor color;
-
+
color.pixel = gdk_rgb_xpixel_from_rgb (rgb);
gdk_gc_set_background (gc, &color);
}
guchar *obuf, *obptr;
guchar *bptr, *bp2;
gint r, g, b;
-
+
bptr = buf;
bpl = image->bpl;
obuf = ((guchar *)image->mem) + y0 * bpl + x0;
guint32 r1b0g0r0;
guint32 g2r2b1g1;
guint32 b3g3r3b2;
-
+
r1b0g0r0 = ((guint32 *)bp2)[0];
g2r2b1g1 = ((guint32 *)bp2)[1];
b3g3r3b2 = ((guint32 *)bp2)[2];
guchar *obuf, *obptr;
guchar *bptr, *bp2;
gint r, g, b;
-
+
bptr = buf;
bpl = image->bpl;
obuf = ((guchar *)image->mem) + y0 * bpl + x0;
#define DM_HEIGHT 8
static guchar DM[8][8] =
{
- { 0, 32, 8, 40, 2, 34, 10, 42 },
+ { 0, 32, 8, 40, 2, 34, 10, 42 },
{ 48, 16, 56, 24, 50, 18, 58, 26 },
- { 12, 44, 4, 36, 14, 46, 6, 38 },
+ { 12, 44, 4, 36, 14, 46, 6, 38 },
{ 60, 28, 52, 20, 62, 30, 54, 22 },
- { 3, 35, 11, 43, 1, 33, 9, 41 },
+ { 3, 35, 11, 43, 1, 33, 9, 41 },
{ 51, 19, 59, 27, 49, 17, 57, 25 },
- { 15, 47, 7, 39, 13, 45, 5, 37 },
+ { 15, 47, 7, 39, 13, 45, 5, 37 },
{ 63, 31, 55, 23, 61, 29, 53, 21 }
};
#endif
{
int i;
guint32 dith;
-
+
if (DM_565 == NULL)
{
DM_565 = g_new (guint32, DM_WIDTH * DM_HEIGHT);
dith = DM[0][i] >> 3;
DM_565[i] = (dith << 20) | dith | (((7 - dith) >> 1) << 10);
#ifdef VERBOSE
- g_print ("%i %x %x\n", i, dith, DM_565[i]);
+ g_message ("%i %x %x", i, dith, DM_565[i]);
#endif
}
}
gint r, g, b;
guchar *dmp;
gint dith;
-
+
bptr = buf;
bpl = image->bpl;
obuf = ((guchar *)image->mem) + y0 * bpl + x0;
guchar *dmp;
gint dith;
gint rs, gs, bs;
-
+
bptr = buf;
bpl = image->bpl;
rs = image_info->nred_shades - 1;
guchar *bptr, *bp2;
guchar c;
guchar *lut;
-
+
lut = cmap->lut;
bptr = buf;
bpl = image->bpl;
guchar *obuf, *obptr;
guchar *bptr, *bp2;
gint r, g, b;
-
+
bptr = buf;
bpl = image->bpl;
obuf = ((guchar *)image->mem) + y0 * bpl + x0;
gint bpl;
guchar *obuf;
guchar *bptr;
-
+
bptr = buf;
bpl = image->bpl;
obuf = ((guchar *)image->mem) + y0 * bpl + x0;
This assumes native byte ordering - what should really be done is to
check whether static_image->byte_order is consistent with the _ENDIAN
config flag, and if not, use a different function.
-
+
This one is even faster than the one below - its inner loop loads 3
words (i.e. 4 24-bit pixels), does a lot of shifting and masking,
then writes 2 words. */
gint bpl;
guchar *bptr, *bp2;
guchar r, g, b;
-
+
bptr = buf;
bpl = image->bpl;
obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 2;
guint32 r1b0g0r0;
guint32 g2r2b1g1;
guint32 b3g3r3b2;
-
+
r1b0g0r0 = ((guint32 *)bp2)[0];
g2r2b1g1 = ((guint32 *)bp2)[1];
b3g3r3b2 = ((guint32 *)bp2)[2];
This assumes native byte ordering - what should really be done is to
check whether static_image->byte_order is consistent with the _ENDIAN
config flag, and if not, use a different function.
-
+
This routine is faster than the one included with Gtk 1.0 for a number
of reasons:
-
+
1. Shifting instead of lookup tables (less memory traffic).
-
+
2. Much less register pressure, especially because shifts are
in the code.
-
+
3. A memcpy is avoided (i.e. the transfer function).
-
+
4. On big-endian architectures, byte swapping is avoided.
-
+
That said, it wouldn't be hard to make it even faster - just make an
inner loop that reads 3 words (i.e. 4 24-bit pixels), does a lot of
shifting and masking, then writes 2 words.
gint bpl;
guchar *bptr, *bp2;
guchar r, g, b;
-
+
bptr = buf;
bpl = image->bpl;
obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 2;
gint bpl;
guchar *bptr, *bp2;
guchar g;
-
+
bptr = buf;
bpl = image->bpl;
obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 2;
for (x = 0; x < width - 3; x += 4)
{
guint32 g3g2g1g0;
-
+
g3g2g1g0 = ((guint32 *)bp2)[0];
((guint32 *)obptr)[0] =
((g3g2g1g0 & 0xf8) << 8) |
gint bpl;
guchar *bptr, *bp2;
guchar g;
-
+
bptr = buf;
bpl = image->bpl;
obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 2;
gint bpl;
guchar *bptr, *bp2;
guchar r, g, b;
-
+
bptr = buf;
bpl = image->bpl;
obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 2;
b = *bp2++;
/* final word is:
g4 g3 g2 b7 b6 b5 b4 b3 r7 r6 r5 r4 r3 g7 g6 g5
- */
+ */
((unsigned short *)obuf)[x] = (r & 0xf8) |
((g & 0xe0) >> 5) |
((g & 0x1c) << 11) |
#ifdef HAIRY_CONVERT_565
static void
gdk_rgb_convert_565_d (GdkImage *image,
- gint x0, gint y0, gint width, gint height,
- guchar *buf, int rowstride,
- gint x_align, gint y_align, GdkRgbCmap *cmap)
+ gint x0, gint y0, gint width, gint height,
+ guchar *buf, int rowstride,
+ gint x_align, gint y_align, GdkRgbCmap *cmap)
{
/* Now this is what I'd call some highly tuned code! */
int x, y;
guchar *obuf, *obptr;
gint bpl;
guchar *bptr, *bp2;
-
+
width += x_align;
height += y_align;
rgb += 0x10040100
- ((rgb & 0x1e0001e0) >> 5)
- ((rgb & 0x00070000) >> 6);
-
+
((unsigned short *)obuf)[0] =
((rgb & 0x0f800000) >> 12) |
((rgb & 0x0003f000) >> 7) |
guint32 g2r2b1g1;
guint32 b3g3r3b2;
guint32 rgb02, rgb13;
-
+
r1b0g0r0 = ((guint32 *)bp2)[0];
g2r2b1g1 = ((guint32 *)bp2)[1];
b3g3r3b2 = ((guint32 *)bp2)[2];
rgb += 0x10040100
- ((rgb & 0x1e0001e0) >> 5)
- ((rgb & 0x00070000) >> 6);
-
+
((unsigned short *)obuf)[0] =
((rgb & 0x0f800000) >> 12) |
((rgb & 0x0003f000) >> 7) |
#else
static void
gdk_rgb_convert_565_d (GdkImage *image,
- gint x0, gint y0, gint width, gint height,
- guchar *buf, int rowstride,
- gint x_align, gint y_align, GdkRgbCmap *cmap)
+ gint x0, gint y0, gint width, gint height,
+ guchar *buf, int rowstride,
+ gint x_align, gint y_align, GdkRgbCmap *cmap)
{
int x, y;
guchar *obuf;
gint bpl;
guchar *bptr;
-
+
width += x_align;
height += y_align;
bptr = buf;
bpl = image->bpl;
obuf = ((guchar *)image->mem) + y0 * bpl + (x0 - x_align) * 2;
-
+
for (y = y_align; y < height; y++)
{
guint32 *dmp = DM_565 + ((y & (DM_HEIGHT - 1)) << DM_WIDTH_SHIFT);
guchar *bp2 = bptr;
-
+
for (x = x_align; x < width; x++)
- {
- gint32 rgb = *bp2++ << 20;
- rgb += *bp2++ << 10;
- rgb += *bp2++;
+ {
+ gint32 rgb = *bp2++ << 20;
+ rgb += *bp2++ << 10;
+ rgb += *bp2++;
rgb += dmp[x & (DM_WIDTH - 1)];
- rgb += 0x10040100
- - ((rgb & 0x1e0001e0) >> 5)
- - ((rgb & 0x00070000) >> 6);
-
- ((unsigned short *)obuf)[x] =
- ((rgb & 0x0f800000) >> 12) |
- ((rgb & 0x0003f000) >> 7) |
- ((rgb & 0x000000f8) >> 3);
- }
-
+ rgb += 0x10040100
+ - ((rgb & 0x1e0001e0) >> 5)
+ - ((rgb & 0x00070000) >> 6);
+
+ ((unsigned short *)obuf)[x] =
+ ((rgb & 0x0f800000) >> 12) |
+ ((rgb & 0x0003f000) >> 7) |
+ ((rgb & 0x000000f8) >> 3);
+ }
+
bptr += rowstride;
obuf += bpl;
}
gint bpl;
guchar *bptr, *bp2;
guchar r, g, b;
-
+
bptr = buf;
bpl = image->bpl;
obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 2;
gint bpl;
guchar *bptr, *bp2;
guchar r, g, b;
-
+
bptr = buf;
bpl = image->bpl;
obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 2;
b = *bp2++;
/* final word is:
g5 g4 g3 b7 b6 b5 b4 b3 0 r7 r6 r5 r4 r3 g7 g6
- */
+ */
((unsigned short *)obuf)[x] = ((r & 0xf8) >> 1) |
((g & 0xc0) >> 6) |
((g & 0x18) << 10) |
guchar *obuf;
gint bpl;
guchar *bptr;
-
+
bptr = buf;
bpl = image->bpl;
obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 3;
gint bpl;
guchar *bptr, *bp2;
int r, g, b;
-
+
bptr = buf;
bpl = image->bpl;
obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 3;
guint32 r1b0g0r0;
guint32 g2r2b1g1;
guint32 b3g3r3b2;
-
+
r1b0g0r0 = ((guint32 *)bp2)[0];
g2r2b1g1 = ((guint32 *)bp2)[1];
b3g3r3b2 = ((guint32 *)bp2)[2];
gint bpl;
guchar *bptr, *bp2;
int r, g, b;
-
+
bptr = buf;
bpl = image->bpl;
obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 3;
gint bpl;
guchar *bptr, *bp2;
int r, g, b;
-
+
bptr = buf;
bpl = image->bpl;
obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 4;
gint bpl;
guchar *bptr, *bp2;
int r, g, b;
-
+
bptr = buf;
bpl = image->bpl;
obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 4;
gint bpp;
guint32 pixel;
gint i;
-
+
r_right = 8 - image_info->visual->red_prec;
r_left = image_info->visual->red_shift;
g_right = 8 - image_info->visual->green_prec;
gint dith;
gint r1, g1, b1;
guchar *dmp;
-
+
r_right = 8 - image_info->visual->red_prec;
r_left = image_info->visual->red_shift;
r_prec = image_info->visual->red_prec;
gint bpp;
guint32 pixel;
gint shift, shift_init;
-
+
r_right = 8 - image_info->visual->red_prec;
r_left = image_info->visual->red_shift;
g_right = 8 - image_info->visual->green_prec;
gint dith;
gint r1, g1, b1;
guchar *dmp;
-
+
r_right = 8 - image_info->visual->red_prec;
r_left = image_info->visual->red_shift;
r_prec = image_info->visual->red_prec;
gint x, y;
guchar *pi_start, *po_start;
guchar *pi, *po;
-
+
pi_start = buf;
po_start = gdk_rgb_ensure_stage ();
for (y = 0; y < height; y++)
gint x_align, gint y_align, GdkRgbCmap *cmap)
{
gdk_rgb_32_to_stage (buf, rowstride, width, height);
-
+
(*image_info->conv) (image, x0, y0, width, height,
image_info->stage_buf, STAGE_ROWSTRIDE,
x_align, y_align, cmap);
gint x_align, gint y_align, GdkRgbCmap *cmap)
{
gdk_rgb_32_to_stage (buf, rowstride, width, height);
-
+
(*image_info->conv_d) (image, x0, y0, width, height,
image_info->stage_buf, STAGE_ROWSTRIDE,
x_align, y_align, cmap);
guchar *pi_start, *po_start;
guchar *pi, *po;
guchar gray;
-
+
pi_start = buf;
po_start = gdk_rgb_ensure_stage ();
for (y = 0; y < height; y++)
gint x_align, gint y_align, GdkRgbCmap *cmap)
{
gdk_rgb_gray_to_stage (buf, rowstride, width, height);
-
+
(*image_info->conv) (image, x0, y0, width, height,
image_info->stage_buf, STAGE_ROWSTRIDE,
x_align, y_align, cmap);
gint x_align, gint y_align, GdkRgbCmap *cmap)
{
gdk_rgb_gray_to_stage (buf, rowstride, width, height);
-
+
(*image_info->conv_d) (image, x0, y0, width, height,
image_info->stage_buf, STAGE_ROWSTRIDE,
x_align, y_align, cmap);
#if 0
static void
gdk_rgb_convert_gray_cmap_d (GdkImage *image,
- gint x0, gint y0, gint width, gint height,
- guchar *buf, gint rowstride,
- gint x_align, gint y_align, GdkRgbCmap *cmap)
+ gint x0, gint y0, gint width, gint height,
+ guchar *buf, gint rowstride,
+ gint x_align, gint y_align, GdkRgbCmap *cmap)
{
(*image_info->conv_indexed_d) (image, x0, y0, width, height,
buf, rowstride,
guchar *pi_start, *po_start;
guchar *pi, *po;
gint rgb;
-
+
pi_start = buf;
po_start = gdk_rgb_ensure_stage ();
for (y = 0; y < height; y++)
gint x_align, gint y_align, GdkRgbCmap *cmap)
{
gdk_rgb_indexed_to_stage (buf, rowstride, width, height, cmap);
-
+
(*image_info->conv) (image, x0, y0, width, height,
image_info->stage_buf, STAGE_ROWSTRIDE,
x_align, y_align, cmap);
GdkRgbCmap *cmap)
{
gdk_rgb_indexed_to_stage (buf, rowstride, width, height, cmap);
-
+
(*image_info->conv_d) (image, x0, y0, width, height,
image_info->stage_buf, STAGE_ROWSTRIDE,
x_align, y_align, cmap);
GdkRgbConvFunc conv_32, conv_32_d;
GdkRgbConvFunc conv_gray, conv_gray_d;
GdkRgbConvFunc conv_indexed, conv_indexed_d;
-
+
depth = image_info->visual->depth;
bpp = image->bpp;
-
+
byte_order = image->byte_order;
-
+
#ifdef WORDS_BIGENDIAN
byterev = (byte_order == GDK_LSB_FIRST);
#else
byterev = (byte_order == GDK_MSB_FIRST);
#endif
-
+
vtype = image_info->visual->type;
if (vtype == GDK_VISUAL_DIRECT_COLOR)
vtype = GDK_VISUAL_TRUE_COLOR;
-
+
red_mask = image_info->visual->red_mask;
green_mask = image_info->visual->green_mask;
blue_mask = image_info->visual->blue_mask;
-
+
conv = NULL;
conv_d = NULL;
-
+
conv_32 = gdk_rgb_convert_32_generic;
conv_32_d = gdk_rgb_convert_32_generic_d;
-
+
conv_gray = gdk_rgb_convert_gray_generic;
conv_gray_d = gdk_rgb_convert_gray_generic_d;
-
+
conv_indexed = gdk_rgb_convert_indexed_generic;
conv_indexed_d = gdk_rgb_convert_indexed_generic_d;
-
+
image_info->dith_default = FALSE;
-
+
if (bpp == 2 && depth == 16 && !byterev &&
red_mask == 0xf800 && green_mask == 0x7e0 && blue_mask == 0x1f)
{
}
else if (bpp == 2 && depth == 16 &&
vtype == GDK_VISUAL_TRUE_COLOR && byterev &&
- red_mask == 0xf800 && green_mask == 0x7e0 && blue_mask == 0x1f)
+ red_mask == 0xf800 && green_mask == 0x7e0 && blue_mask == 0x1f)
conv = gdk_rgb_convert_565_br;
-
+
else if (bpp == 2 && depth == 15 &&
vtype == GDK_VISUAL_TRUE_COLOR && !byterev &&
- red_mask == 0x7c00 && green_mask == 0x3e0 && blue_mask == 0x1f)
+ red_mask == 0x7c00 && green_mask == 0x3e0 && blue_mask == 0x1f)
conv = gdk_rgb_convert_555;
-
+
else if (bpp == 2 && depth == 15 &&
vtype == GDK_VISUAL_TRUE_COLOR && byterev &&
- red_mask == 0x7c00 && green_mask == 0x3e0 && blue_mask == 0x1f)
+ red_mask == 0x7c00 && green_mask == 0x3e0 && blue_mask == 0x1f)
conv = gdk_rgb_convert_555_br;
-
+
/* I'm not 100% sure about the 24bpp tests */
else if (bpp == 3 && depth == 24 &&
vtype == GDK_VISUAL_TRUE_COLOR && byte_order == GDK_LSB_FIRST &&
vtype == GDK_VISUAL_TRUE_COLOR && byterev &&
red_mask == 0xff0000 && green_mask == 0xff00 && blue_mask == 0xff)
conv = gdk_rgb_convert_0888_br;
-
+
else if (vtype == GDK_VISUAL_TRUE_COLOR && byte_order == GDK_LSB_FIRST)
{
conv = gdk_rgb_convert_truecolor_lsb;
conv = gdk_rgb_convert_gray8;
conv_gray = gdk_rgb_convert_gray8_gray;
}
-
+
if (conv_d == NULL)
conv_d = conv;
-
+
image_info->conv = conv;
image_info->conv_d = conv_d;
-
+
image_info->conv_32 = conv_32;
image_info->conv_32_d = conv_32_d;
-
+
image_info->conv_gray = conv_gray;
image_info->conv_gray_d = conv_gray_d;
-
+
image_info->conv_indexed = conv_indexed;
image_info->conv_indexed_d = conv_indexed_d;
}
gdk_flush ();
#endif
#ifdef VERBOSE
- g_print ("flush, %d puts since last flush\n", sincelast);
+ g_message ("flush, %d puts since last flush", sincelast);
sincelast = 0;
#endif
static_image_idx = 0;
{
GdkImage *image;
gint idx;
-
-
+
+
if (width >= (IMAGE_WIDTH >> 1))
{
if (height >= (IMAGE_HEIGHT >> 1))
}
image = static_image[idx];
#ifdef VERBOSE
- g_print ("index %d, x %d, y %d (%d x %d)\n", idx, *x0, *y0, width, height);
+ g_message ("index %d, x %d, y %d (%d x %d)", idx, *x0, *y0, width, height);
sincelast++;
#endif
return image;
GdkImage *image;
gint width1, height1;
guchar *buf_ptr;
-
+
for (y0 = 0; y0 < height; y0 += IMAGE_HEIGHT)
{
height1 = MIN (height - y0, IMAGE_HEIGHT);
{
width1 = MIN (width - x0, IMAGE_WIDTH);
buf_ptr = buf + y0 * rowstride + x0 * pixstride;
-
+
image = gdk_rgb_alloc_scratch (width1, height1, &xs0, &ys0);
-
+
conv (image, xs0, ys0, width1, height1, buf_ptr, rowstride,
x + x0, y + y0, cmap);
-
+
#ifndef DONT_ACTUALLY_DRAW
gdk_draw_image (drawable, gc,
image, xs0, ys0, x + x0, y + y0, width1, height1);
{
guint32 rgb[256];
gint i;
-
+
for (i = 0; i < 256; i++)
- rgb[i] = (i << 16) | (i << 8) | i;
+ rgb[i] = (i << 16) | (i << 8) | i;
info->gray_cmap = gdk_rgb_cmap_new (rgb, 256);
}
GdkRgbCmap *cmap;
int i, j;
guint32 rgb;
-
+
g_return_val_if_fail (n_colors >= 0, NULL);
g_return_val_if_fail (n_colors <= 256, NULL);
cmap = g_new (GdkRgbCmap, 1);
{
rgb = colors[i];
j = ((rgb & 0xf00000) >> 12) |
- ((rgb & 0xf000) >> 8) |
- ((rgb & 0xf0) >> 4);
+ ((rgb & 0xf000) >> 8) |
+ ((rgb & 0xf0) >> 4);
#ifdef VERBOSE
- g_print ("%d %x %x %d\n", i, j, colorcube[j]);
+ g_message ("%d %x %x %d", i, j, colorcube[j]);
#endif
cmap->lut[i] = colorcube[j];
}
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* guaranteed with the way we do things, since if we are doing INCR
* transfers, the order will depend on the timing of the requestor.
*
- * By Owen Taylor <owt1@cornell.edu> 8/16/97
+ * By Owen Taylor <owt1@cornell.edu> 8/16/97
*/
/* Terminology note: when not otherwise specified, the term "incr" below
struct _GtkIncrConversion
{
- GdkAtom target; /* Requested target */
- GdkAtom property; /* Property to store in */
+ GdkAtom target; /* Requested target */
+ GdkAtom property; /* Property to store in */
GtkSelectionData data; /* The data being supplied */
- gint offset; /* Current offset in sent selection.
+ gint offset; /* Current offset in sent selection.
* -1 => All done
* -2 => Only the final (empty) portion
- * left to send */
+ * left to send */
};
struct _GtkIncrInfo
guint32 idle_time; /* Number of seconds since we last heard
from selection owner */
guchar *buffer; /* Buffer in which to accumulate results */
- gint offset; /* Current offset in buffer, -1 indicates
+ gint offset; /* Current offset in buffer, -1 indicates
not yet started */
};
GdkAtom selection; /* selection thats handled */
GdkAtom target; /* target thats handled */
GtkSelectionFunction function; /* callback function */
- GtkCallbackMarshal marshal; /* Marshalling function */
+ GtkCallbackMarshal marshal; /* Marshalling function */
gpointer data; /* callback data */
- GtkDestroyNotify destroy; /* called when callback is removed */
+ GtkDestroyNotify destroy; /* called when callback is removed */
};
/* Local Functions */
-static void gtk_selection_init (void);
-static gint gtk_selection_incr_timeout (GtkIncrInfo *info);
-static gint gtk_selection_retrieval_timeout (GtkRetrievalInfo *info);
-static void gtk_selection_retrieval_report (GtkRetrievalInfo *info,
+static void gtk_selection_init (void);
+static gint gtk_selection_incr_timeout (GtkIncrInfo *info);
+static gint gtk_selection_retrieval_timeout (GtkRetrievalInfo *info);
+static void gtk_selection_retrieval_report (GtkRetrievalInfo *info,
GdkAtom type, gint format,
guchar *buffer, gint length);
-static void gtk_selection_invoke_handler (GtkWidget *widget,
+static void gtk_selection_invoke_handler (GtkWidget *widget,
GtkSelectionData *data);
-static void gtk_selection_default_handler (GtkWidget *widget,
+static void gtk_selection_default_handler (GtkWidget *widget,
GtkSelectionData *data);
/* Local Data */
* Add a handler for a specified selection/target pair
*
* arguments:
- * widget: The widget the handler applies to
+ * widget: The widget the handler applies to
* selection:
* target:
- * format: Format in which this handler will return data
+ * format: Format in which this handler will return data
* function: Callback function (can be NULL)
- * marshal: Callback marshal function
- * data: User data for callback
- * destroy: Called when handler removed
+ * marshal: Callback marshal function
+ * data: User data for callback
+ * destroy: Called when handler removed
*
* results:
*************************************************************/
void
-gtk_selection_add_handler (GtkWidget *widget,
- GdkAtom selection,
- GdkAtom target,
+gtk_selection_add_handler (GtkWidget *widget,
+ GdkAtom selection,
+ GdkAtom target,
GtkSelectionFunction function,
- gpointer data)
+ gpointer data)
{
gtk_selection_add_handler_full (widget, selection, target, function,
NULL, data, NULL);
}
void
-gtk_selection_add_handler_full (GtkWidget *widget,
- GdkAtom selection,
- GdkAtom target,
+gtk_selection_add_handler_full (GtkWidget *widget,
+ GdkAtom selection,
+ GdkAtom target,
GtkSelectionFunction function,
GtkCallbackMarshal marshal,
- gpointer data,
+ gpointer data,
GtkDestroyNotify destroy)
{
GList *selection_handlers;
* a "selection_received" signal will be generated.
*
* arguments:
- * widget: The widget which acts as requestor
+ * widget: The widget which acts as requestor
* selection: Which selection to get
- * target: Form of information desired (e.g., STRING)
- * time: Time of request (usually of triggering event)
- * In emergency, you could use GDK_CURRENT_TIME
+ * target: Form of information desired (e.g., STRING)
+ * time: Time of request (usually of triggering event)
+ * In emergency, you could use GDK_CURRENT_TIME
*
* results:
* TRUE if requested succeeded. FALSE if we could not process
gint
gtk_selection_convert (GtkWidget *widget,
- GdkAtom selection,
- GdkAtom target,
- guint32 time)
+ GdkAtom selection,
+ GdkAtom target,
+ guint32 time)
{
GtkRetrievalInfo *info;
GList *tmp_list;
* Null terminates the stored data.
* arguments:
* type: the type of selection data
- * format: format (number of bits in a unit)
- * data: pointer to the data (will be copied)
- * length: length of the data
+ * format: format (number of bits in a unit)
+ * data: pointer to the data (will be copied)
+ * length: length of the data
* results:
*************************************************************/
void
gtk_selection_data_set (GtkSelectionData *selection_data,
- GdkAtom type,
- gint format,
- guchar *data,
- gint length)
+ GdkAtom type,
+ gint format,
+ guchar *data,
+ gint length)
{
if (selection_data->data)
g_free (selection_data->data);
if (!gdk_property_get (info->requestor, event->property, GDK_SELECTION_TYPE_ATOM,
0, GTK_SELECTION_MAX_SIZE, FALSE,
&type, &format, &length, &mult_atoms) ||
- type != GDK_SELECTION_TYPE_ATOM || format != 8*sizeof(GdkAtom))
+ type != GDK_SELECTION_TYPE_ATOM || format != 8*sizeof(GdkAtom))
{
gdk_selection_send_notify (event->requestor, event->selection,
event->target, GDK_NONE, event->time);
data.length = -1;
#ifdef DEBUG_SELECTION
- g_message("Selection %ld, target %ld (%s) requested by 0x%x (property = %ld)\n",
- event->selection, info->conversions[i].target,
- gdk_atom_name(info->conversions[i].target),
- event->requestor, event->property);
+ g_message ("Selection %ld, target %ld (%s) requested by 0x%x (property = %ld)",
+ event->selection, info->conversions[i].target,
+ gdk_atom_name(info->conversions[i].target),
+ event->requestor, event->property);
#endif
gtk_selection_invoke_handler (widget, &data);
exist */
#ifdef DEBUG_SELECTION
- g_message("Starting INCR...\n");
+ g_message ("Starting INCR...");
#endif
gdk_window_set_events (info->requestor,
* more data.
*
* arguments:
- * window: the requestor window
- * event: the property event structure
+ * window: the requestor window
+ * event: the property event structure
*
* results:
*************************************************************/
gint
-gtk_selection_incr_event (GdkWindow *window,
+gtk_selection_incr_event (GdkWindow *window,
GdkEventProperty *event)
{
GList *tmp_list;
return FALSE;
#ifdef DEBUG_SELECTION
- g_message("PropertyDelete, property %ld\n", event->atom);
+ g_message ("PropertyDelete, property %ld", event->atom);
#endif
/* Now find the appropriate ongoing INCR */
info->conversions[i].offset = -2;
}
#ifdef DEBUG_SELECTION
- g_message("INCR: put %d bytes (offset = %d) into window 0x%lx , property %ld\n",
- num_bytes, info->conversions[i].offset,
- GDK_WINDOW_XWINDOW(info->requestor), event->atom);
+ g_message ("INCR: put %d bytes (offset = %d) into window 0x%lx , property %ld",
+ num_bytes, info->conversions[i].offset,
+ GDK_WINDOW_XWINDOW(info->requestor), event->atom);
#endif
gdk_property_change (info->requestor, event->atom,
info->conversions[i].data.type,
* Timeout callback for the sending portion of the INCR
* protocol
* arguments:
- * info: Information about this incr
+ * info: Information about this incr
* results:
*************************************************************/
* where a retrieval is currently in process. The selection
* owner has responded to our conversion request.
* arguments:
- * widget: Widget getting signal
- * event: Selection event structure
- * info: Information about this retrieval
+ * widget: Widget getting signal
+ * event: Selection event structure
+ * info: Information about this retrieval
* results:
* was event handled?
*************************************************************/
gint
-gtk_selection_notify (GtkWidget *widget,
+gtk_selection_notify (GtkWidget *widget,
GdkEventSelection *event)
{
GList *tmp_list;
guchar *buffer;
gint length;
GdkAtom type;
- gint format;
+ gint format;
#ifdef DEBUG_SELECTION
- g_message("Initial receipt of selection %ld, target %ld (property = %ld)\n",
- event->selection, event->target, event->property);
+ g_message ("Initial receipt of selection %ld, target %ld (property = %ld)",
+ event->selection, event->target, event->property);
#endif
tmp_list = current_retrievals;
* where a retrieval is currently in process. The selection
* owner has added more data.
* arguments:
- * widget: Widget getting signal
- * event: Property event structure
- * info: Information about this retrieval
+ * widget: Widget getting signal
+ * event: Property event structure
+ * info: Information about this retrieval
* results:
* was event handled?
*************************************************************/
gint
-gtk_selection_property_notify (GtkWidget *widget,
+gtk_selection_property_notify (GtkWidget *widget,
GdkEventProperty *event)
{
GList *tmp_list;
guchar *new_buffer;
int length;
GdkAtom type;
- gint format;
+ gint format;
if ((event->state != GDK_PROPERTY_NEW_VALUE) || /* property was deleted */
(event->atom != gdk_selection_property)) /* not the right property */
return FALSE;
#ifdef DEBUG_SELECTION
- g_message("PropertyNewValue, property %ld\n",
- event->atom);
+ g_message ("PropertyNewValue, property %ld",
+ event->atom);
#endif
tmp_list = current_retrievals;
if (!info->buffer)
{
#ifdef DEBUG_SELECTION
- g_message("Start - Adding %d bytes at offset 0\n",
- length);
+ g_message ("Start - Adding %d bytes at offset 0",
+ length);
#endif
info->buffer = new_buffer;
info->offset = length;
{
#ifdef DEBUG_SELECTION
- g_message("Appending %d bytes at offset %d\n",
- length,info->offset);
+ g_message ("Appending %d bytes at offset %d",
+ length,info->offset);
#endif
/* We copy length+1 bytes to preserve guaranteed null termination */
info->buffer = g_realloc (info->buffer, info->offset+length+1);
* gtk_selection_retrieval_report:
* Emits a "selection_received" signal.
* arguments:
- * info: information about the retrieval that completed
- * buffer: buffer containing data (NULL => errror)
+ * info: information about the retrieval that completed
+ * buffer: buffer containing data (NULL => errror)
* results:
*************************************************************/
* gtk_selection_default_handler if none exists.
*
* arguments:
- * widget: selection owner
- * data: selection data [INOUT]
+ * widget: selection owner
+ * data: selection data [INOUT]
*
* results:
* Number of bytes written to buffer, -1 if error
*************************************************************/
static void
-gtk_selection_invoke_handler (GtkWidget *widget,
+gtk_selection_invoke_handler (GtkWidget *widget,
GtkSelectionData *data)
{
GList *tmp_list;
* require 1000 selection targets!
*
* arguments:
- * widget: selection owner
- * data: selection data [INOUT]
+ * widget: selection owner
+ * data: selection data [INOUT]
*
*************************************************************/
static void
-gtk_selection_default_handler (GtkWidget *widget,
+gtk_selection_default_handler (GtkWidget *widget,
GtkSelectionData *data)
{
if (data->target == gtk_selection_atoms[TIMESTAMP])