From a4dd208a7955e25bca710d4bcf355de7e608b9e1 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Sat, 18 Jan 2003 06:12:29 +0000 Subject: [PATCH] use a bitshift on the rgb values instead of a color table --- otk/rendercontrol.hh | 6 ++---- otk/truerendercontrol.cc | 26 +++++++++----------------- otk/truerendercontrol.hh | 7 +++++++ 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/otk/rendercontrol.hh b/otk/rendercontrol.hh index c619597f..37119846 100644 --- a/otk/rendercontrol.hh +++ b/otk/rendercontrol.hh @@ -17,16 +17,14 @@ class RenderControl { protected: const ScreenInfo *_screen; - int _red_bits; - int _green_bits; - int _blue_bits; - + /* // color tables, meaning, 256 (possibly) different shades of each color, // based on the number of bits there are available for each color in the // visual unsigned char _red_color_table[256]; unsigned char _green_color_table[256]; unsigned char _blue_color_table[256]; + */ /* Bool _dither; diff --git a/otk/truerendercontrol.cc b/otk/truerendercontrol.cc index e23b2ef6..a1995c4c 100644 --- a/otk/truerendercontrol.cc +++ b/otk/truerendercontrol.cc @@ -35,20 +35,14 @@ TrueRenderControl::TrueRenderControl(const ScreenInfo *screen) green_mask = screen->visual()->green_mask; blue_mask = screen->visual()->blue_mask; - while (! (red_mask & 1)) { _red_offset++; red_mask >>= 1; } + while (! (red_mask & 1)) { _red_offset++; red_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; } - // scale available colorspace to match our 256x256x256 cube - _red_bits = 255 / red_mask; - _green_bits = 255 / green_mask; - _blue_bits = 255 / blue_mask; - - for (int i = 0; i < 256; i++) { - _red_color_table[i] = i / _red_bits; - _green_color_table[i] = i / _green_bits; - _blue_color_table[i] = i / _blue_bits; - } + _red_shift = _green_shift = _blue_shift = 8; + while (red_mask) { red_mask >>= 1; _red_shift--; } + while (green_mask) { green_mask >>= 1; _green_shift--; } + while (blue_mask) { blue_mask >>= 1; _blue_shift--; } } TrueRenderControl::~TrueRenderControl() @@ -117,15 +111,13 @@ void TrueRenderControl::drawBackground(Surface *sf, for (int y = 0; y < h/3; ++y) for (int x = 0; x < w; ++x, dp += im->bits_per_pixel/8) - renderPixel(im, dp, _red_color_table[255*x/w] << _red_offset); + renderPixel(im, dp, (255*x/w) << _red_offset << _red_shift); for (int y = 0; y < h/3; ++y) for (int x = 0; x < w; ++x, dp += im->bits_per_pixel/8) - renderPixel(im, dp, _green_color_table[255*x/w] << _green_offset); + renderPixel(im, dp, (255*x/w) << _green_offset << _green_shift); for (int y = 0; y < h/3; ++y) for (int x = 0; x < w; ++x, dp += im->bits_per_pixel/8) - renderPixel(im, dp, _blue_color_table[255*x/w] << _blue_offset); - - printf("\nDone %d %d\n", im->bytes_per_line * h, dp - data); + renderPixel(im, dp, (255*x/w) << _blue_offset << _blue_shift); im->data = (char*) data; diff --git a/otk/truerendercontrol.hh b/otk/truerendercontrol.hh index af057be8..dfa0aa34 100644 --- a/otk/truerendercontrol.hh +++ b/otk/truerendercontrol.hh @@ -13,6 +13,13 @@ private: int _green_offset; int _blue_offset; + // the number of bits to shift a color value (from 0-255) to fit it into the + // the color mask + int _red_shift; + int _green_shift; + int _blue_shift; + + public: TrueRenderControl(const ScreenInfo *screen); virtual ~TrueRenderControl(); -- 2.45.2