# 8bpp_simple.cpp

Go to the documentation of this file.

    00001 /* $Id: 8bpp_simple.cpp 26103 2013-11-25 13:06:33Z rubidium $ */
    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           colour = bp->remap[*src];
    00041           break;
    00042
    00043         case BM_TRANSPARENT:
    00044           if (*src != 0) colour = bp->remap[*dst];
    00045           break;
    00046
    00047         default:
    00048           colour = *src;
    00049           break;
    00050       }
    00051       if (colour != 0) *dst = colour;
    00052       dst++;
    00053       src += ScaleByZoom(1, zoom);
    00054     }
    00055   }
    00056 }
    00057
    00058 Sprite *Blitter_8bppSimple::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
    00059 {
    00060   Sprite *dest_sprite;
    00061   dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + (size_t)sprite->height * (size_t)sprite->width);
    00062
    00063   dest_sprite->height = sprite->height;
    00064   dest_sprite->width  = sprite->width;
    00065   dest_sprite->x_offs = sprite->x_offs;
    00066   dest_sprite->y_offs = sprite->y_offs;
    00067
    00068   /* Copy over only the 'remap' channel, as that is what we care about in 8bpp */
    00069   for (int i = 0; i < sprite->height * sprite->width; i++) {
    00070     dest_sprite->data[i] = sprite->data[i].m;
    00071   }
    00072
    00073   return dest_sprite;
    00074 }