src/blitter/8bpp_slow.cpp
branchgamebalance
changeset 9913 e79cd19772dd
parent 9912 1ac8aac92385
equal deleted inserted replaced
9912:1ac8aac92385 9913:e79cd19772dd
     1 #include "../stdafx.h"
       
     2 #include "../zoom.hpp"
       
     3 #include "../gfx.h"
       
     4 #include "8bpp_slow.hpp"
       
     5 
       
     6 static FBlitter_8bppSimple iFBlitter_8bppSimple;
       
     7 
       
     8 void Blitter_8bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
       
     9 {
       
    10 	const byte *src, *src_line;
       
    11 	Pixel8 *dst, *dst_line;
       
    12 
       
    13 	/* Find where to start reading in the source sprite */
       
    14 	src_line = (const byte *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom);
       
    15 	dst_line = (Pixel8 *)bp->dst + bp->top * bp->pitch + bp->left;
       
    16 
       
    17 	for (int y = 0; y < bp->height; y++) {
       
    18 		dst = dst_line;
       
    19 		dst_line += bp->pitch;
       
    20 
       
    21 		src = src_line;
       
    22 		src_line += bp->sprite_width * ScaleByZoom(1, zoom);
       
    23 
       
    24 		for (int x = 0; x < bp->width; x++) {
       
    25 			uint color = 0;
       
    26 
       
    27 			switch (mode) {
       
    28 				case BM_COLOUR_REMAP:
       
    29 					color = bp->remap[*src];
       
    30 					break;
       
    31 
       
    32 				case BM_TRANSPARENT:
       
    33 					if (*src != 0) color = bp->remap[*dst];
       
    34 					break;
       
    35 
       
    36 				default:
       
    37 					color = *src;
       
    38 					break;
       
    39 			}
       
    40 			if (color != 0) *dst = color;
       
    41 			dst++;
       
    42 			src += ScaleByZoom(1, zoom);
       
    43 		}
       
    44 	}
       
    45 }
       
    46 
       
    47 Sprite *Blitter_8bppSimple::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator)
       
    48 {
       
    49 	Sprite *dest_sprite;
       
    50 	dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sprite->height * sprite->width);;
       
    51 
       
    52 	dest_sprite->height = sprite->height;
       
    53 	dest_sprite->width  = sprite->width;
       
    54 	dest_sprite->x_offs = sprite->x_offs;
       
    55 	dest_sprite->y_offs = sprite->y_offs;
       
    56 
       
    57 	/* Copy over only the 'remap' channel, as that is what we care about in 8bpp */
       
    58 	for (int i = 0; i < sprite->height * sprite->width; i++) {
       
    59 		dest_sprite->data[i] = sprite->data[i].m;
       
    60 	}
       
    61 
       
    62 	return dest_sprite;
       
    63 }