28template <BlitterMode mode,
bool Tpal_to_rgb>
35 const Colour *src_px =
reinterpret_cast<const Colour *
>(src->
data + src->
offset[0][zoom]);
39 const uint16_t *src_n =
reinterpret_cast<const uint16_t *
>(src->
data + src->
offset[1][zoom]);
42 for (uint i = bp->
skip_top; i != 0; i--) {
43 src_px = (
const Colour *)((
const uint8_t *)src_px + *(
const uint32_t *)src_px);
44 src_n = (
const uint16_t *)((
const uint8_t *)src_n + *(
const uint32_t *)src_n);
51 const uint8_t *remap = bp->
remap;
53 for (
int y = 0; y < bp->
height; y++) {
55 Colour *dst_ln = dst + bp->
pitch;
58 const Colour *src_px_ln = (
const Colour *)((
const uint8_t *)src_px + *(
const uint32_t *)src_px);
62 const uint16_t *src_n_ln = (
const uint16_t *)((
const uint8_t *)src_n + *(
const uint32_t *)src_n);
71 while (dst < dst_end) {
79 if (dst + n > dst_end) {
80 uint d = dst_end - dst;
85 dst_end = dst + bp->
width;
87 n = std::min(n - d, (uint)bp->
width);
101 while (dst < dst_end) {
102 n = std::min<uint>(*src_n++, dst_end - dst);
104 if (src_px->a == 0) {
115 if (src_px->a == 255) {
122 uint r = remap[
GB(m, 0, 8)];
135 uint r = remap[
GB(m, 0, 8)];
146 if (src_px->a == 255) {
150 uint8_t g =
MakeDark(src_px->r, src_px->g, src_px->b);
153 uint r = remap[
GB(m, 0, 8)];
164 if (src_px->a != 0) {
165 uint8_t g =
MakeDark(src_px->r, src_px->g, src_px->b);
169 uint r = remap[
GB(m, 0, 8)];
181 *dst = Colour(0, 0, 0);
191 if (src_px->a == 255) {
209 if (src_px->a != 0) {
222 if (src_px->a == 255) {
225 if (Tpal_to_rgb && *src_n != 0) {
237 if (Tpal_to_rgb && *src_n != 0) {
259template <
bool Tpal_to_rgb>
263 default: NOT_REACHED();
288template <
bool Tpal_to_rgb>
319 for (
ZoomLevel z = zoom_min; z <= zoom_max; z++) {
320 const SpriteLoader::Sprite *src_orig = &sprite[z];
324 dst_px_orig[z] = std::make_unique<Colour[]>(size + src_orig->
height * 2);
325 dst_n_orig[z] = std::make_unique<uint16_t[]>(size * 2 + src_orig->
height * 4 * 2);
327 uint32_t *dst_px_ln =
reinterpret_cast<uint32_t *
>(dst_px_orig[z].get());
328 uint32_t *dst_n_ln =
reinterpret_cast<uint32_t *
>(dst_n_orig[z].get());
330 const SpriteLoader::CommonPixel *src = (
const SpriteLoader::CommonPixel *)src_orig->
data;
332 for (uint y = src_orig->
height; y > 0; y--) {
334 Colour *dst_px = (Colour *)&dst_px_ln[1];
335 uint16_t *dst_n = (uint16_t *)&dst_n_ln[1];
337 uint16_t *dst_len = dst_n++;
342 for (uint x = src_orig->
width; x > 0; x--) {
344 uint t = a > 0 && a < 255 ? 1 : a;
346 if (last != t || len == 65535) {
362 uint8_t rgb_max = std::max({ src->r, src->g, src->b });
365 if (rgb_max == 0) rgb_max = DEFAULT_BRIGHTNESS;
366 *dst_n |= rgb_max << 8;
371 dst_px->r = colour.r;
372 dst_px->g = colour.g;
373 dst_px->b = colour.b;
386 }
else if (len == 1) {
399 dst_px = (Colour *)
AlignPtr(dst_px, 4);
400 dst_n = (uint16_t *)
AlignPtr(dst_n, 4);
402 *dst_px_ln = (uint8_t *)dst_px - (uint8_t *)dst_px_ln;
403 *dst_n_ln = (uint8_t *)dst_n - (uint8_t *)dst_n_ln;
405 dst_px_ln = (uint32_t *)dst_px;
406 dst_n_ln = (uint32_t *)dst_n;
409 lengths[0][z] =
reinterpret_cast<uint8_t *
>(dst_px_ln) -
reinterpret_cast<uint8_t *
>(dst_px_orig[z].get());
410 lengths[1][z] =
reinterpret_cast<uint8_t *
>(dst_n_ln) -
reinterpret_cast<uint8_t *
>(dst_n_orig[z].get());
414 for (
ZoomLevel z = zoom_min; z <= zoom_max; z++) {
415 len += lengths[0][z] + lengths[1][z];
420 const auto &root_sprite = sprite.Root();
429 for (
ZoomLevel z = zoom_min; z <= zoom_max; z++) {
430 dst->offset[0][z] = offset;
431 offset += lengths[0][z];
432 dst->offset[1][z] = offset;
433 offset += lengths[1][z];
435 std::copy_n(
reinterpret_cast<uint8_t *
>(dst_px_orig[z].get()), lengths[0][z], dst->data + dst->offset[0][z]);
436 std::copy_n(
reinterpret_cast<uint8_t *
>(dst_n_orig[z].get()), lengths[1][z], dst->data + dst->offset[1][z]);
447 return this->EncodeInternal<true>(sprite_type, sprite, allocator);
static FBlitter_32bppOptimized iFBlitter_32bppOptimized
Instantiation of the optimized 32bpp blitter factory.
Optimized 32 bpp blitter.
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.
static Colour MakeTransparent(Colour colour, uint nom, uint denom=256)
Make a pixel looks like it is transparent.
static uint8_t MakeDark(uint8_t r, uint8_t g, uint8_t b)
Make a colour dark grey, for specialized 32bpp remapping.
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.
Sprite * Encode(SpriteType sprite_type, const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator) override
Convert a sprite from the loader to our own format.
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override
Draws a sprite to a (screen) buffer.
Factory for the optimised 32 bpp blitter (without palette animation).
Interface for something that can allocate memory for a sprite.
T * Allocate(size_t size)
Allocate memory for a sprite.
SpriteCollMap< Sprite > SpriteCollection
Type defining a collection of sprites, one for each zoom level.
@ Sprite
FaceVar describes an offset to the given SpriteID.
SpriteType
Types of sprites that might be loaded.
@ Font
A sprite used for fonts.
constexpr T * AlignPtr(T *x, uint n)
Return the smallest multiple of n equal or greater than x Applies to pointers only.
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.
A number of safeguards to prevent using unsafe methods.
ClientSettings _settings_client
The current settings for this game.
Types related to global configuration settings.
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...
GUISettings gui
settings related to the GUI
ZoomLevel zoom_min
minimum zoom out level
ZoomLevel zoom_max
maximum zoom out level
uint16_t width
Width of the sprite.
SpriteLoader::CommonPixel * data
The sprite itself.
uint16_t height
Height of the sprite.
Data structure describing a sprite.
uint16_t width
Width of the sprite.
uint16_t height
Height of the sprite.
int16_t y_offs
Number of pixels to shift the sprite downwards.
std::byte data[]
Sprite data.
int16_t x_offs
Number of pixels to shift the sprite to the right.
Functions related to zooming.
ZoomLevel
All zoom levels we know.