12 #include "../stdafx.h" 13 #include "../zoom_func.h" 14 #include "../settings_type.h" 17 #include "../safeguards.h" 29 template <BlitterMode mode>
40 const uint16 *src_n = (
const uint16 *)(src->
data + src->
offset[zoom][1]);
43 for (uint i = bp->
skip_top; i != 0; i--) {
44 src_px = (
const Colour *)((
const byte *)src_px + *(
const uint32 *)src_px);
45 src_n = (
const uint16 *)((
const byte *)src_n + *(
const uint32 *)src_n);
52 const byte *remap = bp->
remap;
54 for (
int y = 0; y < bp->
height; y++) {
59 const Colour *src_px_ln = (
const Colour *)((
const byte *)src_px + *(
const uint32 *)src_px);
63 const uint16 *src_n_ln = (
const uint16 *)((
const byte *)src_n + *(
const uint32 *)src_n);
72 while (dst < dst_end) {
80 if (dst + n > dst_end) {
81 uint d = dst_end - dst;
86 dst_end = dst + bp->
width;
88 n = min<uint>(n - d, (uint)bp->
width);
100 dst_end += bp->
width;
102 while (dst < dst_end) {
103 n = min<uint>(*src_n++, (uint)(dst_end - dst));
105 if (src_px->a == 0) {
116 if (src_px->a == 255) {
123 uint r = remap[
GB(m, 0, 8)];
136 uint r = remap[
GB(m, 0, 8)];
147 if (src_px->a == 255) {
151 uint8 g =
MakeDark(src_px->r, src_px->g, src_px->b);
154 uint r = remap[
GB(m, 0, 8)];
165 if (src_px->a != 0) {
166 uint8 g =
MakeDark(src_px->r, src_px->g, src_px->b);
170 uint r = remap[
GB(m, 0, 8)];
196 if (src_px->a == 255) {
212 if (src_px->a == 255) {
248 default: NOT_REACHED();
249 case BM_NORMAL: Draw<BM_NORMAL> (bp, zoom);
return;
287 for (
ZoomLevel z = zoom_min; z <= zoom_max; z++) {
292 dst_px_orig[z] = CallocT<Colour>(size + src_orig->
height * 2);
293 dst_n_orig[z] = CallocT<uint16>(size * 2 + src_orig->
height * 4 * 2);
295 uint32 *dst_px_ln = (uint32 *)dst_px_orig[z];
296 uint32 *dst_n_ln = (uint32 *)dst_n_orig[z];
300 for (uint y = src_orig->
height; y > 0; y--) {
302 uint16 *dst_n = (uint16 *)(dst_n_ln + 1);
304 uint16 *dst_len = dst_n++;
309 for (uint x = src_orig->
width; x > 0; x--) {
311 uint t = a > 0 && a < 255 ? 1 : a;
313 if (last != t || len == 65535) {
329 uint8 rgb_max =
max(src->
r,
max(src->
g, src->
b));
332 if (rgb_max == 0) rgb_max = DEFAULT_BRIGHTNESS;
333 *dst_n |= rgb_max << 8;
337 dst_px->r = colour.r;
338 dst_px->g = colour.g;
339 dst_px->b = colour.b;
347 }
else if (len == 1) {
361 dst_n = (uint16 *)
AlignPtr(dst_n, 4);
363 *dst_px_ln = (uint8 *)dst_px - (uint8 *)dst_px_ln;
364 *dst_n_ln = (uint8 *)dst_n - (uint8 *)dst_n_ln;
366 dst_px_ln = (uint32 *)dst_px;
367 dst_n_ln = (uint32 *)dst_n;
370 lengths[z][0] = (byte *)dst_px_ln - (byte *)dst_px_orig[z];
371 lengths[z][1] = (byte *)dst_n_ln - (byte *)dst_n_orig[z];
375 for (
ZoomLevel z = zoom_min; z <= zoom_max; z++) {
376 len += lengths[z][0] + lengths[z][1];
387 memset(dst, 0,
sizeof(*dst));
389 for (
ZoomLevel z = zoom_min; z <= zoom_max; z++) {
390 dst->
offset[z][0] = z == zoom_min ? 0 : lengths[z - 1][1] + dst->
offset[z - 1][1];
393 memcpy(dst->
data + dst->
offset[z][0], dst_px_orig[z], lengths[z][0]);
394 memcpy(dst->
data + dst->
offset[z][1], dst_n_orig[z], lengths[z][1]);
396 free(dst_px_orig[z]);
int left
The left offset in the 'dst' in pixels to start drawing.
ZoomLevelByte zoom_max
maximum zoom out level
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.
Sprite * Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
Convert a sprite from the loader to our own format.
Factory for the optimised 32 bpp blitter (without palette animation).
int16 y_offs
Number of pixels to shift the sprite downwards.
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.
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.
ZoomLevelByte zoom_min
minimum zoom out level
uint16 width
Width of the sprite.
ZoomLevel
All zoom levels we know.
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.
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
Draws a sprite to a (screen) buffer.
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.
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.
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.