OpenTTD Source  20241121-master-g67a0fccfad
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 
17 protected:
18  uint16_t *anim_buf;
19  void *anim_alloc;
24 
25 public:
27  anim_buf(nullptr),
28  anim_alloc(nullptr),
29  anim_buf_width(0),
30  anim_buf_height(0),
32  {
33  this->palette = _cur_palette;
34  }
35 
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;
49 
50  std::string_view 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 
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 */
Optimized 32 bpp blitter.
BlitterMode
The modes of blitting we can do.
Definition: base.hpp:17
The base factory, keeping track of all blitters.
Definition: factory.hpp:21
BlitterFactory(const char *name, const char *description, bool usable=true)
Construct the blitter, and register it.
Definition: factory.hpp:58
The optimised 32 bpp blitter with palette animation.
Definition: 32bpp_anim.hpp:16
void CopyFromBuffer(void *video, const void *src, int width, int height) override
Copy from a buffer to the screen.
Definition: 32bpp_anim.cpp:384
Palette palette
The current palette.
Definition: 32bpp_anim.hpp:23
Blitter::PaletteAnimation UsePaletteAnimation() override
Check if the blitter uses palette animation at all.
Definition: 32bpp_anim.cpp:538
void * anim_alloc
The raw allocated buffer, not necessarily aligned correctly.
Definition: 32bpp_anim.hpp:19
int anim_buf_width
The width of the animation buffer.
Definition: 32bpp_anim.hpp:20
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
Colour LookupColourInPalette(uint index)
Look up the colour in the current palette.
Definition: 32bpp_anim.hpp:56
std::string_view GetName() override
Get the name of the blitter, the same as the Factory-instance returns.
Definition: 32bpp_anim.hpp:50
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
void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override
Draw a colourtable to the screen.
Definition: 32bpp_anim.cpp:288
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
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
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
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
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
void PostResize() override
Post resize event.
Definition: 32bpp_anim.cpp:543
void CopyToBuffer(const void *video, void *dst, int width, int height) override
Copy from the screen to a buffer.
Definition: 32bpp_anim.cpp:424
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
int anim_buf_height
The height of the animation buffer.
Definition: 32bpp_anim.hpp:21
int anim_buf_pitch
The pitch of the animation buffer (width rounded up to 16 byte boundary).
Definition: 32bpp_anim.hpp:22
The optimised 32 bpp blitter (without palette animation).
How all blitters should look like.
Definition: base.hpp:29
PaletteAnimation
Types of palette animation.
Definition: base.hpp:50
Factory for the 32bpp blitter with animation.
Definition: 32bpp_anim.hpp:74
Blitter * CreateInstance() override
Create an instance of this Blitter-class.
Definition: 32bpp_anim.hpp:77
Palette _cur_palette
Current palette.
Definition: palette.cpp:24
uint32_t PaletteID
The number of the palette.
Definition: gfx_type.h:19
Parameters related to blitting.
Definition: base.hpp:32
Information about the currently used palette.
Definition: gfx_type.h:328
Colour palette[256]
Current palette. Entry 0 has to be always fully transparent!
Definition: gfx_type.h:329
Structure to access the alpha, red, green, and blue channels from a 32 bit number.
Definition: gfx_type.h:165
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:16