calc_error() needs the colormap color values; changed to reference the

fl_cmap array (this might actually be off from the colormap value that
is actually allocated, but hopefully this patch will eliminate extra
color allocations anyways...)


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.0@1242 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Michael R Sweet 2000-06-27 23:30:54 +00:00
parent a141e143ba
commit 753c53cc75
2 changed files with 16 additions and 14 deletions

View File

@ -1,5 +1,5 @@
//
// "$Id: fl_color.cxx,v 1.12.2.2 2000/06/05 21:21:06 mike Exp $"
// "$Id: fl_color.cxx,v 1.12.2.3 2000/06/27 23:30:54 easysw Exp $"
//
// Color functions for the Fast Light Tool Kit (FLTK).
//
@ -125,7 +125,7 @@ void fl_color(uchar r,uchar g,uchar b) {
// an X color, and does a least-squares match to find the closest
// color if X cannot allocate that color.
static unsigned fl_cmap[256] = {
unsigned fl_cmap[256] = {
#include "fl_cmap.h" // this is a file produced by "cmap.C":
};
@ -351,5 +351,5 @@ Fl_Color contrast(Fl_Color fg, Fl_Color bg) {
}
//
// End of "$Id: fl_color.cxx,v 1.12.2.2 2000/06/05 21:21:06 mike Exp $".
// End of "$Id: fl_color.cxx,v 1.12.2.3 2000/06/27 23:30:54 easysw Exp $".
//

View File

@ -1,5 +1,5 @@
//
// "$Id: fl_draw_image.cxx,v 1.5.2.3 2000/06/27 23:07:51 easysw Exp $"
// "$Id: fl_draw_image.cxx,v 1.5.2.4 2000/06/27 23:30:54 easysw Exp $"
//
// Image drawing routines for the Fast Light Tool Kit (FLTK).
//
@ -80,13 +80,14 @@ static int ri,gi,bi; // saved error-diffusion value
// we could allocate to each of the colors in a 4-bit image. This is
// then used to find the pixel values and actual colors for error diffusion.
static uchar cube[16*16*16];
extern unsigned fl_cmap[];
// calculate sum-of-squares error between 4-bit index and pixel colors:
static int calc_error(int r, int g, int b, int i) {
int t; int s;
t = ((r<<4)+8)-fl_xmap[0][i].r; s = t*t;
t = ((g<<4)+8)-fl_xmap[0][i].g; s += t*t;
t = ((b<<4)+8)-fl_xmap[0][i].b; s += t*t;
t = ((r<<4)+8)-((fl_cmap[i] >> 24) & 255); s = t*t;
t = ((g<<4)+8)-((fl_cmap[i] >> 16) & 255); s += t*t;
t = ((b<<4)+8)-((fl_cmap[i] >> 8) & 255); s += t*t;
return s;
}
@ -116,6 +117,7 @@ static void fill_color_cube() {
fl_xpixel((Fl_Color)(i+FL_GRAY_RAMP));
i = (i+7)%FL_NUM_GRAY; if (!i) break;
}
memset(alloc_color, 1, sizeof(alloc_color));
#else
memset(alloc_color, 0, sizeof(alloc_color));
#endif /* 0 */
@ -168,15 +170,15 @@ static void color8_converter(const uchar *from, uchar *to, int w, int delta) {
g += from[1]; if (g < 0) g = 0; else if (g>255) g = 255;
b += from[2]; if (b < 0) b = 0; else if (b>255) b = 255;
i = cube[((r<<4)&0xf00)+(g&0xf0)+(b>>4)];
Fl_XColor* x = fl_xmap[0] + i;
r -= x->r;
g -= x->g;
b -= x->b;
if (!alloc_color[i])
{
fl_xpixel((Fl_Color)i);
alloc_color[i] = 1;
}
Fl_XColor* x = fl_xmap[0] + i;
r -= x->r;
g -= x->g;
b -= x->b;
*to = uchar(x->pixel);
}
ri = r; gi = g; bi = b;
@ -201,13 +203,13 @@ static void mono8_converter(const uchar *from, uchar *to, int w, int delta) {
for (; w--; from += d, to += td) {
r += from[0]; if (r < 0) r = 0; else if (r>255) r = 255;
i = cube[(r>>4)*0x111];
Fl_XColor* x = fl_xmap[0] + i;
r -= x->g;
if (!alloc_color[i])
{
fl_xpixel((Fl_Color)i);
alloc_color[i] = 1;
}
Fl_XColor* x = fl_xmap[0] + i;
r -= x->g;
*to = uchar(x->pixel);
}
ri = r;
@ -650,5 +652,5 @@ void fl_rectf(int x, int y, int w, int h, uchar r, uchar g, uchar b) {
#endif
//
// End of "$Id: fl_draw_image.cxx,v 1.5.2.3 2000/06/27 23:07:51 easysw Exp $".
// End of "$Id: fl_draw_image.cxx,v 1.5.2.4 2000/06/27 23:30:54 easysw Exp $".
//