Added color reduction for 16bpp displays
This commit is contained in:
parent
47fb66e54b
commit
d4e4e25e28
2 changed files with 39 additions and 7 deletions
|
@ -156,19 +156,19 @@ void TrueRenderControl::drawGradientBackground(
|
|||
if (texture.bevel() == RenderTexture::Bevel1) {
|
||||
for (off = 1, x = 1; x < w - 1; ++x, off++)
|
||||
highlight(data + off,
|
||||
data + off + (h-1) * w,
|
||||
texture.relief()==RenderTexture::Raised);
|
||||
data + off + (h-1) * w,
|
||||
texture.relief()==RenderTexture::Raised);
|
||||
for (off = 0, x = 0; x < h; ++x, off++)
|
||||
highlight(data + off * w,
|
||||
data + off * w + w - 1,
|
||||
texture.relief()==RenderTexture::Raised);
|
||||
data + off * w + w - 1,
|
||||
texture.relief()==RenderTexture::Raised);
|
||||
}
|
||||
|
||||
if (texture.bevel() == RenderTexture::Bevel2) {
|
||||
for (off = 2, x = 2; x < w - 2; ++x, off++)
|
||||
highlight(data + off + w,
|
||||
data + off + (h-2) * w,
|
||||
texture.relief()==RenderTexture::Raised);
|
||||
data + off + (h-2) * w,
|
||||
texture.relief()==RenderTexture::Raised);
|
||||
for (off = 1, x = 1; x < h-1; ++x, off++)
|
||||
highlight(data + off * w + 1,
|
||||
data + off * w + w - 2,
|
||||
|
@ -176,7 +176,8 @@ void TrueRenderControl::drawGradientBackground(
|
|||
}
|
||||
}
|
||||
|
||||
//XXX: any dithering should be done now
|
||||
reduceDepth(im, data);
|
||||
|
||||
im->data = (char*) data;
|
||||
|
||||
sf.setPixmap(im);
|
||||
|
@ -186,6 +187,34 @@ void TrueRenderControl::drawGradientBackground(
|
|||
XDestroyImage(im);
|
||||
}
|
||||
|
||||
void TrueRenderControl::reduceDepth(XImage *im, pixel32 *data) const
|
||||
{
|
||||
int r, g, b;
|
||||
int x,y;
|
||||
pixel16 *p = (pixel16 *)data;
|
||||
switch (im->bits_per_pixel) {
|
||||
case 32:
|
||||
return;
|
||||
case 16:
|
||||
for (y = 0; y < im->height; y++) {
|
||||
for (x = 0; x < im->width; x++) {
|
||||
r = (data[x] >> 16) & 0xFF;
|
||||
r = r >> _red_shift;
|
||||
g = (data[x] >> 8) & 0xFF;
|
||||
g = g >> _green_shift;
|
||||
b = data[x] & 0xFF;
|
||||
b = b >> _blue_shift;
|
||||
p[x] = (r << _red_offset) + (g << _green_offset) + (b << _blue_offset);
|
||||
}
|
||||
data += im->width;
|
||||
p += im->bytes_per_line/2;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
printf("your bit depth is currently unhandled\n");
|
||||
}
|
||||
}
|
||||
|
||||
void TrueRenderControl::highlight(pixel32 *x, pixel32 *y, bool raised) const
|
||||
{
|
||||
int r, g, b;
|
||||
|
|
|
@ -22,8 +22,10 @@ namespace otk {
|
|||
|
||||
#ifdef HAVE_STDINT_H
|
||||
typedef uint32_t pixel32;
|
||||
typedef uint16_t pixel16;
|
||||
#else
|
||||
typedef u_int32_t pixel32;
|
||||
typedef u_int16_t pixel16;
|
||||
#endif
|
||||
|
||||
class TrueRenderControl : public RenderControl {
|
||||
|
@ -48,6 +50,7 @@ public:
|
|||
const RenderTexture &texture) const;
|
||||
|
||||
inline void highlight(pixel32 *x, pixel32 *y, bool raised) const;
|
||||
void reduceDepth(XImage *im, pixel32 *data) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue