Some code reformatting.

Fixed pixmap creating issue for 24-bit displays.
This commit is contained in:
Sanel Zukan 2009-11-23 12:52:03 +00:00
parent b25a148298
commit a324dc2eb0

View File

@ -38,7 +38,7 @@
if(bshift >= 0) \ if(bshift >= 0) \
tmp |= (((int)b << bshift) & bmask); \ tmp |= (((int)b << bshift) & bmask); \
else \ else \
tmp |= (((int)b >> (-bshift)) & bmask); tmp |= (((int)b >> (-bshift)) & bmask)
static Pixmap create_xpixmap(Fl_Image* img, XImage** xim, Pixmap pix, int wp_w, int wp_h) { static Pixmap create_xpixmap(Fl_Image* img, XImage** xim, Pixmap pix, int wp_w, int wp_h) {
@ -116,7 +116,8 @@ static Pixmap create_xpixmap(Fl_Image* img, XImage** xim, Pixmap pix, int wp_w,
msb = false; msb = false;
unsigned int r, g, b, tmp; unsigned int r, g, b, tmp;
unsigned char* dest = (unsigned char*)malloc(sizeof(unsigned char) * iw * ih * id); //unsigned char* dest = (unsigned char*)malloc(sizeof(unsigned char) * iw * ih * id);
unsigned char* dest = (unsigned char*)malloc(ih * (*xim)->bytes_per_line);
unsigned char* destptr = dest; unsigned char* destptr = dest;
unsigned char* src = (unsigned char*)img->data()[0]; unsigned char* src = (unsigned char*)img->data()[0];
@ -134,17 +135,11 @@ static Pixmap create_xpixmap(Fl_Image* img, XImage** xim, Pixmap pix, int wp_w,
CALC_PIXEL(tmp, rshift, rmask, gshift, gmask, bshift, bmask); CALC_PIXEL(tmp, rshift, rmask, gshift, gmask, bshift, bmask);
if(msb) { if(msb) {
// big endian
*destptr++ = (tmp & 0xff000000) >> 24; *destptr++ = (tmp & 0xff000000) >> 24;
*destptr++ = (tmp & 0xff0000) >> 16; *destptr++ = (tmp & 0xff0000) >> 16;
*destptr++ = (tmp & 0xff00) >> 8; *destptr++ = (tmp & 0xff00) >> 8;
// FIXME: check this somehow !
if(id == 4)
*destptr++ = (tmp & 0xff); *destptr++ = (tmp & 0xff);
} else { } else {
// little endian
if(id == 4)
*destptr++ = (tmp & 0xff); *destptr++ = (tmp & 0xff);
*destptr++ = (tmp & 0xff00) >> 8; *destptr++ = (tmp & 0xff00) >> 8;
*destptr++ = (tmp & 0xff0000) >> 16; *destptr++ = (tmp & 0xff0000) >> 16;
@ -187,13 +182,11 @@ static Pixmap create_xpixmap(Fl_Image* img, XImage** xim, Pixmap pix, int wp_w,
CALC_PIXEL(tmp, rshift, rmask, gshift, gmask, bshift, bmask); CALC_PIXEL(tmp, rshift, rmask, gshift, gmask, bshift, bmask);
if(msb) { if(msb) {
// big endian
*destptr++ = (tmp & 0xff0000) >> 16; *destptr++ = (tmp & 0xff0000) >> 16;
*destptr++ = (tmp & 0xff00) >> 8; *destptr++ = (tmp & 0xff00) >> 8;
*destptr++ = (tmp & 0xff); *destptr++ = (tmp & 0xff);
} else { } else {
// little endian
*destptr++ = (tmp & 0xff); *destptr++ = (tmp & 0xff);
*destptr++ = (tmp & 0xff00) >> 8; *destptr++ = (tmp & 0xff00) >> 8;
*destptr++ = (tmp & 0xff0000) >> 16; *destptr++ = (tmp & 0xff0000) >> 16;
@ -208,12 +201,10 @@ static Pixmap create_xpixmap(Fl_Image* img, XImage** xim, Pixmap pix, int wp_w,
b = *src++; b = *src++;
if(msb) { if(msb) {
// big endian
*destptr++ = b; *destptr++ = b;
*destptr++ = g; *destptr++ = g;
*destptr++ = r; *destptr++ = r;
} else { } else {
// little endian
*destptr++ = r; *destptr++ = r;
*destptr++ = g; *destptr++ = g;
*destptr++ = b; *destptr++ = b;
@ -235,12 +226,9 @@ static Pixmap create_xpixmap(Fl_Image* img, XImage** xim, Pixmap pix, int wp_w,
CALC_PIXEL(tmp, rshift, rmask, gshift, gmask, bshift, bmask); CALC_PIXEL(tmp, rshift, rmask, gshift, gmask, bshift, bmask);
if(msb) { if(msb) {
// big endian
*destptr++ = (tmp >> 8) & 0xff; *destptr++ = (tmp >> 8) & 0xff;
*destptr++ = (tmp & 0xff); *destptr++ = (tmp & 0xff);
} else { } else {
// little endian
*destptr++ = (tmp & 0xff); *destptr++ = (tmp & 0xff);
*destptr++ = (tmp >> 8) & 0xff; *destptr++ = (tmp >> 8) & 0xff;
} }