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