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