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 = min<uint>(n - d, (uint)bp->
width);
100 while (dst < dst_end) {
101 n = min<uint>(*src_n++, (uint)(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 =
max(src->
r,
max(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]);
int left
The left offset in the 'dst' in pixels to start drawing.
Sprite * Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override
Convert a sprite from the loader to our own format.
int height
The height in pixels that needs to be drawn to dst.
Perform transparency colour remapping.
int skip_top
How much pixels of the source to skip on the top (based on zoom of dst)
byte data[]
Data, all zoomlevels.
Data structure describing a sprite.
uint32 offset[ZOOM_LVL_COUNT][2]
Offsets (from .data) to streams for different zoom levels, and the normal and remap image information...
uint32 data
Conversion of the channel information to a 32 bit number.
int width
The width in pixels that needs to be drawn to dst.
uint8 a
colour channels in LE order
static Colour LookupColourInPalette(uint index)
Look up the colour in the current palette.
int skip_left
How much pixels of the source to skip on the left (based on zoom of dst)
static T max(const T a, const T b)
Returns the maximum of two values.
static Colour ComposeColourPANoCheck(Colour colour, uint a, Colour current)
Compose a colour based on Pixel value, alpha value, and the current pixel value.
Definition of a common pixel in OpenTTD's realm.
SpriteType type
The sprite type.
Data stored about a (single) sprite.
Factory for the optimised 32 bpp blitter (without palette animation).
int16 y_offs
Number of pixels to shift the sprite downwards.
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override
Draws a sprite to a (screen) buffer.
Parameters related to blitting.
ClientSettings _settings_client
The current settings for this game.
int pitch
The pitch of the destination buffer.
int16 x_offs
The x-offset of where the sprite will be drawn.
SpriteLoader::CommonPixel * data
The sprite itself.
Perform a crash remapping.
ZoomLevel zoom_max
maximum zoom out level
Structure for passing information from the sprite loader to the blitter.
static FBlitter_32bppOptimized iFBlitter_32bppOptimized
Instantiation of the optimized 32bpp blitter factory.
static T * AlignPtr(T *x, uint n)
Return the smallest multiple of n equal or greater than x Applies to pointers only.
Perform remapping to a completely blackened sprite.
uint16 height
Height of the sprite.
uint16 width
Width of the sprite.
uint16 width
Width of the sprite.
int top
The top offset in the 'dst' in pixels to start drawing.
GUISettings gui
settings related to the GUI
const byte * remap
XXX – Temporary storage for remap array.
const void * sprite
Pointer to the sprite how ever the encoder stored it.
static uint8 MakeDark(uint8 r, uint8 g, uint8 b)
Make a colour dark grey, for specialized 32bpp remapping.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Perform a colour remapping.
uint16 height
Height of the sprite.
int16 x_offs
Number of pixels to shift the sprite to the right.
void * dst
Destination buffer.
Structure to access the alpha, red, green, and blue channels from a 32 bit number.
Perform the simple blitting.
int16 y_offs
The y-offset of where the sprite will be drawn.
Optimized 32 bpp blitter.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
BlitterMode
The modes of blitting we can do.
ZoomLevel
All zoom levels we know.
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.
ZoomLevel zoom_min
minimum zoom out level
static Colour MakeTransparent(Colour colour, uint nom, uint denom=256)
Make a pixel looks like it is transparent.
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.