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

OpenTTD Source 14.0-RC3

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_t *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_t colour) override;
41 void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8_t colour, int width, int dash) override;
42 void DrawRect(void *video, int width, int height, uint8_t 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 size_t BufferSize(uint width, uint height) override;
47 void PaletteAnimate(const Palette &palette) override;
48 Blitter::PaletteAnimation UsePaletteAnimation() override;
49
50 const char *GetName() override { return "32bpp-anim"; }
51 void PostResize() override;
52
56 inline Colour LookupColourInPalette(uint index)
57 {
58 return this->palette.palette[index];
59 }
60
61 inline int ScreenToAnimOffset(const uint32_t *video)
62 {
63 int raw_offset = video - (const uint32_t *)_screen.dst_ptr;
64 if (_screen.pitch == this->anim_buf_pitch) return raw_offset;
65 int lines = raw_offset / _screen.pitch;
66 int across = raw_offset % _screen.pitch;
67 return across + (lines * this->anim_buf_pitch);
68 }
69
70 template <BlitterMode mode> void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
71 };
72
74 class FBlitter_32bppAnim : public BlitterFactory {
75 public:
76 FBlitter_32bppAnim() : BlitterFactory("32bpp-anim", "32bpp Animation Blitter (palette animation)") {}
77 Blitter *CreateInstance() override { return new Blitter_32bppAnim(); }
78 };
79
80 #endif /* BLITTER_32BPP_ANIM_HPP */
_cur_palette
Palette _cur_palette
Current palette.
Definition: palette.cpp:24
FBlitter_32bppAnim
Factory for the 32bpp blitter with animation.
Definition: 32bpp_anim.hpp:74
Blitter_32bppAnim::DrawRect
void DrawRect(void *video, int width, int height, uint8_t colour) override
Make a single horizontal line in a single colour on the video-buffer.
Definition: 32bpp_anim.cpp:357
Blitter_32bppAnim::PostResize
void PostResize() override
Post resize event.
Definition: 32bpp_anim.cpp:543
BlitterMode
BlitterMode
The modes of blitting we can do.
Definition: base.hpp:17
Blitter
How all blitters should look like.
Definition: base.hpp:29
BlitterFactory
The base factory, keeping track of all blitters.
Definition: factory.hpp:21
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:384
FBlitter_32bppAnim::CreateInstance
Blitter * CreateInstance() override
Create an instance of this Blitter-class.
Definition: 32bpp_anim.hpp:77
ZoomLevel
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:19
Blitter_32bppAnim::SetPixel
void SetPixel(void *video, int x, int y, uint8_t colour) override
Draw a pixel with a given colour on the video-buffer.
Definition: 32bpp_anim.cpp:329
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
PaletteID
uint32_t PaletteID
The number of the palette.
Definition: gfx_type.h:18
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
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:497
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:424
Palette::palette
Colour palette[256]
Current palette. Entry 0 has to be always fully transparent!
Definition: gfx_type.h:324
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:502
Colour
Structure to access the alpha, red, green, and blue channels from a 32 bit number.
Definition: gfx_type.h:159
BlitterFactory::BlitterFactory
BlitterFactory(const char *name, const char *description, bool usable=true)
Construct the blitter, and register it.
Definition: factory.hpp:58
Blitter::PaletteAnimation
PaletteAnimation
Types of palette animation.
Definition: base.hpp:50
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
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
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_t colour, int width, int dash) override
Draw a line with a given colour.
Definition: 32bpp_anim.cpp:339
Blitter_32bppAnim::UsePaletteAnimation
Blitter::PaletteAnimation UsePaletteAnimation() override
Check if the blitter uses palette animation at all.
Definition: 32bpp_anim.cpp:538
Blitter::BlitterParams
Parameters related to blitting.
Definition: base.hpp:32
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:269
Blitter_32bppAnim::LookupColourInPalette
Colour LookupColourInPalette(uint index)
Look up the colour in the current palette.
Definition: 32bpp_anim.hpp:56
Palette
Information about the currently used palette.
Definition: gfx_type.h:323
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:446
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:288