blef
This commit is contained in:
parent
e6d6a1b6b5
commit
3fa1352428
2 changed files with 7 additions and 56 deletions
|
@ -16,8 +16,6 @@ class RenderControl {
|
||||||
protected:
|
protected:
|
||||||
const ScreenInfo *_screen;
|
const ScreenInfo *_screen;
|
||||||
|
|
||||||
// the number of bits (1-255) that each shade of color spans across. best
|
|
||||||
// case is 1, which gives 255 shades
|
|
||||||
int _red_bits;
|
int _red_bits;
|
||||||
int _green_bits;
|
int _green_bits;
|
||||||
int _blue_bits;
|
int _blue_bits;
|
||||||
|
|
|
@ -36,14 +36,11 @@ TrueRenderControl::TrueRenderControl(const ScreenInfo *screen)
|
||||||
while (! (green_mask & 1)) { _green_offset++; green_mask >>= 1; }
|
while (! (green_mask & 1)) { _green_offset++; green_mask >>= 1; }
|
||||||
while (! (blue_mask & 1)) { _blue_offset++; blue_mask >>= 1; }
|
while (! (blue_mask & 1)) { _blue_offset++; blue_mask >>= 1; }
|
||||||
|
|
||||||
// use the mask to determine the number of bits for each shade of color
|
// scale available colorspace to match our 256x256x256 cube
|
||||||
// so, best case, red_mask == 0xff (255), with each bit as a different
|
|
||||||
// shade!
|
|
||||||
_red_bits = 255 / red_mask;
|
_red_bits = 255 / red_mask;
|
||||||
_green_bits = 255 / green_mask;
|
_green_bits = 255 / green_mask;
|
||||||
_blue_bits = 255 / blue_mask;
|
_blue_bits = 255 / blue_mask;
|
||||||
|
|
||||||
// compute color tables, based on the number of bits for each shade
|
|
||||||
for (int i = 0; i < 256; i++) {
|
for (int i = 0; i < 256; i++) {
|
||||||
_red_color_table[i] = i / _red_bits;
|
_red_color_table[i] = i / _red_bits;
|
||||||
_green_color_table[i] = i / _green_bits;
|
_green_color_table[i] = i / _green_bits;
|
||||||
|
@ -58,54 +55,8 @@ TrueRenderControl::~TrueRenderControl()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline
|
static inline void renderPixel(XImage *im, unsigned char *dp,
|
||||||
void assignPixel(unsigned int bit_depth, unsigned char **data, unsigned long pixel) {
|
unsigned long pixel)
|
||||||
unsigned char *pixel_data = *data;
|
|
||||||
switch (bit_depth) {
|
|
||||||
case 8: // 8bpp
|
|
||||||
*pixel_data++ = pixel;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 16: // 16bpp LSB
|
|
||||||
*pixel_data++ = pixel;
|
|
||||||
*pixel_data++ = pixel >> 8;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 17: // 16bpp MSB
|
|
||||||
*pixel_data++ = pixel >> 8;
|
|
||||||
*pixel_data++ = pixel;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 24: // 24bpp LSB
|
|
||||||
*pixel_data++ = pixel;
|
|
||||||
*pixel_data++ = pixel >> 8;
|
|
||||||
*pixel_data++ = pixel >> 16;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 25: // 24bpp MSB
|
|
||||||
*pixel_data++ = pixel >> 16;
|
|
||||||
*pixel_data++ = pixel >> 8;
|
|
||||||
*pixel_data++ = pixel;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 32: // 32bpp LSB
|
|
||||||
*pixel_data++ = pixel;
|
|
||||||
*pixel_data++ = pixel >> 8;
|
|
||||||
*pixel_data++ = pixel >> 16;
|
|
||||||
*pixel_data++ = pixel >> 24;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 33: // 32bpp MSB
|
|
||||||
*pixel_data++ = pixel >> 24;
|
|
||||||
*pixel_data++ = pixel >> 16;
|
|
||||||
*pixel_data++ = pixel >> 8;
|
|
||||||
*pixel_data++ = pixel;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
*data = pixel_data; // assign back so we don't lose our place
|
|
||||||
}
|
|
||||||
|
|
||||||
void renderPixel(XImage *im, unsigned char *dp, unsigned long pixel)
|
|
||||||
{
|
{
|
||||||
unsigned int bpp = im->bits_per_pixel + (im->byte_order == MSBFirst) ? 1 : 0;
|
unsigned int bpp = im->bits_per_pixel + (im->byte_order == MSBFirst) ? 1 : 0;
|
||||||
|
|
||||||
|
@ -143,6 +94,8 @@ void renderPixel(XImage *im, unsigned char *dp, unsigned long pixel)
|
||||||
*dp++ = pixel >> 8;
|
*dp++ = pixel >> 8;
|
||||||
*dp++ = pixel;
|
*dp++ = pixel;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
assert(false); // wtf?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,7 +113,7 @@ void TrueRenderControl::render(Widget *wi)
|
||||||
//GC gc = XCreateGC(**display, _screen->rootWindow(), GCCapStyle, &gcv);
|
//GC gc = XCreateGC(**display, _screen->rootWindow(), GCCapStyle, &gcv);
|
||||||
|
|
||||||
// XXX + 1?
|
// XXX + 1?
|
||||||
unsigned char *data = new unsigned char[im->bytes_per_line * (h + 1)];
|
unsigned char *data = new unsigned char[im->bytes_per_line * h];
|
||||||
unsigned char *dp = data;
|
unsigned char *dp = data;
|
||||||
|
|
||||||
for (int x = 0; x < w; ++x, dp += im->bits_per_pixel/8)
|
for (int x = 0; x < w; ++x, dp += im->bits_per_pixel/8)
|
||||||
|
@ -175,7 +128,7 @@ void TrueRenderControl::render(Widget *wi)
|
||||||
for (int x = 0; x < w; ++x, dp += im->bits_per_pixel/8)
|
for (int x = 0; x < w; ++x, dp += im->bits_per_pixel/8)
|
||||||
renderPixel(im, dp, _blue_color_table[x] << _blue_offset);
|
renderPixel(im, dp, _blue_color_table[x] << _blue_offset);
|
||||||
|
|
||||||
printf("\nDone\n");
|
printf("\nDone %d %d\n", im->bytes_per_line * h, dp - data);
|
||||||
|
|
||||||
im->data = (char*) data;
|
im->data = (char*) data;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue