10 #include "../stdafx.h"
11 #include "../video/video_driver.hpp"
12 #include "../palette_func.h"
16 #include "../table/sprites.h"
18 #include "../safeguards.h"
23 Blitter_32bppAnim::~Blitter_32bppAnim()
28 template <BlitterMode mode>
31 const SpriteData *src = (
const SpriteData *)bp->
sprite;
33 const Colour *src_px = (
const Colour *)(src->data + src->offset[zoom][0]);
34 const uint16_t *src_n = (
const uint16_t *)(src->data + src->offset[zoom][1]);
36 for (uint i = bp->
skip_top; i != 0; i--) {
37 src_px = (
const Colour *)((
const uint8_t *)src_px + *(
const uint32_t *)src_px);
38 src_n = (
const uint16_t *)((
const uint8_t *)src_n + *(
const uint32_t *)src_n);
42 uint16_t *anim = this->anim_buf + this->ScreenToAnimOffset((uint32_t *)bp->
dst) + bp->
top * this->anim_buf_pitch + bp->
left;
44 const uint8_t *remap = bp->
remap;
46 for (
int y = 0; y < bp->
height; y++) {
50 const Colour *src_px_ln = (
const Colour *)((
const uint8_t *)src_px + *(
const uint32_t *)src_px);
53 const uint16_t *src_n_ln = (
const uint16_t *)((
const uint8_t *)src_n + *(
const uint32_t *)src_n);
60 while (dst < dst_end) {
68 if (dst > dst_end) anim += dst - dst_end;
70 if (dst + n > dst_end) {
71 uint d = dst_end - dst;
76 dst_end = dst + bp->
width;
78 n = std::min(n - d, (uint)bp->
width);
92 while (dst < dst_end) {
93 n = std::min<uint>(*src_n++, dst_end - dst);
107 if (src_px->a == 255) {
115 uint r = remap[
GB(m, 0, 8)];
116 *anim = r | (m & 0xFF00);
131 uint r = remap[
GB(m, 0, 8)];
144 if (src_px->a == 255) {
148 uint8_t g =
MakeDark(src_px->r, src_px->g, src_px->b);
152 uint r = remap[
GB(m, 0, 8)];
153 *anim = r | (m & 0xFF00);
165 if (src_px->a != 0) {
166 uint8_t g =
MakeDark(src_px->r, src_px->g, src_px->b);
171 uint r = remap[
GB(m, 0, 8)];
196 if (src_px->a == 255) {
218 if (src_px->a != 0) {
234 if (src_px->a == 255) {
237 uint m =
GB(*src_n, 0, 8);
246 uint m =
GB(*src_n, 0, 8);
278 default: NOT_REACHED();
279 case BM_NORMAL: Draw<BM_NORMAL> (bp, zoom);
return;
297 uint16_t *anim = this->
anim_buf + this->ScreenToAnimOffset((uint32_t *)dst);
301 for (
int i = 0; i != width; i++) {
307 udst = udst - width + _screen.pitch;
314 for (
int i = 0; i != width; i++) {
320 udst = udst - width + _screen.pitch;
326 Debug(misc, 0,
"32bpp blitter doesn't know how to draw this colour table ('{}')", pal);
336 this->
anim_buf[this->ScreenToAnimOffset((uint32_t *)video) + x + y * this->
anim_buf_pitch] = colour | (DEFAULT_BRIGHTNESS << 8);
339 void 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)
344 this->DrawLineGeneric(x, y, x2, y2, screen_width, screen_height, width, dash, [&](
int x,
int y) {
345 *((
Colour *)video + x + y * _screen.pitch) = c;
348 uint16_t *
const offset_anim_buf = this->
anim_buf + this->ScreenToAnimOffset((uint32_t *)video);
349 const uint16_t anim_colour = colour | (DEFAULT_BRIGHTNESS << 8);
350 this->DrawLineGeneric(x, y, x2, y2, screen_width, screen_height, width, dash, [&](
int x,
int y) {
351 *((
Colour *)video + x + y * _screen.pitch) = c;
366 uint16_t *anim_line = this->ScreenToAnimOffset((uint32_t *)video) + this->
anim_buf;
370 uint16_t *anim = anim_line;
372 for (
int i = width; i > 0; i--) {
375 *anim = colour | (DEFAULT_BRIGHTNESS << 8);
379 video = (uint32_t *)video + _screen.pitch;
380 anim_line += this->anim_buf_pitch;
387 assert(video >= _screen.dst_ptr && video <= (uint32_t *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
389 const uint32_t *usrc = (
const uint32_t *)src;
390 uint16_t *anim_line = this->ScreenToAnimOffset((uint32_t *)video) + this->
anim_buf;
392 for (; height > 0; height--) {
395 uint16_t *anim_pal = anim_line;
397 memcpy(
static_cast<void *
>(dst), usrc, width *
sizeof(uint32_t));
399 dst += _screen.pitch;
401 memcpy(anim_line, usrc, width *
sizeof(uint16_t));
402 usrc = (
const uint32_t *)&((
const uint16_t *)usrc)[width];
412 for (
int i = 0; i < width; i++) {
413 uint colour =
GB(*anim_pal, 0, 8);
427 assert(video >= _screen.dst_ptr && video <= (uint32_t *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
428 uint32_t *udst = (uint32_t *)dst;
429 const uint32_t *src = (
const uint32_t *)video;
431 if (this->
anim_buf ==
nullptr)
return;
433 const uint16_t *anim_line = this->ScreenToAnimOffset((
const uint32_t *)video) + this->
anim_buf;
435 for (; height > 0; height--) {
436 memcpy(udst, src, width *
sizeof(uint32_t));
437 src += _screen.pitch;
440 memcpy(udst, anim_line, width *
sizeof(uint16_t));
441 udst = (uint32_t *)&((uint16_t *)udst)[width];
449 assert(video >= _screen.dst_ptr && video <= (uint32_t *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
454 dst = this->
anim_buf + left + (top + height - 1) * this->anim_buf_pitch;
464 uint tw = width + (scroll_x >= 0 ? -scroll_x : scroll_x);
465 uint th = height - scroll_y;
466 for (; th > 0; th--) {
467 memcpy(dst, src, tw *
sizeof(uint16_t));
485 uint tw = width + (scroll_x >= 0 ? -scroll_x : scroll_x);
486 uint th = height + scroll_y;
487 for (; th > 0; th--) {
488 memmove(dst, src, tw *
sizeof(uint16_t));
499 return (
sizeof(uint32_t) +
sizeof(uint16_t)) * width * height;
512 const uint16_t *anim = this->
anim_buf;
516 const int width = this->anim_buf_width;
517 const int pitch_offset = _screen.pitch - width;
518 const int anim_pitch_offset = this->anim_buf_pitch - width;
520 for (
int x = width; x != 0 ; x--) {
521 uint16_t value = *anim;
522 uint8_t colour =
GB(value, 0, 8);
531 anim += anim_pitch_offset;
545 if (_screen.width != this->anim_buf_width || _screen.height != this->anim_buf_height ||
546 _screen.pitch != this->anim_buf_pitch) {
551 this->anim_buf_pitch = (_screen.width + 7) & ~7;
555 this->
anim_buf =
reinterpret_cast<uint16_t *
>((
reinterpret_cast<uintptr_t
>(this->
anim_alloc) + 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.
@ BM_BLACK_REMAP
Perform remapping to a completely blackened sprite.
@ BM_COLOUR_REMAP
Perform a colour remapping.
@ BM_TRANSPARENT_REMAP
Perform transparency colour remapping.
@ BM_TRANSPARENT
Perform transparency darkening remapping.
@ BM_NORMAL
Perform the simple blitting.
@ BM_CRASH_REMAP
Perform a crash remapping.
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 CopyFromBuffer(void *video, const void *src, int width, int height) override
Copy from a buffer to the screen.
Palette palette
The current palette.
Blitter::PaletteAnimation UsePaletteAnimation() override
Check if the blitter uses palette animation at all.
void * anim_alloc
The raw allocated buffer, not necessarily aligned correctly.
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.
@ 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.
void free(const void *ptr)
Version of the standard free that accepts const pointers.
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.
Structure to access the alpha, red, green, and blue channels from a 32 bit number.
uint32_t data
Conversion of the channel information to a 32 bit number.
uint8_t a
colour channels in LE order
ZoomLevel
All zoom levels we know.