OpenTTD Source: src/blitter/8bpp_simple.cpp Source File

OpenTTD Source 13.2.1

8bpp_simple.cpp
Go to the documentation of this file.
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 */
7
10 #include "../stdafx.h"
11 #include "../zoom_func.h"
12 #include "8bpp_simple.hpp"
13
14 #include "../safeguards.h"
15
17 static FBlitter_8bppSimple iFBlitter_8bppSimple;
18
19 void Blitter_8bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
20 {
21 const uint8 *src, *src_line;
22 uint8 *dst, *dst_line;
23
24 /* Find where to start reading in the source sprite */
25 src_line = (const uint8 *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom);
26 dst_line = (uint8 *)bp->dst + bp->top * bp->pitch + bp->left;
27
28 for (int y = 0; y < bp->height; y++) {
29 dst = dst_line;
30 dst_line += bp->pitch;
31
32 src = src_line;
33 src_line += bp->sprite_width * ScaleByZoom(1, zoom);
34
35 for (int x = 0; x < bp->width; x++) {
36 uint colour = 0;
37
38 switch (mode) {
39 case BM_COLOUR_REMAP:
40 case BM_CRASH_REMAP:
41 colour = bp->remap[*src];
42 break;
43
44 case BM_TRANSPARENT:
45 if (*src != 0) colour = bp->remap[*dst];
46 break;
47
48 case BM_BLACK_REMAP:
49 if (*src != 0) *dst = 0;
50 break;
51
52 default:
53 colour = *src;
54 break;
55 }
56 if (colour != 0) *dst = colour;
57 dst++;
58 src += ScaleByZoom(1, zoom);
59 }
60 }
61 }
62
63 Sprite *Blitter_8bppSimple::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
64 {
65 Sprite *dest_sprite;
66 dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + (size_t)sprite->height * (size_t)sprite->width);
67
68 dest_sprite->height = sprite->height;
69 dest_sprite->width = sprite->width;
70 dest_sprite->x_offs = sprite->x_offs;
71 dest_sprite->y_offs = sprite->y_offs;
72
73 /* Copy over only the 'remap' channel, as that is what we care about in 8bpp */
74 for (int i = 0; i < sprite->height * sprite->width; i++) {
75 dest_sprite->data[i] = sprite->data[i].m;
76 }
77
78 return dest_sprite;
79 }
SpriteLoader::CommonPixel::m
uint8 m
Remap-channel.
Definition: spriteloader.hpp:39
8bpp_simple.hpp
FBlitter_8bppSimple
Factory for the most trivial 8bpp blitter.
Definition: 8bpp_simple.hpp:26
Blitter::BlitterParams::top
int top
The top offset in the 'dst' in pixels to start drawing.
Definition: base.hpp:42
BM_TRANSPARENT
@ BM_TRANSPARENT
Perform transparency colour remapping.
Definition: base.hpp:20
Blitter::BlitterParams::skip_left
int skip_left
How much pixels of the source to skip on the left (based on zoom of dst)
Definition: base.hpp:35
BlitterMode
BlitterMode
The modes of blitting we can do.
Definition: base.hpp:17
Blitter::BlitterParams::width
int width
The width in pixels that needs to be drawn to dst.
Definition: base.hpp:37
Sprite::data
byte data[]
Sprite data.
Definition: spritecache.h:22
Blitter::BlitterParams::dst
void * dst
Destination buffer.
Definition: base.hpp:44
Sprite::height
uint16 height
Height of the sprite.
Definition: spritecache.h:18
Sprite::x_offs
int16 x_offs
Number of pixels to shift the sprite to the right.
Definition: spritecache.h:20
Blitter::BlitterParams::sprite_width
int sprite_width
Real width of the sprite.
Definition: base.hpp:39
ZoomLevel
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:19
Blitter::BlitterParams::pitch
int pitch
The pitch of the destination buffer.
Definition: base.hpp:45
SpriteLoader::Sprite::data
SpriteLoader::CommonPixel * data
The sprite itself.
Definition: spriteloader.hpp:55
Blitter::BlitterParams::sprite
const void * sprite
Pointer to the sprite how ever the encoder stored it.
Definition: base.hpp:32
Blitter_8bppSimple::Draw
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override
Draw an image to the screen, given an amount of params defined above.
Definition: 8bpp_simple.cpp:19
BM_COLOUR_REMAP
@ BM_COLOUR_REMAP
Perform a colour remapping.
Definition: base.hpp:19
iFBlitter_8bppSimple
static FBlitter_8bppSimple iFBlitter_8bppSimple
Instantiation of the simple 8bpp blitter factory.
Definition: 8bpp_simple.cpp:17
BM_CRASH_REMAP
@ BM_CRASH_REMAP
Perform a crash remapping.
Definition: base.hpp:21
Sprite::width
uint16 width
Width of the sprite.
Definition: spritecache.h:19
SpriteLoader::Sprite::x_offs
int16 x_offs
The x-offset of where the sprite will be drawn.
Definition: spriteloader.hpp:51
BM_BLACK_REMAP
@ BM_BLACK_REMAP
Perform remapping to a completely blackened sprite.
Definition: base.hpp:22
SpriteLoader::Sprite::width
uint16 width
Width of the sprite.
Definition: spriteloader.hpp:50
ScaleByZoom
static int ScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL) When shifting right,...
Definition: zoom_func.h:22
Blitter::BlitterParams::left
int left
The left offset in the 'dst' in pixels to start drawing.
Definition: base.hpp:41
Sprite::y_offs
int16 y_offs
Number of pixels to shift the sprite downwards.
Definition: spritecache.h:21
SpriteLoader::Sprite
Structure for passing information from the sprite loader to the blitter.
Definition: spriteloader.hpp:48
Blitter::BlitterParams
Parameters related to blitting.
Definition: base.hpp:31
Blitter::BlitterParams::height
int height
The height in pixels that needs to be drawn to dst.
Definition: base.hpp:38
SpriteLoader::Sprite::y_offs
int16 y_offs
The y-offset of where the sprite will be drawn.
Definition: spriteloader.hpp:52
SpriteLoader::Sprite::height
uint16 height
Height of the sprite.
Definition: spriteloader.hpp:49
Blitter::BlitterParams::skip_top
int skip_top
How much pixels of the source to skip on the top (based on zoom of dst)
Definition: base.hpp:36
Sprite
Data structure describing a sprite.
Definition: spritecache.h:17
Blitter::BlitterParams::remap
const byte * remap
XXX – Temporary storage for remap array.
Definition: base.hpp:33
Blitter_8bppSimple::Encode
Sprite * Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override
Convert a sprite from the loader to our own format.
Definition: 8bpp_simple.cpp:63