src/blitter/8bpp_debug.cpp
changeset 7348 becce3f57dc7
child 7352 e2e8432018f6
equal deleted inserted replaced
7347:7a77358b0537 7348:becce3f57dc7
       
     1 #include "../stdafx.h"
       
     2 #include "../zoom.hpp"
       
     3 #include "../gfx.h"
       
     4 #include "../functions.h"
       
     5 #include "8bpp_debug.hpp"
       
     6 
       
     7 static FBlitter_8bppDebug iFBlitter_8bppDebug;
       
     8 
       
     9 extern void* AllocSprite(size_t);
       
    10 
       
    11 void Blitter_8bppDebug::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
       
    12 {
       
    13 	const byte *src, *src_line;
       
    14 	Pixel8 *dst, *dst_line;
       
    15 
       
    16 	/* Find where to start reading in the source sprite */
       
    17 	src_line = (const byte *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom);
       
    18 	dst_line = (Pixel8 *)bp->dst + bp->top * bp->pitch + bp->left;
       
    19 
       
    20 	for (int y = 0; y < bp->height; y++) {
       
    21 		dst = dst_line;
       
    22 		dst_line += bp->pitch;
       
    23 
       
    24 		src = src_line;
       
    25 		src_line += bp->sprite_width * ScaleByZoom(1, zoom);
       
    26 
       
    27 		for (int x = 0; x < bp->width; x++) {
       
    28 			if (*src != 0) *dst = *src;
       
    29 			dst++;
       
    30 			src += ScaleByZoom(1, zoom);
       
    31 		}
       
    32 		assert(src <= src_line);
       
    33 	}
       
    34 }
       
    35 
       
    36 Sprite *Blitter_8bppDebug::Encode(SpriteLoader::Sprite *sprite)
       
    37 {
       
    38 	Sprite *dest_sprite;
       
    39 	dest_sprite = (Sprite *)AllocSprite(sizeof(*dest_sprite) + sprite->height * sprite->width);
       
    40 
       
    41 	dest_sprite->height = sprite->height;
       
    42 	dest_sprite->width  = sprite->width;
       
    43 	dest_sprite->x_offs = sprite->x_offs;
       
    44 	dest_sprite->y_offs = sprite->y_offs;
       
    45 
       
    46 	/* Write a random color as sprite; this makes debugging really easy */
       
    47 	uint color = InteractiveRandom() % 150 + 2;
       
    48 	for (int i = 0; i < sprite->height * sprite->width; i++) {
       
    49 		dest_sprite->data[i] = (sprite->data[i].m == 0) ? 0 : color;
       
    50 	}
       
    51 
       
    52 	return dest_sprite;
       
    53 }