src/blitter/8bpp_slow.cpp
changeset 6852 439563b70fd3
child 6856 aa95d0fd29f1
equal deleted inserted replaced
6851:0a0a094fb9f1 6852:439563b70fd3
       
     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 extern void* AllocSprite(size_t);
       
     9 
       
    10 void Blitter_8bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
       
    11 {
       
    12 	const byte *src, *src_line;
       
    13 	Pixel8 *dst, *dst_line;
       
    14 
       
    15 	/* Find where to start reading in the source sprite */
       
    16 	src_line = (const byte *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom);
       
    17 	dst_line = (Pixel8 *)bp->dst + bp->top * bp->pitch + bp->left;
       
    18 
       
    19 	for (int y = 0; y < bp->height; y++) {
       
    20 		dst = dst_line;
       
    21 		dst_line += bp->pitch;
       
    22 
       
    23 		src = src_line;
       
    24 		src_line += bp->sprite_width * ScaleByZoom(1, zoom);
       
    25 
       
    26 		for (int x = 0; x < bp->width; x++) {
       
    27 			uint color = 0;
       
    28 
       
    29 			switch (mode) {
       
    30 				case BM_COLOUR_REMAP:
       
    31 					color = bp->remap[*src];
       
    32 					break;
       
    33 
       
    34 				case BM_TRANSPARENT:
       
    35 					if (*src != 0) color = bp->remap[*dst];
       
    36 					break;
       
    37 
       
    38 				default:
       
    39 					color = *src;
       
    40 					break;
       
    41 			}
       
    42 			if (color != 0) *dst = color;
       
    43 			dst++;
       
    44 			src += ScaleByZoom(1, zoom);
       
    45 		}
       
    46 	}
       
    47 }
       
    48 
       
    49 Sprite *Blitter_8bppSimple::Encode(SpriteLoader::Sprite *sprite)
       
    50 {
       
    51 	Sprite *dest_sprite;
       
    52 	dest_sprite = (Sprite *)AllocSprite(sizeof(*dest_sprite) + sprite->height * sprite->width);
       
    53 
       
    54 	dest_sprite->height = sprite->height;
       
    55 	dest_sprite->width  = sprite->width;
       
    56 	dest_sprite->x_offs = sprite->x_offs;
       
    57 	dest_sprite->y_offs = sprite->y_offs;
       
    58 
       
    59 	/* Copy over only the 'remap' channel, as that is what we care about in 8bpp */
       
    60 	for (int i = 0; i < sprite->height * sprite->width; i++) {
       
    61 		dest_sprite->data[i] = sprite->data[i].m;
       
    62 	}
       
    63 
       
    64 	return dest_sprite;
       
    65 }