src/blitter/32bpp_optimized.cpp
author smatz
Tue, 10 Jun 2008 17:28:37 +0000
changeset 10894 1389262b0c9e
parent 10429 1b99254f9607
child 11082 45ab75d184a0
permissions -rw-r--r--
(svn r13445) -Codechange: make 32bpp_optimized blitter ~10-20% faster in drawing (depends on architecture and compiler)
8587
6db234b2b897 (svn r11652) -Codechange: add the svn $ header for several files
smatz
parents: 8049
diff changeset
     1
/* $Id$ */
6db234b2b897 (svn r11652) -Codechange: add the svn $ header for several files
smatz
parents: 8049
diff changeset
     2
10429
1b99254f9607 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 8760
diff changeset
     3
/** @file 32bpp_optimized.cpp Implementation of the optimized 32 bpp blitter. */
1b99254f9607 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 8760
diff changeset
     4
8049
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
     5
#include "../stdafx.h"
8619
c2434269c3eb (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8587
diff changeset
     6
#include "../zoom_func.h"
c2434269c3eb (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8587
diff changeset
     7
#include "../gfx_func.h"
8049
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
     8
#include "../debug.h"
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
     9
#include "32bpp_optimized.hpp"
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    10
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    11
static FBlitter_32bppOptimized iFBlitter_32bppOptimized;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    12
10894
1389262b0c9e (svn r13445) -Codechange: make 32bpp_optimized blitter ~10-20% faster in drawing (depends on architecture and compiler)
smatz
parents: 10429
diff changeset
    13
template <BlitterMode mode, ZoomLevel zoom> inline void Blitter_32bppOptimized::Draw(Blitter::BlitterParams *bp)
8049
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    14
{
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    15
	const SpriteLoader::CommonPixel *src, *src_line;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    16
	uint32 *dst, *dst_line;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    17
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    18
	/* Find where to start reading in the source sprite */
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    19
	src_line = (const SpriteLoader::CommonPixel *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom);
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    20
	dst_line = (uint32 *)bp->dst + bp->top * bp->pitch + bp->left;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    21
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    22
	for (int y = 0; y < bp->height; y++) {
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    23
		dst = dst_line;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    24
		dst_line += bp->pitch;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    25
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    26
		src = src_line;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    27
		src_line += bp->sprite_width * ScaleByZoom(1, zoom);
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    28
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    29
		for (int x = 0; x < bp->width; x++) {
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    30
			if (src->a == 0) {
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    31
				/* src->r is 'misused' here to indicate how much more pixels are following with an alpha of 0 */
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    32
				int skip = UnScaleByZoom(src->r, zoom);
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    33
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    34
				dst += skip;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    35
				x   += skip - 1;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    36
				src += ScaleByZoom(1, zoom) * skip;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    37
				continue;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    38
			}
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    39
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    40
			switch (mode) {
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    41
				case BM_COLOUR_REMAP:
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    42
					/* In case the m-channel is zero, do not remap this pixel in any way */
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    43
					if (src->m == 0) {
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    44
						*dst = ComposeColourRGBA(src->r, src->g, src->b, src->a, *dst);
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    45
					} else {
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    46
						if (bp->remap[src->m] != 0) *dst = ComposeColourPA(this->LookupColourInPalette(bp->remap[src->m]), src->a, *dst);
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    47
					}
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    48
					break;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    49
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    50
				case BM_TRANSPARENT:
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    51
					/* TODO -- We make an assumption here that the remap in fact is transparency, not some color.
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    52
					 *  This is never a problem with the code we produce, but newgrfs can make it fail... or at least:
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    53
					 *  we produce a result the newgrf maker didn't expect ;) */
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    54
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    55
					/* Make the current color a bit more black, so it looks like this image is transparent */
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    56
					*dst = MakeTransparent(*dst, 192);
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    57
					break;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    58
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    59
				default:
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    60
					*dst = ComposeColourRGBA(src->r, src->g, src->b, src->a, *dst);
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    61
					break;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    62
			}
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    63
			dst++;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    64
			src += ScaleByZoom(1, zoom);
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    65
		}
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    66
	}
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    67
}
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    68
10894
1389262b0c9e (svn r13445) -Codechange: make 32bpp_optimized blitter ~10-20% faster in drawing (depends on architecture and compiler)
smatz
parents: 10429
diff changeset
    69
template <BlitterMode mode> inline void Blitter_32bppOptimized::Draw(Blitter::BlitterParams *bp, ZoomLevel zoom)
1389262b0c9e (svn r13445) -Codechange: make 32bpp_optimized blitter ~10-20% faster in drawing (depends on architecture and compiler)
smatz
parents: 10429
diff changeset
    70
{
1389262b0c9e (svn r13445) -Codechange: make 32bpp_optimized blitter ~10-20% faster in drawing (depends on architecture and compiler)
smatz
parents: 10429
diff changeset
    71
	switch (zoom) {
1389262b0c9e (svn r13445) -Codechange: make 32bpp_optimized blitter ~10-20% faster in drawing (depends on architecture and compiler)
smatz
parents: 10429
diff changeset
    72
		default: NOT_REACHED();
1389262b0c9e (svn r13445) -Codechange: make 32bpp_optimized blitter ~10-20% faster in drawing (depends on architecture and compiler)
smatz
parents: 10429
diff changeset
    73
		case ZOOM_LVL_NORMAL: Draw<mode, ZOOM_LVL_NORMAL>(bp); return;
1389262b0c9e (svn r13445) -Codechange: make 32bpp_optimized blitter ~10-20% faster in drawing (depends on architecture and compiler)
smatz
parents: 10429
diff changeset
    74
		case ZOOM_LVL_OUT_2X: Draw<mode, ZOOM_LVL_OUT_2X>(bp); return;
1389262b0c9e (svn r13445) -Codechange: make 32bpp_optimized blitter ~10-20% faster in drawing (depends on architecture and compiler)
smatz
parents: 10429
diff changeset
    75
		case ZOOM_LVL_OUT_4X: Draw<mode, ZOOM_LVL_OUT_4X>(bp); return;
1389262b0c9e (svn r13445) -Codechange: make 32bpp_optimized blitter ~10-20% faster in drawing (depends on architecture and compiler)
smatz
parents: 10429
diff changeset
    76
		case ZOOM_LVL_OUT_8X: Draw<mode, ZOOM_LVL_OUT_8X>(bp); return;
1389262b0c9e (svn r13445) -Codechange: make 32bpp_optimized blitter ~10-20% faster in drawing (depends on architecture and compiler)
smatz
parents: 10429
diff changeset
    77
	}
1389262b0c9e (svn r13445) -Codechange: make 32bpp_optimized blitter ~10-20% faster in drawing (depends on architecture and compiler)
smatz
parents: 10429
diff changeset
    78
}
1389262b0c9e (svn r13445) -Codechange: make 32bpp_optimized blitter ~10-20% faster in drawing (depends on architecture and compiler)
smatz
parents: 10429
diff changeset
    79
1389262b0c9e (svn r13445) -Codechange: make 32bpp_optimized blitter ~10-20% faster in drawing (depends on architecture and compiler)
smatz
parents: 10429
diff changeset
    80
void Blitter_32bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
1389262b0c9e (svn r13445) -Codechange: make 32bpp_optimized blitter ~10-20% faster in drawing (depends on architecture and compiler)
smatz
parents: 10429
diff changeset
    81
{
1389262b0c9e (svn r13445) -Codechange: make 32bpp_optimized blitter ~10-20% faster in drawing (depends on architecture and compiler)
smatz
parents: 10429
diff changeset
    82
	switch (mode) {
1389262b0c9e (svn r13445) -Codechange: make 32bpp_optimized blitter ~10-20% faster in drawing (depends on architecture and compiler)
smatz
parents: 10429
diff changeset
    83
		default: NOT_REACHED();
1389262b0c9e (svn r13445) -Codechange: make 32bpp_optimized blitter ~10-20% faster in drawing (depends on architecture and compiler)
smatz
parents: 10429
diff changeset
    84
		case BM_NORMAL:       Draw<BM_NORMAL>      (bp, zoom); return;
1389262b0c9e (svn r13445) -Codechange: make 32bpp_optimized blitter ~10-20% faster in drawing (depends on architecture and compiler)
smatz
parents: 10429
diff changeset
    85
		case BM_COLOUR_REMAP: Draw<BM_COLOUR_REMAP>(bp, zoom); return;
1389262b0c9e (svn r13445) -Codechange: make 32bpp_optimized blitter ~10-20% faster in drawing (depends on architecture and compiler)
smatz
parents: 10429
diff changeset
    86
		case BM_TRANSPARENT:  Draw<BM_TRANSPARENT> (bp, zoom); return;
1389262b0c9e (svn r13445) -Codechange: make 32bpp_optimized blitter ~10-20% faster in drawing (depends on architecture and compiler)
smatz
parents: 10429
diff changeset
    87
	}
1389262b0c9e (svn r13445) -Codechange: make 32bpp_optimized blitter ~10-20% faster in drawing (depends on architecture and compiler)
smatz
parents: 10429
diff changeset
    88
}
1389262b0c9e (svn r13445) -Codechange: make 32bpp_optimized blitter ~10-20% faster in drawing (depends on architecture and compiler)
smatz
parents: 10429
diff changeset
    89
8049
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    90
Sprite *Blitter_32bppOptimized::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator)
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    91
{
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    92
	Sprite *dest_sprite;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    93
	SpriteLoader::CommonPixel *dst;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    94
	dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sprite->height * sprite->width * sizeof(SpriteLoader::CommonPixel));
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    95
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    96
	dest_sprite->height = sprite->height;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    97
	dest_sprite->width  = sprite->width;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    98
	dest_sprite->x_offs = sprite->x_offs;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
    99
	dest_sprite->y_offs = sprite->y_offs;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   100
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   101
	dst = (SpriteLoader::CommonPixel *)dest_sprite->data;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   102
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   103
	memcpy(dst, sprite->data, sprite->height * sprite->width * sizeof(SpriteLoader::CommonPixel));
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   104
	/* Skip to the end of the array, and work backwards to find transparent blocks */
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   105
	dst = dst + sprite->height * sprite->width - 1;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   106
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   107
	for (uint y = sprite->height; y > 0; y--) {
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   108
		int trans = 0;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   109
		/* Process sprite line backwards, to compute lengths of transparent blocks */
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   110
		for (uint x = sprite->width; x > 0; x--) {
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   111
			if (dst->a == 0) {
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   112
				/* Save transparent block length in red channel; max value is 255 the red channel can contain */
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   113
				if (trans < 255) trans++;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   114
				dst->r = trans;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   115
				dst->g = 0;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   116
				dst->b = 0;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   117
				dst->m = 0;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   118
			} else {
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   119
				trans = 0;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   120
				if (dst->m != 0) {
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   121
					/* Pre-convert the mapping channel to a RGB value */
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   122
					uint color = this->LookupColourInPalette(dst->m);
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   123
					dst->r = GB(color, 16, 8);
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   124
					dst->g = GB(color, 8,  8);
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   125
					dst->b = GB(color, 0,  8);
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   126
				}
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   127
			}
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   128
			dst--;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   129
		}
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   130
	}
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   131
	return dest_sprite;
00faaf0c0b52 (svn r11078) -Add: added 32bpp-optimized, which is almost twice as fast as 32bpp-simple (based on the work of frosch)
truelight
parents:
diff changeset
   132
}