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"
27static 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;
68void 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;
92template <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;
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.
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.
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.
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.
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 LookupColourInPalette(uint index)
Look up the colour in the current palette.
static Colour MakeTransparent(Colour colour, uint nom, uint denom=256)
Make a pixel looks like it is transparent.
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.
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.
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.
Sprite * Encode(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator) override
Convert a sprite from the loader to our own format.
bool NeedsAnimationBuffer() override
Does this blitter require a separate animation buffer from the video backend?
Blitter::PaletteAnimation UsePaletteAnimation() override
Check if the blitter uses palette animation at all.
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 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.
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.
void SetPixel(void *video, int x, int y, uint8_t colour) override
Draw a pixel with a given colour on the video-buffer.
void CopyFromBuffer(void *video, const void *src, int width, int height) override
Copy from a buffer to the screen.
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
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_VIDEO_BACKEND
Palette animation should be done by video backend (8bpp only!)
Factory for the 40 bpp animated blitter (for OpenGL).
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.
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
virtual uint8_t * GetAnimBuffer()
Get a pointer to the animation buffer of the video back-end.
Common functionality for all blitter implementations.
bool _screen_disable_anim
Disable palette animation (important for 32bpp-anim blitter during giant screenshot)
@ Recolour
Recolour sprite.
uint32_t PaletteID
The number of the palette.
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.
Data stored about a (single) sprite.
uint8_t data[]
Data, all zoomlevels.
uint32_t offset[ZOOM_LVL_END][2]
Offsets (from .data) to streams for different zoom levels, and the normal and remap image information...
Data structure describing a sprite.
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 b
colour channels in BE order
ZoomLevel
All zoom levels we know.