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;
54 Colour *dst = (Colour *)video;
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;
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) {
…}
92template <BlitterMode mode>
99 const Colour *src_px =
reinterpret_cast<const Colour *
>(src->
data + src->
offset[0][zoom]);
103 const uint16_t *src_n =
reinterpret_cast<const uint16_t *
>(src->
data + src->
offset[1][zoom]);
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++) {
121 Colour *dst_ln = dst + bp->
pitch;
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) {
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();
359 Colour *udst = (Colour *)dst;
367 for (
int i = 0; i != width; i++) {
373 udst = udst - width + _screen.pitch;
374 anim = anim - width + _screen.pitch;
379 for (
int i = 0; i != width; i++) {
383 *anim = remap[*anim];
388 udst = udst - width + _screen.pitch;
389 anim = anim - width + _screen.pitch;
394 for (
int i = 0; i != width; i++) {
395 if (*anim != 0) *anim = remap[*anim];
398 anim = anim - width + _screen.pitch;
405 return this->EncodeInternal<false>(sprite_type, sprite, allocator);
412 assert(video >= _screen.dst_ptr && video <= (uint32_t *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
413 uint32_t *dst = (uint32_t *)video;
414 const uint32_t *usrc = (
const uint32_t *)src;
417 if (anim_buf ==
nullptr)
return;
418 uint8_t *anim_line = ((uint32_t *)video - (uint32_t *)_screen.dst_ptr) + anim_buf;
420 for (; height > 0; height--) {
421 std::copy_n(usrc, width, dst);
423 dst += _screen.pitch;
425 std::copy_n(
reinterpret_cast<const uint8_t *
>(usrc), width, anim_line);
426 usrc = (
const uint32_t *)((
const uint8_t *)usrc + width);
427 anim_line += _screen.pitch;
434 assert(video >= _screen.dst_ptr && video <= (uint32_t *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
435 uint32_t *udst = (uint32_t *)dst;
436 const uint32_t *src = (
const uint32_t *)video;
439 if (anim_buf ==
nullptr)
return;
440 const uint8_t *anim_line = ((
const uint32_t *)video - (uint32_t *)_screen.dst_ptr) + anim_buf;
442 for (; height > 0; height--) {
443 std::copy_n(src, width, udst);
444 src += _screen.pitch;
447 std::copy_n(anim_line, width,
reinterpret_cast<uint8_t *
>(udst));
448 udst = (uint32_t *)((uint8_t *)udst + width);
449 anim_line += _screen.pitch;
456 if (anim_buf ==
nullptr) {
461 uint32_t *udst = (uint32_t *)dst;
462 const uint32_t *src = (
const uint32_t *)video;
463 const uint8_t *anim_line = ((
const uint32_t *)video - (uint32_t *)_screen.dst_ptr) + anim_buf;
465 for (; height > 0; height--) {
466 for (
int x = 0; x < width; x++) {
467 udst[x] = this->RealizeBlendedColour(anim_line[x], src[x]).data;
469 src += _screen.pitch;
470 anim_line += _screen.pitch;
478 assert(video >= _screen.dst_ptr && video <= (uint32_t *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
484 dst = anim_buf + left + (top + height - 1) * _screen.pitch;
485 src = dst - scroll_y * _screen.pitch;
494 uint tw = width + (scroll_x >= 0 ? -scroll_x : scroll_x);
495 uint th = height - scroll_y;
496 Blitter::MovePixels(src, dst, tw, th, -_screen.pitch);
499 dst = anim_buf + left + top * _screen.pitch;
500 src = dst - scroll_y * _screen.pitch;
509 uint tw = width + (scroll_x >= 0 ? -scroll_x : scroll_x);
510 uint th = height + scroll_y;
511 Blitter::MovePixels(src, dst, tw, th, _screen.pitch);
519 return (
sizeof(uint32_t) +
sizeof(uint8_t)) * width * height;
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.
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(SpriteType sprite_type, 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.
@ VideoBackend
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.
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)
SpriteType
Types of sprites that might be loaded.
@ 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 uint8_t GetColourBrightness(Colour colour)
Get the brightness of a 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.
SpriteCollMap< uint32_t > offset[2]
Offsets (from .data) to streams for different zoom levels, and the normal and remap image information...
Data structure describing a sprite.
ZoomLevel
All zoom levels we know.