12 #include "../stdafx.h"
13 #include "../zoom_func.h"
14 #include "../settings_type.h"
15 #include "../video/video_driver.hpp"
16 #include "40bpp_anim.hpp"
19 #include "../table/sprites.h"
21 #include "../safeguards.h"
28 static const Colour _black_colour(0, 0, 0);
36 *((
Colour *)video + x + y * _screen.pitch) = _black_colour;
55 uint8 *anim = anim_line;
57 for (
int i = width; i > 0; i--) {
63 video = (uint32 *)video + _screen.pitch;
64 anim_line += _screen.pitch;
68 void Blitter_40bppAnim::DrawLine(
void *video,
int x,
int y,
int x2,
int y2,
int screen_width,
int screen_height, uint8 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;
92 template <BlitterMode mode>
103 const uint16 *src_n = (
const uint16 *)(src->
data + src->
offset[zoom][1]);
106 for (uint i = bp->
skip_top; i != 0; i--) {
107 src_px = (
const Colour *)((
const byte *)src_px + *(
const uint32 *)src_px);
108 src_n = (
const uint16 *)((
const byte *)src_n + *(
const uint32 *)src_n);
117 const byte *remap = bp->
remap;
119 for (
int y = 0; y < bp->
height; y++) {
122 uint8 *anim_ln = anim + bp->
pitch;
125 const Colour *src_px_ln = (
const Colour *)((
const byte *)src_px + *(
const uint32 *)src_px);
129 const uint16 *src_n_ln = (
const uint16 *)((
const byte *)src_n + *(
const uint32 *)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 m =
GB(*src_n, 0, 8);
207 uint8 m =
GB(*src_n, 0, 8);
208 Colour b = this->RealizeBlendedColour(*anim, *dst);
231 *dst++ = _black_colour;
244 if (src_px->a == 255) {
250 Colour b = *anim != 0 ?
Colour(this->GetColourBrightness(*dst), 0, 0) : *dst;
257 Colour b = this->RealizeBlendedColour(*anim, *dst);
268 if (src_px->a == 255) {
270 *anim++ =
GB(*src_n, 0, 8);
271 *dst++ = src_px->
data;
278 uint8 m =
GB(*src_n, 0, 8);
279 Colour b = this->RealizeBlendedColour(*anim, *dst);
314 assert(_screen.dst_ptr !=
nullptr);
318 Blitter_32bppOptimized::Draw<true>(bp, mode, zoom);
323 default: NOT_REACHED();
324 case BM_NORMAL: Draw<BM_NORMAL> (bp, zoom);
return;
348 for (
int i = 0; i != width; i++) {
349 Colour b = *anim != 0 ?
Colour(this->GetColourBrightness(*udst), 0, 0) : *udst;
354 udst = udst - width + _screen.pitch;
355 anim = anim - width + _screen.pitch;
358 const uint8 *remap = GetNonSprite(pal,
ST_RECOLOUR) + 1;
360 for (
int i = 0; i != width; i++) {
361 if (*anim == 0) *udst =
MakeGrey(*udst);
362 *anim = remap[*anim];
366 udst = udst - width + _screen.pitch;
367 anim = anim - width + _screen.pitch;
370 const uint8 *remap = GetNonSprite(pal,
ST_RECOLOUR) + 1;
372 for (
int i = 0; i != width; i++) {
373 *anim = remap[*anim];
376 anim = anim - width + _screen.pitch;
383 return this->EncodeInternal<false>(sprite, allocator);
390 assert(video >= _screen.dst_ptr && video <= (uint32 *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
391 uint32 *dst = (uint32 *)video;
392 const uint32 *usrc = (
const uint32 *)src;
395 if (anim_buf ==
nullptr)
return;
396 uint8 *anim_line = ((uint32 *)video - (uint32 *)_screen.dst_ptr) + anim_buf;
398 for (; height > 0; height--) {
399 memcpy(dst, usrc, width *
sizeof(uint32));
401 dst += _screen.pitch;
403 memcpy(anim_line, usrc, width *
sizeof(uint8));
404 usrc = (
const uint32 *)((
const uint8 *)usrc + width);
405 anim_line += _screen.pitch;
412 assert(video >= _screen.dst_ptr && video <= (uint32 *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
413 uint32 *udst = (uint32 *)dst;
414 const uint32 *src = (
const uint32 *)video;
417 if (anim_buf ==
nullptr)
return;
418 const uint8 *anim_line = ((
const uint32 *)video - (uint32 *)_screen.dst_ptr) + anim_buf;
420 for (; height > 0; height--) {
421 memcpy(udst, src, width *
sizeof(uint32));
422 src += _screen.pitch;
425 memcpy(udst, anim_line, width *
sizeof(uint8));
426 udst = (uint32 *)((uint8 *)udst + width);
427 anim_line += _screen.pitch;
434 if (anim_buf ==
nullptr) {
439 uint32 *udst = (uint32 *)dst;
440 const uint32 *src = (
const uint32 *)video;
441 const uint8 *anim_line = ((
const uint32 *)video - (uint32 *)_screen.dst_ptr) + anim_buf;
443 for (; height > 0; height--) {
444 for (
int x = 0; x < width; x++) {
445 udst[x] = this->RealizeBlendedColour(anim_line[x], src[x]).
data;
447 src += _screen.pitch;
448 anim_line += _screen.pitch;
456 assert(video >= _screen.dst_ptr && video <= (uint32 *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
462 dst = anim_buf + left + (top + height - 1) * _screen.pitch;
463 src = dst - scroll_y * _screen.pitch;
472 uint tw = width + (scroll_x >= 0 ? -scroll_x : scroll_x);
473 uint th = height - scroll_y;
474 for (; th > 0; th--) {
475 memcpy(dst, src, tw *
sizeof(uint8));
476 src -= _screen.pitch;
477 dst -= _screen.pitch;
481 dst = anim_buf + left + top * _screen.pitch;
482 src = dst - scroll_y * _screen.pitch;
493 uint tw = width + (scroll_x >= 0 ? -scroll_x : scroll_x);
494 uint th = height + scroll_y;
495 for (; th > 0; th--) {
496 memmove(dst, src, tw *
sizeof(uint8));
497 src += _screen.pitch;
498 dst += _screen.pitch;
507 return width * height * (
sizeof(uint32) +
sizeof(uint8));
uint32 data
Conversion of the channel information to a 32 bit number.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
int top
The top offset in the 'dst' in pixels to start drawing.
@ BM_TRANSPARENT
Perform transparency colour remapping.
int skip_left
How much pixels of the source to skip on the left (based on zoom of dst)
void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override
Draw a colourtable to the screen.
BlitterMode
The modes of blitting we can do.
int width
The width in pixels that needs to be drawn to dst.
void * dst
Destination buffer.
static const PaletteID PALETTE_TO_TRANSPARENT
This sets the sprite to transparent.
static Colour ComposeColourPANoCheck(Colour colour, uint a, Colour current)
Compose a colour based on Pixel value, alpha value, and the current pixel value.
ZoomLevel
All zoom levels we know.
void SetPixel(void *video, int x, int y, uint8 colour) override
Draw a pixel with a given colour on the video-buffer.
int pitch
The pitch of the destination buffer.
void CopyToBuffer(const void *video, void *dst, int width, int height) override
Copy from the screen to a buffer.
void CopyFromBuffer(void *video, const void *src, int width, int height) override
Copy from a buffer to the screen.
@ BM_NORMAL
Perform the simple blitting.
int BufferSize(int width, int height) override
Calculate how much memory there is needed for an image of this size in the video-buffer.
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override
Draws a sprite to a (screen) buffer.
const void * sprite
Pointer to the sprite how ever the encoder stored it.
byte data[]
Data, all zoomlevels.
void SetPixel(void *video, int x, int y, uint8 colour) override
Draw a pixel with a given colour on the video-buffer.
static Colour MakeGrey(Colour colour)
Make a colour grey - based.
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.
bool _screen_disable_anim
Disable palette animation (important for 32bpp-anim blitter during giant screenshot)
@ BM_COLOUR_REMAP
Perform a colour remapping.
static const PaletteID PALETTE_NEWSPAPER
Recolour sprite for newspaper-greying.
@ BM_CRASH_REMAP
Perform a crash remapping.
static Colour LookupColourInPalette(uint index)
Look up the colour in the current palette.
void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override
Draw a colourtable to the screen.
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.
@ BM_BLACK_REMAP
Perform remapping to a completely blackened sprite.
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.
Factory for the 40 bpp animated blitter (for OpenGL).
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
static uint8 MakeDark(uint8 r, uint8 g, uint8 b)
Make a colour dark grey, for specialized 32bpp remapping.
void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash) override
Draw a line with a given colour.
virtual uint8 * GetAnimBuffer()
Get a pointer to the animation buffer of the video back-end.
Structure to access the alpha, red, green, and blue channels from a 32 bit number.
PaletteAnimation
Types of palette animation.
uint8 a
colour channels in LE order
void DrawRect(void *video, int width, int height, uint8 colour) override
Make a single horizontal line in a single colour on the video-buffer.
uint32 PaletteID
The number of the palette.
int left
The left offset in the 'dst' in pixels to start drawing.
@ PALETTE_ANIMATION_VIDEO_BACKEND
Palette animation should be done by video backend (8bpp only!)
void DrawRect(void *video, int width, int height, uint8 colour) override
Make a single horizontal line in a single colour on the video-buffer.
uint32 offset[ZOOM_LVL_COUNT][2]
Offsets (from .data) to streams for different zoom levels, and the normal and remap image information...
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.
Structure for passing information from the sprite loader to the blitter.
Sprite * Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override
Convert a sprite from the loader to our own format.
static Colour MakeTransparent(Colour colour, uint nom, uint denom=256)
Make a pixel looks like it is transparent.
bool NeedsAnimationBuffer() override
Does this blitter require a separate animation buffer from the video backend?
void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash) override
Draw a line with a given colour.
Parameters related to blitting.
int height
The height in pixels that needs to be drawn to dst.
@ ST_RECOLOUR
Recolour sprite.
Data stored about a (single) sprite.
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.
int skip_top
How much pixels of the source to skip on the top (based on zoom of dst)
Data structure describing a sprite.
const byte * remap
XXX – Temporary storage for remap array.
Blitter::PaletteAnimation UsePaletteAnimation() override
Check if the blitter uses palette animation at all.