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