2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file 8bpp_simple.cpp Implementation of the simple 8 bpp blitter. */
|
2007-06-12 12:27:40 +00:00
|
|
|
|
2007-06-11 11:50:49 +00:00
|
|
|
#include "../stdafx.h"
|
2007-12-23 10:56:02 +00:00
|
|
|
#include "../zoom_func.h"
|
2007-06-11 15:13:30 +00:00
|
|
|
#include "8bpp_simple.hpp"
|
2007-06-11 11:50:49 +00:00
|
|
|
|
2014-04-23 20:13:33 +00:00
|
|
|
#include "../safeguards.h"
|
|
|
|
|
2011-05-01 10:15:33 +00:00
|
|
|
/** Instantiation of the simple 8bpp blitter factory. */
|
2007-06-11 11:50:49 +00:00
|
|
|
static FBlitter_8bppSimple iFBlitter_8bppSimple;
|
|
|
|
|
|
|
|
void Blitter_8bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
|
|
|
|
{
|
2007-06-12 20:24:12 +00:00
|
|
|
const uint8 *src, *src_line;
|
|
|
|
uint8 *dst, *dst_line;
|
2007-06-11 11:50:49 +00:00
|
|
|
|
|
|
|
/* Find where to start reading in the source sprite */
|
2007-06-12 20:24:12 +00:00
|
|
|
src_line = (const uint8 *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom);
|
|
|
|
dst_line = (uint8 *)bp->dst + bp->top * bp->pitch + bp->left;
|
2007-06-11 11:50:49 +00:00
|
|
|
|
|
|
|
for (int y = 0; y < bp->height; y++) {
|
|
|
|
dst = dst_line;
|
|
|
|
dst_line += bp->pitch;
|
|
|
|
|
|
|
|
src = src_line;
|
|
|
|
src_line += bp->sprite_width * ScaleByZoom(1, zoom);
|
|
|
|
|
|
|
|
for (int x = 0; x < bp->width; x++) {
|
2009-02-09 02:57:15 +00:00
|
|
|
uint colour = 0;
|
2007-06-11 11:50:49 +00:00
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case BM_COLOUR_REMAP:
|
2014-04-13 19:22:23 +00:00
|
|
|
case BM_CRASH_REMAP:
|
2009-02-09 02:57:15 +00:00
|
|
|
colour = bp->remap[*src];
|
2007-06-11 11:50:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BM_TRANSPARENT:
|
2009-02-09 02:57:15 +00:00
|
|
|
if (*src != 0) colour = bp->remap[*dst];
|
2007-06-11 11:50:49 +00:00
|
|
|
break;
|
|
|
|
|
2014-10-06 18:45:51 +00:00
|
|
|
case BM_BLACK_REMAP:
|
2017-03-30 21:33:40 +00:00
|
|
|
if (*src != 0) *dst = 0;
|
2014-10-06 18:45:51 +00:00
|
|
|
break;
|
|
|
|
|
2007-06-11 11:50:49 +00:00
|
|
|
default:
|
2009-02-09 02:57:15 +00:00
|
|
|
colour = *src;
|
2007-06-11 11:50:49 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-02-09 02:57:15 +00:00
|
|
|
if (colour != 0) *dst = colour;
|
2007-06-11 11:50:49 +00:00
|
|
|
dst++;
|
|
|
|
src += ScaleByZoom(1, zoom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-06 19:38:36 +00:00
|
|
|
Sprite *Blitter_8bppSimple::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
|
2007-06-11 11:50:49 +00:00
|
|
|
{
|
|
|
|
Sprite *dest_sprite;
|
2013-11-25 13:06:33 +00:00
|
|
|
dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + (size_t)sprite->height * (size_t)sprite->width);
|
2007-06-11 11:50:49 +00:00
|
|
|
|
|
|
|
dest_sprite->height = sprite->height;
|
|
|
|
dest_sprite->width = sprite->width;
|
|
|
|
dest_sprite->x_offs = sprite->x_offs;
|
|
|
|
dest_sprite->y_offs = sprite->y_offs;
|
|
|
|
|
|
|
|
/* Copy over only the 'remap' channel, as that is what we care about in 8bpp */
|
|
|
|
for (int i = 0; i < sprite->height * sprite->width; i++) {
|
|
|
|
dest_sprite->data[i] = sprite->data[i].m;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dest_sprite;
|
|
|
|
}
|