peter1138@7368: /* $Id$ */ peter1138@7368: peter1138@7368: /** @file 8bpp_simple.cpp */ peter1138@7368: truelight@7348: #include "../stdafx.h" truelight@7348: #include "../zoom.hpp" truelight@7348: #include "../gfx.h" truelight@7357: #include "8bpp_simple.hpp" truelight@7348: truelight@7348: static FBlitter_8bppSimple iFBlitter_8bppSimple; truelight@7348: truelight@7348: void Blitter_8bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) truelight@7348: { truelight@7374: const uint8 *src, *src_line; truelight@7374: uint8 *dst, *dst_line; truelight@7348: truelight@7348: /* Find where to start reading in the source sprite */ truelight@7374: src_line = (const uint8 *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom); truelight@7374: dst_line = (uint8 *)bp->dst + bp->top * bp->pitch + bp->left; truelight@7348: truelight@7348: for (int y = 0; y < bp->height; y++) { truelight@7348: dst = dst_line; truelight@7348: dst_line += bp->pitch; truelight@7348: truelight@7348: src = src_line; truelight@7348: src_line += bp->sprite_width * ScaleByZoom(1, zoom); truelight@7348: truelight@7348: for (int x = 0; x < bp->width; x++) { truelight@7348: uint color = 0; truelight@7348: truelight@7348: switch (mode) { truelight@7348: case BM_COLOUR_REMAP: truelight@7348: color = bp->remap[*src]; truelight@7348: break; truelight@7348: truelight@7348: case BM_TRANSPARENT: truelight@7348: if (*src != 0) color = bp->remap[*dst]; truelight@7348: break; truelight@7348: truelight@7348: default: truelight@7348: color = *src; truelight@7348: break; truelight@7348: } truelight@7348: if (color != 0) *dst = color; truelight@7348: dst++; truelight@7348: src += ScaleByZoom(1, zoom); truelight@7348: } truelight@7348: } truelight@7348: } truelight@7348: truelight@7385: void Blitter_8bppSimple::DrawColorMappingRect(void *dst, int width, int height, int pal) truelight@7385: { truelight@7385: const uint8 *ctab = GetNonSprite(pal) + 1; truelight@7385: truelight@7385: do { truelight@7385: for (int i = 0; i != width; i++) _screen.renderer->SetPixel(dst, i, 0, ctab[((uint8 *)dst)[i]]); truelight@7385: dst = _screen.renderer->MoveTo(dst, 0, 1); truelight@7385: } while (height--); truelight@7385: } truelight@7385: truelight@7352: Sprite *Blitter_8bppSimple::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator) truelight@7348: { truelight@7348: Sprite *dest_sprite; truelight@7352: dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sprite->height * sprite->width);; truelight@7348: truelight@7348: dest_sprite->height = sprite->height; truelight@7348: dest_sprite->width = sprite->width; truelight@7348: dest_sprite->x_offs = sprite->x_offs; truelight@7348: dest_sprite->y_offs = sprite->y_offs; truelight@7348: truelight@7348: /* Copy over only the 'remap' channel, as that is what we care about in 8bpp */ truelight@7348: for (int i = 0; i < sprite->height * sprite->width; i++) { truelight@7348: dest_sprite->data[i] = sprite->data[i].m; truelight@7348: } truelight@7348: truelight@7348: return dest_sprite; truelight@7348: }