# 8bpp_debug.cpp

Go to the documentation of this file.

    00001 /* $Id: 8bpp_debug.cpp 15428 2009-02-09 02:57:15Z rubidium $ */
    00002
    00005 #include "../stdafx.h"
    00006 #include "../zoom_func.h"
    00007 #include "../core/random_func.hpp"
    00008 #include "8bpp_debug.hpp"
    00009
    00010 static FBlitter_8bppDebug iFBlitter_8bppDebug;
    00011
    00012 void Blitter_8bppDebug::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
    00013 {
    00014   const uint8 *src, *src_line;
    00015   uint8 *dst, *dst_line;
    00016
    00017   /* Find where to start reading in the source sprite */
    00018   src_line = (const uint8 *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom);
    00019   dst_line = (uint8 *)bp->dst + bp->top * bp->pitch + bp->left;
    00020
    00021   for (int y = 0; y < bp->height; y++) {
    00022     dst = dst_line;
    00023     dst_line += bp->pitch;
    00024
    00025     src = src_line;
    00026     src_line += bp->sprite_width * ScaleByZoom(1, zoom);
    00027
    00028     for (int x = 0; x < bp->width; x++) {
    00029       if (*src != 0) *dst = *src;
    00030       dst++;
    00031       src += ScaleByZoom(1, zoom);
    00032     }
    00033     assert(src <= src_line);
    00034   }
    00035 }
    00036
    00037 Sprite *Blitter_8bppDebug::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator)
    00038 {
    00039   Sprite *dest_sprite;
    00040   dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sprite->height * sprite->width);
    00041
    00042   dest_sprite->height = sprite->height;
    00043   dest_sprite->width  = sprite->width;
    00044   dest_sprite->x_offs = sprite->x_offs;
    00045   dest_sprite->y_offs = sprite->y_offs;
    00046
    00047   /* Write a random colour as sprite; this makes debugging really easy */
    00048   uint colour = InteractiveRandom() % 150 + 2;
    00049   for (int i = 0; i < sprite->height * sprite->width; i++) {
    00050     dest_sprite->data[i] = (sprite->data[i].m == 0) ? 0 : colour;
    00051   }
    00052
    00053   return dest_sprite;
    00054 }