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 
00018 static FBlitter_8bppDebug iFBlitter_8bppDebug;
00019 
00020 void Blitter_8bppDebug::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
00021 {
00022   const uint8 *src, *src_line;
00023   uint8 *dst, *dst_line;
00024 
00025   /* Find where to start reading in the source sprite */
00026   src_line = (const uint8 *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom);
00027   dst_line = (uint8 *)bp->dst + bp->top * bp->pitch + bp->left;
00028 
00029   for (int y = 0; y < bp->height; y++) {
00030     dst = dst_line;
00031     dst_line += bp->pitch;
00032 
00033     src = src_line;
00034     src_line += bp->sprite_width * ScaleByZoom(1, zoom);
00035 
00036     for (int x = 0; x < bp->width; x++) {
00037       if (*src != 0) *dst = *src;
00038       dst++;
00039       src += ScaleByZoom(1, zoom);
00040     }
00041     assert(src <= src_line);
00042   }
00043 }
00044 
00045 Sprite *Blitter_8bppDebug::Encode(SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
00046 {
00047   Sprite *dest_sprite;
00048   dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sprite->height * sprite->width);
00049 
00050   dest_sprite->height = sprite->height;
00051   dest_sprite->width  = sprite->width;
00052   dest_sprite->x_offs = sprite->x_offs;
00053   dest_sprite->y_offs = sprite->y_offs;
00054 
00055   /* Write a random colour as sprite; this makes debugging really easy */
00056   uint colour = InteractiveRandom() % 150 + 2;
00057   for (int i = 0; i < sprite->height * sprite->width; i++) {
00058     dest_sprite->data[i] = (sprite->data[i].m == 0) ? 0 : colour;
00059   }
00060 
00061   return dest_sprite;
00062 }

Generated on Sun May 8 07:30:10 2011 for OpenTTD by  doxygen 1.6.1