summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerek Foreman <manmower@gmail.com>2003-02-14 01:49:27 +0000
committerDerek Foreman <manmower@gmail.com>2003-02-14 01:49:27 +0000
commit1431cd19584e750309561e0054fd013d566965cb (patch)
tree909fe0a18ac2bfb522977cce9efa03f3f14e652e
parent238355f190d9a147f812605af5506173e788e378 (diff)
8bpp pseudo color. it's horrid code. the graphics are horrid.
I have done many terrible things and I'm so very very sorry. :(
-rw-r--r--otk/pseudorendercontrol.cc52
-rw-r--r--otk/pseudorendercontrol.hh1
2 files changed, 38 insertions, 15 deletions
diff --git a/otk/pseudorendercontrol.cc b/otk/pseudorendercontrol.cc
index f2cf8059..89e95ab6 100644
--- a/otk/pseudorendercontrol.cc
+++ b/otk/pseudorendercontrol.cc
@@ -27,28 +27,31 @@ PseudoRenderControl::PseudoRenderControl(int screen)
int depth = info->depth();
// determine the number of colors and the bits-per-color
- int bpc = 2; // XXX THIS SHOULD BE A USER OPTION
- assert(bpc >= 1);
- _ncolors = 1 << (bpc * 3);
+ _bpc = 2; // XXX THIS SHOULD BE A USER OPTION
+ assert(_bpc >= 1);
+ _ncolors = 1 << (_bpc * 3);
if (_ncolors > 1 << depth) {
fprintf(stderr,
_("PseudoRenderControl: Invalid colormap size. Resizing.\n"));
- bpc = 1 << (depth/3) >> 3;
- _ncolors = 1 << (bpc * 3);
+ _bpc = 1 << (depth/3) >> 3;
+ _ncolors = 1 << (_bpc * 3);
}
// build a color cube
_colors = new XColor[_ncolors];
-
- int cpc = 1 << bpc; // colors per channel
- for (int n = _ncolors - 1,
- r = (1 << (bpc + 1)) -1, i = 0; i < cpc; r >>= 1, ++i)
- for (int g = (1 << (bpc + 1)) -1, j = 0; j < cpc; g >>= 1, ++j)
- for (int b = (1 << (bpc + 1)) -1, k = 0; k < cpc; b >>= 1, ++k, --n) {
- _colors[n].red = r | r << 8;
- _colors[n].green = g | g << 8;
- _colors[n].blue = b | b << 8;
+int tr, tg, tb;
+ int cpc = 1 << _bpc; // colors per channel
+ for (int n = 0,
+ r = 0; r < cpc; r++)
+ for (int g = 0; g < cpc; g++)
+ for (int b = 0; b < cpc; b++, n++) {
+ tr = (int)(((float)(r)/(float)(cpc-1)) * 0xFF);
+ tg = (int)(((float)(g)/(float)(cpc-1)) * 0xFF);
+ tb = (int)(((float)(b)/(float)(cpc-1)) * 0xFF);
+ _colors[n].red = tr | tr << 8;
+ _colors[n].green = tg | tg << 8;
+ _colors[n].blue = tb | tb << 8;
_colors[n].flags = DoRed|DoGreen|DoBlue; // used to track allocation
}
@@ -87,10 +90,12 @@ PseudoRenderControl::PseudoRenderControl(int screen)
_colors[i].red = icolors[close].red;
_colors[i].green = icolors[close].green;
_colors[i].blue = icolors[close].blue;
+ _colors[i].pixel = icolors[close].pixel;
// try alloc this closest color, it had better succeed!
- if (XAllocColor(**display, info->colormap(), &_colors[i]))
+ if (XAllocColor(**display, info->colormap(), &_colors[i])) {
_colors[i].flags = DoRed|DoGreen|DoBlue; // mark as alloced
+ }
else
assert(false); // wtf has gone wrong, its already alloced for chissake!
}
@@ -111,6 +116,23 @@ PseudoRenderControl::~PseudoRenderControl()
void PseudoRenderControl::reduceDepth(Surface &sf, XImage *im) const
{
+ pixel32 *data = sf.pixelData();
+ char *p = (char *)data;
+ int x, y, r, g, b;
+ for (y = 0; y < im->height; y++) {
+ for (x = 0; x < im->width; x++) {
+ r = (data[x] >> default_red_shift) & 0xFF;
+ r = r >> (8-_bpc);
+ g = (data[x] >> default_green_shift) & 0xFF;
+ g = g >> (8-_bpc);
+ b = (data[x] >> default_blue_shift) & 0xFF;
+ b = b >> (8-_bpc);
+ p[x] = _colors[(r << (2*_bpc)) + (g << (1*_bpc)) + b].pixel;
+ }
+ data += im->width;
+ p += im->bytes_per_line;
+ }
+
}
}
diff --git a/otk/pseudorendercontrol.hh b/otk/pseudorendercontrol.hh
index 27d06206..a52e7cc3 100644
--- a/otk/pseudorendercontrol.hh
+++ b/otk/pseudorendercontrol.hh
@@ -8,6 +8,7 @@ namespace otk {
class PseudoRenderControl : public RenderControl {
private:
+ int _bpc; // number of bits per color
int _ncolors; // number of allocated colors, size of the XColor array
XColor *_colors; // the valid allocated colors