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

OpenTTD Source 15.0-RC2

32bpp_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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#include "../stdafx.h"
11#include "32bpp_base.hpp"
12#include "common.hpp"
13
14#include "../safeguards.h"
15
16 void *Blitter_32bppBase::MoveTo(void *video, int x, int y)
17{
18 return (uint32_t *)video + x + y * _screen.pitch;
19}
20
21 void Blitter_32bppBase::SetPixel(void *video, int x, int y, PixelColour colour)
22{
23 *((Colour *)video + x + y * _screen.pitch) = LookupColourInPalette(colour.p);
24}
25
26 void Blitter_32bppBase::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, PixelColour colour, int width, int dash)
27{
28 const Colour c = LookupColourInPalette(colour.p);
29 this->DrawLineGeneric(x, y, x2, y2, screen_width, screen_height, width, dash, [=](int x, int y) {
30 *((Colour *)video + x + y * _screen.pitch) = c;
31 });
32}
33
34 void Blitter_32bppBase::DrawRect(void *video, int width, int height, PixelColour colour)
35{
36 Colour colour32 = LookupColourInPalette(colour.p);
37
38 do {
39 Colour *dst = (Colour *)video;
40 for (int i = width; i > 0; i--) {
41 *dst = colour32;
42 dst++;
43 }
44 video = (uint32_t *)video + _screen.pitch;
45 } while (--height);
46}
47
48 void Blitter_32bppBase::CopyFromBuffer(void *video, const void *src, int width, int height)
49{
50 uint32_t *dst = (uint32_t *)video;
51 const uint32_t *usrc = (const uint32_t *)src;
52
53 for (; height > 0; height--) {
54 std::copy_n(usrc, width, dst);
55 usrc += width;
56 dst += _screen.pitch;
57 }
58}
59
60 void Blitter_32bppBase::CopyToBuffer(const void *video, void *dst, int width, int height)
61{
62 uint32_t *udst = (uint32_t *)dst;
63 const uint32_t *src = (const uint32_t *)video;
64
65 for (; height > 0; height--) {
66 std::copy_n(src, width, udst);
67 src += _screen.pitch;
68 udst += width;
69 }
70}
71
72 void Blitter_32bppBase::CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch)
73{
74 uint32_t *udst = (uint32_t *)dst;
75 const uint32_t *src = (const uint32_t *)video;
76
77 for (; height > 0; height--) {
78 std::copy_n(src, width, udst);
79 src += _screen.pitch;
80 udst += dst_pitch;
81 }
82}
83
84 void Blitter_32bppBase::ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y)
85{
86 const uint32_t *src;
87 uint32_t *dst;
88
89 if (scroll_y > 0) {
90 /* Calculate pointers */
91 dst = (uint32_t *)video + left + (top + height - 1) * _screen.pitch;
92 src = dst - scroll_y * _screen.pitch;
93
94 /* Decrease height and increase top */
95 top += scroll_y;
96 height -= scroll_y;
97 assert(height > 0);
98
99 /* Adjust left & width */
100 if (scroll_x >= 0) {
101 dst += scroll_x;
102 left += scroll_x;
103 width -= scroll_x;
104 } else {
105 src -= scroll_x;
106 width += scroll_x;
107 }
108
109 Blitter::MovePixels(src, dst, width, height, -_screen.pitch);
110 } else {
111 /* Calculate pointers */
112 dst = (uint32_t *)video + left + top * _screen.pitch;
113 src = dst - scroll_y * _screen.pitch;
114
115 /* Decrease height. (scroll_y is <=0). */
116 height += scroll_y;
117 assert(height > 0);
118
119 /* Adjust left & width */
120 if (scroll_x >= 0) {
121 dst += scroll_x;
122 left += scroll_x;
123 width -= scroll_x;
124 } else {
125 src -= scroll_x;
126 width += scroll_x;
127 }
128
129 Blitter::MovePixels(src, dst, width, height, _screen.pitch);
130 }
131}
132
133 size_t Blitter_32bppBase::BufferSize(uint width, uint height)
134{
135 return sizeof(uint32_t) * width * height;
136}
137
138 void Blitter_32bppBase::PaletteAnimate(const Palette &)
139{
140 /* By default, 32bpp doesn't have palette animation */
141}
142
143 Blitter::PaletteAnimation Blitter_32bppBase::UsePaletteAnimation()
144{
145 return Blitter::PaletteAnimation::None;
146}
32bpp_base.hpp
Base for all 32 bits blitters.
Blitter_32bppBase::BufferSize
size_t BufferSize(uint width, uint height) override
Calculate how much memory there is needed for an image of this size in the video-buffer.
Definition 32bpp_base.cpp:133
Blitter_32bppBase::CopyToBuffer
void CopyToBuffer(const void *video, void *dst, int width, int height) override
Copy from the screen to a buffer.
Definition 32bpp_base.cpp:60
Blitter_32bppBase::LookupColourInPalette
static Colour LookupColourInPalette(uint index)
Look up the colour in the current palette.
Definition 32bpp_base.hpp:36
Blitter_32bppBase::DrawRect
void DrawRect(void *video, int width, int height, PixelColour colour) override
Make a single horizontal line in a single colour on the video-buffer.
Definition 32bpp_base.cpp:34
Blitter_32bppBase::SetPixel
void SetPixel(void *video, int x, int y, PixelColour colour) override
Draw a pixel with a given colour on the video-buffer.
Definition 32bpp_base.cpp:21
Blitter_32bppBase::UsePaletteAnimation
Blitter::PaletteAnimation UsePaletteAnimation() override
Check if the blitter uses palette animation at all.
Definition 32bpp_base.cpp:143
Blitter_32bppBase::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 32bpp_base.cpp:16
Blitter_32bppBase::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 32bpp_base.cpp:72
Blitter_32bppBase::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 32bpp_base.cpp:138
Blitter_32bppBase::CopyFromBuffer
void CopyFromBuffer(void *video, const void *src, int width, int height) override
Copy from a buffer to the screen.
Definition 32bpp_base.cpp:48
Blitter_32bppBase::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 32bpp_base.cpp:84
Blitter_32bppBase::DrawLine
void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, PixelColour colour, int width, int dash) override
Draw a line with a given colour.
Definition 32bpp_base.cpp:26
Blitter::PaletteAnimation
PaletteAnimation
Types of palette animation.
Definition base.hpp:50
Blitter::PaletteAnimation::None
@ None
No palette animation.
common.hpp
Common functionality for all blitter implementations.
Palette
Information about the currently used palette.
Definition gfx_type.h:373
PixelColour
Colour for pixel/line drawing.
Definition gfx_type.h:405
PixelColour::p
uint8_t p
Palette index.
Definition gfx_type.h:406