rubidium@6872: /* $Id$ */ rubidium@6872: richk@6720: #include "../stdafx.h" rubidium@6872: #include "../gfx_func.h" rubidium@6872: #include "../zoom_func.h" richk@6720: #include "../debug.h" rubidium@6872: #include "32bpp_simple.hpp" rubidium@6872: richk@6720: #include "../table/sprites.h" richk@6720: richk@6720: static FBlitter_32bppSimple iFBlitter_32bppSimple; richk@6720: richk@6720: void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) richk@6720: { richk@6720: const SpriteLoader::CommonPixel *src, *src_line; richk@6720: uint32 *dst, *dst_line; richk@6720: richk@6720: /* Find where to start reading in the source sprite */ richk@6720: src_line = (const SpriteLoader::CommonPixel *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom); richk@6720: dst_line = (uint32 *)bp->dst + bp->top * bp->pitch + bp->left; richk@6720: richk@6720: for (int y = 0; y < bp->height; y++) { richk@6720: dst = dst_line; richk@6720: dst_line += bp->pitch; richk@6720: richk@6720: src = src_line; richk@6720: src_line += bp->sprite_width * ScaleByZoom(1, zoom); richk@6720: richk@6720: for (int x = 0; x < bp->width; x++) { richk@6720: switch (mode) { richk@6720: case BM_COLOUR_REMAP: richk@6720: /* In case the m-channel is zero, do not remap this pixel in any way */ richk@6720: if (src->m == 0) { richk@6720: if (src->a != 0) *dst = ComposeColourRGBA(src->r, src->g, src->b, src->a, *dst); richk@6720: } else { richk@6720: if (bp->remap[src->m] != 0) *dst = ComposeColourPA(this->LookupColourInPalette(bp->remap[src->m]), src->a, *dst); richk@6720: } richk@6720: break; richk@6720: richk@6720: case BM_TRANSPARENT: richk@6720: /* TODO -- We make an assumption here that the remap in fact is transparency, not some color. richk@6720: * This is never a problem with the code we produce, but newgrfs can make it fail... or at least: richk@6720: * we produce a result the newgrf maker didn't expect ;) */ richk@6720: richk@6720: /* Make the current color a bit more black, so it looks like this image is transparent */ rubidium@6870: if (src->a != 0) *dst = MakeTransparent(*dst, 192); richk@6720: break; richk@6720: richk@6720: default: richk@6720: if (src->a != 0) *dst = ComposeColourRGBA(src->r, src->g, src->b, src->a, *dst); richk@6720: break; richk@6720: } richk@6720: dst++; richk@6720: src += ScaleByZoom(1, zoom); richk@6720: } richk@6720: } richk@6720: } richk@6720: richk@6720: void Blitter_32bppSimple::DrawColorMappingRect(void *dst, int width, int height, int pal) richk@6720: { richk@6720: uint32 *udst = (uint32 *)dst; richk@6720: richk@6720: if (pal == PALETTE_TO_TRANSPARENT) { richk@6720: do { richk@6720: for (int i = 0; i != width; i++) { rubidium@6870: *udst = MakeTransparent(*udst, 154); richk@6720: udst++; richk@6720: } richk@6720: udst = udst - width + _screen.pitch; richk@6720: } while (--height); richk@6720: return; richk@6720: } richk@6720: if (pal == PALETTE_TO_STRUCT_GREY) { richk@6720: do { richk@6720: for (int i = 0; i != width; i++) { richk@6720: *udst = MakeGrey(*udst); richk@6720: udst++; richk@6720: } richk@6720: udst = udst - width + _screen.pitch; richk@6720: } while (--height); richk@6720: return; richk@6720: } richk@6720: richk@6720: DEBUG(misc, 0, "32bpp blitter doesn't know how to draw this color table ('%d')", pal); richk@6720: } richk@6720: richk@6720: Sprite *Blitter_32bppSimple::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator) richk@6720: { richk@6720: Sprite *dest_sprite; richk@6720: SpriteLoader::CommonPixel *dst; richk@6720: dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sprite->height * sprite->width * sizeof(SpriteLoader::CommonPixel)); richk@6720: richk@6720: dest_sprite->height = sprite->height; richk@6720: dest_sprite->width = sprite->width; richk@6720: dest_sprite->x_offs = sprite->x_offs; richk@6720: dest_sprite->y_offs = sprite->y_offs; richk@6720: richk@6720: dst = (SpriteLoader::CommonPixel *)dest_sprite->data; richk@6720: richk@6720: memcpy(dst, sprite->data, sprite->height * sprite->width * sizeof(SpriteLoader::CommonPixel)); richk@6720: for (int i = 0; i < sprite->height * sprite->width; i++) { richk@6720: if (dst[i].m != 0) { richk@6720: /* Pre-convert the mapping channel to a RGB value */ richk@6720: uint color = this->LookupColourInPalette(dst[i].m); richk@6720: dst[i].r = GB(color, 16, 8); richk@6720: dst[i].g = GB(color, 8, 8); richk@6720: dst[i].b = GB(color, 0, 8); richk@6720: } richk@6720: } richk@6720: richk@6720: return dest_sprite; richk@6720: }