Switched the file to GNU indentation, for consistency.

Thu Jan 22 18:58:44 1998  Federico Mena  <federico@bananoid.nuclecu.unam.mx>

	* gdk/gdkcc.c: Switched the file to GNU indentation, for consistency.
This commit is contained in:
Federico Mena
1998-01-23 06:26:39 +00:00
committed by Arturo Espinosa
parent 01f66785cb
commit 3779493d17
9 changed files with 2614 additions and 2376 deletions

View File

@ -1,5 +1,7 @@
Thu Jan 22 18:58:44 1998 Federico Mena <federico@bananoid.nuclecu.unam.mx>
* gdk/gdkcc.c: Switched the file to GNU indentation, for consistency.
* gdk/gdktypes.h (struct _GdkColorContext): Picky, picky... fix
two lines with wrong indentation :-)

View File

@ -1,5 +1,7 @@
Thu Jan 22 18:58:44 1998 Federico Mena <federico@bananoid.nuclecu.unam.mx>
* gdk/gdkcc.c: Switched the file to GNU indentation, for consistency.
* gdk/gdktypes.h (struct _GdkColorContext): Picky, picky... fix
two lines with wrong indentation :-)

View File

@ -1,5 +1,7 @@
Thu Jan 22 18:58:44 1998 Federico Mena <federico@bananoid.nuclecu.unam.mx>
* gdk/gdkcc.c: Switched the file to GNU indentation, for consistency.
* gdk/gdktypes.h (struct _GdkColorContext): Picky, picky... fix
two lines with wrong indentation :-)

View File

@ -1,5 +1,7 @@
Thu Jan 22 18:58:44 1998 Federico Mena <federico@bananoid.nuclecu.unam.mx>
* gdk/gdkcc.c: Switched the file to GNU indentation, for consistency.
* gdk/gdktypes.h (struct _GdkColorContext): Picky, picky... fix
two lines with wrong indentation :-)

View File

@ -1,5 +1,7 @@
Thu Jan 22 18:58:44 1998 Federico Mena <federico@bananoid.nuclecu.unam.mx>
* gdk/gdkcc.c: Switched the file to GNU indentation, for consistency.
* gdk/gdktypes.h (struct _GdkColorContext): Picky, picky... fix
two lines with wrong indentation :-)

View File

@ -1,5 +1,7 @@
Thu Jan 22 18:58:44 1998 Federico Mena <federico@bananoid.nuclecu.unam.mx>
* gdk/gdkcc.c: Switched the file to GNU indentation, for consistency.
* gdk/gdktypes.h (struct _GdkColorContext): Picky, picky... fix
two lines with wrong indentation :-)

View File

@ -1,5 +1,7 @@
Thu Jan 22 18:58:44 1998 Federico Mena <federico@bananoid.nuclecu.unam.mx>
* gdk/gdkcc.c: Switched the file to GNU indentation, for consistency.
* gdk/gdktypes.h (struct _GdkColorContext): Picky, picky... fix
two lines with wrong indentation :-)

View File

@ -78,7 +78,8 @@ hash_color(gpointer key)
}
static gint
compare_colors(gpointer a, gpointer b)
compare_colors (gpointer a,
gpointer b)
{
GdkColor *aa = a;
GdkColor *bb = b;
@ -87,7 +88,9 @@ compare_colors(gpointer a, gpointer b)
}
static void
free_hash_entry(gpointer key, gpointer value, gpointer user_data)
free_hash_entry (gpointer key,
gpointer value,
gpointer user_data)
{
g_free (key); /* key and value are the same GdkColor */
}
@ -116,7 +119,8 @@ my_x_query_colors(GdkColormap *colormap,
XQueryColors (gdk_display, GDK_COLORMAP_XCOLORMAP (colormap), xcolors, ncolors);
for (i = 0; i < ncolors; i++) {
for (i = 0; i < ncolors; i++)
{
colors[i].red = xcolors[i].red;
colors[i].green = xcolors[i].green;
colors[i].blue = xcolors[i].blue;
@ -150,12 +154,14 @@ init_bw(GdkColorContext *cc)
cc->mode = GDK_CC_MODE_BW;
color.red = color.green = color.blue = 0;
if (!gdk_color_alloc (cc->colormap, &color))
cc->black_pixel = 0;
else
cc->black_pixel = color.pixel;
color.red = color.green = color.blue = 0xffff;
if (!gdk_color_alloc (cc->colormap, &color))
cc->white_pixel = cc->black_pixel ? 0 : 1;
else
@ -183,17 +189,20 @@ retrygray:
clrs = cstart;
for (i = 0; i < cc->num_colors; i++) {
for (i = 0; i < cc->num_colors; i++)
{
clrs->red = clrs->green = clrs->blue = dinc * i;
if (!gdk_color_alloc(cc->colormap, clrs)) {
if (!gdk_color_alloc (cc->colormap, clrs))
{
gdk_colors_free (cc->colormap, cc->clut, i, 0);
cc->num_colors /= 2;
if (cc->num_colors > 1)
goto retrygray;
else {
else
{
g_free (cc->clut);
cc->clut = NULL;
init_bw (cc);
@ -279,12 +288,14 @@ init_true_color(GdkColorContext *cc)
cc->shifts.red = 0;
cc->bits.red = 0;
while (!(rmask & 1)) {
while (!(rmask & 1))
{
rmask >>= 1;
cc->shifts.red++;
}
while (rmask & 1) {
while (rmask & 1)
{
rmask >>= 1;
cc->bits.red++;
}
@ -296,12 +307,14 @@ init_true_color(GdkColorContext *cc)
cc->shifts.green = 0;
cc->bits.green = 0;
while (!(gmask & 1)) {
while (!(gmask & 1))
{
gmask >>= 1;
cc->shifts.green++;
}
while (gmask & 1) {
while (gmask & 1)
{
gmask >>= 1;
cc->bits.green++;
}
@ -313,12 +326,14 @@ init_true_color(GdkColorContext *cc)
cc->shifts.blue = 0;
cc->bits.blue = 0;
while (!(bmask & 1)) {
while (!(bmask & 1))
{
bmask >>= 1;
cc->shifts.blue++;
}
while (bmask & 1) {
while (bmask & 1)
{
bmask >>= 1;
cc->bits.blue++;
}
@ -373,17 +388,21 @@ retrydirect:
clrs = cstart;
cc->num_colors = (rval + 1) * (gval + 1) * (bval + 1);
for (n = 0; n < cc->max_entry; n++) {
for (n = 0; n < cc->max_entry; n++)
{
dinc = (double) n / cc->max_entry;
clrs->red = rtable[(int) (dinc * rval)];
clrs->green = gtable[(int) (dinc * gval)];
clrs->blue = btable[(int) (dinc * bval)];
if (gdk_color_alloc(cc->colormap, clrs)) {
if (gdk_color_alloc (cc->colormap, clrs))
{
cc->clut[count++] = clrs->pixel;
clrs++;
} else {
}
else
{
gdk_colors_free (cc->colormap, cc->clut, count, 0);
rval >>= 1;
@ -406,7 +425,8 @@ retrydirect:
if (cc->num_colors >1)
goto retrydirect;
else {
else
{
g_free (cc->clut);
cc->clut = NULL;
init_bw (cc);
@ -432,7 +452,8 @@ init_palette(GdkColorContext *cc)
{
/* restore correct mode for this cc */
switch (cc->visual->type) {
switch (cc->visual->type)
{
case GDK_VISUAL_STATIC_GRAY:
case GDK_VISUAL_GRAYSCALE:
if (GDK_VISUAL_XVISUAL (cc->visual)->map_entries == 2)
@ -466,7 +487,8 @@ init_palette(GdkColorContext *cc)
/* clear hash table if present */
if (cc->color_hash) {
if (cc->color_hash)
{
/* XXX: quick-and-dirty way to remove everything */
g_hash_table_destroy (cc->color_hash);
@ -510,7 +532,8 @@ gdk_color_context_new(GdkVisual *visual,
retry_count = 0;
while (retry_count < 2) {
while (retry_count < 2)
{
/* Only create a private colormap if the visual found isn't equal
* to the default visual and we don't have a private colormap,
* -or- if we are instructed to create a private colormap (which
@ -519,7 +542,8 @@ gdk_color_context_new(GdkVisual *visual,
if (use_private_colormap
|| ((cc->visual != gdk_visual_get_system ()) /* default visual? */
&& (GDK_COLORMAP_XCOLORMAP(colormap) == GDK_COLORMAP_XCOLORMAP(default_colormap)))) {
&& (GDK_COLORMAP_XCOLORMAP (colormap) == GDK_COLORMAP_XCOLORMAP (default_colormap))))
{
g_warning ("gdk_color_context_new: non-default visual detected, "
"using private colormap");
@ -529,7 +553,8 @@ gdk_color_context_new(GdkVisual *visual,
!= GDK_COLORMAP_XCOLORMAP (default_colormap));
}
switch (visual->type) {
switch (visual->type)
{
case GDK_VISUAL_STATIC_GRAY:
case GDK_VISUAL_GRAYSCALE:
if (gdk_debug_level >= 1)
@ -576,10 +601,12 @@ gdk_color_context_new(GdkVisual *visual,
g_assert_not_reached ();
}
if ((cc->mode == GDK_CC_MODE_BW) && (cc->visual->depth > 1)) {
if ((cc->mode == GDK_CC_MODE_BW) && (cc->visual->depth > 1))
{
use_private_colormap = TRUE;
retry_count++;
} else
}
else
break;
}
@ -632,10 +659,13 @@ gdk_color_context_free(GdkColorContext *cc)
g_assert (cc != NULL);
if ((cc->visual->type == GDK_VISUAL_STATIC_COLOR)
|| (cc->visual->type == GDK_VISUAL_PSEUDO_COLOR)) {
|| (cc->visual->type == GDK_VISUAL_PSEUDO_COLOR))
{
gdk_colors_free (cc->colormap, cc->clut, cc->num_allocated, 0);
g_free (cc->clut);
} else if (cc->clut != NULL) {
}
else if (cc->clut != NULL)
{
gdk_colors_free (cc->colormap, cc->clut, cc->num_colors, 0);
g_free (cc->clut);
}
@ -650,7 +680,8 @@ gdk_color_context_free(GdkColorContext *cc)
init_palette (cc);
if (cc->color_hash) {
if (cc->color_hash)
{
g_hash_table_foreach (cc->color_hash,
free_hash_entry,
NULL);
@ -673,8 +704,10 @@ gdk_color_context_get_pixel(GdkColorContext *cc,
*failed = FALSE;
switch (cc->mode) {
case GDK_CC_MODE_BW: {
switch (cc->mode)
{
case GDK_CC_MODE_BW:
{
gdouble value;
red <<= 8;
@ -691,7 +724,8 @@ gdk_color_context_get_pixel(GdkColorContext *cc,
return cc->black_pixel;
}
case GDK_CC_MODE_MY_GRAY: {
case GDK_CC_MODE_MY_GRAY:
{
gulong ired, igreen, iblue;
red <<= 8;
@ -726,14 +760,16 @@ gdk_color_context_get_pixel(GdkColorContext *cc,
return ccp->std_cmap.base_pixel + ired + igreen + iblue;
}
case GDK_CC_MODE_TRUE: {
case GDK_CC_MODE_TRUE:
{
gulong ired, igreen, iblue;
red <<= 8;
green <<= 8;
blue <<= 8;
if (cc->clut == NULL) {
if (cc->clut == NULL)
{
red >>= 16 - cc->bits.red;
green >>= 16 - cc->bits.green;
blue >>= 16 - cc->bits.blue;
@ -756,7 +792,8 @@ gdk_color_context_get_pixel(GdkColorContext *cc,
return gdk_color_context_get_pixel_from_palette (cc, &red, &green, &blue, failed);
case GDK_CC_MODE_STD_CMAP:
default: {
default:
{
GdkColor color;
GdkColor *result;
@ -770,7 +807,8 @@ gdk_color_context_get_pixel(GdkColorContext *cc,
result = g_hash_table_lookup (cc->color_hash, &color);
if (!result) {
if (!result)
{
color.red = red;
color.green = green;
color.blue = blue;
@ -778,7 +816,8 @@ gdk_color_context_get_pixel(GdkColorContext *cc,
if (!gdk_color_alloc (cc->colormap, &color))
*failed = TRUE;
else {
else
{
GdkColor *cnew;
/* XXX: the following comment comes directly from
@ -794,7 +833,8 @@ gdk_color_context_get_pixel(GdkColorContext *cc,
* might be necessary for us to resize the CLUT.
*/
if (cc->num_allocated == cc->max_colors) {
if (cc->num_allocated == cc->max_colors)
{
cc->max_colors *= 2;
if (gdk_debug_level >= 1)
@ -858,13 +898,15 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
/* First allocate all pixels */
for (i = 0; i < ncolors; i++) {
for (i = 0; i < ncolors; i++)
{
/* colors[i] is only zero if the pixel at that location hasn't
* been allocated yet. This is a sanity check required for proper
* color allocation by the progressive image loader
*/
if (colors[i] == 0) {
if (colors[i] == 0)
{
defs[i].red = reds[i];
defs[i].green = greens[i];
defs[i].blue = blues[i];
@ -874,10 +916,12 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
/* successfully allocated, store it */
if (!bad_alloc) {
if (!bad_alloc)
{
defs[i].pixel = colors[i];
allocated[ncols++] = colors[i];
} else
}
else
failed[nopen++] = i;
}
}
@ -886,7 +930,8 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
/* all colors available, all done */
if ((ncols == ncolors) || (nopen == 0)) {
if ((ncols == ncolors) || (nopen == 0))
{
if (gdk_debug_level >= 1)
g_print ("gdk_color_context_get_pixels: got all %i colors; "
"(%i colors allocated so far", ncolors, cc->num_allocated);
@ -907,7 +952,8 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
/* see if the colormap has any colors to read */
if (cmapsize < 0) {
if (cmapsize < 0)
{
g_warning ("gdk_color_context_get_pixels: oops! no colors available, "
"your images will look *really* ugly.");
@ -920,7 +966,8 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
/* initialize pixels */
for (i = 0; i < cmapsize; i++) {
for (i = 0; i < cmapsize; i++)
{
cmap[i].pixel = i;
cmap[i].red = cmap[i].green = cmap[i].blue = 0;
}
@ -931,7 +978,8 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
/* speedup: downscale here instead of in the matching code */
for (i = 0; i < cmapsize; i++) {
for (i = 0; i < cmapsize; i++)
{
cmap[i].red >>= 8;
cmap[i].green >>= 8;
cmap[i].blue >>= 8;
@ -943,7 +991,8 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
nopen = 0;
idx = 0;
do {
do
{
gint d, j, mdist, close, ri, gi, bi;
gint rd, gd, bd;
@ -964,20 +1013,23 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
* closest. Uses plain least squares.
*/
for (j = 0; (j < cmapsize) && (mdist != 0); j++) {
for (j = 0; (j < cmapsize) && (mdist != 0); j++)
{
rd = ri - cmap[j].red;
gd = gi - cmap[j].green;
bd = bi - cmap[j].blue;
d = rd * rd + gd * gd + bd * bd;
if (d < mdist) {
if (d < mdist)
{
close = j;
mdist = d;
}
}
if (close != -1) {
if (close != -1)
{
rd = cmap[close].red;
gd = cmap[close].green;
bd = cmap[close].blue;
@ -988,7 +1040,8 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
/* store */
if (!bad_alloc) {
if (!bad_alloc)
{
defs[i] = cmap[close];
defs[i].pixel = colors[i];
allocated[ncols++] = colors[i];
@ -1000,7 +1053,8 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
} else
failed[nopen++] = i;
/* deal with in next stage if allocation failed */
} while (++idx < counter);
}
while (++idx < counter);
*nallocated = ncols;
@ -1008,7 +1062,8 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
* note above.
*/
if ((ncols == ncolors) || (nopen == 0)) {
if ((ncols == ncolors) || (nopen == 0))
{
if (gdk_debug_level >= 1)
g_print ("gdk_color_context_get_pixels: got %i colors, %i exact and "
"%i close (%i colors allocated so far)",
@ -1021,7 +1076,8 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
idx = 0;
do {
do
{
gint d, mdist, close, ri, gi, bi;
gint j, rd, gd, bd;
@ -1038,7 +1094,8 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
/* search allocated colors */
for (j = 0; (j < ncols) && (mdist != 0); j++) {
for (j = 0; (j < ncols) && (mdist != 0); j++)
{
k = allocated[j];
rd = ri - defs[k].red;
@ -1047,13 +1104,15 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
d = rd * rd + gd * gd + bd * bd;
if (d < mdist) {
if (d < mdist)
{
close = k;
mdist = d;
}
}
if (close < 0) {
if (close < 0)
{
/* too bad, map to black */
defs[i].pixel = cc->black_pixel;
@ -1061,7 +1120,9 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
#ifdef DEBUG
black_col++;
#endif
} else {
}
else
{
defs[i] = defs[close];
#ifdef DEBUG
subst_col++;
@ -1069,7 +1130,8 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
}
colors[i] = defs[i].pixel;
} while (++idx < nopen);
}
while (++idx < nopen);
if (gdk_debug_level >= 1)
g_print ("gdk_color_context_get_pixels: got %i colors, %i exact, %i close, "
@ -1114,7 +1176,8 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
/* First allocate all pixels */
for (i = 0; i < ncolors; i++) {
for (i = 0; i < ncolors; i++)
{
/* used[i] is only -1 if the pixel at that location hasn't
* been allocated yet. This is a sanity check required for proper
* color allocation by the progressive image loader.
@ -1122,8 +1185,10 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
* allocation.
*/
if (used[i] != FALSE) {
if (colors[i] == 0) {
if (used[i] != FALSE)
{
if (colors[i] == 0)
{
defs[i].red = reds[i];
defs[i].green = greens[i];
defs[i].blue = blues[i];
@ -1132,10 +1197,12 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
/* successfully allocated, store it */
if (!bad_alloc) {
if (!bad_alloc)
{
defs[i].pixel = colors[i];
allocated[ncols++] = colors[i];
} else
}
else
failed[nopen++] = i;
}
#ifdef DEBUG
@ -1149,7 +1216,8 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
*nallocated = ncols;
if ((ncols == ncolors) || (nopen == 0)) {
if ((ncols == ncolors) || (nopen == 0))
{
if (gdk_debug_level >= 1)
g_print ("gdk_color_context_get_pixels_incremental: got all %i colors "
"(%i colors allocated so far)",
@ -1160,7 +1228,8 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
cmapsize = MIN (cc->num_colors, MAX_IMAGE_COLORS);
if (cmapsize < 0) {
if (cmapsize < 0)
{
g_warning ("gdk_color_context_get_pixels_incremental: oops! "
"No colors available images will look *really* ugly.");
return;
@ -1172,7 +1241,8 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
/* initialize pixels */
for (i = 0; i < cmapsize; i++) {
for (i = 0; i < cmapsize; i++)
{
cmap[i].pixel = i;
cmap[i].red = cmap[i].green = cmap[i].blue = 0;
}
@ -1181,7 +1251,8 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
my_x_query_colors (cc->colormap, cmap, cmapsize);
for (i = 0; i < cmapsize; i++) {
for (i = 0; i < cmapsize; i++)
{
cmap[i].red >>= 8;
cmap[i].green >>= 8;
cmap[i].blue >>= 8;
@ -1193,7 +1264,8 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
nopen = 0;
idx = 0;
do {
do
{
gint d, j, mdist, close, ri, gi, bi;
gint rd, gd, bd;
@ -1208,20 +1280,23 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
gi = greens[i];
bi = blues[i];
for (j = 0; (j < cmapsize) && (mdist != 0); j++) {
for (j = 0; (j < cmapsize) && (mdist != 0); j++)
{
rd = ri - cmap[j].red;
gd = gi - cmap[j].green;
bd = bi - cmap[j].blue;
d = rd * rd + gd * gd + bd * bd;
if (d < mdist) {
if (d < mdist)
{
close = j;
mdist = d;
}
}
if (close != -1) {
if (close != -1)
{
rd = cmap[close].red;
gd = cmap[close].green;
bd = cmap[close].blue;
@ -1232,23 +1307,28 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
/* store */
if (!bad_alloc) {
if (!bad_alloc)
{
defs[i] = cmap[close];
defs[i].pixel = colors[i];
allocated[ncols++] = colors[i];
#ifdef DEBUG
close_col++;
#endif
} else
}
else
failed[nopen++] = i;
} else
}
else
failed[nopen++] = i;
/* deal with in next stage if allocation failed */
} while (++idx < counter);
}
while (++idx < counter);
*nallocated = ncols;
if ((ncols == ncolors) || (nopen == 0)) {
if ((ncols == ncolors) || (nopen == 0))
{
if (gdk_debug_level >= 1)
g_print ("gdk_color_context_get_pixels_incremental: "
"got %i colors, %i exact and %i close "
@ -1262,7 +1342,8 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
idx = 0;
do {
do
{
gint d, mdist, close, ri, gi, bi;
gint j, rd, gd, bd;
@ -1277,7 +1358,8 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
/* search allocated colors */
for (j = 0; (j < ncols) && (mdist != 0); j++) {
for (j = 0; (j < ncols) && (mdist != 0); j++)
{
k = allocated[j];
/* downscale */
@ -1288,13 +1370,15 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
d = rd * rd + gd * gd + bd * bd;
if (d < mdist) {
if (d < mdist)
{
close = k;
mdist = d;
}
}
if (close < 0) {
if (close < 0)
{
/* too bad, map to black */
defs[i].pixel = cc->black_pixel;
@ -1302,7 +1386,9 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
#ifdef DEBUG
black_col++;
#endif
} else {
}
else
{
defs[i] = defs[close];
#ifdef DEBUG
subst_col++;
@ -1310,7 +1396,8 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
}
colors[i] = defs[i].pixel;
} while (++idx < nopen);
}
while (++idx < nopen);
if (gdk_debug_level >= 1)
g_print ("gdk_color_context_get_pixels_incremental: "
@ -1337,9 +1424,11 @@ gdk_color_context_query_colors(GdkColorContext *cc,
g_assert (cc != NULL);
g_assert (colors != NULL);
switch (cc->mode) {
switch (cc->mode)
{
case GDK_CC_MODE_BW:
for (i = 0, tc = colors; i < num_colors; i++, tc++) {
for (i = 0, tc = colors; i < num_colors; i++, tc++)
{
if (tc->pixel == cc->white_pixel)
tc->red = tc->green = tc->blue = 65535;
else
@ -1349,12 +1438,14 @@ gdk_color_context_query_colors(GdkColorContext *cc,
case GDK_CC_MODE_TRUE:
if (cc->clut == NULL)
for (i = 0, tc = colors; i < num_colors; i++, tc++) {
for (i = 0, tc = colors; i < num_colors; i++, tc++)
{
tc->red = (tc->pixel & cc->masks.red) * 65535 / cc->masks.red;
tc->green = (tc->pixel & cc->masks.green) * 65535 / cc->masks.green;
tc->blue = (tc->pixel & cc->masks.blue) * 65535 / cc->masks.blue;
}
else {
else
{
my_x_query_colors (cc->colormap, colors, num_colors);
return 1;
}
@ -1362,27 +1453,35 @@ gdk_color_context_query_colors(GdkColorContext *cc,
case GDK_CC_MODE_STD_CMAP:
default:
if (cc->cmap == NULL) {
if (cc->cmap == NULL)
{
my_x_query_colors (cc->colormap, colors, num_colors);
return 1;
} else {
}
else
{
gint first, last, half;
gulong half_pixel;
for (i = 0, tc = colors; i < num_colors; i++) {
for (i = 0, tc = colors; i < num_colors; i++)
{
first = 0;
last = cc->num_colors - 1;
while (first <= last) {
while (first <= last)
{
half = (first + last) / 2;
half_pixel = cc->cmap[half].pixel;
if (tc->pixel == half_pixel) {
if (tc->pixel == half_pixel)
{
tc->red = cc->cmap[half].red;
tc->green = cc->cmap[half].green;
tc->blue = cc->cmap[half].blue;
first = last + 1; /* false break */
} else {
}
else
{
if (tc->pixel > half_pixel)
first = half + 1;
else
@ -1414,7 +1513,8 @@ gdk_color_context_add_palette(GdkColorContext *cc,
/* restore previous mode if we aren't adding a new palette */
if (num_palette == 0) {
if (num_palette == 0)
{
/* GDK_CC_MODE_STD_CMAP uses a hash table, so we'd better initialize one */
/* XXX: here, the hash table is already initialized */
@ -1435,7 +1535,8 @@ gdk_color_context_add_palette(GdkColorContext *cc,
j = 0;
for (i = 0; i < num_palette; i++) {
for (i = 0; i < num_palette; i++)
{
erg = 0;
pixel[0] = 0;
@ -1449,7 +1550,8 @@ gdk_color_context_add_palette(GdkColorContext *cc,
/* only store if we succeed */
if (erg) {
if (erg)
{
/* store in palette */
cc->palette[j].red = r;
@ -1470,7 +1572,8 @@ gdk_color_context_add_palette(GdkColorContext *cc,
/* clear the hash table, we don't use it when dithering */
if (cc->color_hash) {
if (cc->color_hash)
{
g_hash_table_destroy (cc->color_hash);
cc->color_hash = NULL;
}
@ -1510,7 +1613,8 @@ gdk_color_context_init_dither(GdkColorContext *cc)
for (rr = 0; rr < 32; rr++)
for (gg = 0; gg < 32; gg++)
for (bb = 0; bb < 32; bb++) {
for (bb = 0; bb < 32; bb++)
{
err = (rr << 3) | (rr >> 2);
erg = (gg << 3) | (gg >> 2);
erb = (bb << 3) | (bb >> 2);
@ -1555,14 +1659,16 @@ gdk_color_context_get_pixel_from_palette(GdkColorContext *cc,
*failed = FALSE;
for (i = 0; i < cc->num_palette; i++) {
for (i = 0; i < cc->num_palette; i++)
{
dr = *red - cc->palette[i].red;
dg = *green - cc->palette[i].green;
db = *blue - cc->palette[i].blue;
dif = dr * dr + dg * dg + db * db;
if (dif < mindif) {
if (dif < mindif)
{
mindif = dif;
j = i;
pixel = cc->palette[i].pixel;
@ -1579,7 +1685,8 @@ gdk_color_context_get_pixel_from_palette(GdkColorContext *cc,
if (j == -1)
*failed = TRUE;
else {
else
{
*red = ABS (err);
*green = ABS (erg);
*blue = ABS (erb);
@ -1608,14 +1715,16 @@ gdk_color_context_get_index_from_palette(GdkColorContext *cc,
*failed = FALSE;
for (i = 0; i < cc->num_palette; i++) {
for (i = 0; i < cc->num_palette; i++)
{
dr = *red - cc->palette[i].red;
dg = *green - cc->palette[i].green;
db = *blue - cc->palette[i].blue;
dif = dr * dr + dg * dg + db * db;
if (dif < mindif) {
if (dif < mindif)
{
mindif = dif;
j = i;
err = dr;
@ -1629,10 +1738,13 @@ gdk_color_context_get_index_from_palette(GdkColorContext *cc,
/* we failed to map onto a color */
if (j == -1) {
if (j == -1)
{
*failed = TRUE;
j = 0;
} else {
}
else
{
/* return error fractions */
*red = err;

View File

@ -78,7 +78,8 @@ hash_color(gpointer key)
}
static gint
compare_colors(gpointer a, gpointer b)
compare_colors (gpointer a,
gpointer b)
{
GdkColor *aa = a;
GdkColor *bb = b;
@ -87,7 +88,9 @@ compare_colors(gpointer a, gpointer b)
}
static void
free_hash_entry(gpointer key, gpointer value, gpointer user_data)
free_hash_entry (gpointer key,
gpointer value,
gpointer user_data)
{
g_free (key); /* key and value are the same GdkColor */
}
@ -116,7 +119,8 @@ my_x_query_colors(GdkColormap *colormap,
XQueryColors (gdk_display, GDK_COLORMAP_XCOLORMAP (colormap), xcolors, ncolors);
for (i = 0; i < ncolors; i++) {
for (i = 0; i < ncolors; i++)
{
colors[i].red = xcolors[i].red;
colors[i].green = xcolors[i].green;
colors[i].blue = xcolors[i].blue;
@ -150,12 +154,14 @@ init_bw(GdkColorContext *cc)
cc->mode = GDK_CC_MODE_BW;
color.red = color.green = color.blue = 0;
if (!gdk_color_alloc (cc->colormap, &color))
cc->black_pixel = 0;
else
cc->black_pixel = color.pixel;
color.red = color.green = color.blue = 0xffff;
if (!gdk_color_alloc (cc->colormap, &color))
cc->white_pixel = cc->black_pixel ? 0 : 1;
else
@ -183,17 +189,20 @@ retrygray:
clrs = cstart;
for (i = 0; i < cc->num_colors; i++) {
for (i = 0; i < cc->num_colors; i++)
{
clrs->red = clrs->green = clrs->blue = dinc * i;
if (!gdk_color_alloc(cc->colormap, clrs)) {
if (!gdk_color_alloc (cc->colormap, clrs))
{
gdk_colors_free (cc->colormap, cc->clut, i, 0);
cc->num_colors /= 2;
if (cc->num_colors > 1)
goto retrygray;
else {
else
{
g_free (cc->clut);
cc->clut = NULL;
init_bw (cc);
@ -279,12 +288,14 @@ init_true_color(GdkColorContext *cc)
cc->shifts.red = 0;
cc->bits.red = 0;
while (!(rmask & 1)) {
while (!(rmask & 1))
{
rmask >>= 1;
cc->shifts.red++;
}
while (rmask & 1) {
while (rmask & 1)
{
rmask >>= 1;
cc->bits.red++;
}
@ -296,12 +307,14 @@ init_true_color(GdkColorContext *cc)
cc->shifts.green = 0;
cc->bits.green = 0;
while (!(gmask & 1)) {
while (!(gmask & 1))
{
gmask >>= 1;
cc->shifts.green++;
}
while (gmask & 1) {
while (gmask & 1)
{
gmask >>= 1;
cc->bits.green++;
}
@ -313,12 +326,14 @@ init_true_color(GdkColorContext *cc)
cc->shifts.blue = 0;
cc->bits.blue = 0;
while (!(bmask & 1)) {
while (!(bmask & 1))
{
bmask >>= 1;
cc->shifts.blue++;
}
while (bmask & 1) {
while (bmask & 1)
{
bmask >>= 1;
cc->bits.blue++;
}
@ -373,17 +388,21 @@ retrydirect:
clrs = cstart;
cc->num_colors = (rval + 1) * (gval + 1) * (bval + 1);
for (n = 0; n < cc->max_entry; n++) {
for (n = 0; n < cc->max_entry; n++)
{
dinc = (double) n / cc->max_entry;
clrs->red = rtable[(int) (dinc * rval)];
clrs->green = gtable[(int) (dinc * gval)];
clrs->blue = btable[(int) (dinc * bval)];
if (gdk_color_alloc(cc->colormap, clrs)) {
if (gdk_color_alloc (cc->colormap, clrs))
{
cc->clut[count++] = clrs->pixel;
clrs++;
} else {
}
else
{
gdk_colors_free (cc->colormap, cc->clut, count, 0);
rval >>= 1;
@ -406,7 +425,8 @@ retrydirect:
if (cc->num_colors >1)
goto retrydirect;
else {
else
{
g_free (cc->clut);
cc->clut = NULL;
init_bw (cc);
@ -432,7 +452,8 @@ init_palette(GdkColorContext *cc)
{
/* restore correct mode for this cc */
switch (cc->visual->type) {
switch (cc->visual->type)
{
case GDK_VISUAL_STATIC_GRAY:
case GDK_VISUAL_GRAYSCALE:
if (GDK_VISUAL_XVISUAL (cc->visual)->map_entries == 2)
@ -466,7 +487,8 @@ init_palette(GdkColorContext *cc)
/* clear hash table if present */
if (cc->color_hash) {
if (cc->color_hash)
{
/* XXX: quick-and-dirty way to remove everything */
g_hash_table_destroy (cc->color_hash);
@ -510,7 +532,8 @@ gdk_color_context_new(GdkVisual *visual,
retry_count = 0;
while (retry_count < 2) {
while (retry_count < 2)
{
/* Only create a private colormap if the visual found isn't equal
* to the default visual and we don't have a private colormap,
* -or- if we are instructed to create a private colormap (which
@ -519,7 +542,8 @@ gdk_color_context_new(GdkVisual *visual,
if (use_private_colormap
|| ((cc->visual != gdk_visual_get_system ()) /* default visual? */
&& (GDK_COLORMAP_XCOLORMAP(colormap) == GDK_COLORMAP_XCOLORMAP(default_colormap)))) {
&& (GDK_COLORMAP_XCOLORMAP (colormap) == GDK_COLORMAP_XCOLORMAP (default_colormap))))
{
g_warning ("gdk_color_context_new: non-default visual detected, "
"using private colormap");
@ -529,7 +553,8 @@ gdk_color_context_new(GdkVisual *visual,
!= GDK_COLORMAP_XCOLORMAP (default_colormap));
}
switch (visual->type) {
switch (visual->type)
{
case GDK_VISUAL_STATIC_GRAY:
case GDK_VISUAL_GRAYSCALE:
if (gdk_debug_level >= 1)
@ -576,10 +601,12 @@ gdk_color_context_new(GdkVisual *visual,
g_assert_not_reached ();
}
if ((cc->mode == GDK_CC_MODE_BW) && (cc->visual->depth > 1)) {
if ((cc->mode == GDK_CC_MODE_BW) && (cc->visual->depth > 1))
{
use_private_colormap = TRUE;
retry_count++;
} else
}
else
break;
}
@ -632,10 +659,13 @@ gdk_color_context_free(GdkColorContext *cc)
g_assert (cc != NULL);
if ((cc->visual->type == GDK_VISUAL_STATIC_COLOR)
|| (cc->visual->type == GDK_VISUAL_PSEUDO_COLOR)) {
|| (cc->visual->type == GDK_VISUAL_PSEUDO_COLOR))
{
gdk_colors_free (cc->colormap, cc->clut, cc->num_allocated, 0);
g_free (cc->clut);
} else if (cc->clut != NULL) {
}
else if (cc->clut != NULL)
{
gdk_colors_free (cc->colormap, cc->clut, cc->num_colors, 0);
g_free (cc->clut);
}
@ -650,7 +680,8 @@ gdk_color_context_free(GdkColorContext *cc)
init_palette (cc);
if (cc->color_hash) {
if (cc->color_hash)
{
g_hash_table_foreach (cc->color_hash,
free_hash_entry,
NULL);
@ -673,8 +704,10 @@ gdk_color_context_get_pixel(GdkColorContext *cc,
*failed = FALSE;
switch (cc->mode) {
case GDK_CC_MODE_BW: {
switch (cc->mode)
{
case GDK_CC_MODE_BW:
{
gdouble value;
red <<= 8;
@ -691,7 +724,8 @@ gdk_color_context_get_pixel(GdkColorContext *cc,
return cc->black_pixel;
}
case GDK_CC_MODE_MY_GRAY: {
case GDK_CC_MODE_MY_GRAY:
{
gulong ired, igreen, iblue;
red <<= 8;
@ -726,14 +760,16 @@ gdk_color_context_get_pixel(GdkColorContext *cc,
return ccp->std_cmap.base_pixel + ired + igreen + iblue;
}
case GDK_CC_MODE_TRUE: {
case GDK_CC_MODE_TRUE:
{
gulong ired, igreen, iblue;
red <<= 8;
green <<= 8;
blue <<= 8;
if (cc->clut == NULL) {
if (cc->clut == NULL)
{
red >>= 16 - cc->bits.red;
green >>= 16 - cc->bits.green;
blue >>= 16 - cc->bits.blue;
@ -756,7 +792,8 @@ gdk_color_context_get_pixel(GdkColorContext *cc,
return gdk_color_context_get_pixel_from_palette (cc, &red, &green, &blue, failed);
case GDK_CC_MODE_STD_CMAP:
default: {
default:
{
GdkColor color;
GdkColor *result;
@ -770,7 +807,8 @@ gdk_color_context_get_pixel(GdkColorContext *cc,
result = g_hash_table_lookup (cc->color_hash, &color);
if (!result) {
if (!result)
{
color.red = red;
color.green = green;
color.blue = blue;
@ -778,7 +816,8 @@ gdk_color_context_get_pixel(GdkColorContext *cc,
if (!gdk_color_alloc (cc->colormap, &color))
*failed = TRUE;
else {
else
{
GdkColor *cnew;
/* XXX: the following comment comes directly from
@ -794,7 +833,8 @@ gdk_color_context_get_pixel(GdkColorContext *cc,
* might be necessary for us to resize the CLUT.
*/
if (cc->num_allocated == cc->max_colors) {
if (cc->num_allocated == cc->max_colors)
{
cc->max_colors *= 2;
if (gdk_debug_level >= 1)
@ -858,13 +898,15 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
/* First allocate all pixels */
for (i = 0; i < ncolors; i++) {
for (i = 0; i < ncolors; i++)
{
/* colors[i] is only zero if the pixel at that location hasn't
* been allocated yet. This is a sanity check required for proper
* color allocation by the progressive image loader
*/
if (colors[i] == 0) {
if (colors[i] == 0)
{
defs[i].red = reds[i];
defs[i].green = greens[i];
defs[i].blue = blues[i];
@ -874,10 +916,12 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
/* successfully allocated, store it */
if (!bad_alloc) {
if (!bad_alloc)
{
defs[i].pixel = colors[i];
allocated[ncols++] = colors[i];
} else
}
else
failed[nopen++] = i;
}
}
@ -886,7 +930,8 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
/* all colors available, all done */
if ((ncols == ncolors) || (nopen == 0)) {
if ((ncols == ncolors) || (nopen == 0))
{
if (gdk_debug_level >= 1)
g_print ("gdk_color_context_get_pixels: got all %i colors; "
"(%i colors allocated so far", ncolors, cc->num_allocated);
@ -907,7 +952,8 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
/* see if the colormap has any colors to read */
if (cmapsize < 0) {
if (cmapsize < 0)
{
g_warning ("gdk_color_context_get_pixels: oops! no colors available, "
"your images will look *really* ugly.");
@ -920,7 +966,8 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
/* initialize pixels */
for (i = 0; i < cmapsize; i++) {
for (i = 0; i < cmapsize; i++)
{
cmap[i].pixel = i;
cmap[i].red = cmap[i].green = cmap[i].blue = 0;
}
@ -931,7 +978,8 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
/* speedup: downscale here instead of in the matching code */
for (i = 0; i < cmapsize; i++) {
for (i = 0; i < cmapsize; i++)
{
cmap[i].red >>= 8;
cmap[i].green >>= 8;
cmap[i].blue >>= 8;
@ -943,7 +991,8 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
nopen = 0;
idx = 0;
do {
do
{
gint d, j, mdist, close, ri, gi, bi;
gint rd, gd, bd;
@ -964,20 +1013,23 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
* closest. Uses plain least squares.
*/
for (j = 0; (j < cmapsize) && (mdist != 0); j++) {
for (j = 0; (j < cmapsize) && (mdist != 0); j++)
{
rd = ri - cmap[j].red;
gd = gi - cmap[j].green;
bd = bi - cmap[j].blue;
d = rd * rd + gd * gd + bd * bd;
if (d < mdist) {
if (d < mdist)
{
close = j;
mdist = d;
}
}
if (close != -1) {
if (close != -1)
{
rd = cmap[close].red;
gd = cmap[close].green;
bd = cmap[close].blue;
@ -988,7 +1040,8 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
/* store */
if (!bad_alloc) {
if (!bad_alloc)
{
defs[i] = cmap[close];
defs[i].pixel = colors[i];
allocated[ncols++] = colors[i];
@ -1000,7 +1053,8 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
} else
failed[nopen++] = i;
/* deal with in next stage if allocation failed */
} while (++idx < counter);
}
while (++idx < counter);
*nallocated = ncols;
@ -1008,7 +1062,8 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
* note above.
*/
if ((ncols == ncolors) || (nopen == 0)) {
if ((ncols == ncolors) || (nopen == 0))
{
if (gdk_debug_level >= 1)
g_print ("gdk_color_context_get_pixels: got %i colors, %i exact and "
"%i close (%i colors allocated so far)",
@ -1021,7 +1076,8 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
idx = 0;
do {
do
{
gint d, mdist, close, ri, gi, bi;
gint j, rd, gd, bd;
@ -1038,7 +1094,8 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
/* search allocated colors */
for (j = 0; (j < ncols) && (mdist != 0); j++) {
for (j = 0; (j < ncols) && (mdist != 0); j++)
{
k = allocated[j];
rd = ri - defs[k].red;
@ -1047,13 +1104,15 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
d = rd * rd + gd * gd + bd * bd;
if (d < mdist) {
if (d < mdist)
{
close = k;
mdist = d;
}
}
if (close < 0) {
if (close < 0)
{
/* too bad, map to black */
defs[i].pixel = cc->black_pixel;
@ -1061,7 +1120,9 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
#ifdef DEBUG
black_col++;
#endif
} else {
}
else
{
defs[i] = defs[close];
#ifdef DEBUG
subst_col++;
@ -1069,7 +1130,8 @@ gdk_color_context_get_pixels(GdkColorContext *cc,
}
colors[i] = defs[i].pixel;
} while (++idx < nopen);
}
while (++idx < nopen);
if (gdk_debug_level >= 1)
g_print ("gdk_color_context_get_pixels: got %i colors, %i exact, %i close, "
@ -1114,7 +1176,8 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
/* First allocate all pixels */
for (i = 0; i < ncolors; i++) {
for (i = 0; i < ncolors; i++)
{
/* used[i] is only -1 if the pixel at that location hasn't
* been allocated yet. This is a sanity check required for proper
* color allocation by the progressive image loader.
@ -1122,8 +1185,10 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
* allocation.
*/
if (used[i] != FALSE) {
if (colors[i] == 0) {
if (used[i] != FALSE)
{
if (colors[i] == 0)
{
defs[i].red = reds[i];
defs[i].green = greens[i];
defs[i].blue = blues[i];
@ -1132,10 +1197,12 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
/* successfully allocated, store it */
if (!bad_alloc) {
if (!bad_alloc)
{
defs[i].pixel = colors[i];
allocated[ncols++] = colors[i];
} else
}
else
failed[nopen++] = i;
}
#ifdef DEBUG
@ -1149,7 +1216,8 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
*nallocated = ncols;
if ((ncols == ncolors) || (nopen == 0)) {
if ((ncols == ncolors) || (nopen == 0))
{
if (gdk_debug_level >= 1)
g_print ("gdk_color_context_get_pixels_incremental: got all %i colors "
"(%i colors allocated so far)",
@ -1160,7 +1228,8 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
cmapsize = MIN (cc->num_colors, MAX_IMAGE_COLORS);
if (cmapsize < 0) {
if (cmapsize < 0)
{
g_warning ("gdk_color_context_get_pixels_incremental: oops! "
"No colors available images will look *really* ugly.");
return;
@ -1172,7 +1241,8 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
/* initialize pixels */
for (i = 0; i < cmapsize; i++) {
for (i = 0; i < cmapsize; i++)
{
cmap[i].pixel = i;
cmap[i].red = cmap[i].green = cmap[i].blue = 0;
}
@ -1181,7 +1251,8 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
my_x_query_colors (cc->colormap, cmap, cmapsize);
for (i = 0; i < cmapsize; i++) {
for (i = 0; i < cmapsize; i++)
{
cmap[i].red >>= 8;
cmap[i].green >>= 8;
cmap[i].blue >>= 8;
@ -1193,7 +1264,8 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
nopen = 0;
idx = 0;
do {
do
{
gint d, j, mdist, close, ri, gi, bi;
gint rd, gd, bd;
@ -1208,20 +1280,23 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
gi = greens[i];
bi = blues[i];
for (j = 0; (j < cmapsize) && (mdist != 0); j++) {
for (j = 0; (j < cmapsize) && (mdist != 0); j++)
{
rd = ri - cmap[j].red;
gd = gi - cmap[j].green;
bd = bi - cmap[j].blue;
d = rd * rd + gd * gd + bd * bd;
if (d < mdist) {
if (d < mdist)
{
close = j;
mdist = d;
}
}
if (close != -1) {
if (close != -1)
{
rd = cmap[close].red;
gd = cmap[close].green;
bd = cmap[close].blue;
@ -1232,23 +1307,28 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
/* store */
if (!bad_alloc) {
if (!bad_alloc)
{
defs[i] = cmap[close];
defs[i].pixel = colors[i];
allocated[ncols++] = colors[i];
#ifdef DEBUG
close_col++;
#endif
} else
}
else
failed[nopen++] = i;
} else
}
else
failed[nopen++] = i;
/* deal with in next stage if allocation failed */
} while (++idx < counter);
}
while (++idx < counter);
*nallocated = ncols;
if ((ncols == ncolors) || (nopen == 0)) {
if ((ncols == ncolors) || (nopen == 0))
{
if (gdk_debug_level >= 1)
g_print ("gdk_color_context_get_pixels_incremental: "
"got %i colors, %i exact and %i close "
@ -1262,7 +1342,8 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
idx = 0;
do {
do
{
gint d, mdist, close, ri, gi, bi;
gint j, rd, gd, bd;
@ -1277,7 +1358,8 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
/* search allocated colors */
for (j = 0; (j < ncols) && (mdist != 0); j++) {
for (j = 0; (j < ncols) && (mdist != 0); j++)
{
k = allocated[j];
/* downscale */
@ -1288,13 +1370,15 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
d = rd * rd + gd * gd + bd * bd;
if (d < mdist) {
if (d < mdist)
{
close = k;
mdist = d;
}
}
if (close < 0) {
if (close < 0)
{
/* too bad, map to black */
defs[i].pixel = cc->black_pixel;
@ -1302,7 +1386,9 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
#ifdef DEBUG
black_col++;
#endif
} else {
}
else
{
defs[i] = defs[close];
#ifdef DEBUG
subst_col++;
@ -1310,7 +1396,8 @@ gdk_color_context_get_pixels_incremental(GdkColorContext *cc,
}
colors[i] = defs[i].pixel;
} while (++idx < nopen);
}
while (++idx < nopen);
if (gdk_debug_level >= 1)
g_print ("gdk_color_context_get_pixels_incremental: "
@ -1337,9 +1424,11 @@ gdk_color_context_query_colors(GdkColorContext *cc,
g_assert (cc != NULL);
g_assert (colors != NULL);
switch (cc->mode) {
switch (cc->mode)
{
case GDK_CC_MODE_BW:
for (i = 0, tc = colors; i < num_colors; i++, tc++) {
for (i = 0, tc = colors; i < num_colors; i++, tc++)
{
if (tc->pixel == cc->white_pixel)
tc->red = tc->green = tc->blue = 65535;
else
@ -1349,12 +1438,14 @@ gdk_color_context_query_colors(GdkColorContext *cc,
case GDK_CC_MODE_TRUE:
if (cc->clut == NULL)
for (i = 0, tc = colors; i < num_colors; i++, tc++) {
for (i = 0, tc = colors; i < num_colors; i++, tc++)
{
tc->red = (tc->pixel & cc->masks.red) * 65535 / cc->masks.red;
tc->green = (tc->pixel & cc->masks.green) * 65535 / cc->masks.green;
tc->blue = (tc->pixel & cc->masks.blue) * 65535 / cc->masks.blue;
}
else {
else
{
my_x_query_colors (cc->colormap, colors, num_colors);
return 1;
}
@ -1362,27 +1453,35 @@ gdk_color_context_query_colors(GdkColorContext *cc,
case GDK_CC_MODE_STD_CMAP:
default:
if (cc->cmap == NULL) {
if (cc->cmap == NULL)
{
my_x_query_colors (cc->colormap, colors, num_colors);
return 1;
} else {
}
else
{
gint first, last, half;
gulong half_pixel;
for (i = 0, tc = colors; i < num_colors; i++) {
for (i = 0, tc = colors; i < num_colors; i++)
{
first = 0;
last = cc->num_colors - 1;
while (first <= last) {
while (first <= last)
{
half = (first + last) / 2;
half_pixel = cc->cmap[half].pixel;
if (tc->pixel == half_pixel) {
if (tc->pixel == half_pixel)
{
tc->red = cc->cmap[half].red;
tc->green = cc->cmap[half].green;
tc->blue = cc->cmap[half].blue;
first = last + 1; /* false break */
} else {
}
else
{
if (tc->pixel > half_pixel)
first = half + 1;
else
@ -1414,7 +1513,8 @@ gdk_color_context_add_palette(GdkColorContext *cc,
/* restore previous mode if we aren't adding a new palette */
if (num_palette == 0) {
if (num_palette == 0)
{
/* GDK_CC_MODE_STD_CMAP uses a hash table, so we'd better initialize one */
/* XXX: here, the hash table is already initialized */
@ -1435,7 +1535,8 @@ gdk_color_context_add_palette(GdkColorContext *cc,
j = 0;
for (i = 0; i < num_palette; i++) {
for (i = 0; i < num_palette; i++)
{
erg = 0;
pixel[0] = 0;
@ -1449,7 +1550,8 @@ gdk_color_context_add_palette(GdkColorContext *cc,
/* only store if we succeed */
if (erg) {
if (erg)
{
/* store in palette */
cc->palette[j].red = r;
@ -1470,7 +1572,8 @@ gdk_color_context_add_palette(GdkColorContext *cc,
/* clear the hash table, we don't use it when dithering */
if (cc->color_hash) {
if (cc->color_hash)
{
g_hash_table_destroy (cc->color_hash);
cc->color_hash = NULL;
}
@ -1510,7 +1613,8 @@ gdk_color_context_init_dither(GdkColorContext *cc)
for (rr = 0; rr < 32; rr++)
for (gg = 0; gg < 32; gg++)
for (bb = 0; bb < 32; bb++) {
for (bb = 0; bb < 32; bb++)
{
err = (rr << 3) | (rr >> 2);
erg = (gg << 3) | (gg >> 2);
erb = (bb << 3) | (bb >> 2);
@ -1555,14 +1659,16 @@ gdk_color_context_get_pixel_from_palette(GdkColorContext *cc,
*failed = FALSE;
for (i = 0; i < cc->num_palette; i++) {
for (i = 0; i < cc->num_palette; i++)
{
dr = *red - cc->palette[i].red;
dg = *green - cc->palette[i].green;
db = *blue - cc->palette[i].blue;
dif = dr * dr + dg * dg + db * db;
if (dif < mindif) {
if (dif < mindif)
{
mindif = dif;
j = i;
pixel = cc->palette[i].pixel;
@ -1579,7 +1685,8 @@ gdk_color_context_get_pixel_from_palette(GdkColorContext *cc,
if (j == -1)
*failed = TRUE;
else {
else
{
*red = ABS (err);
*green = ABS (erg);
*blue = ABS (erb);
@ -1608,14 +1715,16 @@ gdk_color_context_get_index_from_palette(GdkColorContext *cc,
*failed = FALSE;
for (i = 0; i < cc->num_palette; i++) {
for (i = 0; i < cc->num_palette; i++)
{
dr = *red - cc->palette[i].red;
dg = *green - cc->palette[i].green;
db = *blue - cc->palette[i].blue;
dif = dr * dr + dg * dg + db * db;
if (dif < mindif) {
if (dif < mindif)
{
mindif = dif;
j = i;
err = dr;
@ -1629,10 +1738,13 @@ gdk_color_context_get_index_from_palette(GdkColorContext *cc,
/* we failed to map onto a color */
if (j == -1) {
if (j == -1)
{
*failed = TRUE;
j = 0;
} else {
}
else
{
/* return error fractions */
*red = err;