11#include "../zoom_func.h"
12#include "../settings_type.h"
13#include "../palette_func.h"
16#include "../safeguards.h"
28template <BlitterMode mode,
bool Tpal_to_rgb>
39 const uint16_t *src_n = (
const uint16_t *)(src->
data + src->
offset[zoom][1]);
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++) {
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)];
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();
264 case BM_NORMAL: Draw<BM_NORMAL, Tpal_to_rgb>(bp, zoom);
return;
265 case BM_COLOUR_REMAP: Draw<BM_COLOUR_REMAP, Tpal_to_rgb>(bp, zoom);
return;
266 case BM_TRANSPARENT: Draw<BM_TRANSPARENT, Tpal_to_rgb>(bp, zoom);
return;
268 case BM_CRASH_REMAP: Draw<BM_CRASH_REMAP, Tpal_to_rgb>(bp, zoom);
return;
269 case BM_BLACK_REMAP: Draw<BM_BLACK_REMAP, Tpal_to_rgb>(bp, zoom);
return;
285 this->Draw<false>(bp, mode, zoom);
318 for (
ZoomLevel z = zoom_min; z <= zoom_max; z++) {
323 dst_px_orig[z] = CallocT<Colour>(size + src_orig->
height * 2);
324 dst_n_orig[z] = CallocT<uint16_t>(size * 2 + src_orig->
height * 4 * 2);
326 uint32_t *dst_px_ln = (uint32_t *)dst_px_orig[z];
327 uint32_t *dst_n_ln = (uint32_t *)dst_n_orig[z];
331 for (uint y = src_orig->height; y > 0; y--) {
334 uint16_t *dst_n = (uint16_t *)&dst_n_ln[1];
336 uint16_t *dst_len = dst_n++;
341 for (uint x = src_orig->width; x > 0; x--) {
343 uint t = a > 0 && a < 255 ? 1 : a;
345 if (last != t || len == 65535) {
361 uint8_t rgb_max = std::max({ src->r, src->g, src->b });
364 if (rgb_max == 0) rgb_max = DEFAULT_BRIGHTNESS;
365 *dst_n |= rgb_max << 8;
370 dst_px->r = colour.r;
371 dst_px->g = colour.g;
372 dst_px->
b = colour.
b;
385 }
else if (len == 1) {
399 dst_n = (uint16_t *)
AlignPtr(dst_n, 4);
401 *dst_px_ln = (uint8_t *)dst_px - (uint8_t *)dst_px_ln;
402 *dst_n_ln = (uint8_t *)dst_n - (uint8_t *)dst_n_ln;
404 dst_px_ln = (uint32_t *)dst_px;
405 dst_n_ln = (uint32_t *)dst_n;
408 lengths[z][0] = (uint8_t *)dst_px_ln - (uint8_t *)dst_px_orig[z];
409 lengths[z][1] = (uint8_t *)dst_n_ln - (uint8_t *)dst_n_orig[z];
413 for (
ZoomLevel z = zoom_min; z <= zoom_max; z++) {
414 len += lengths[z][0] + lengths[z][1];
417 Sprite *dest_sprite = allocator.
Allocate<
Sprite>(
sizeof(*dest_sprite) +
sizeof(SpriteData) + len);
424 SpriteData *dst = (SpriteData *)dest_sprite->data;
425 memset(dst, 0,
sizeof(*dst));
427 for (
ZoomLevel z = zoom_min; z <= zoom_max; z++) {
428 dst->offset[z][0] = z == zoom_min ? 0 : lengths[z - 1][1] + dst->offset[z - 1][1];
429 dst->offset[z][1] = lengths[z][0] + dst->offset[z][0];
431 memcpy(dst->data + dst->offset[z][0], dst_px_orig[z], lengths[z][0]);
432 memcpy(dst->data + dst->offset[z][1], dst_n_orig[z], lengths[z][1]);
434 free(dst_px_orig[z]);
446 return this->EncodeInternal<true>(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.
@ 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.
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.
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override
Draws a sprite to a (screen) buffer.
Sprite * Encode(const SpriteLoader::SpriteCollection &sprite, SpriteAllocator &allocator) override
Convert a sprite from the loader to our own format.
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.
std::array< Sprite, ZOOM_LVL_END > SpriteCollection
Type defining a collection of sprites, one for each zoom level.
@ 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.
ClientSettings _settings_client
The current settings for this game.
void free(const void *ptr)
Version of the standard free that accepts const pointers.
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...
GUISettings gui
settings related to the GUI
ZoomLevel zoom_min
minimum zoom out level
ZoomLevel zoom_max
maximum zoom out level
Definition of a common pixel in OpenTTD's realm.
Structure for passing information from the sprite loader to the blitter.
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.
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.
@ ZOOM_LVL_MAX
Maximum zoom level.
@ ZOOM_LVL_END
End for iteration.
@ ZOOM_LVL_MIN
Minimum zoom level.