From ce4263f9012035ac7d836174cd3c640f19d56222 Mon Sep 17 00:00:00 2001 From: Federico Mena Date: Sat, 31 Jan 1998 00:09:58 +0000 Subject: [PATCH] red/green/blue parameters are now expected to be in [0, 65535], to be Fri Jan 30 08:51:16 1998 Federico Mena * gdk/gdkcc.c (gdk_color_context_get_pixel): red/green/blue parameters are now expected to be in [0, 65535], to be consistent with the rest of Gdk. (gdk_color_context_get_pixels): Made it use 16-bit color values as well. Fixed mdist=1000000 buglet (it should start with at least 0x1000000). (gdk_color_context_get_pixels_incremental): Same as gdk_color_context_get_pixels(). --- ChangeLog | 11 ++++++ ChangeLog.pre-2-0 | 11 ++++++ ChangeLog.pre-2-10 | 11 ++++++ ChangeLog.pre-2-2 | 11 ++++++ ChangeLog.pre-2-4 | 11 ++++++ ChangeLog.pre-2-6 | 11 ++++++ ChangeLog.pre-2-8 | 11 ++++++ gdk/gdkcc.c | 93 +++++++++++++++------------------------------ gdk/x11/gdkcc-x11.c | 93 +++++++++++++++------------------------------ 9 files changed, 137 insertions(+), 126 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6cb2f52b11..a5ea909e7e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Fri Jan 30 08:51:16 1998 Federico Mena + + * gdk/gdkcc.c (gdk_color_context_get_pixel): red/green/blue + parameters are now expected to be in [0, 65535], to be consistent + with the rest of Gdk. + (gdk_color_context_get_pixels): Made it use 16-bit color values as + well. Fixed mdist=1000000 buglet (it should start with at least + 0x1000000). + (gdk_color_context_get_pixels_incremental): Same as + gdk_color_context_get_pixels(). + Thu Jan 29 22:57:39 1998 Owen Taylor * gtk/gtkstyle.c (gtk_default_draw_polygon): Close diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 6cb2f52b11..a5ea909e7e 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,14 @@ +Fri Jan 30 08:51:16 1998 Federico Mena + + * gdk/gdkcc.c (gdk_color_context_get_pixel): red/green/blue + parameters are now expected to be in [0, 65535], to be consistent + with the rest of Gdk. + (gdk_color_context_get_pixels): Made it use 16-bit color values as + well. Fixed mdist=1000000 buglet (it should start with at least + 0x1000000). + (gdk_color_context_get_pixels_incremental): Same as + gdk_color_context_get_pixels(). + Thu Jan 29 22:57:39 1998 Owen Taylor * gtk/gtkstyle.c (gtk_default_draw_polygon): Close diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 6cb2f52b11..a5ea909e7e 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,14 @@ +Fri Jan 30 08:51:16 1998 Federico Mena + + * gdk/gdkcc.c (gdk_color_context_get_pixel): red/green/blue + parameters are now expected to be in [0, 65535], to be consistent + with the rest of Gdk. + (gdk_color_context_get_pixels): Made it use 16-bit color values as + well. Fixed mdist=1000000 buglet (it should start with at least + 0x1000000). + (gdk_color_context_get_pixels_incremental): Same as + gdk_color_context_get_pixels(). + Thu Jan 29 22:57:39 1998 Owen Taylor * gtk/gtkstyle.c (gtk_default_draw_polygon): Close diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 6cb2f52b11..a5ea909e7e 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,14 @@ +Fri Jan 30 08:51:16 1998 Federico Mena + + * gdk/gdkcc.c (gdk_color_context_get_pixel): red/green/blue + parameters are now expected to be in [0, 65535], to be consistent + with the rest of Gdk. + (gdk_color_context_get_pixels): Made it use 16-bit color values as + well. Fixed mdist=1000000 buglet (it should start with at least + 0x1000000). + (gdk_color_context_get_pixels_incremental): Same as + gdk_color_context_get_pixels(). + Thu Jan 29 22:57:39 1998 Owen Taylor * gtk/gtkstyle.c (gtk_default_draw_polygon): Close diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 6cb2f52b11..a5ea909e7e 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,14 @@ +Fri Jan 30 08:51:16 1998 Federico Mena + + * gdk/gdkcc.c (gdk_color_context_get_pixel): red/green/blue + parameters are now expected to be in [0, 65535], to be consistent + with the rest of Gdk. + (gdk_color_context_get_pixels): Made it use 16-bit color values as + well. Fixed mdist=1000000 buglet (it should start with at least + 0x1000000). + (gdk_color_context_get_pixels_incremental): Same as + gdk_color_context_get_pixels(). + Thu Jan 29 22:57:39 1998 Owen Taylor * gtk/gtkstyle.c (gtk_default_draw_polygon): Close diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 6cb2f52b11..a5ea909e7e 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,14 @@ +Fri Jan 30 08:51:16 1998 Federico Mena + + * gdk/gdkcc.c (gdk_color_context_get_pixel): red/green/blue + parameters are now expected to be in [0, 65535], to be consistent + with the rest of Gdk. + (gdk_color_context_get_pixels): Made it use 16-bit color values as + well. Fixed mdist=1000000 buglet (it should start with at least + 0x1000000). + (gdk_color_context_get_pixels_incremental): Same as + gdk_color_context_get_pixels(). + Thu Jan 29 22:57:39 1998 Owen Taylor * gtk/gtkstyle.c (gtk_default_draw_polygon): Close diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 6cb2f52b11..a5ea909e7e 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,14 @@ +Fri Jan 30 08:51:16 1998 Federico Mena + + * gdk/gdkcc.c (gdk_color_context_get_pixel): red/green/blue + parameters are now expected to be in [0, 65535], to be consistent + with the rest of Gdk. + (gdk_color_context_get_pixels): Made it use 16-bit color values as + well. Fixed mdist=1000000 buglet (it should start with at least + 0x1000000). + (gdk_color_context_get_pixels_incremental): Same as + gdk_color_context_get_pixels(). + Thu Jan 29 22:57:39 1998 Owen Taylor * gtk/gtkstyle.c (gtk_default_draw_polygon): Close diff --git a/gdk/gdkcc.c b/gdk/gdkcc.c index 4598a18554..d105db5f5f 100644 --- a/gdk/gdkcc.c +++ b/gdk/gdkcc.c @@ -52,11 +52,6 @@ * cwikla@wri.com */ -/* NOTES: - * - * - When a CC is destroyed, remember to destroy the hash table properly. - */ - #include #include @@ -710,13 +705,9 @@ gdk_color_context_get_pixel (GdkColorContext *cc, { gdouble value; - red <<= 8; - green <<= 8; - blue <<= 8; - - value = red / 65535.0 * 0.30 - + green / 65535.0 * 0.59 - + blue / 65535.0 * 0.11; + value = (red / 65535.0 * 0.30 + + green / 65535.0 * 0.59 + + blue / 65535.0 * 0.11); if (value > 0.5) return cc->white_pixel; @@ -728,28 +719,21 @@ gdk_color_context_get_pixel (GdkColorContext *cc, { gulong ired, igreen, iblue; - red <<= 8; - green <<= 8; - blue <<= 8; - red = red * 0.30 + green * 0.59 + blue * 0.11; green = 0; blue = 0; - if ((ired = red * (ccp->std_cmap.red_max + 1) / 0xffff) - > ccp->std_cmap.red_max) + if ((ired = red * (ccp->std_cmap.red_max + 1) / 0xffff) > ccp->std_cmap.red_max) ired = ccp->std_cmap.red_max; ired *= ccp->std_cmap.red_mult; - if ((igreen = green * (ccp->std_cmap.green_max + 1) / 0xffff) - > ccp->std_cmap.green_max) + if ((igreen = green * (ccp->std_cmap.green_max + 1) / 0xffff) > ccp->std_cmap.green_max) igreen = ccp->std_cmap.green_max; igreen *= ccp->std_cmap.green_mult; - if ((iblue = blue * (ccp->std_cmap.blue_max + 1) / 0xffff) - > ccp->std_cmap.blue_max) + if ((iblue = blue * (ccp->std_cmap.blue_max + 1) / 0xffff) > ccp->std_cmap.blue_max) iblue = ccp->std_cmap.blue_max; iblue *= ccp->std_cmap.blue_mult; @@ -764,10 +748,6 @@ gdk_color_context_get_pixel (GdkColorContext *cc, { gulong ired, igreen, iblue; - red <<= 8; - green <<= 8; - blue <<= 8; - if (cc->clut == NULL) { red >>= 16 - cc->bits.red; @@ -797,10 +777,6 @@ gdk_color_context_get_pixel (GdkColorContext *cc, GdkColor color; GdkColor *result; - red <<= 8; - green <<= 8; - blue <<= 8; - color.red = red; color.green = green; color.blue = blue; @@ -976,15 +952,6 @@ gdk_color_context_get_pixels (GdkColorContext *cc, my_x_query_colors (cc->colormap, cmap, cmapsize); - /* speedup: downscale here instead of in the matching code */ - - for (i = 0; i < cmapsize; i++) - { - cmap[i].red >>= 8; - cmap[i].green >>= 8; - cmap[i].blue >>= 8; - } - /* get a close match for any unallocated colors */ counter = nopen; @@ -998,7 +965,7 @@ gdk_color_context_get_pixels (GdkColorContext *cc, i = failed[idx]; - mdist = 1000000; + mdist = 0x1000000; close = -1; /* Store these vals. Small performance increase as this skips three @@ -1015,9 +982,11 @@ gdk_color_context_get_pixels (GdkColorContext *cc, for (j = 0; (j < cmapsize) && (mdist != 0); j++) { - rd = ri - cmap[j].red; - gd = gi - cmap[j].green; - bd = bi - cmap[j].blue; + /* Don't replace these by shifts; the sign may get clobbered */ + + rd = (ri - cmap[j].red) / 256; + gd = (gi - cmap[j].green) / 256; + bd = (bi - cmap[j].blue) / 256; d = rd * rd + gd * gd + bd * bd; @@ -1083,7 +1052,7 @@ gdk_color_context_get_pixels (GdkColorContext *cc, i = failed[idx]; - mdist = 1000000; + mdist = 0x1000000; close = -1; /* store */ @@ -1098,9 +1067,11 @@ gdk_color_context_get_pixels (GdkColorContext *cc, { k = allocated[j]; - rd = ri - defs[k].red; - gd = gi - defs[k].green; - bd = bi - defs[k].blue; + /* Don't replace these by shifts; the sign may get clobbered */ + + rd = (ri - defs[k].red) / 256; + gd = (gi - defs[k].green) / 256; + bd = (bi - defs[k].blue) / 256; d = rd * rd + gd * gd + bd * bd; @@ -1247,17 +1218,10 @@ gdk_color_context_get_pixels_incremental (GdkColorContext *cc, cmap[i].red = cmap[i].green = cmap[i].blue = 0; } - /* read and downscale */ + /* read */ my_x_query_colors (cc->colormap, cmap, cmapsize); - for (i = 0; i < cmapsize; i++) - { - cmap[i].red >>= 8; - cmap[i].green >>= 8; - cmap[i].blue >>= 8; - } - /* now match any unallocated colors */ counter = nopen; @@ -1271,7 +1235,7 @@ gdk_color_context_get_pixels_incremental (GdkColorContext *cc, i = failed[idx]; - mdist = 1000000; + mdist = 0x1000000; close = -1; /* store */ @@ -1282,9 +1246,11 @@ gdk_color_context_get_pixels_incremental (GdkColorContext *cc, for (j = 0; (j < cmapsize) && (mdist != 0); j++) { - rd = ri - cmap[j].red; - gd = gi - cmap[j].green; - bd = bi - cmap[j].blue; + /* Don't replace these by shifts; the sign may get clobbered */ + + rd = (ri - cmap[j].red) / 256; + gd = (gi - cmap[j].green) / 256; + bd = (bi - cmap[j].blue) / 256; d = rd * rd + gd * gd + bd * bd; @@ -1349,7 +1315,7 @@ gdk_color_context_get_pixels_incremental (GdkColorContext *cc, i = failed[idx]; - mdist = 1000000; + mdist = 0x1000000; close = -1; ri = reds[i]; @@ -1363,10 +1329,11 @@ gdk_color_context_get_pixels_incremental (GdkColorContext *cc, k = allocated[j]; /* downscale */ + /* Don't replace these by shifts; the sign may get clobbered */ - rd = ri - defs[k].red; - gd = gi - defs[k].green; - bd = bi - defs[k].blue; + rd = (ri - defs[k].red) / 256; + gd = (gi - defs[k].green) / 256; + bd = (bi - defs[k].blue) / 256; d = rd * rd + gd * gd + bd * bd; diff --git a/gdk/x11/gdkcc-x11.c b/gdk/x11/gdkcc-x11.c index 4598a18554..d105db5f5f 100644 --- a/gdk/x11/gdkcc-x11.c +++ b/gdk/x11/gdkcc-x11.c @@ -52,11 +52,6 @@ * cwikla@wri.com */ -/* NOTES: - * - * - When a CC is destroyed, remember to destroy the hash table properly. - */ - #include #include @@ -710,13 +705,9 @@ gdk_color_context_get_pixel (GdkColorContext *cc, { gdouble value; - red <<= 8; - green <<= 8; - blue <<= 8; - - value = red / 65535.0 * 0.30 - + green / 65535.0 * 0.59 - + blue / 65535.0 * 0.11; + value = (red / 65535.0 * 0.30 + + green / 65535.0 * 0.59 + + blue / 65535.0 * 0.11); if (value > 0.5) return cc->white_pixel; @@ -728,28 +719,21 @@ gdk_color_context_get_pixel (GdkColorContext *cc, { gulong ired, igreen, iblue; - red <<= 8; - green <<= 8; - blue <<= 8; - red = red * 0.30 + green * 0.59 + blue * 0.11; green = 0; blue = 0; - if ((ired = red * (ccp->std_cmap.red_max + 1) / 0xffff) - > ccp->std_cmap.red_max) + if ((ired = red * (ccp->std_cmap.red_max + 1) / 0xffff) > ccp->std_cmap.red_max) ired = ccp->std_cmap.red_max; ired *= ccp->std_cmap.red_mult; - if ((igreen = green * (ccp->std_cmap.green_max + 1) / 0xffff) - > ccp->std_cmap.green_max) + if ((igreen = green * (ccp->std_cmap.green_max + 1) / 0xffff) > ccp->std_cmap.green_max) igreen = ccp->std_cmap.green_max; igreen *= ccp->std_cmap.green_mult; - if ((iblue = blue * (ccp->std_cmap.blue_max + 1) / 0xffff) - > ccp->std_cmap.blue_max) + if ((iblue = blue * (ccp->std_cmap.blue_max + 1) / 0xffff) > ccp->std_cmap.blue_max) iblue = ccp->std_cmap.blue_max; iblue *= ccp->std_cmap.blue_mult; @@ -764,10 +748,6 @@ gdk_color_context_get_pixel (GdkColorContext *cc, { gulong ired, igreen, iblue; - red <<= 8; - green <<= 8; - blue <<= 8; - if (cc->clut == NULL) { red >>= 16 - cc->bits.red; @@ -797,10 +777,6 @@ gdk_color_context_get_pixel (GdkColorContext *cc, GdkColor color; GdkColor *result; - red <<= 8; - green <<= 8; - blue <<= 8; - color.red = red; color.green = green; color.blue = blue; @@ -976,15 +952,6 @@ gdk_color_context_get_pixels (GdkColorContext *cc, my_x_query_colors (cc->colormap, cmap, cmapsize); - /* speedup: downscale here instead of in the matching code */ - - for (i = 0; i < cmapsize; i++) - { - cmap[i].red >>= 8; - cmap[i].green >>= 8; - cmap[i].blue >>= 8; - } - /* get a close match for any unallocated colors */ counter = nopen; @@ -998,7 +965,7 @@ gdk_color_context_get_pixels (GdkColorContext *cc, i = failed[idx]; - mdist = 1000000; + mdist = 0x1000000; close = -1; /* Store these vals. Small performance increase as this skips three @@ -1015,9 +982,11 @@ gdk_color_context_get_pixels (GdkColorContext *cc, for (j = 0; (j < cmapsize) && (mdist != 0); j++) { - rd = ri - cmap[j].red; - gd = gi - cmap[j].green; - bd = bi - cmap[j].blue; + /* Don't replace these by shifts; the sign may get clobbered */ + + rd = (ri - cmap[j].red) / 256; + gd = (gi - cmap[j].green) / 256; + bd = (bi - cmap[j].blue) / 256; d = rd * rd + gd * gd + bd * bd; @@ -1083,7 +1052,7 @@ gdk_color_context_get_pixels (GdkColorContext *cc, i = failed[idx]; - mdist = 1000000; + mdist = 0x1000000; close = -1; /* store */ @@ -1098,9 +1067,11 @@ gdk_color_context_get_pixels (GdkColorContext *cc, { k = allocated[j]; - rd = ri - defs[k].red; - gd = gi - defs[k].green; - bd = bi - defs[k].blue; + /* Don't replace these by shifts; the sign may get clobbered */ + + rd = (ri - defs[k].red) / 256; + gd = (gi - defs[k].green) / 256; + bd = (bi - defs[k].blue) / 256; d = rd * rd + gd * gd + bd * bd; @@ -1247,17 +1218,10 @@ gdk_color_context_get_pixels_incremental (GdkColorContext *cc, cmap[i].red = cmap[i].green = cmap[i].blue = 0; } - /* read and downscale */ + /* read */ my_x_query_colors (cc->colormap, cmap, cmapsize); - for (i = 0; i < cmapsize; i++) - { - cmap[i].red >>= 8; - cmap[i].green >>= 8; - cmap[i].blue >>= 8; - } - /* now match any unallocated colors */ counter = nopen; @@ -1271,7 +1235,7 @@ gdk_color_context_get_pixels_incremental (GdkColorContext *cc, i = failed[idx]; - mdist = 1000000; + mdist = 0x1000000; close = -1; /* store */ @@ -1282,9 +1246,11 @@ gdk_color_context_get_pixels_incremental (GdkColorContext *cc, for (j = 0; (j < cmapsize) && (mdist != 0); j++) { - rd = ri - cmap[j].red; - gd = gi - cmap[j].green; - bd = bi - cmap[j].blue; + /* Don't replace these by shifts; the sign may get clobbered */ + + rd = (ri - cmap[j].red) / 256; + gd = (gi - cmap[j].green) / 256; + bd = (bi - cmap[j].blue) / 256; d = rd * rd + gd * gd + bd * bd; @@ -1349,7 +1315,7 @@ gdk_color_context_get_pixels_incremental (GdkColorContext *cc, i = failed[idx]; - mdist = 1000000; + mdist = 0x1000000; close = -1; ri = reds[i]; @@ -1363,10 +1329,11 @@ gdk_color_context_get_pixels_incremental (GdkColorContext *cc, k = allocated[j]; /* downscale */ + /* Don't replace these by shifts; the sign may get clobbered */ - rd = ri - defs[k].red; - gd = gi - defs[k].green; - bd = bi - defs[k].blue; + rd = (ri - defs[k].red) / 256; + gd = (gi - defs[k].green) / 256; + bd = (bi - defs[k].blue) / 256; d = rd * rd + gd * gd + bd * bd;