|
OpenTTD Source
1.11.0-beta1
|
Go to the documentation of this file.
10 #include "../stdafx.h"
11 #include "../zoom_func.h"
12 #include "../settings_type.h"
15 #include "../safeguards.h"
27 template <BlitterMode mode>
38 const uint16 *src_n = (
const uint16 *)(src->
data + src->
offset[zoom][1]);
41 for (uint i = bp->
skip_top; i != 0; i--) {
42 src_px = (
const Colour *)((
const byte *)src_px + *(
const uint32 *)src_px);
43 src_n = (
const uint16 *)((
const byte *)src_n + *(
const uint32 *)src_n);
50 const byte *remap = bp->
remap;
52 for (
int y = 0; y < bp->
height; y++) {
57 const Colour *src_px_ln = (
const Colour *)((
const byte *)src_px + *(
const uint32 *)src_px);
61 const uint16 *src_n_ln = (
const uint16 *)((
const byte *)src_n + *(
const uint32 *)src_n);
70 while (dst < dst_end) {
78 if (dst + n > dst_end) {
79 uint d = dst_end - dst;
84 dst_end = dst + bp->
width;
86 n = std::min(n - d, (uint)bp->
width);
100 while (dst < dst_end) {
101 n = std::min<uint>(*src_n++, dst_end - dst);
103 if (src_px->a == 0) {
114 if (src_px->a == 255) {
121 uint r = remap[
GB(m, 0, 8)];
134 uint r = remap[
GB(m, 0, 8)];
145 if (src_px->a == 255) {
149 uint8 g =
MakeDark(src_px->r, src_px->g, src_px->b);
152 uint r = remap[
GB(m, 0, 8)];
163 if (src_px->a != 0) {
164 uint8 g =
MakeDark(src_px->r, src_px->g, src_px->b);
168 uint r = remap[
GB(m, 0, 8)];
194 if (src_px->a == 255) {
210 if (src_px->a == 255) {
246 default: NOT_REACHED();
247 case BM_NORMAL: Draw<BM_NORMAL> (bp, zoom);
return;
285 for (
ZoomLevel z = zoom_min; z <= zoom_max; z++) {
290 dst_px_orig[z] = CallocT<Colour>(size + src_orig->
height * 2);
291 dst_n_orig[z] = CallocT<uint16>(size * 2 + src_orig->
height * 4 * 2);
293 uint32 *dst_px_ln = (uint32 *)dst_px_orig[z];
294 uint32 *dst_n_ln = (uint32 *)dst_n_orig[z];
298 for (uint y = src_orig->
height; y > 0; y--) {
300 uint16 *dst_n = (uint16 *)(dst_n_ln + 1);
302 uint16 *dst_len = dst_n++;
307 for (uint x = src_orig->
width; x > 0; x--) {
309 uint t = a > 0 && a < 255 ? 1 : a;
311 if (last != t || len == 65535) {
327 uint8 rgb_max = std::max({src->
r, src->
g, src->
b});
330 if (rgb_max == 0) rgb_max = DEFAULT_BRIGHTNESS;
331 *dst_n |= rgb_max << 8;
335 dst_px->r = colour.r;
336 dst_px->g = colour.g;
337 dst_px->b = colour.b;
345 }
else if (len == 1) {
359 dst_n = (uint16 *)
AlignPtr(dst_n, 4);
361 *dst_px_ln = (uint8 *)dst_px - (uint8 *)dst_px_ln;
362 *dst_n_ln = (uint8 *)dst_n - (uint8 *)dst_n_ln;
364 dst_px_ln = (uint32 *)dst_px;
365 dst_n_ln = (uint32 *)dst_n;
368 lengths[z][0] = (
byte *)dst_px_ln - (
byte *)dst_px_orig[z];
369 lengths[z][1] = (
byte *)dst_n_ln - (
byte *)dst_n_orig[z];
373 for (
ZoomLevel z = zoom_min; z <= zoom_max; z++) {
374 len += lengths[z][0] + lengths[z][1];
385 memset(dst, 0,
sizeof(*dst));
387 for (
ZoomLevel z = zoom_min; z <= zoom_max; z++) {
388 dst->
offset[z][0] = z == zoom_min ? 0 : lengths[z - 1][1] + dst->
offset[z - 1][1];
391 memcpy(dst->
data + dst->
offset[z][0], dst_px_orig[z], lengths[z][0]);
392 memcpy(dst->
data + dst->
offset[z][1], dst_n_orig[z], lengths[z][1]);
394 free(dst_px_orig[z]);
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.
@ ST_FONT
A sprite used for fonts.
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)
BlitterMode
The modes of blitting we can do.
int width
The width in pixels that needs to be drawn to dst.
Sprite * Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override
Convert a sprite from the loader to our own format.
@ ZOOM_LVL_COUNT
Number of zoom levels.
void * dst
Destination buffer.
uint16 height
Height of the sprite.
static Colour ComposeColourPANoCheck(Colour colour, uint a, Colour current)
Compose a colour based on Pixel value, alpha value, and the current pixel value.
int16 x_offs
Number of pixels to shift the sprite to the right.
ZoomLevel
All zoom levels we know.
int pitch
The pitch of the destination buffer.
ClientSettings _settings_client
The current settings for this game.
@ ZOOM_LVL_MAX
Maximum zoom level.
ZoomLevel zoom_max
maximum zoom out level
@ BM_NORMAL
Perform the simple blitting.
SpriteLoader::CommonPixel * data
The sprite itself.
const void * sprite
Pointer to the sprite how ever the encoder stored it.
byte data[]
Data, all zoomlevels.
SpriteType type
The sprite type.
@ BM_COLOUR_REMAP
Perform a colour remapping.
Definition of a common pixel in OpenTTD's realm.
@ BM_CRASH_REMAP
Perform a crash remapping.
uint16 width
Width of the sprite.
static Colour LookupColourInPalette(uint index)
Look up the colour in the current palette.
int16 x_offs
The x-offset of where the sprite will be drawn.
@ BM_BLACK_REMAP
Perform remapping to a completely blackened sprite.
static uint8 MakeDark(uint8 r, uint8 g, uint8 b)
Make a colour dark grey, for specialized 32bpp remapping.
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override
Draws a sprite to a (screen) buffer.
Structure to access the alpha, red, green, and blue channels from a 32 bit number.
ZoomLevel zoom_min
minimum zoom out level
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.
uint16 width
Width of the sprite.
uint8 a
colour channels in LE order
Factory for the optimised 32 bpp blitter (without palette animation).
int left
The left offset in the 'dst' in pixels to start drawing.
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.
int16 y_offs
Number of pixels to shift the sprite downwards.
Structure for passing information from the sprite loader to the blitter.
static Colour MakeTransparent(Colour colour, uint nom, uint denom=256)
Make a pixel looks like it is transparent.
Parameters related to blitting.
@ ZOOM_LVL_NORMAL
The normal zoom level.
int height
The height in pixels that needs to be drawn to dst.
int16 y_offs
The y-offset of where the sprite will be drawn.
Data stored about a (single) sprite.
uint16 height
Height of the sprite.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
int skip_top
How much pixels of the source to skip on the top (based on zoom of dst)
Data structure describing a sprite.
static T * AlignPtr(T *x, uint n)
Return the smallest multiple of n equal or greater than x Applies to pointers only.
const byte * remap
XXX – Temporary storage for remap array.
GUISettings gui
settings related to the GUI
static FBlitter_32bppOptimized iFBlitter_32bppOptimized
Instantiation of the optimized 32bpp blitter factory.