OpenTTD Source
20240919-master-gdf0233f4c2
|
10 #include "../stdafx.h"
11 #include "../zoom_func.h"
12 #include "../settings_type.h"
13 #include "../video/video_driver.hpp"
14 #include "../palette_func.h"
15 #include "40bpp_anim.hpp"
18 #include "../table/sprites.h"
20 #include "../safeguards.h"
27 static const Colour _black_colour(0, 0, 0);
35 size_t y_offset =
static_cast<size_t>(y) * _screen.pitch;
36 *((
Colour *)video + x + y_offset) = _black_colour;
55 uint8_t *anim = anim_line;
57 for (
int i = width; i > 0; i--) {
63 video = (uint32_t *)video + _screen.pitch;
64 anim_line += _screen.pitch;
68 void Blitter_40bppAnim::DrawLine(
void *video,
int x,
int y,
int x2,
int y2,
int screen_width,
int screen_height, uint8_t colour,
int width,
int dash)
79 this->DrawLineGeneric(x, y, x2, y2, screen_width, screen_height, width, dash, [=](
int x,
int y) {
80 *((
Colour *)video + x + y * _screen.pitch) = _black_colour;
81 *(anim + x + y * _screen.pitch) = colour;
92 template <BlitterMode mode>
103 const uint16_t *src_n = (
const uint16_t *)(src->
data + src->
offset[zoom][1]);
106 for (uint i = bp->
skip_top; i != 0; i--) {
107 src_px = (
const Colour *)((
const uint8_t *)src_px + *(
const uint32_t *)src_px);
108 src_n = (
const uint16_t *)((
const uint8_t *)src_n + *(
const uint32_t *)src_n);
117 const uint8_t *remap = bp->
remap;
119 for (
int y = 0; y < bp->
height; y++) {
122 uint8_t *anim_ln = anim + bp->
pitch;
125 const Colour *src_px_ln = (
const Colour *)((
const uint8_t *)src_px + *(
const uint32_t *)src_px);
129 const uint16_t *src_n_ln = (
const uint16_t *)((
const uint8_t *)src_n + *(
const uint32_t *)src_n);
138 while (dst < dst_end) {
141 if (src_px->a == 0) {
146 if (dst > dst_end) anim += dst - dst_end;
148 if (dst + n > dst_end) {
149 uint d = dst_end - dst;
154 dst_end = dst + bp->
width;
156 n = std::min<uint>(n - d, (uint)bp->
width);
168 dst_end += bp->
width;
170 while (dst < dst_end) {
171 n = std::min<uint>(*src_n++, (uint)(dst_end - dst));
173 if (src_px->a == 0) {
186 if (src_px->a == 255) {
188 uint8_t m =
GB(*src_n, 0, 8);
207 uint8_t m =
GB(*src_n, 0, 8);
208 Colour b = this->RealizeBlendedColour(*anim, *dst);
231 *dst++ = _black_colour;
240 if (src_px->a == 255) {
246 Colour b = *anim != 0 ?
Colour(this->GetColourBrightness(*dst), 0, 0) : *dst;
253 Colour b = this->RealizeBlendedColour(*anim, *dst);
266 if (src_px->a != 0) {
270 *anim = remap[*anim];
286 if (src_px->a == 255) {
288 *anim++ =
GB(*src_n, 0, 8);
289 *dst++ = src_px->
data;
296 uint8_t m =
GB(*src_n, 0, 8);
297 Colour b = this->RealizeBlendedColour(*anim, *dst);
332 assert(_screen.dst_ptr !=
nullptr);
336 Blitter_32bppOptimized::Draw<true>(bp, mode, zoom);
341 default: NOT_REACHED();
342 case BM_NORMAL: Draw<BM_NORMAL> (bp, zoom);
return;
367 for (
int i = 0; i != width; i++) {
368 Colour b = *anim != 0 ?
Colour(this->GetColourBrightness(*udst), 0, 0) : *udst;
373 udst = udst - width + _screen.pitch;
374 anim = anim - width + _screen.pitch;
379 for (
int i = 0; i != width; i++) {
380 if (*anim == 0) *udst =
MakeGrey(*udst);
381 *anim = remap[*anim];
385 udst = udst - width + _screen.pitch;
386 anim = anim - width + _screen.pitch;
391 for (
int i = 0; i != width; i++) {
392 *anim = remap[*anim];
395 anim = anim - width + _screen.pitch;
402 return this->EncodeInternal<false>(sprite, allocator);
409 assert(video >= _screen.dst_ptr && video <= (uint32_t *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
410 uint32_t *dst = (uint32_t *)video;
411 const uint32_t *usrc = (
const uint32_t *)src;
414 if (anim_buf ==
nullptr)
return;
415 uint8_t *anim_line = ((uint32_t *)video - (uint32_t *)_screen.dst_ptr) + anim_buf;
417 for (; height > 0; height--) {
418 memcpy(dst, usrc, width *
sizeof(uint32_t));
420 dst += _screen.pitch;
422 memcpy(anim_line, usrc, width *
sizeof(uint8_t));
423 usrc = (
const uint32_t *)((
const uint8_t *)usrc + width);
424 anim_line += _screen.pitch;
431 assert(video >= _screen.dst_ptr && video <= (uint32_t *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
432 uint32_t *udst = (uint32_t *)dst;
433 const uint32_t *src = (
const uint32_t *)video;
436 if (anim_buf ==
nullptr)
return;
437 const uint8_t *anim_line = ((
const uint32_t *)video - (uint32_t *)_screen.dst_ptr) + anim_buf;
439 for (; height > 0; height--) {
440 memcpy(udst, src, width *
sizeof(uint32_t));
441 src += _screen.pitch;
444 memcpy(udst, anim_line, width *
sizeof(uint8_t));
445 udst = (uint32_t *)((uint8_t *)udst + width);
446 anim_line += _screen.pitch;
453 if (anim_buf ==
nullptr) {
458 uint32_t *udst = (uint32_t *)dst;
459 const uint32_t *src = (
const uint32_t *)video;
460 const uint8_t *anim_line = ((
const uint32_t *)video - (uint32_t *)_screen.dst_ptr) + anim_buf;
462 for (; height > 0; height--) {
463 for (
int x = 0; x < width; x++) {
464 udst[x] = this->RealizeBlendedColour(anim_line[x], src[x]).
data;
466 src += _screen.pitch;
467 anim_line += _screen.pitch;
475 assert(video >= _screen.dst_ptr && video <= (uint32_t *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
481 dst = anim_buf + left + (top + height - 1) * _screen.pitch;
482 src = dst - scroll_y * _screen.pitch;
491 uint tw = width + (scroll_x >= 0 ? -scroll_x : scroll_x);
492 uint th = height - scroll_y;
493 for (; th > 0; th--) {
494 memcpy(dst, src, tw *
sizeof(uint8_t));
495 src -= _screen.pitch;
496 dst -= _screen.pitch;
500 dst = anim_buf + left + top * _screen.pitch;
501 src = dst - scroll_y * _screen.pitch;
512 uint tw = width + (scroll_x >= 0 ? -scroll_x : scroll_x);
513 uint th = height + scroll_y;
514 for (; th > 0; th--) {
515 memmove(dst, src, tw *
sizeof(uint8_t));
516 src += _screen.pitch;
517 dst += _screen.pitch;
526 return (
sizeof(uint32_t) +
sizeof(uint8_t)) * width * height;
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.
@ Recolour
Recolour sprite.
int top
The top offset in the 'dst' in pixels to start drawing.
@ BM_TRANSPARENT
Perform transparency darkening remapping.
int skip_left
How much pixels of the source to skip on the left (based on zoom of dst)
void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override
Draw a colourtable to the screen.
BlitterMode
The modes of blitting we can do.
int width
The width in pixels that needs to be drawn to dst.
void SetPixel(void *video, int x, int y, uint8_t colour) override
Draw a pixel with a given colour on the video-buffer.
const uint8_t * remap
XXX – Temporary storage for remap array.
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
void * dst
Destination buffer.
static const PaletteID PALETTE_TO_TRANSPARENT
This sets the sprite to transparent.
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.
static Colour ComposeColourPANoCheck(Colour colour, uint a, Colour current)
Compose a colour based on Pixel value, alpha value, and the current pixel value.
uint8_t data[]
Data, all zoomlevels.
int pitch
The pitch of the destination buffer.
void CopyToBuffer(const void *video, void *dst, int width, int height) override
Copy from the screen to a buffer.
uint32_t PaletteID
The number of the palette.
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.
Interface for something that can allocate memory for a sprite.
std::array< Sprite, ZOOM_LVL_END > SpriteCollection
Type defining a collection of sprites, one for each zoom level.
void CopyFromBuffer(void *video, const void *src, int width, int height) override
Copy from a buffer to the screen.
@ BM_NORMAL
Perform the simple blitting.
void SetPixel(void *video, int x, int y, uint8_t colour) override
Draw a pixel with a given colour on the video-buffer.
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override
Draws a sprite to a (screen) buffer.
Sprite * Encode(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator) override
Convert a sprite from the loader to our own format.
const void * sprite
Pointer to the sprite how ever the encoder stored it.
static Colour MakeGrey(Colour colour)
Make a colour grey - based.
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.
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.
bool _screen_disable_anim
Disable palette animation (important for 32bpp-anim blitter during giant screenshot)
@ BM_COLOUR_REMAP
Perform a colour remapping.
static const PaletteID PALETTE_NEWSPAPER
Recolour sprite for newspaper-greying.
virtual uint8_t * GetAnimBuffer()
Get a pointer to the animation buffer of the video back-end.
@ BM_CRASH_REMAP
Perform a crash remapping.
static Colour LookupColourInPalette(uint index)
Look up the colour in the current palette.
void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override
Draw a colourtable to the screen.
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.
@ BM_BLACK_REMAP
Perform remapping to a completely blackened sprite.
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.
Factory for the 40 bpp animated blitter (for OpenGL).
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
uint32_t data
Conversion of the channel information to a 32 bit number.
Structure to access the alpha, red, green, and blue channels from a 32 bit number.
PaletteAnimation
Types of palette animation.
static uint8_t MakeDark(uint8_t r, uint8_t g, uint8_t b)
Make a colour dark grey, for specialized 32bpp remapping.
uint8_t GetNearestColourIndex(uint8_t r, uint8_t g, uint8_t b)
Get nearest colour palette index from an RGB colour.
uint32_t offset[ZOOM_LVL_END][2]
Offsets (from .data) to streams for different zoom levels, and the normal and remap image information...
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.
int left
The left offset in the 'dst' in pixels to start drawing.
@ PALETTE_ANIMATION_VIDEO_BACKEND
Palette animation should be done by video backend (8bpp only!)
static Colour ComposeColourRGBANoCheck(uint r, uint g, uint b, uint a, Colour current)
Compose a colour based on RGBA values and the current pixel value.
static Colour MakeTransparent(Colour colour, uint nom, uint denom=256)
Make a pixel looks like it is transparent.
bool NeedsAnimationBuffer() override
Does this blitter require a separate animation buffer from the video backend?
Parameters related to blitting.
int height
The height in pixels that needs to be drawn to dst.
Data stored about a (single) sprite.
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.
int skip_top
How much pixels of the source to skip on the top (based on zoom of dst)
Data structure describing a sprite.
@ BM_TRANSPARENT_REMAP
Perform transparency colour remapping.
uint8_t a
colour channels in LE order
Blitter::PaletteAnimation UsePaletteAnimation() override
Check if the blitter uses palette animation at all.
ZoomLevel
All zoom levels we know.