OpenTTD Source: src/blitter/32bpp_anim.hpp Source File

OpenTTD Source 15.3

32bpp_anim.hpp
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#ifndef BLITTER_32BPP_ANIM_HPP
11#define BLITTER_32BPP_ANIM_HPP
12
13#include "32bpp_optimized.hpp"
14
16 class Blitter_32bppAnim : public Blitter_32bppOptimized {
17protected:
18 uint16_t *anim_buf;
19 std::unique_ptr<uint16_t[]> anim_alloc;
20 int anim_buf_width;
21 int anim_buf_height;
22 int anim_buf_pitch;
23 Palette palette;
24
25public:
26 Blitter_32bppAnim() :
27 anim_buf(nullptr),
28 anim_buf_width(0),
29 anim_buf_height(0),
30 anim_buf_pitch(0)
31 {
32 this->palette = _cur_palette;
33 }
34
35 void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
36 void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override;
37 void SetPixel(void *video, int x, int y, PixelColour colour) override;
38 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;
39 void DrawRect(void *video, int width, int height, PixelColour colour) override;
40 void CopyFromBuffer(void *video, const void *src, int width, int height) override;
41 void CopyToBuffer(const void *video, void *dst, int width, int height) override;
42 void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y) override;
43 size_t BufferSize(uint width, uint height) override;
44 void PaletteAnimate(const Palette &palette) override;
45 Blitter::PaletteAnimation UsePaletteAnimation() override;
46
47 std::string_view GetName() override { return "32bpp-anim"; }
48 void PostResize() override;
49
53 inline Colour LookupColourInPalette(uint index)
54 {
55 return this->palette.palette[index];
56 }
57
58 inline int ScreenToAnimOffset(const uint32_t *video)
59 {
60 int raw_offset = video - (const uint32_t *)_screen.dst_ptr;
61 if (_screen.pitch == this->anim_buf_pitch) return raw_offset;
62 int lines = raw_offset / _screen.pitch;
63 int across = raw_offset % _screen.pitch;
64 return across + (lines * this->anim_buf_pitch);
65 }
66
67 template <BlitterMode mode> void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
68};
69
71 class FBlitter_32bppAnim : public BlitterFactory {
72public:
73 FBlitter_32bppAnim() : BlitterFactory("32bpp-anim", "32bpp Animation Blitter (palette animation)") {}
74 std::unique_ptr<Blitter> CreateInstance() override { return std::make_unique<Blitter_32bppAnim>(); }
75};
76
77#endif /* BLITTER_32BPP_ANIM_HPP */
32bpp_optimized.hpp
Optimized 32 bpp blitter.
BlitterMode
BlitterMode
The modes of blitting we can do.
Definition base.hpp:17
BlitterFactory
The base factory, keeping track of all blitters.
Definition factory.hpp:21
Blitter_32bppAnim
The optimised 32 bpp blitter with palette animation.
Definition 32bpp_anim.hpp:16
Blitter_32bppAnim::CopyFromBuffer
void CopyFromBuffer(void *video, const void *src, int width, int height) override
Copy from a buffer to the screen.
Definition 32bpp_anim.cpp:379
Blitter_32bppAnim::palette
Palette palette
The current palette.
Definition 32bpp_anim.hpp:23
Blitter_32bppAnim::anim_alloc
std::unique_ptr< uint16_t[]> anim_alloc
The raw allocated buffer, not necessarily aligned correctly.
Definition 32bpp_anim.hpp:19
Blitter_32bppAnim::UsePaletteAnimation
Blitter::PaletteAnimation UsePaletteAnimation() override
Check if the blitter uses palette animation at all.
Definition 32bpp_anim.cpp:523
Blitter_32bppAnim::anim_buf_width
int anim_buf_width
The width of the animation buffer.
Definition 32bpp_anim.hpp:20
Blitter_32bppAnim::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_anim.cpp:441
Blitter_32bppAnim::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_anim.cpp:334
Blitter_32bppAnim::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_anim.cpp:324
Blitter_32bppAnim::LookupColourInPalette
Colour LookupColourInPalette(uint index)
Look up the colour in the current palette.
Definition 32bpp_anim.hpp:53
Blitter_32bppAnim::GetName
std::string_view GetName() override
Get the name of the blitter, the same as the Factory-instance returns.
Definition 32bpp_anim.hpp:47
Blitter_32bppAnim::DrawColourMappingRect
void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override
Draw a colourtable to the screen.
Definition 32bpp_anim.cpp:283
Blitter_32bppAnim::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_anim.cpp:482
Blitter_32bppAnim::anim_buf
uint16_t * anim_buf
In this buffer we keep track of the 8bpp indexes so we can do palette animation.
Definition 32bpp_anim.hpp:18
Blitter_32bppAnim::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_anim.cpp:487
Blitter_32bppAnim::PostResize
void PostResize() override
Post resize event.
Definition 32bpp_anim.cpp:528
Blitter_32bppAnim::CopyToBuffer
void CopyToBuffer(const void *video, void *dst, int width, int height) override
Copy from the screen to a buffer.
Definition 32bpp_anim.cpp:419
Blitter_32bppAnim::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 32bpp_anim.cpp:264
Blitter_32bppAnim::anim_buf_height
int anim_buf_height
The height of the animation buffer.
Definition 32bpp_anim.hpp:21
Blitter_32bppAnim::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_anim.cpp:352
Blitter_32bppAnim::anim_buf_pitch
int anim_buf_pitch
The pitch of the animation buffer (width rounded up to 16 byte boundary).
Definition 32bpp_anim.hpp:22
Blitter_32bppOptimized
The optimised 32 bpp blitter (without palette animation).
Definition 32bpp_optimized.hpp:16
Blitter::PaletteAnimation
PaletteAnimation
Types of palette animation.
Definition base.hpp:50
FBlitter_32bppAnim
Factory for the 32bpp blitter with animation.
Definition 32bpp_anim.hpp:71
FBlitter_32bppAnim::CreateInstance
std::unique_ptr< Blitter > CreateInstance() override
Create an instance of this Blitter-class.
Definition 32bpp_anim.hpp:74
_cur_palette
Palette _cur_palette
Current palette.
Definition palette.cpp:24
PaletteID
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
Blitter::BlitterParams
Parameters related to blitting.
Definition base.hpp:32
Palette
Information about the currently used palette.
Definition gfx_type.h:373
Palette::palette
Colour palette[256]
Current palette. Entry 0 has to be always fully transparent!
Definition gfx_type.h:374
PixelColour
Colour for pixel/line drawing.
Definition gfx_type.h:405
ZoomLevel
ZoomLevel
All zoom levels we know.
Definition zoom_type.h:20