44 size_t y_offset =
static_cast<size_t>(y) * _screen.pitch;
64 Colour *dst = (Colour *)video;
65 uint8_t *anim = anim_line;
67 for (
int i = width; i > 0; i--) {
73 video = (uint32_t *)video + _screen.pitch;
74 anim_line += anim_pitch;
90 this->DrawLineGeneric(x, y, x2, y2, screen_width, screen_height, width, dash, [=](
int x,
int y) {
92 *(anim + x + y * anim_pitch) = colour.
p;
103template <BlitterMode mode>
110 const Colour *src_px =
reinterpret_cast<const Colour *
>(src->
data + src->
offset[0][zoom]);
114 const uint16_t *src_n =
reinterpret_cast<const uint16_t *
>(src->
data + src->
offset[1][zoom]);
117 for (uint i = bp->
skip_top; i != 0; i--) {
118 src_px = (
const Colour *)((
const uint8_t *)src_px + *(
const uint32_t *)src_px);
119 src_n = (
const uint16_t *)((
const uint8_t *)src_n + *(
const uint32_t *)src_n);
129 const uint8_t *remap = bp->
remap;
131 for (
int y = 0; y < bp->
height; y++) {
133 Colour *dst_ln = dst + bp->
pitch;
134 uint8_t *anim_ln = anim + anim_pitch;
137 const Colour *src_px_ln = (
const Colour *)((
const uint8_t *)src_px + *(
const uint32_t *)src_px);
141 const uint16_t *src_n_ln = (
const uint16_t *)((
const uint8_t *)src_n + *(
const uint32_t *)src_n);
150 while (dst < dst_end) {
153 if (src_px->a == 0) {
158 if (dst > dst_end) anim += dst - dst_end;
160 if (dst + n > dst_end) {
161 uint d = dst_end - dst;
166 dst_end = dst + bp->
width;
168 n = std::min<uint>(n - d, (uint)bp->
width);
180 dst_end += bp->
width;
182 while (dst < dst_end) {
183 n = std::min<uint>(*src_n++, (uint)(dst_end - dst));
185 if (src_px->a == 0) {
198 if (src_px->a == 255) {
200 uint8_t m =
GB(*src_n, 0, 8);
219 uint8_t m =
GB(*src_n, 0, 8);
220 Colour b = this->RealizeBlendedColour(*anim, *dst);
252 if (src_px->a == 255) {
265 Colour b = this->RealizeBlendedColour(*anim, *dst);
278 if (src_px->a != 0) {
282 *anim = remap[*anim];
298 if (src_px->a == 255) {
300 *anim++ =
GB(*src_n, 0, 8);
301 *dst++ = src_px->data;
308 uint8_t m =
GB(*src_n, 0, 8);
309 Colour b = this->RealizeBlendedColour(*anim, *dst);
344 assert(_screen.dst_ptr !=
nullptr);
353 default: NOT_REACHED();
371 Colour *udst = (Colour *)dst;
380 for (
int i = 0; i != width; i++) {
386 udst = udst - width + _screen.pitch;
387 anim = anim - width + anim_pitch;
392 for (
int i = 0; i != width; i++) {
396 *anim = remap[*anim];
401 udst = udst - width + _screen.pitch;
402 anim = anim - width + anim_pitch;
407 for (
int i = 0; i != width; i++) {
408 if (*anim != 0) *anim = remap[*anim];
411 anim = anim - width + anim_pitch;
418 return this->EncodeInternal<false>(sprite_type, sprite, allocator);
425 assert(video >= _screen.dst_ptr && video <= (uint32_t *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
426 uint32_t *dst = (uint32_t *)video;
427 const uint32_t *usrc = (
const uint32_t *)src;
433 for (; height > 0; height--) {
434 std::copy_n(usrc, width, dst);
436 dst += _screen.pitch;
438 std::copy_n(
reinterpret_cast<const uint8_t *
>(usrc), width, anim_line);
439 usrc = (
const uint32_t *)((
const uint8_t *)usrc + width);
440 anim_line += anim_pitch;
447 assert(video >= _screen.dst_ptr && video <= (uint32_t *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
448 uint32_t *udst = (uint32_t *)dst;
449 const uint32_t *src = (
const uint32_t *)video;
455 for (; height > 0; height--) {
456 std::copy_n(src, width, udst);
457 src += _screen.pitch;
460 std::copy_n(anim_line, width,
reinterpret_cast<uint8_t *
>(udst));
461 udst = (uint32_t *)((uint8_t *)udst + width);
462 anim_line += anim_pitch;
473 uint32_t *udst = (uint32_t *)dst;
474 const uint32_t *src = (
const uint32_t *)video;
478 for (; height > 0; height--) {
479 for (
int x = 0; x < width; x++) {
480 udst[x] = this->RealizeBlendedColour(anim_line[x], src[x]).data;
482 src += _screen.pitch;
483 anim_line += anim_pitch;
491 assert(video >= _screen.dst_ptr && video <= (uint32_t *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
498 dst = anim_buf + left + (top + height - 1) * anim_pitch;
499 src = dst - scroll_y * anim_pitch;
508 uint tw = width + (scroll_x >= 0 ? -scroll_x : scroll_x);
509 uint th = height - scroll_y;
510 Blitter::MovePixels(src, dst, tw, th, -anim_pitch);
513 dst = anim_buf + left + top * anim_pitch;
514 src = dst - scroll_y * anim_pitch;
523 uint tw = width + (scroll_x >= 0 ? -scroll_x : scroll_x);
524 uint th = height + scroll_y;
525 Blitter::MovePixels(src, dst, tw, th, anim_pitch);
533 return (
sizeof(uint32_t) +
sizeof(uint8_t)) * width * height;
A 32 bpp blitter with animation support.
static T * ScreenToAnimationBuffer(const void *video, T *animation_buffer, int animation_buffer_pitch)
Converts video buffer pointer into the animation buffer pointer.
static FBlitter_40bppAnim iFBlitter_40bppAnim
Instantiation of the 40bpp with animation blitter factory.
static uint8_t * ScreenToAnimationBuffer(const void *video)
Converts video buffer pointer into the animation buffer pointer.
static const Colour _black_colour
Cached black value.
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.
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.
static Colour ComposeColourPANoCheck(Colour colour, uint a, Colour current)
Compose a colour based on Pixel value, alpha value, and the current pixel value.
static Colour LookupColourInPalette(uint index)
Look up the colour in the current palette.
void DrawRect(void *video, int width, int height, PixelColour colour) override
Make a single horizontal line in a single colour on the video-buffer.
void SetPixel(void *video, int x, int y, PixelColour colour) override
Draw a pixel with a given colour on the video-buffer.
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 DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, PixelColour colour, int width, int dash) override
Draw a line with a given colour.
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.
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.
void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, PixelColour colour, int width, int dash) override
Draw a line with a given colour.
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 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 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 CopyFromBuffer(void *video, const void *src, int width, int height) override
Copy from a buffer to the screen.
void DrawRect(void *video, int width, int height, PixelColour colour) override
Make a single horizontal line in a single colour on the video-buffer.
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.
void SetPixel(void *video, int x, int y, PixelColour colour) override
Draw a pixel with a given colour on the video-buffer.
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.
SpriteCollMap< Sprite > SpriteCollection
Type defining a collection of sprites, one for each zoom level.
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
constexpr uint8_t * GetAnimBuffer() const
Get a pointer to the animation buffer of the video back-end.
constexpr int GetAnimBufferPitch() const
Get the animation buffer pitch in uint8_t elements per row.
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.
Functions related to palettes.
static uint8_t GetColourBrightness(Colour colour)
Get the brightness of a colour.
A number of safeguards to prevent using unsafe methods.
Functions to cache sprites in memory.
This file contains all sprite-related enums and defines.
static const PaletteID PALETTE_TO_TRANSPARENT
This sets the sprite to transparent.
static const PaletteID PALETTE_NEWSPAPER
Recolour sprite for newspaper-greying.
Definition of base types and functions in a cross-platform compatible way.
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...
Colour for pixel/line drawing.
Data structure describing a sprite.
Base of all video drivers.
ZoomLevel
All zoom levels we know.