--- /tmp/mw/microwindows-0.91/src/engine/devdraw.c 2003-11-16 23:34:12.000000000 +0100 +++ apps/src/microwin/src/engine/devdraw.c 2005-04-20 09:52:19.000000000 +0200 @@ -798,25 +798,6 @@ transcolor = pimage->transcolor; bpp = pimage->bpp; - /* - * Merge the images's palette and build a palette index conversion table. - */ - if (pimage->bpp <= 8) { - if(!pimage->palette) { - /* for jpeg's without a palette*/ - for(yoff=0; yoffpalsize; ++yoff) - convtable[yoff] = yoff; - } else GdMakePaletteConversionTable(psd, pimage->palette, - pimage->palsize, convtable, MERGEPALETTE); - - /* The following is no longer used. One reason is that it required */ - /* the transparent color to be unique, which was unnessecary */ - - /* convert transcolor to converted palette index for speed*/ - /* if (transcolor != -1L) - transcolor = (unsigned long) convtable[transcolor]; */ - } - minx = x; maxx = x + width - 1; imagebits = pimage->imagebits; @@ -855,6 +836,8 @@ if ((bpp == 32) && ((pimage->compression & MWIMAGE_ALPHA_CHANNEL) != 0)) { + unsigned int old; + unsigned char r1, g1, b1, r2, g2, b2, a, aa; long *data = (long *) imagebits; /* DPRINTF("Nano-X: GdDrawImage (%d,%d) %dx%d x=%d-%d\n ", @@ -863,56 +846,57 @@ while (height > 0) { cr = *data++; + + if (clip == CLIP_VISIBLE || GdClipPoint(psd, x, y)) { #if MW_CPU_BIG_ENDIAN - if (rgborder) - { - /* Fix endian and swap R/B order */ - cr = ((cr & 0xFFFFFF00UL) >> 8) - | ((cr & 0x000000FFUL) << 24); - } - else - { - /* Fix endian */ - cr = ((cr & 0xFF000000UL) >> 24) - | ((cr & 0x00FF0000UL) >> 8) - | ((cr & 0x0000FF00UL) << 8) - | ((cr & 0x000000FFUL) << 24); - } + if (rgborder) { + /* Fix endian and swap R/B order */ + cr = ((cr & 0xFFFFFF00UL) >> 8) + | ((cr & 0x000000FFUL) << 24); + } + else { + /* Fix endian */ + cr = ((cr & 0xFF000000UL) >> 24) + | ((cr & 0x00FF0000UL) >> 8) + | ((cr & 0x0000FF00UL) << 8) + | ((cr & 0x000000FFUL) << 24); + } #else /* little endian*/ - if (rgborder) { - /* Swap R/B order */ - cr = (cr & 0xFF00FF00UL) - | ((cr & 0x00FF0000UL) >> 16) - | ((cr & 0x000000FFUL) << 16); - } + if (rgborder) { + /* Swap R/B order */ + cr = (cr & 0xFF00FF00UL) + | ((cr & 0x00FF0000UL) >> 16) + | ((cr & 0x000000FFUL) << 16); + } #endif - - switch (psd->pixtype) { - case MWPF_PALETTE: - default: - pixel = GdFindColor(psd, cr); - break; - case MWPF_TRUECOLOR8888: - pixel = COLOR2PIXEL8888(cr); - break; - case MWPF_TRUECOLOR0888: - case MWPF_TRUECOLOR888: - pixel = COLOR2PIXEL888(cr); - break; - case MWPF_TRUECOLOR565: - pixel = COLOR2PIXEL565(cr); - break; - case MWPF_TRUECOLOR555: - pixel = COLOR2PIXEL555(cr); - break; - case MWPF_TRUECOLOR332: - pixel = COLOR2PIXEL332(cr); - break; + a = (unsigned char)(cr >> 24); + /* often used shortcut: 0 -> keep old pixel */ + if (a != 0) { + /* often used shortcut: 255 -> only new pixel */ + if (a != 255) + { + b2 = (unsigned char)(cr >> 16); + g2 = (unsigned char)(cr >> 8); + r2 = (unsigned char)(cr); + + old = psd->ReadPixel(psd, x, y); + old = GdGetColorRGB(psd, old); + + b1 = (unsigned char)(old >> 16); + g1 = (unsigned char)(old >> 8); + r1 = (unsigned char)(old); + + aa = 255 - a; + r2 = (r2 * a + r1 * aa) / 256; + g2 = (g2 * a + g1 * aa) / 256; + b2 = (b2 * a + b1 * aa) / 256; + cr = MWRGB(r2, g2, b2); + } + pixel = GdFindColor(psd, cr); + psd->DrawPixel(psd, x, y, pixel); + } } - if (clip == CLIP_VISIBLE || GdClipPoint(psd, x, y)) - psd->DrawPixel(psd, x, y, pixel); - if (x++ == maxx) { /* printf("EOL\n "); */ x = minx; @@ -992,7 +976,31 @@ imagebits += extra; } } - } else { /* bpp == 8, 4, or 1, palettized image. */ + } else if (bpp == 8 && !pimage->palsize) { /* 8 bpp grayscale */ + unsigned char val; + + while (height > 0) { + val = *imagebits; + imagebits++; + + /* handle transparent color */ + if (transcolor != val) { + if (clip == CLIP_VISIBLE + || GdClipPoint(psd, x, y)) + { + pixel = GdFindColor(psd, (val << 16) | (val << 8) | val); + psd->DrawPixel(psd, x, y, pixel); + } + } + + if (x++ == maxx) { + x = minx; + y += yoff; + height--; + imagebits += extra; + } + } + } else if (pimage->palsize) { /* bpp == 8, 4, or 1, palettized image. */ bitcount = 0; while (height > 0) {