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