Commit 8b4d2c26 authored by slevy's avatar slevy
Browse files

Add new magic encoded-color name - "rgb888", by analogy with rgb565.

If a color-index variable is named rgb888, it's interpreted as a full 24-bit color value:
  R*65536 + G*256 + B
with 0 <= R,G,B <= 255.
parent 0286a3b5
......@@ -16,6 +16,12 @@ static char copyright[] = "Copyright (c) 2002 NCSA, University of Illinois Urban
/*
* $Log$
* Revision 1.130 2013/11/30 20:58:01 slevy
* Add new magic encoded-color name - "rgb888", by analogy with rgb565.
* If a color-index variable is named rgb888, it's interpreted as a full 24-bit color value:
* R*65536 + G*256 + B
* with 0 <= R,G,B <= 255.
*
* Revision 1.129 2013/07/12 14:19:21 slevy
* Allow picking vectors (as in "vec on", "vecscale", etc.).
* Make use of vecalpha value.
......@@ -978,7 +984,7 @@ void specks_recolor( struct stuff *st, struct specklist *sl, int by )
int ncmap = st->ncmap;
struct cment *cmap = st->cmap;
int index;
int rgb565;
enum RGBCode { NONE, RGB565, RGB888 } rgbcode;
unsigned char (*rgbmap)[256];
sl->coloredby = by;
......@@ -1027,7 +1033,9 @@ void specks_recolor( struct stuff *st, struct specklist *sl, int by )
}
normal = (cmax != cmin && ncmap>2) ? (ncmap-2)/(cmax - cmin) : 0;
rgb565 = !strcmp(vd->name, "rgb565") || !strcmp(vd->name, "colors565");
rgbcode = NONE;
if(0==strcmp(vd->name, "rgb565") || 0==strcmp(vd->name, "colors565")) rgbcode = RGB565;
else if(0==strcmp(vd->name, "rgb888") || 0==strcmp(vd->name, "colors888")) rgbcode = RGB888;
/* cexact field means:
* 0 (default): scale data range to cmap index 1..ncmap-2;
......@@ -1037,7 +1045,8 @@ void specks_recolor( struct stuff *st, struct specklist *sl, int by )
*/
rgbmap = &st->rgbmap[0];
for(i = 0; i < nel; i++, sp = NextSpeck(sp, sl, 1)) {
if(rgb565) {
switch(rgbcode) {
case RGB565:
index = sp->val[by];
sp->rgba = PACKRGBA(
rgbmap[0][(index&0xF800)>>(11-(8-5))],
......@@ -1045,7 +1054,18 @@ void specks_recolor( struct stuff *st, struct specklist *sl, int by )
rgbmap[2][(index&0x1F)<<(8-5)],
0 )
| (sp->rgba & EXTRABITS);
} else {
break;
case RGB888:
index = sp->val[by];
sp->rgba = PACKRGBA(
rgbmap[0][(index>>16)&0xFF],
rgbmap[1][(index>>8)&0xFF],
rgbmap[2][index&0xFF],
0 )
| (sp->rgba & EXTRABITS);
break;
default:
index = vd->cexact ? sp->val[by] + cmin
: (sp->val[by] - cmin) * normal + 1;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment