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

OpenTTD Source 12.2

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 <http://www.gnu.org/licenses/>.
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 {
17 protected:
18 uint16 *anim_buf;
19 void *anim_alloc;
20 int anim_buf_width;
21 int anim_buf_height;
22 int anim_buf_pitch;
23 Palette palette;
24
25 public:
26 Blitter_32bppAnim() :
27 anim_buf(nullptr),
28 anim_alloc(nullptr),
29 anim_buf_width(0),
30 anim_buf_height(0),
31 anim_buf_pitch(0)
32 {
33 this->palette = _cur_palette;
34 }
35
36 ~Blitter_32bppAnim();
37
38 void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
39 void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override;
40 void SetPixel(void *video, int x, int y, uint8 colour) override;
41 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;
42 void DrawRect(void *video, int width, int height, uint8 colour) override;
43 void CopyFromBuffer(void *video, const void *src, int width, int height) override;
44 void CopyToBuffer(const void *video, void *dst, int width, int height) override;
45 void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y) override;
46 int BufferSize(int width, int height) override;
47 void PaletteAnimate(const Palette &palette) override;
48 Blitter::PaletteAnimation UsePaletteAnimation() override;
49
50 const char *GetName() override { return "32bpp-anim"; }
51 int GetBytesPerPixel() override { return 6; }
52 void PostResize() override;
53
57 inline Colour LookupColourInPalette(uint index)
58 {
59 return this->palette.palette[index];
60 }
61
62 inline int ScreenToAnimOffset(const uint32 *video)
63 {
64 int raw_offset = video - (const uint32 *)_screen.dst_ptr;
65 if (_screen.pitch == this->anim_buf_pitch) return raw_offset;
66 int lines = raw_offset / _screen.pitch;
67 int across = raw_offset % _screen.pitch;
68 return across + (lines * this->anim_buf_pitch);
69 }
70
71 template <BlitterMode mode> void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
72 };
73
75 class FBlitter_32bppAnim : public BlitterFactory {
76 public:
77 FBlitter_32bppAnim() : BlitterFactory("32bpp-anim", "32bpp Animation Blitter (palette animation)") {}
78 Blitter *CreateInstance() override { return new Blitter_32bppAnim(); }
79 };
80
81 #endif /* BLITTER_32BPP_ANIM_HPP */
FBlitter_32bppAnim
Factory for the 32bpp blitter with animation.
Definition: 32bpp_anim.hpp:75
Blitter_32bppAnim::PostResize
void PostResize() override
Post resize event.
Definition: 32bpp_anim.cpp:527
BlitterMode
BlitterMode
The modes of blitting we can do.
Definition: base.hpp:17
Blitter
How all blitters should look like.
Definition: base.hpp:28
BlitterFactory
The base factory, keeping track of all blitters.
Definition: factory.hpp:23
Blitter_32bppAnim::anim_buf
uint16 * 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::CopyFromBuffer
void CopyFromBuffer(void *video, const void *src, int width, int height) override
Copy from a buffer to the screen.
Definition: 32bpp_anim.cpp:368
FBlitter_32bppAnim::CreateInstance
Blitter * CreateInstance() override
Create an instance of this Blitter-class.
Definition: 32bpp_anim.hpp:78
ZoomLevel
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:21
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_32bppAnim::anim_buf_width
int anim_buf_width
The width of the animation buffer.
Definition: 32bpp_anim.hpp:20
Blitter_32bppAnim::anim_alloc
void * anim_alloc
The raw allocated buffer, not necessarily aligned correctly.
Definition: 32bpp_anim.hpp:19
Blitter_32bppAnim::anim_buf_height
int anim_buf_height
The height of the animation buffer.
Definition: 32bpp_anim.hpp:21
32bpp_optimized.hpp
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:408
Palette::palette
Colour palette[256]
Current palette. Entry 0 has to be always fully transparent!
Definition: gfx_type.h:314
Blitter_32bppAnim::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: 32bpp_anim.cpp:341
Blitter_32bppAnim::GetBytesPerPixel
int GetBytesPerPixel() override
Get how many bytes are needed to store a pixel.
Definition: 32bpp_anim.hpp:51
Blitter_32bppAnim::palette
Palette palette
The current palette.
Definition: 32bpp_anim.hpp:23
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:486
Colour
Structure to access the alpha, red, green, and blue channels from a 32 bit number.
Definition: gfx_type.h:163
BlitterFactory::BlitterFactory
BlitterFactory(const char *name, const char *description, bool usable=true)
Construct the blitter, and register it.
Definition: factory.hpp:60
Blitter::PaletteAnimation
PaletteAnimation
Types of palette animation.
Definition: base.hpp:49
Blitter_32bppAnim::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: 32bpp_anim.cpp:481
Blitter_32bppAnim::GetName
const char * GetName() override
Get the name of the blitter, the same as the Factory-instance returns.
Definition: 32bpp_anim.hpp:50
PaletteID
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:18
Blitter_32bppAnim
The optimised 32 bpp blitter with palette animation.
Definition: 32bpp_anim.hpp:16
Blitter_32bppAnim::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: 32bpp_anim.cpp:323
Blitter_32bppAnim::UsePaletteAnimation
Blitter::PaletteAnimation UsePaletteAnimation() override
Check if the blitter uses palette animation at all.
Definition: 32bpp_anim.cpp:522
_cur_palette
Palette _cur_palette
Current palette.
Definition: gfx.cpp:49
Blitter::BlitterParams
Parameters related to blitting.
Definition: base.hpp:31
Blitter_32bppAnim::SetPixel
void SetPixel(void *video, int x, int y, uint8 colour) override
Draw a pixel with a given colour on the video-buffer.
Definition: 32bpp_anim.cpp:313
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:254
Blitter_32bppAnim::LookupColourInPalette
Colour LookupColourInPalette(uint index)
Look up the colour in the current palette.
Definition: 32bpp_anim.hpp:57
Palette
Information about the currently used palette.
Definition: gfx_type.h:313
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:430
Blitter_32bppOptimized
The optimised 32 bpp blitter (without palette animation).
Definition: 32bpp_optimized.hpp:16
Blitter_32bppAnim::DrawColourMappingRect
void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override
Draw a colourtable to the screen.
Definition: 32bpp_anim.cpp:272