1 /* convert.c - convert RImage to Pixmap
3 * Raster graphics library
5 * Copyright (c) 1997-2000 Alfredo K. Kojima
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * 1. Using Grayscale visual with Dithering crashes wmaker
24 * 2. Ghost dock/appicon is wrong in Pseudocolor, Staticgray, Grayscale
31 #include <X11/Xutil.h>
46 extern Pixmap
R_CreateXImageMappedPixmap(RContext
*context
, RXImage
*ximage
);
51 #define HAS_ALPHA(I) ((I)->format == RRGBAFormat)
54 typedef struct RConversionTable
{
55 unsigned short table
[256];
58 struct RConversionTable
*next
;
62 typedef struct RStdConversionTable
{
63 unsigned int table
[256];
68 struct RStdConversionTable
*next
;
69 } RStdConversionTable
;
73 static RConversionTable
*conversionTable
= NULL
;
74 static RStdConversionTable
*stdConversionTable
= NULL
;
77 static unsigned short*
78 computeTable(unsigned short mask
)
80 RConversionTable
*tmp
= conversionTable
;
84 if (tmp
->index
== mask
)
92 tmp
= (RConversionTable
*)malloc(sizeof(RConversionTable
));
97 tmp
->table
[i
] = (i
*mask
+ 0x7f)/0xff;
100 tmp
->next
= conversionTable
;
101 conversionTable
= tmp
;
107 computeStdTable(unsigned int mult
, unsigned int max
)
109 RStdConversionTable
*tmp
= stdConversionTable
;
113 if (tmp
->mult
== mult
&& tmp
->max
== max
)
121 tmp
= (RStdConversionTable
*)malloc(sizeof(RStdConversionTable
));
125 for (i
=0; i
<256; i
++) {
126 tmp
->table
[i
] = (i
*max
)/0xff * mult
;
131 tmp
->next
= stdConversionTable
;
132 stdConversionTable
= tmp
;
137 /***************************************************************************/
141 convertTrueColor_generic(RXImage
*ximg
, RImage
*image
,
142 char *err
, char *nerr
,
146 const int dr
, const int dg
, const int db
,
147 const unsigned short roffs
,
148 const unsigned short goffs
,
149 const unsigned short boffs
)
155 unsigned char *ptr
= image
->data
;
156 int channels
= image
->format
== RRGBAFormat
? 4 : 3;
159 /* convert and dither the image to XImage */
160 for (y
=0; y
<image
->height
; y
++) {
164 for (x
=0; x
<image
->width
; x
++, ptr
+=channels
) {
167 pixel
= *ptr
+ err
[x
];
168 if (pixel
<0) pixel
=0; else if (pixel
>0xff) pixel
=0xff;
174 pixel
= *(ptr
+1) + err
[x
+1];
175 if (pixel
<0) pixel
=0; else if (pixel
>0xff) pixel
=0xff;
181 pixel
= *(ptr
+2) + err
[x
+2];
182 if (pixel
<0) pixel
=0; else if (pixel
>0xff) pixel
=0xff;
188 pixel
= (r
<<roffs
) | (g
<<goffs
) | (b
<<boffs
);
189 XPutPixel(ximg
->image
, x
, y
, pixel
);
191 /* distribute error */
205 nerr
[x
+1+3*1]=ger
-2*g
;
206 nerr
[x
+2+3*1]=ber
-2*b
;
208 /* skip to next line */
219 image2TrueColor(RContext
*ctx
, RImage
*image
)
222 unsigned short rmask
, gmask
, bmask
;
223 unsigned short roffs
, goffs
, boffs
;
224 unsigned short *rtable
, *gtable
, *btable
;
225 int channels
= (image
->format
== RRGBAFormat
? 4 : 3);
227 ximg
= RCreateXImage(ctx
, ctx
->depth
, image
->width
, image
->height
);
232 roffs
= ctx
->red_offset
;
233 goffs
= ctx
->green_offset
;
234 boffs
= ctx
->blue_offset
;
236 rmask
= ctx
->visual
->red_mask
>> roffs
;
237 gmask
= ctx
->visual
->green_mask
>> goffs
;
238 bmask
= ctx
->visual
->blue_mask
>> boffs
;
240 rtable
= computeTable(rmask
);
241 gtable
= computeTable(gmask
);
242 btable
= computeTable(bmask
);
244 if (rtable
==NULL
|| gtable
==NULL
|| btable
==NULL
) {
245 RErrorCode
= RERR_NOMEMORY
;
246 RDestroyXImage(ctx
, ximg
);
255 if (ctx
->attribs
->render_mode
==RBestMatchRendering
) {
259 unsigned char *ptr
= image
->data
;
263 puts("true color match");
265 if (rmask
==0xff && gmask
==0xff && bmask
==0xff) {
266 for (y
=0; y
< image
->height
; y
++) {
267 for (x
=0; x
< image
->width
; x
++, ptr
+=channels
) {
269 pixel
= (*(ptr
)<<roffs
) | (*(ptr
+1)<<goffs
) | (*(ptr
+2)<<boffs
);
270 XPutPixel(ximg
->image
, x
, y
, pixel
);
274 for (y
=0, ofs
=0; y
< image
->height
; y
++) {
275 for (x
=0; x
< image
->width
; x
++, ofs
+=channels
-3) {
277 r
= rtable
[ptr
[ofs
++]];
278 g
= gtable
[ptr
[ofs
++]];
279 b
= btable
[ptr
[ofs
++]];
280 pixel
= (r
<<roffs
) | (g
<<goffs
) | (b
<<boffs
);
281 XPutPixel(ximg
->image
, x
, y
, pixel
);
287 const int dr
=0xff/rmask
;
288 const int dg
=0xff/gmask
;
289 const int db
=0xff/bmask
;
292 puts("true color dither");
297 int ch
= image
->format
== RRGBAFormat
? 4 : 3;
299 err
= malloc(ch
*(image
->width
+2));
300 nerr
= malloc(ch
*(image
->width
+2));
304 RErrorCode
= RERR_NOMEMORY
;
305 RDestroyXImage(ctx
, ximg
);
309 memset(err
, 0, ch
*(image
->width
+2));
310 memset(nerr
, 0, ch
*(image
->width
+2));
312 convertTrueColor_generic(ximg
, image
, err
, nerr
,
313 rtable
, gtable
, btable
,
314 dr
, dg
, db
, roffs
, goffs
, boffs
);
329 /***************************************************************************/
332 convertPseudoColor_to_8(RXImage
*ximg
, RImage
*image
,
333 char *err
, char *nerr
,
337 const int dr
, const int dg
, const int db
,
338 unsigned long *pixels
,
345 unsigned char *ptr
= image
->data
;
346 unsigned char *optr
= ximg
->image
->data
;
347 int channels
= image
->format
== RRGBAFormat
? 4 : 3;
350 /* convert and dither the image to XImage */
351 for (y
=0; y
<image
->height
; y
++) {
355 for (x
=0; x
<image
->width
*3; x
+=3, ptr
+=channels
) {
358 pixel
= *ptr
+ err
[x
];
359 if (pixel
<0) pixel
=0; else if (pixel
>0xff) pixel
=0xff;
365 pixel
= *(ptr
+1) + err
[x
+1];
366 if (pixel
<0) pixel
=0; else if (pixel
>0xff) pixel
=0xff;
372 pixel
= *(ptr
+2) + err
[x
+2];
373 if (pixel
<0) pixel
=0; else if (pixel
>0xff) pixel
=0xff;
378 *optr
++ = pixels
[r
*cpcpc
+ g
*cpc
+ b
];
380 /* distribute error */
395 nerr
[x
+1+3*1]=ger
-2*g
;
396 nerr
[x
+2+3*1]=ber
-2*b
;
398 /* skip to next line */
403 optr
+= ximg
->image
->bytes_per_line
- image
->width
;
410 image2PseudoColor(RContext
*ctx
, RImage
*image
)
413 register int x
, y
, r
, g
, b
;
416 const int cpc
=ctx
->attribs
->colors_per_channel
;
417 const unsigned short rmask
= cpc
-1; /* different sizes could be used */
418 const unsigned short gmask
= rmask
; /* for r,g,b */
419 const unsigned short bmask
= rmask
;
420 unsigned short *rtable
, *gtable
, *btable
;
421 const int cpccpc
= cpc
*cpc
;
422 int channels
= image
->format
== RRGBAFormat
? 4 : 3;
424 ximg
= RCreateXImage(ctx
, ctx
->depth
, image
->width
, image
->height
);
431 /* Tables are same at the moment because rmask==gmask==bmask. */
432 rtable
= computeTable(rmask
);
433 gtable
= computeTable(gmask
);
434 btable
= computeTable(bmask
);
436 if (rtable
==NULL
|| gtable
==NULL
|| btable
==NULL
) {
437 RErrorCode
= RERR_NOMEMORY
;
438 RDestroyXImage(ctx
, ximg
);
442 if (ctx
->attribs
->render_mode
== RBestMatchRendering
) {
445 printf("pseudo color match with %d colors per channel\n", cpc
);
447 for (y
=0; y
<image
->height
; y
++) {
448 for (x
=0; x
<image
->width
; x
++, ptr
+=channels
-3) {
453 pixel
= r
*cpccpc
+ g
*cpc
+ b
;
454 /*data[ofs] = ctx->colors[pixel].pixel;*/
455 XPutPixel(ximg
->image
, x
, y
, ctx
->colors
[pixel
].pixel
);
462 const int dr
=0xff/rmask
;
463 const int dg
=0xff/gmask
;
464 const int db
=0xff/bmask
;
468 printf("pseudo color dithering with %d colors per channel\n", cpc
);
470 err
= malloc(4*(image
->width
+3));
471 nerr
= malloc(4*(image
->width
+3));
475 RErrorCode
= RERR_NOMEMORY
;
476 RDestroyXImage(ctx
, ximg
);
479 memset(err
, 0, 4*(image
->width
+3));
480 memset(nerr
, 0, 4*(image
->width
+3));
482 convertPseudoColor_to_8(ximg
, image
, err
+4, nerr
+4,
483 rtable
, gtable
, btable
,
484 dr
, dg
, db
, ctx
->pixels
, cpc
);
495 * For standard colormap
498 image2StandardPseudoColor(RContext
*ctx
, RImage
*image
)
501 register int x
, y
, r
, g
, b
;
505 unsigned int *rtable
, *gtable
, *btable
;
506 unsigned int base_pixel
= ctx
->std_rgb_map
->base_pixel
;
507 int channels
= image
->format
== RRGBAFormat
? 4 : 3;
508 /*register unsigned char maxrgb = 0xff;*/
510 ximg
= RCreateXImage(ctx
, ctx
->depth
, image
->width
, image
->height
);
517 data
= (unsigned char *)ximg
->image
->data
;
520 rtable
= computeStdTable(ctx
->std_rgb_map
->red_mult
,
521 ctx
->std_rgb_map
->red_max
);
523 gtable
= computeStdTable(ctx
->std_rgb_map
->green_mult
,
524 ctx
->std_rgb_map
->green_max
);
526 btable
= computeStdTable(ctx
->std_rgb_map
->blue_mult
,
527 ctx
->std_rgb_map
->blue_max
);
529 if (rtable
==NULL
|| gtable
==NULL
|| btable
==NULL
) {
530 RErrorCode
= RERR_NOMEMORY
;
531 RDestroyXImage(ctx
, ximg
);
536 if (ctx
->attribs
->render_mode
== RBestMatchRendering
) {
537 for (y
=0; y
<image
->height
; y
++) {
538 for (x
=0; x
<image
->width
; x
++, ptr
+=channels
) {
540 pixel
= (rtable
[*ptr
] + gtable
[*(ptr
+1)]
541 + btable
[*(ptr
+2)] + base_pixel
) & 0xffffffff;
543 XPutPixel(ximg
->image
, x
, y
, pixel
);
554 printf("pseudo color dithering with %d colors per channel\n", cpc
);
556 err
= (short*)malloc(3*(image
->width
+2)*sizeof(short));
557 nerr
= (short*)malloc(3*(image
->width
+2)*sizeof(short));
563 RErrorCode
= RERR_NOMEMORY
;
564 RDestroyXImage(ctx
, ximg
);
567 for (x
=0, x1
=0; x
<image
->width
*3; x1
+=channels
-3) {
568 err
[x
++] = ptr
[x1
++];
569 err
[x
++] = ptr
[x1
++];
570 err
[x
++] = ptr
[x1
++];
572 err
[x
] = err
[x
+1] = err
[x
+2] = 0;
573 /* convert and dither the image to XImage */
574 for (y
=0, ofs
=0; y
<image
->height
; y
++) {
575 if (y
<image
->height
-1) {
577 for (x
=0, x1
=(y
+1)*image
->width
*channels
;
580 nerr
[x
++] = ptr
[x1
++];
581 nerr
[x
++] = ptr
[x1
++];
582 nerr
[x
++] = ptr
[x1
++];
586 nerr
[x
++] = ptr
[x1
++];
587 nerr
[x
++] = ptr
[x1
++];
588 nerr
[x
++] = ptr
[x1
++];
590 for (x
=0; x
<image
->width
*3; x
+=3, ofs
++) {
592 if (err
[x
]>0xff) err
[x
]=0xff; else if (err
[x
]<0) err
[x
]=0;
593 if (err
[x
+1]>0xff) err
[x
+1]=0xff; else if (err
[x
+1]<0) err
[x
+1]=0;
594 if (err
[x
+2]>0xff) err
[x
+2]=0xff; else if (err
[x
+2]<0) err
[x
+2]=0;
597 g
= gtable
[err
[x
+1]];
598 b
= btable
[err
[x
+2]];
602 data
[ofs
] = base_pixel
+ pixel
;
605 rer
= err
[x
] - (ctx
->colors
[pixel
].red
>>8);
606 ger
= err
[x
+1] - (ctx
->colors
[pixel
].green
>>8);
607 ber
= err
[x
+2] - (ctx
->colors
[pixel
].blue
>>8);
609 /* distribute error */
610 err
[x
+3*1]+=(rer
*7)/16;
611 err
[x
+1+3*1]+=(ger
*7)/16;
612 err
[x
+2+3*1]+=(ber
*7)/16;
615 nerr
[x
+1]+=(ger
*5)/16;
616 nerr
[x
+2]+=(ber
*5)/16;
619 nerr
[x
-3*1]+=(rer
*3)/16;
620 nerr
[x
-3*1+1]+=(ger
*3)/16;
621 nerr
[x
-3*1+2]+=(ber
*3)/16;
625 nerr
[x
+1+3*1]+=ger
/16;
626 nerr
[x
+2+3*1]+=ber
/16;
628 /* skip to next line */
633 ofs
+= ximg
->image
->bytes_per_line
- image
->width
;
638 ximg
->image
->data
= (char*)data
;
646 image2GrayScale(RContext
*ctx
, RImage
*image
)
649 register int x
, y
, g
;
651 const int cpc
=ctx
->attribs
->colors_per_channel
;
652 unsigned short gmask
;
653 unsigned short *table
;
655 int channels
= image
->format
== RRGBAFormat
? 4 : 3;
657 /*register unsigned char maxrgb = 0xff;*/
659 ximg
= RCreateXImage(ctx
, ctx
->depth
, image
->width
, image
->height
);
666 data
= (unsigned char *)ximg
->image
->data
;
668 if (ctx
->vclass
== StaticGray
)
669 gmask
= (1<<ctx
->depth
) - 1; /* use all grays */
671 gmask
= cpc
*cpc
*cpc
-1;
673 table
= computeTable(gmask
);
676 RErrorCode
= RERR_NOMEMORY
;
677 RDestroyXImage(ctx
, ximg
);
681 if (ctx
->attribs
->render_mode
== RBestMatchRendering
) {
684 printf("grayscale match with %d colors per channel\n", cpc
);
686 for (y
=0; y
<image
->height
; y
++) {
687 for (x
=0; x
<image
->width
; x
++) {
689 g
= table
[(*ptr
* 30 + *(ptr
+1) * 59 + *(ptr
+2) * 11)/100];
691 /*data[ofs] = ctx->colors[g].pixel;*/
692 XPutPixel(ximg
->image
, x
, y
, ctx
->colors
[g
].pixel
);
701 const int dg
=0xff/gmask
;
704 printf("grayscale dither with %d colors per channel\n", cpc
);
706 gerr
= (short*)malloc((image
->width
+2)*sizeof(short));
707 ngerr
= (short*)malloc((image
->width
+2)*sizeof(short));
708 if (!gerr
|| !ngerr
) {
711 RErrorCode
= RERR_NOMEMORY
;
712 RDestroyXImage(ctx
, ximg
);
715 for (x
=0; x
<image
->width
; x
++) {
716 gerr
[x
] = (ptr
[x
*3]*30 + ptr
[x
*3+1]*59 + ptr
[x
*3+2]*11)/100;
719 /* convert and dither the image to XImage */
720 for (y
=0; y
<image
->height
; y
++) {
721 if (y
<image
->height
-1) {
723 for (x
=0, x1
=(y
+1)*image
->width
*3; x
<image
->width
; x1
+=channels
) {
724 ngerr
[x
] = (ptr
[x1
]*30 + ptr
[x1
+1]*59 + ptr
[x1
+2]*11)/100;
728 ngerr
[x
] = (ptr
[x1
]*30 + ptr
[x1
+1]*59 + ptr
[x1
+2]*11)/100;
730 for (x
=0; x
<image
->width
; x
++) {
732 if (gerr
[x
]>0xff) gerr
[x
]=0xff; else if (gerr
[x
]<0) gerr
[x
]=0;
736 /*data[ofs] = ctx->colors[g].pixel;*/
737 XPutPixel(ximg
->image
, x
, y
, ctx
->colors
[g
].pixel
);
739 ger
= gerr
[x
] - g
*dg
;
741 /* distribute error */
750 /* skip to next line */
758 ximg
->image
->data
= (char*)data
;
765 image2Bitmap(RContext
*ctx
, RImage
*image
, int threshold
)
768 unsigned char *alpha
;
771 ximg
= RCreateXImage(ctx
, 1, image
->width
, image
->height
);
775 alpha
= image
->data
+3;
777 for (y
= 0; y
< image
->height
; y
++) {
778 for (x
= 0; x
< image
->width
; x
++) {
779 XPutPixel(ximg
->image
, x
, y
, (*alpha
<= threshold
? 0 : 1));
791 hermesConvert(RContext
*context
, RImage
*image
)
798 ximage
= RCreateXImage(context
, context
->depth
,
799 image
->width
, image
->height
);
804 if (HAS_ALPHA(image
)) {
805 if (ximage
->image
->byte_order
==LSBFirst
) {
806 source
.r
= 0x000000ff;
807 source
.g
= 0x0000ff00;
808 source
.b
= 0x00ff0000;
809 source
.a
= 0xff000000;
811 source
.r
= 0xff000000;
812 source
.g
= 0x00ff0000;
813 source
.b
= 0x0000ff00;
814 source
.a
= 0x000000ff;
818 if (ximage
->image
->byte_order
==LSBFirst
) {
832 source
.has_colorkey
= 0;
834 dest
.r
= context
->visual
->red_mask
;
835 dest
.g
= context
->visual
->green_mask
;
836 dest
.b
= context
->visual
->blue_mask
;
838 dest
.bits
= ximage
->image
->bits_per_pixel
;
839 if (context
->vclass
== TrueColor
)
843 dest
.has_colorkey
= 0;
845 Hermes_ConverterRequest(context
->hermes_data
->converter
, &source
, &dest
);
847 Hermes_ConverterPalette(context
->hermes_data
->converter
,
848 context
->hermes_data
->palette
, 0);
850 Hermes_ConverterCopy(context
->hermes_data
->converter
,
851 image
->data
, 0, 0, image
->width
, image
->height
,
852 image
->width
* (image
->format
== RRGBFormat
? 3 : 4),
853 ximage
->image
->data
, 0, 0,
854 image
->width
, image
->height
,
855 ximage
->image
->bytes_per_line
);
859 #endif /* HAVE_HERMES */
863 RConvertImage(RContext
*context
, RImage
*image
, Pixmap
*pixmap
)
870 assert(context
!=NULL
);
872 assert(pixmap
!=NULL
);
875 ximg
= hermesConvert(context
, image
);
876 #else /* !HAVE_HERMES */
877 /* clear error message */
878 switch (context
->vclass
) {
880 ximg
= image2TrueColor(context
, image
);
888 if (context
->attribs
->standard_colormap_mode
!= RIgnoreStdColormap
)
889 ximg
= image2StandardPseudoColor(context
, image
);
891 ximg
= image2PseudoColor(context
, image
);
899 ximg
= image2GrayScale(context
, image
);
902 #endif /* !HAVE_HERMES */
909 *pixmap
= XCreatePixmap(context
->dpy
, context
->drawable
, image
->width
,
910 image
->height
, context
->depth
);
913 if (context
->flags
.use_shared_pixmap
&& ximg
->is_shared
)
914 tmp
= R_CreateXImageMappedPixmap(context
, ximg
);
919 * We have to copy the shm Pixmap into a normal Pixmap because
920 * otherwise, we would have to control when Pixmaps are freed so
921 * that we can detach their shm segments. This is a problem if the
922 * program crash, leaving stale shared memory segments in the
923 * system (lots of them). But with some work, we can optimize
924 * things and remove this XCopyArea. This will require
925 * explicitly freeing all pixmaps when exiting or restarting
928 XCopyArea(context
->dpy
, tmp
, *pixmap
, context
->copy_gc
, 0, 0,
929 image
->width
, image
->height
, 0, 0);
930 XFreePixmap(context
->dpy
, tmp
);
932 RPutXImage(context
, *pixmap
, context
->copy_gc
, ximg
, 0, 0, 0, 0,
933 image
->width
, image
->height
);
936 RPutXImage(context
, *pixmap
, context
->copy_gc
, ximg
, 0, 0, 0, 0,
937 image
->width
, image
->height
);
940 RDestroyXImage(context
, ximg
);
947 RConvertImageMask(RContext
*context
, RImage
*image
, Pixmap
*pixmap
,
948 Pixmap
*mask
, int threshold
)
954 assert(context
!=NULL
);
956 assert(pixmap
!=NULL
);
959 if (!RConvertImage(context
, image
, pixmap
))
962 if (image
->format
==RRGBFormat
) {
967 ximg
= image2Bitmap(context
, image
, threshold
);
972 *mask
= XCreatePixmap(context
->dpy
, context
->drawable
, image
->width
,
974 gcv
.foreground
= context
->black
;
975 gcv
.background
= context
->white
;
976 gcv
.graphics_exposures
= False
;
977 gc
= XCreateGC(context
->dpy
, *mask
, GCForeground
|GCBackground
978 |GCGraphicsExposures
, &gcv
);
979 RPutXImage(context
, *mask
, gc
, ximg
, 0, 0, 0, 0,
980 image
->width
, image
->height
);
981 RDestroyXImage(context
, ximg
);
988 RGetClosestXColor(RContext
*context
, RColor
*color
, XColor
*retColor
)
990 if (context
->vclass
== TrueColor
) {
991 unsigned short rmask
, gmask
, bmask
;
992 unsigned short roffs
, goffs
, boffs
;
993 unsigned short *rtable
, *gtable
, *btable
;
995 roffs
= context
->red_offset
;
996 goffs
= context
->green_offset
;
997 boffs
= context
->blue_offset
;
999 rmask
= context
->visual
->red_mask
>> roffs
;
1000 gmask
= context
->visual
->green_mask
>> goffs
;
1001 bmask
= context
->visual
->blue_mask
>> boffs
;
1003 rtable
= computeTable(rmask
);
1004 gtable
= computeTable(gmask
);
1005 btable
= computeTable(bmask
);
1007 retColor
->pixel
= (rtable
[color
->red
]<<roffs
) |
1008 (gtable
[color
->green
]<<goffs
) | (btable
[color
->blue
]<<boffs
);
1010 retColor
->red
= color
->red
<< 8;
1011 retColor
->green
= color
->green
<< 8;
1012 retColor
->blue
= color
->blue
<< 8;
1013 retColor
->flags
= DoRed
|DoGreen
|DoBlue
;
1015 } else if (context
->vclass
== PseudoColor
1016 || context
->vclass
== StaticColor
) {
1018 if (context
->attribs
->standard_colormap_mode
!= RIgnoreStdColormap
) {
1019 unsigned int *rtable
, *gtable
, *btable
;
1021 rtable
= computeStdTable(context
->std_rgb_map
->red_mult
,
1022 context
->std_rgb_map
->red_max
);
1024 gtable
= computeStdTable(context
->std_rgb_map
->green_mult
,
1025 context
->std_rgb_map
->green_max
);
1027 btable
= computeStdTable(context
->std_rgb_map
->blue_mult
,
1028 context
->std_rgb_map
->blue_max
);
1030 if (rtable
==NULL
|| gtable
==NULL
|| btable
==NULL
) {
1031 RErrorCode
= RERR_NOMEMORY
;
1035 retColor
->pixel
= (rtable
[color
->red
]
1036 + gtable
[color
->green
]
1037 + btable
[color
->blue
]
1038 + context
->std_rgb_map
->base_pixel
) & 0xffffffff;
1039 retColor
->red
= color
->red
<<8;
1040 retColor
->green
= color
->green
<<8;
1041 retColor
->blue
= color
->blue
<<8;
1042 retColor
->flags
= DoRed
|DoGreen
|DoBlue
;
1045 const int cpc
=context
->attribs
->colors_per_channel
;
1046 const unsigned short rmask
= cpc
-1; /* different sizes could be used */
1047 const unsigned short gmask
= rmask
; /* for r,g,b */
1048 const unsigned short bmask
= rmask
;
1049 unsigned short *rtable
, *gtable
, *btable
;
1050 const int cpccpc
= cpc
*cpc
;
1053 rtable
= computeTable(rmask
);
1054 gtable
= computeTable(gmask
);
1055 btable
= computeTable(bmask
);
1057 if (rtable
==NULL
|| gtable
==NULL
|| btable
==NULL
) {
1058 RErrorCode
= RERR_NOMEMORY
;
1061 index
= rtable
[color
->red
]*cpccpc
+ gtable
[color
->green
]*cpc
1062 + btable
[color
->blue
];
1063 *retColor
= context
->colors
[index
];
1066 } else if (context
->vclass
== GrayScale
|| context
->vclass
== StaticGray
) {
1068 const int cpc
= context
->attribs
->colors_per_channel
;
1069 unsigned short gmask
;
1070 unsigned short *table
;
1073 if (context
->vclass
== StaticGray
)
1074 gmask
= (1<<context
->depth
) - 1; /* use all grays */
1076 gmask
= cpc
*cpc
*cpc
-1;
1078 table
= computeTable(gmask
);
1082 index
= table
[(color
->red
*30 + color
->green
*59 + color
->blue
*11)/100];
1084 *retColor
= context
->colors
[index
];
1086 RErrorCode
= RERR_INTERNAL
;