8bpp_simple.cpp

Go to the documentation of this file.
00001 /* $Id: 8bpp_simple.cpp 26541 2014-04-29 18:18:52Z frosch $ */
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 "8bpp_simple.hpp"
00015 
00017 static FBlitter_8bppSimple iFBlitter_8bppSimple;
00018 
00019 void Blitter_8bppSimple::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       uint colour = 0;
00037 
00038       switch (mode) {
00039         case BM_COLOUR_REMAP:
00040         case BM_CRASH_REMAP:
00041           colour = bp->remap[*src];
00042           break;
00043 
00044         case BM_TRANSPARENT:
00045           if (*src != 0) colour = bp->remap[*dst];
00046           break;
00047 
00048         default:
00049           colour = *src;
00050           break;
00051       }
00052       if (colour != 0) *dst = colour;
00053       dst++;
00054       src += ScaleByZoom(1, zoom);
00055     }
00056   }
00057 }
00058 
00059 Sprite *Blitter_8bppSimple::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
00060 {
00061   Sprite *dest_sprite;
00062   dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + (size_t)sprite->height * (size_t)sprite->width);
00063 
00064   dest_sprite->height = sprite->height;
00065   dest_sprite->width  = sprite->width;
00066   dest_sprite->x_offs = sprite->x_offs;
00067   dest_sprite->y_offs = sprite->y_offs;
00068 
00069   /* Copy over only the 'remap' channel, as that is what we care about in 8bpp */
00070   for (int i = 0; i < sprite->height * sprite->width; i++) {
00071     dest_sprite->data[i] = sprite->data[i].m;
00072   }
00073 
00074   return dest_sprite;
00075 }