For true color map images, the color query is impressively optimized.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2296 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02master
parent
0ecbd9a5ab
commit
6feb22a648
|
@ -29,6 +29,11 @@ static struct color_cache_entry color_cache[Color_cache_size];
|
|||
|
||||
static int num_overflows = 0;
|
||||
|
||||
Bool direct_rgb = False;
|
||||
int byte_order;
|
||||
int bitmap_unit;
|
||||
int bits_per_pixel;
|
||||
|
||||
void gr_init_color_cache(void)
|
||||
{
|
||||
int i;
|
||||
|
@ -46,10 +51,22 @@ unsigned long gr_pixel_rgb(int rgb)
|
|||
unsigned int r, g, b;
|
||||
int h, i;
|
||||
XColor color;
|
||||
unsigned short tmp;
|
||||
|
||||
r = (rgb >> 16) & 0xFF;
|
||||
g = (rgb >> 8) & 0xFF;
|
||||
b = rgb & 0xFF;
|
||||
|
||||
if (direct_rgb){
|
||||
switch ( bits_per_pixel ){
|
||||
case 16:
|
||||
tmp = ((r >> 3) << 11) + ((g >> 2) << 5) + ((b >> 3) << 0);
|
||||
return (unsigned long) tmp;
|
||||
case 32:
|
||||
return (r << 16) + (g << 8) + (b << 0);
|
||||
}
|
||||
}
|
||||
|
||||
h = Hash_rgb(r, g, b);
|
||||
i = h;
|
||||
while(1) {
|
||||
|
|
|
@ -32,6 +32,11 @@ extern int grx, gry; /* Coordinates of the current point */
|
|||
extern unsigned long grcolor; /* Current drawing color */
|
||||
extern XFontStruct * grfont; /* Current font */
|
||||
|
||||
extern Bool direct_rgb;
|
||||
extern int byte_order;
|
||||
extern int bitmap_unit;
|
||||
extern int bits_per_pixel;
|
||||
|
||||
#define Wcvt(y) (grwindow.h - 1 - (y))
|
||||
#define Bcvt(y) (grbstore.h - 1 - (y))
|
||||
#define WtoB(y) ((y) + grbstore.h - grwindow.h)
|
||||
|
|
|
@ -40,6 +40,22 @@ value gr_make_image(value m)
|
|||
XDefaultDepth(grdisplay, grscreen),
|
||||
ZPixmap, 0, NULL, width, height,
|
||||
BitmapPad(grdisplay), 0);
|
||||
|
||||
/* To optimize RGB => color id calculation */
|
||||
if( !direct_rgb ){
|
||||
/* they are declared in color.c */
|
||||
byte_order = idata->byte_order;
|
||||
bitmap_unit = idata->bitmap_unit;
|
||||
bits_per_pixel = idata->bits_per_pixel;
|
||||
#ifdef DIRECT_RGB_DEBUG
|
||||
fprintf(stderr, "Byte_order: %d = %s\n", byte_order,
|
||||
byte_order ? "LSBFirst" : "MSBFirst");
|
||||
fprintf(stderr, "Bitmp_unit: %d\n", bitmap_unit);
|
||||
fprintf(stderr, "Bits per pixel: %d\n", idata->bits_per_pixel);
|
||||
#endif
|
||||
direct_rgb = True;
|
||||
}
|
||||
|
||||
bdata = (char *) stat_alloc(height * idata->bytes_per_line);
|
||||
idata->data = bdata;
|
||||
has_transp = False;
|
||||
|
|
Loading…
Reference in New Issue