- if (surface->bpp == 8)
- {
- if (surface->clut.data)
- {
- lookup8_normal=getColor(surface->clut, background, foreground).lookup;
-
- int i;
- for (i=0; i<16; ++i)
- lookup8_invert[i] = lookup8_normal[i^0xF];
-
- opcode=0;
- } else
- opcode=1;
- } else if (surface->bpp == 16)
- {
- opcode=2;
- for (int i=0; i<16; ++i)
- {
-#define BLEND(y, x, a) (y + (((x-y) * a)>>8))
- unsigned char da = background.a, dr = background.r, dg = background.g, db = background.b;
- int sa = i * 16;
- if (sa < 256)
- {
- dr = BLEND(background.r, foreground.r, sa) & 0xFF;
- dg = BLEND(background.g, foreground.g, sa) & 0xFF;
- db = BLEND(background.b, foreground.b, sa) & 0xFF;
- }
-#undef BLEND
-#if BYTE_ORDER == LITTLE_ENDIAN
- lookup16_normal[i] = bswap_16(((db >> 3) << 11) | ((dg >> 2) << 5) | (dr >> 3));
-#else
- lookup16_normal[i] = ((db >> 3) << 11) | ((dg >> 2) << 5) | (dr >> 3);
-#endif
- da ^= 0xFF;
- }
- for (int i=0; i<16; ++i)
- lookup16_invert[i]=lookup16_normal[i^0xF];
- } else if (surface->bpp == 32)
- {
- opcode=3;
- for (int i=0; i<16; ++i)
- {
-#define BLEND(y, x, a) (y + (((x-y) * a)>>8))
-
- unsigned char da = background.a, dr = background.r, dg = background.g, db = background.b;
- int sa = i * 16;
- if (sa < 256)
- {
- da = BLEND(background.a, foreground.a, sa) & 0xFF;
- dr = BLEND(background.r, foreground.r, sa) & 0xFF;
- dg = BLEND(background.g, foreground.g, sa) & 0xFF;
- db = BLEND(background.b, foreground.b, sa) & 0xFF;
- }
-#undef BLEND
- da ^= 0xFF;
- lookup32_normal[i]=db | (dg << 8) | (dr << 16) | (da << 24);;
- }
- for (int i=0; i<16; ++i)
- lookup32_invert[i]=lookup32_normal[i^0xF];
- } else
- {
- eWarning("can't render to %dbpp", surface->bpp);
- return;
- }
-