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

OpenTTD Source 12.0-beta1

8bpp_base.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 "../gfx_func.h"
12 #include "8bpp_base.hpp"
13 #include "common.hpp"
14
15 #include "../safeguards.h"
16
17 void Blitter_8bppBase::DrawColourMappingRect(void *dst, int width, int height, PaletteID pal)
18 {
19 const uint8 *ctab = GetNonSprite(pal, ST_RECOLOUR) + 1;
20
21 do {
22 for (int i = 0; i != width; i++) *((uint8 *)dst + i) = ctab[((uint8 *)dst)[i]];
23 dst = (uint8 *)dst + _screen.pitch;
24 } while (--height);
25 }
26
27 void *Blitter_8bppBase::MoveTo(void *video, int x, int y)
28 {
29 return (uint8 *)video + x + y * _screen.pitch;
30 }
31
32 void Blitter_8bppBase::SetPixel(void *video, int x, int y, uint8 colour)
33 {
34 *((uint8 *)video + x + y * _screen.pitch) = colour;
35 }
36
37 void Blitter_8bppBase::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash)
38 {
39 this->DrawLineGeneric(x, y, x2, y2, screen_width, screen_height, width, dash, [=](int x, int y) {
40 *((uint8 *)video + x + y * _screen.pitch) = colour;
41 });
42 }
43
44 void Blitter_8bppBase::DrawRect(void *video, int width, int height, uint8 colour)
45 {
46 do {
47 memset(video, colour, width);
48 video = (uint8 *)video + _screen.pitch;
49 } while (--height);
50 }
51
52 void Blitter_8bppBase::CopyFromBuffer(void *video, const void *src, int width, int height)
53 {
54 uint8 *dst = (uint8 *)video;
55 const uint8 *usrc = (const uint8 *)src;
56
57 for (; height > 0; height--) {
58 memcpy(dst, usrc, width * sizeof(uint8));
59 usrc += width;
60 dst += _screen.pitch;
61 }
62 }
63
64 void Blitter_8bppBase::CopyToBuffer(const void *video, void *dst, int width, int height)
65 {
66 uint8 *udst = (uint8 *)dst;
67 const uint8 *src = (const uint8 *)video;
68
69 for (; height > 0; height--) {
70 memcpy(udst, src, width * sizeof(uint8));
71 src += _screen.pitch;
72 udst += width;
73 }
74 }
75
76 void Blitter_8bppBase::CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch)
77 {
78 uint8 *udst = (uint8 *)dst;
79 const uint8 *src = (const uint8 *)video;
80
81 for (; height > 0; height--) {
82 memcpy(udst, src, width * sizeof(uint8));
83 src += _screen.pitch;
84 udst += dst_pitch;
85 }
86 }
87
88 void Blitter_8bppBase::ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y)
89 {
90 const uint8 *src;
91 uint8 *dst;
92
93 if (scroll_y > 0) {
94 /* Calculate pointers */
95 dst = (uint8 *)video + left + (top + height - 1) * _screen.pitch;
96 src = dst - scroll_y * _screen.pitch;
97
98 /* Decrease height and increase top */
99 top += scroll_y;
100 height -= scroll_y;
101 assert(height > 0);
102
103 /* Adjust left & width */
104 if (scroll_x >= 0) {
105 dst += scroll_x;
106 left += scroll_x;
107 width -= scroll_x;
108 } else {
109 src -= scroll_x;
110 width += scroll_x;
111 }
112
113 for (int h = height; h > 0; h--) {
114 memcpy(dst, src, width * sizeof(uint8));
115 src -= _screen.pitch;
116 dst -= _screen.pitch;
117 }
118 } else {
119 /* Calculate pointers */
120 dst = (uint8 *)video + left + top * _screen.pitch;
121 src = dst - scroll_y * _screen.pitch;
122
123 /* Decrease height. (scroll_y is <=0). */
124 height += scroll_y;
125 assert(height > 0);
126
127 /* Adjust left & width */
128 if (scroll_x >= 0) {
129 dst += scroll_x;
130 left += scroll_x;
131 width -= scroll_x;
132 } else {
133 src -= scroll_x;
134 width += scroll_x;
135 }
136
137 /* the y-displacement may be 0 therefore we have to use memmove,
138 * because source and destination may overlap */
139 for (int h = height; h > 0; h--) {
140 memmove(dst, src, width * sizeof(uint8));
141 src += _screen.pitch;
142 dst += _screen.pitch;
143 }
144 }
145 }
146
147 int Blitter_8bppBase::BufferSize(int width, int height)
148 {
149 return width * height;
150 }
151
152 void Blitter_8bppBase::PaletteAnimate(const Palette &palette)
153 {
154 /* Video backend takes care of the palette animation */
155 }
156
157 Blitter::PaletteAnimation Blitter_8bppBase::UsePaletteAnimation()
158 {
159 return Blitter::PALETTE_ANIMATION_VIDEO_BACKEND;
160 }
Blitter_8bppBase::CopyToBuffer
void CopyToBuffer(const void *video, void *dst, int width, int height) override
Copy from the screen to a buffer.
Definition: 8bpp_base.cpp:64
common.hpp
Blitter_8bppBase::UsePaletteAnimation
Blitter::PaletteAnimation UsePaletteAnimation() override
Check if the blitter uses palette animation at all.
Definition: 8bpp_base.cpp:157
Blitter_8bppBase::DrawLine
void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash) override
Draw a line with a given colour.
Definition: 8bpp_base.cpp:37
Blitter_8bppBase::PaletteAnimate
void PaletteAnimate(const Palette &palette) override
Called when the 8bpp palette is changed; you should redraw all pixels on the screen that are equal to...
Definition: 8bpp_base.cpp:152
Blitter::PaletteAnimation
PaletteAnimation
Types of palette animation.
Definition: base.hpp:49
Blitter_8bppBase::CopyImageToBuffer
void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) override
Copy from the screen to a buffer in a palette format for 8bpp and RGBA format for 32bpp.
Definition: 8bpp_base.cpp:76
Blitter_8bppBase::ScrollBuffer
void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y) override
Scroll the videobuffer some 'x' and 'y' value.
Definition: 8bpp_base.cpp:88
Blitter_8bppBase::BufferSize
int BufferSize(int width, int height) override
Calculate how much memory there is needed for an image of this size in the video-buffer.
Definition: 8bpp_base.cpp:147
Blitter_8bppBase::SetPixel
void SetPixel(void *video, int x, int y, uint8 colour) override
Draw a pixel with a given colour on the video-buffer.
Definition: 8bpp_base.cpp:32
PaletteID
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:18
Blitter::PALETTE_ANIMATION_VIDEO_BACKEND
@ PALETTE_ANIMATION_VIDEO_BACKEND
Palette animation should be done by video backend (8bpp only!)
Definition: base.hpp:51
Blitter_8bppBase::DrawRect
void DrawRect(void *video, int width, int height, uint8 colour) override
Make a single horizontal line in a single colour on the video-buffer.
Definition: 8bpp_base.cpp:44
Blitter_8bppBase::MoveTo
void * MoveTo(void *video, int x, int y) override
Move the destination pointer the requested amount x and y, keeping in mind any pitch and bpp of the r...
Definition: 8bpp_base.cpp:27
ST_RECOLOUR
@ ST_RECOLOUR
Recolour sprite.
Definition: gfx_type.h:305
Palette
Information about the currently used palette.
Definition: gfx_type.h:313
Blitter_8bppBase::CopyFromBuffer
void CopyFromBuffer(void *video, const void *src, int width, int height) override
Copy from a buffer to the screen.
Definition: 8bpp_base.cpp:52
Blitter_8bppBase::DrawColourMappingRect
void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override
Draw a colourtable to the screen.
Definition: 8bpp_base.cpp:17
8bpp_base.hpp