Fixes for transparent Pixmaps under WIN32 from Matt.

git-svn-id: file:///fltk/svn/fltk/trunk@162 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Michael R Sweet 1998-12-15 15:42:35 +00:00
parent 30800cc268
commit 82d46419ba

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Pixmap.cxx,v 1.6 1998/12/06 15:12:23 mike Exp $"
// "$Id: Fl_Pixmap.cxx,v 1.7 1998/12/15 15:42:35 mike Exp $"
//
// Pixmap drawing code for the Fast Light Tool Kit (FLTK).
//
@ -37,6 +37,8 @@
#include <FL/Fl_Menu_Item.H>
#include <FL/Fl_Pixmap.H>
#include <stdio.h>
extern uchar **fl_mask_bitmap; // used by fl_draw_pixmap.C to store mask
void fl_restore_clip(); // in fl_rect.C
@ -66,29 +68,57 @@ void Fl_Pixmap::draw(int XP, int YP, int WP, int HP, int cx, int cy) {
fl_mask_bitmap = 0;
#ifdef WIN32 // Matt: mask done
if (bitmap) {
// we need to pad the lines out to words & swap the bits
// in each byte.
int w1 = (w+7)/8;
int w2 = ((w+15)/16)*2;
uchar* newarray = new uchar[w2*h];
const uchar* src = bitmap;
uchar* dest = newarray;
static uchar reverse[16] =
{ 0x00, 0x88, 0x44, 0xcc, 0x22, 0xaa, 0x66, 0xee,
0x11, 0x99, 0x55, 0xdd, 0x33, 0xbb, 0x77, 0xff };
for (int y=0; y < h; y++) {
for (int n = 0; n < w1; n++, src++)
*dest++ = ~((reverse[*src & 0x0f] & 0xf0) |
(reverse[(*src >> 4) & 0x0f] & 0x0f));
dest += w2-w1;
// this won't work ehen the user changes display mode during run or
// has two screens with differnet depths
static uchar hiNibble[16] =
{ 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
0x10, 0x90, 0x50, 0xd0, 0x20, 0xb0, 0x70, 0xf0 };
static uchar loNibble[16] =
{ 0x00, 0x08, 0x04, 0x0c, 0x02, 0x0a, 0x06, 0x0e,
0x01, 0x09, 0x05, 0x0d, 0x02, 0x0b, 0x07, 0x0f };
int np = GetDeviceCaps(fl_gc, PLANES); //: was always one on sample machines
int bpp = GetDeviceCaps(fl_gc, BITSPIXEL);//: 1,4,8,16,24,32 and more odd stuff?
int Bpr = (bpp*w+7)/8; //: bytes per row
int pad = Bpr&1, w1 = (w+7)/8, shr = ((w-1)&7)+1;
if (bpp==4) shr = (shr+1)/2;
uchar *newarray = new uchar[(Bpr+pad)*h], *dst = newarray, *src = bitmap;
for (int i=0; i<h; i++) {
//: this is slooow, but we do it only once per pixmap
for (int j=w1; j>0; j--) {
uchar b = *src++;
if (bpp==1) {
*dst++ = ( hiNibble[b&15] ) | ( loNibble[(b>>4)&15] );
} else if (bpp==4) {
for (int k=(j==1)?shr:4; k>0; k--) {
*dst++ = "\377\360\017\000"[b&3];
b = b >> 2;
}
} else {
for (int k=(j==1)?shr:8; k>0; k--) {
if (b&1) {
*dst++=0;
if (bpp>8) *dst++=0;
if (bpp>16) *dst++=0;
if (bpp>24) *dst++=0;
} else {
*dst++=0xff;
if (bpp>8) *dst++=0xff;
if (bpp>16) *dst++=0xff;
if (bpp>24) *dst++=0xff;
}
b = b >> 1;
}
}
}
dst += pad;
}
mask = (ulong)CreateBitmap(w, h, 1, 1, newarray);
mask = (ulong)CreateBitmap(w, h, np, bpp, newarray);
delete[] newarray;
}
#else
if (bitmap) {
mask = XCreateBitmapFromData(fl_display, fl_window,
(const char*)bitmap, (w+7)&-8, h);
(const char*)bitmap, (w+7)&-8, h);
delete[] bitmap;
}
#endif
@ -133,7 +163,7 @@ Fl_Pixmap::~Fl_Pixmap() {
}
static void pixmap_labeltype(
const Fl_Label* o, int x, int y, int w, int h, Fl_Align a)
const Fl_Label* o, int x, int y, int w, int h, Fl_Align a)
{
Fl_Pixmap* b = (Fl_Pixmap*)(o->value);
if (b->w<0) fl_measure_pixmap(b->data, b->w, b->h);
@ -166,5 +196,5 @@ void Fl_Pixmap::label(Fl_Menu_Item* o) {
}
//
// End of "$Id: Fl_Pixmap.cxx,v 1.6 1998/12/06 15:12:23 mike Exp $".
// End of "$Id: Fl_Pixmap.cxx,v 1.7 1998/12/15 15:42:35 mike Exp $".
//