Update: Translations from eints
[openttd-github.git] / src / blitter / 8bpp_simple.cpp
blob6686ec0e2ad4d90a720a215bb5eae00848ec690a
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
8 /** @file 8bpp_simple.cpp Implementation of the simple 8 bpp blitter. */
10 #include "../stdafx.h"
11 #include "../zoom_func.h"
12 #include "8bpp_simple.hpp"
14 #include "../safeguards.h"
16 /** Instantiation of the simple 8bpp blitter factory. */
17 static FBlitter_8bppSimple iFBlitter_8bppSimple;
19 void Blitter_8bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
21 const uint8_t *src, *src_line;
22 uint8_t *dst, *dst_line;
24 /* Find where to start reading in the source sprite */
25 src_line = (const uint8_t *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom);
26 dst_line = (uint8_t *)bp->dst + bp->top * bp->pitch + bp->left;
28 for (int y = 0; y < bp->height; y++) {
29 dst = dst_line;
30 dst_line += bp->pitch;
32 src = src_line;
33 src_line += bp->sprite_width * ScaleByZoom(1, zoom);
35 for (int x = 0; x < bp->width; x++) {
36 uint colour = 0;
38 switch (mode) {
39 case BM_COLOUR_REMAP:
40 case BM_CRASH_REMAP:
41 colour = bp->remap[*src];
42 break;
44 case BM_TRANSPARENT:
45 case BM_TRANSPARENT_REMAP:
46 if (*src != 0) colour = bp->remap[*dst];
47 break;
49 case BM_BLACK_REMAP:
50 if (*src != 0) *dst = 0;
51 break;
53 default:
54 colour = *src;
55 break;
57 if (colour != 0) *dst = colour;
58 dst++;
59 src += ScaleByZoom(1, zoom);
64 Sprite *Blitter_8bppSimple::Encode(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator)
66 Sprite *dest_sprite;
67 dest_sprite = allocator.Allocate<Sprite>(sizeof(*dest_sprite) + static_cast<size_t>(sprite[ZOOM_LVL_MIN].height) * static_cast<size_t>(sprite[ZOOM_LVL_MIN].width));
69 dest_sprite->height = sprite[ZOOM_LVL_MIN].height;
70 dest_sprite->width = sprite[ZOOM_LVL_MIN].width;
71 dest_sprite->x_offs = sprite[ZOOM_LVL_MIN].x_offs;
72 dest_sprite->y_offs = sprite[ZOOM_LVL_MIN].y_offs;
74 /* Copy over only the 'remap' channel, as that is what we care about in 8bpp */
75 for (int i = 0; i < sprite[ZOOM_LVL_MIN].height * sprite[ZOOM_LVL_MIN].width; i++) {
76 dest_sprite->data[i] = sprite[ZOOM_LVL_MIN].data[i].m;
79 return dest_sprite;