From: Dana Jansens Date: Sat, 18 Jan 2003 02:25:32 +0000 (+0000) Subject: blef X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=5b52a8f5610d3cc0a39ecb6b341e69596d892099;p=chaz%2Fopenbox blef --- diff --git a/otk/truerendercontrol.cc b/otk/truerendercontrol.cc index 26fa06a7..95b629b1 100644 --- a/otk/truerendercontrol.cc +++ b/otk/truerendercontrol.cc @@ -57,6 +57,96 @@ TrueRenderControl::~TrueRenderControl() } +static inline +void assignPixel(unsigned int bit_depth, unsigned char **data, 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; + + printf("%lx \n", pixel); + + switch (bpp) { + case 8: // 8bpp + *dp++ = pixel; + break; + case 16: // 16bpp LSB + *dp++ = pixel; + *dp++ = pixel >> 8; + break; + case 17: // 16bpp MSB + *dp++ = pixel >> 8; + *dp++ = pixel; + break; + case 24: // 24bpp LSB + *dp++ = pixel; + *dp++ = pixel >> 8; + *dp++ = pixel >> 16; + break; + case 25: // 24bpp MSB + *dp++ = pixel >> 16; + *dp++ = pixel >> 8; + *dp++ = pixel; + break; + case 32: // 32bpp LSB + *dp++ = pixel; + *dp++ = pixel >> 8; + *dp++ = pixel >> 16; + *dp++ = pixel >> 24; + break; + case 33: // 32bpp MSB + *dp++ = pixel >> 24; + *dp++ = pixel >> 16; + *dp++ = pixel >> 8; + *dp++ = pixel; + break; + } +} + void TrueRenderControl::render(::Drawable d) { XGCValues gcv; @@ -68,23 +158,28 @@ void TrueRenderControl::render(::Drawable d) ZPixmap, 0, NULL, w, h, 32, 0); //GC gc = XCreateGC(**display, _screen->rootWindow(), GCCapStyle, &gcv); - im->data = new char[im->bytes_per_line * (h + 1)]; // XXX + 1? - char *dp = im->data; - - for (int x = 0; x < w; ++x, ++dp) - *dp = 0; - for (int y = 0; y < 10; ++h) - for (int x = 0; x < w; ++x, ++dp) - *dp = _red_color_table[x] << _red_offset; - for (int y = 0; y < 10; ++h) - for (int x = 0; x < w; ++x, ++dp) - *dp = _green_color_table[x] << _green_offset; - for (int y = 0; y < 10; ++h) - for (int x = 0; x < w; ++x, ++dp) - *dp = _blue_color_table[x] << _blue_offset; - for (int x = 0; x < w; ++x, ++dp) - *dp = 0; - + // XXX + 1? + unsigned char *data = new unsigned char[im->bytes_per_line * (h + 1)]; + unsigned char *dp = data; + + for (int x = 0; x < w; ++x, dp += im->bits_per_pixel/8) + renderPixel(im, dp, 0); + for (int y = 0; y < 10; ++y) + for (int x = 0; x < w; ++x, dp += im->bits_per_pixel/8) + renderPixel(im, dp, _red_color_table[x] << _red_offset); + for (int y = 0; y < 10; ++y) + for (int x = 0; x < w; ++x, dp += im->bits_per_pixel/8) + renderPixel(im, dp, _green_color_table[x] << _green_offset); + for (int y = 0; y < 10; ++y) + for (int x = 0; x < w; ++x, dp += im->bits_per_pixel/8) + renderPixel(im, dp, _blue_color_table[x] << _blue_offset); + for (int x = 0; x < w; ++x, dp += im->bits_per_pixel/8) + renderPixel(im, dp, 0); + + printf("\nDone\n"); + + im->data = (char*) data; + XPutImage(**display, p, DefaultGC(**display, _screen->screen()), im, 0, 0, 0, 0, w, h);