# 8bpp_debug.cpp

Go to the documentation of this file.

    00001 /* $Id$ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
    00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
    00008  */
    00009
    00012 #include "../stdafx.h"
    00013 #include "../zoom_func.h"
    00014 #include "../core/random_func.hpp"
    00015 #include "8bpp_debug.hpp"
    00016
    00017 static FBlitter_8bppDebug iFBlitter_8bppDebug;
    00018
    00019 void Blitter_8bppDebug::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
    00020 {
    00021   const uint8 *src, *src_line;
    00022   uint8 *dst, *dst_line;
    00023
    00024   /* Find where to start reading in the source sprite */
    00025   src_line = (const uint8 *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom);
    00026   dst_line = (uint8 *)bp->dst + bp->top * bp->pitch + bp->left;
    00027
    00028   for (int y = 0; y < bp->height; y++) {
    00029     dst = dst_line;
    00030     dst_line += bp->pitch;
    00031
    00032     src = src_line;
    00033     src_line += bp->sprite_width * ScaleByZoom(1, zoom);
    00034
    00035     for (int x = 0; x < bp->width; x++) {
    00036       if (*src != 0) *dst = *src;
    00037       dst++;
    00038       src += ScaleByZoom(1, zoom);
    00039     }
    00040     assert(src <= src_line);
    00041   }
    00042 }
    00043
    00044 Sprite *Blitter_8bppDebug::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator)
    00045 {
    00046   Sprite *dest_sprite;
    00047   dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sprite->height * sprite->width);
    00048
    00049   dest_sprite->height = sprite->height;
    00050   dest_sprite->width  = sprite->width;
    00051   dest_sprite->x_offs = sprite->x_offs;
    00052   dest_sprite->y_offs = sprite->y_offs;
    00053
    00054   /* Write a random colour as sprite; this makes debugging really easy */
    00055   uint colour = InteractiveRandom() % 150 + 2;
    00056   for (int i = 0; i < sprite->height * sprite->width; i++) {
    00057     dest_sprite->data[i] = (sprite->data[i].m == 0) ? 0 : colour;
    00058   }
    00059
    00060   return dest_sprite;
    00061 }