11#include "../video/video_driver.hpp"
12#include "../palette_func.h"
16#include "../table/sprites.h"
18#include "../safeguards.h"
23template <BlitterMode mode>
26 const SpriteData *src = (
const SpriteData *)bp->
sprite;
28 const Colour *src_px = (
const Colour *)(src->data + src->offset[zoom][0]);
29 const uint16_t *src_n = (
const uint16_t *)(src->data + src->offset[zoom][1]);
31 for (uint i = bp->
skip_top; i != 0; i--) {
32 src_px = (
const Colour *)((
const uint8_t *)src_px + *(
const uint32_t *)src_px);
33 src_n = (
const uint16_t *)((
const uint8_t *)src_n + *(
const uint32_t *)src_n);
39 const uint8_t *remap = bp->
remap;
41 for (
int y = 0; y < bp->
height; y++) {
42 Colour *dst_ln = dst + bp->
pitch;
45 const Colour *src_px_ln = (
const Colour *)((
const uint8_t *)src_px + *(
const uint32_t *)src_px);
48 const uint16_t *src_n_ln = (
const uint16_t *)((
const uint8_t *)src_n + *(
const uint32_t *)src_n);
55 while (dst < dst_end) {
63 if (dst > dst_end) anim += dst - dst_end;
65 if (dst + n > dst_end) {
66 uint d = dst_end - dst;
71 dst_end = dst + bp->
width;
73 n = std::min(n - d, (uint)bp->
width);
87 while (dst < dst_end) {
88 n = std::min<uint>(*src_n++, dst_end - dst);
102 if (src_px->a == 255) {
110 uint r = remap[
GB(m, 0, 8)];
111 *anim = r | (m & 0xFF00);
126 uint r = remap[
GB(m, 0, 8)];
139 if (src_px->a == 255) {
143 uint8_t g =
MakeDark(src_px->r, src_px->g, src_px->b);
147 uint r = remap[
GB(m, 0, 8)];
148 *anim = r | (m & 0xFF00);
160 if (src_px->a != 0) {
161 uint8_t g =
MakeDark(src_px->r, src_px->g, src_px->b);
166 uint r = remap[
GB(m, 0, 8)];
181 *dst++ = Colour(0, 0, 0);
191 if (src_px->a == 255) {
213 if (src_px->a != 0) {
229 if (src_px->a == 255) {
232 uint m =
GB(*src_n, 0, 8);
241 uint m =
GB(*src_n, 0, 8);
273 default: NOT_REACHED();
291 Colour *udst = (Colour *)dst;
292 uint16_t *anim = this->
anim_buf + this->ScreenToAnimOffset((uint32_t *)dst);
296 for (
int i = 0; i != width; i++) {
302 udst = udst - width + _screen.pitch;
309 for (
int i = 0; i != width; i++) {
315 udst = udst - width + _screen.pitch;
321 Debug(misc, 0,
"32bpp blitter doesn't know how to draw this colour table ('{}')", pal);
331 this->
anim_buf[this->ScreenToAnimOffset((uint32_t *)video) + x + y * this->
anim_buf_pitch] = colour | (DEFAULT_BRIGHTNESS << 8);
334void Blitter_32bppAnim::DrawLine(
void *video,
int x,
int y,
int x2,
int y2,
int screen_width,
int screen_height, uint8_t colour,
int width,
int dash)
339 this->DrawLineGeneric(x, y, x2, y2, screen_width, screen_height, width, dash, [&](
int x,
int y) {
340 *((Colour *)video + x + y * _screen.pitch) = c;
343 uint16_t *
const offset_anim_buf = this->
anim_buf + this->ScreenToAnimOffset((uint32_t *)video);
344 const uint16_t anim_colour = colour | (DEFAULT_BRIGHTNESS << 8);
345 this->DrawLineGeneric(x, y, x2, y2, screen_width, screen_height, width, dash, [&](
int x,
int y) {
346 *((Colour *)video + x + y * _screen.pitch) = c;
361 uint16_t *anim_line = this->ScreenToAnimOffset((uint32_t *)video) + this->
anim_buf;
364 Colour *dst = (Colour *)video;
365 uint16_t *anim = anim_line;
367 for (
int i = width; i > 0; i--) {
370 *anim = colour | (DEFAULT_BRIGHTNESS << 8);
374 video = (uint32_t *)video + _screen.pitch;
382 assert(video >= _screen.dst_ptr && video <= (uint32_t *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
383 Colour *dst = (Colour *)video;
384 const uint32_t *usrc = (
const uint32_t *)src;
385 uint16_t *anim_line = this->ScreenToAnimOffset((uint32_t *)video) + this->
anim_buf;
387 for (; height > 0; height--) {
389 Colour *dst_pal = dst;
390 uint16_t *anim_pal = anim_line;
392 memcpy(
static_cast<void *
>(dst), usrc, width *
sizeof(uint32_t));
394 dst += _screen.pitch;
396 memcpy(anim_line, usrc, width *
sizeof(uint16_t));
397 usrc = (
const uint32_t *)&((
const uint16_t *)usrc)[width];
407 for (
int i = 0; i < width; i++) {
408 uint colour =
GB(*anim_pal, 0, 8);
422 assert(video >= _screen.dst_ptr && video <= (uint32_t *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
423 uint32_t *udst = (uint32_t *)dst;
424 const uint32_t *src = (
const uint32_t *)video;
426 if (this->
anim_buf ==
nullptr)
return;
428 const uint16_t *anim_line = this->ScreenToAnimOffset((
const uint32_t *)video) + this->
anim_buf;
430 for (; height > 0; height--) {
431 memcpy(udst, src, width *
sizeof(uint32_t));
432 src += _screen.pitch;
435 memcpy(udst, anim_line, width *
sizeof(uint16_t));
436 udst = (uint32_t *)&((uint16_t *)udst)[width];
444 assert(video >= _screen.dst_ptr && video <= (uint32_t *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
459 uint tw = width + (scroll_x >= 0 ? -scroll_x : scroll_x);
460 uint th = height - scroll_y;
461 for (; th > 0; th--) {
462 memcpy(dst, src, tw *
sizeof(uint16_t));
480 uint tw = width + (scroll_x >= 0 ? -scroll_x : scroll_x);
481 uint th = height + scroll_y;
482 for (; th > 0; th--) {
483 memmove(dst, src, tw *
sizeof(uint16_t));
494 return (
sizeof(uint32_t) +
sizeof(uint16_t)) * width * height;
507 const uint16_t *anim = this->
anim_buf;
508 Colour *dst = (Colour *)_screen.dst_ptr;
512 const int pitch_offset = _screen.pitch - width;
515 for (
int x = width; x != 0 ; x--) {
516 uint16_t value = *anim;
517 uint8_t colour =
GB(value, 0, 8);
526 anim += anim_pitch_offset;
540 if (_screen.width != this->anim_buf_width || _screen.height != this->anim_buf_height ||
541 _screen.pitch != this->anim_buf_pitch) {
549 this->
anim_buf =
reinterpret_cast<uint16_t *
>((
reinterpret_cast<uintptr_t
>(this->
anim_alloc.get()) + 0xF) & (~0xF));
static FBlitter_32bppAnim iFBlitter_32bppAnim
Instantiation of the 32bpp with animation blitter factory.
A 32 bpp blitter with animation support.
BlitterMode
The modes of blitting we can do.
@ Transparent
Perform transparency darkening remapping.
@ CrashRemap
Perform a crash remapping.
@ BlackRemap
Perform remapping to a completely blackened sprite.
@ Normal
Perform the simple blitting.
@ TransparentRemap
Perform transparency colour remapping.
@ ColourRemap
Perform a colour remapping.
debug_inline static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
void CopyFromBuffer(void *video, const void *src, int width, int height) override
Copy from a buffer to the screen.
Palette palette
The current palette.
std::unique_ptr< uint16_t[]> anim_alloc
The raw allocated buffer, not necessarily aligned correctly.
Blitter::PaletteAnimation UsePaletteAnimation() override
Check if the blitter uses palette animation at all.
int anim_buf_width
The width of the animation buffer.
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.
Colour LookupColourInPalette(uint index)
Look up the colour in the current palette.
void SetPixel(void *video, int x, int y, uint8_t colour) override
Draw a pixel with a given colour on the video-buffer.
void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override
Draw a colourtable to the screen.
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.
uint16_t * anim_buf
In this buffer we keep track of the 8bpp indexes so we can do palette animation.
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.
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.
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...
void PostResize() override
Post resize event.
void CopyToBuffer(const void *video, void *dst, int width, int height) override
Copy from the screen to a buffer.
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override
Draw an image to the screen, given an amount of params defined above.
int anim_buf_height
The height of the animation buffer.
int anim_buf_pitch
The pitch of the animation buffer (width rounded up to 16 byte boundary).
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 ComposeColourPANoCheck(Colour colour, uint a, Colour current)
Compose a colour based on Pixel value, alpha value, and the current pixel 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.
static Colour MakeTransparent(Colour colour, uint nom, uint denom=256)
Make a pixel looks like it is transparent.
static Colour MakeGrey(Colour colour)
Make a colour grey - based.
static uint8_t MakeDark(uint8_t r, uint8_t g, uint8_t b)
Make a colour dark grey, for specialized 32bpp remapping.
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.
static Colour ComposeColourRGBA(uint r, uint g, uint b, uint a, Colour current)
Compose a colour based on RGBA values and the current pixel value.
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override
Draws a sprite to a (screen) buffer.
void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override
Draw a colourtable to the screen.
PaletteAnimation
Types of palette animation.
@ Blitter
The blitter takes care of the palette animation.
Factory for the 32bpp blitter with animation.
virtual void MakeDirty(int left, int top, int width, int height)=0
Mark a particular area dirty.
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Common functionality for all blitter implementations.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
bool _screen_disable_anim
Disable palette animation (important for 32bpp-anim blitter during giant screenshot)
uint32_t PaletteID
The number of the palette.
static constexpr uint8_t PALETTE_ANIM_START
Index in the _palettes array from which all animations are taking places (table/palettes....
uint8_t GetNearestColourIndex(uint8_t r, uint8_t g, uint8_t b)
Get nearest colour palette index from an RGB colour.
static const PaletteID PALETTE_TO_TRANSPARENT
This sets the sprite to transparent.
static const PaletteID PALETTE_NEWSPAPER
Recolour sprite for newspaper-greying.
Parameters related to blitting.
int skip_top
How much pixels of the source to skip on the top (based on zoom of dst)
void * dst
Destination buffer.
int left
The left offset in the 'dst' in pixels to start drawing.
int pitch
The pitch of the destination buffer.
int skip_left
How much pixels of the source to skip on the left (based on zoom of dst)
int height
The height in pixels that needs to be drawn to dst.
const uint8_t * remap
XXX – Temporary storage for remap array.
int width
The width in pixels that needs to be drawn to dst.
const void * sprite
Pointer to the sprite how ever the encoder stored it.
int top
The top offset in the 'dst' in pixels to start drawing.
Information about the currently used palette.
int first_dirty
The first dirty element.
ZoomLevel
All zoom levels we know.