src/blitter/32bpp_simple.cpp
author truelight
Tue, 19 Jun 2007 12:19:31 +0000
changeset 7455 d6f39d44664b
parent 7433 8e410e7ec0d7
child 7465 6f991aac5551
permissions -rw-r--r--
(svn r10215) -Fix r10214: forgot 2 cases of the same mistake
7385
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
     1
#include "../stdafx.h"
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
     2
#include "../zoom.hpp"
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
     3
#include "../gfx.h"
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
     4
#include "../debug.h"
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
     5
#include "../table/sprites.h"
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
     6
#include "32bpp_simple.hpp"
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
     7
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
     8
static FBlitter_32bppSimple iFBlitter_32bppSimple;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
     9
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    10
/**
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    11
 * Compose a color based on RGB values.
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    12
 */
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    13
static inline uint ComposeColor(uint r, uint g, uint b)
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    14
{
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    15
	return (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF) << 0;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    16
}
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    17
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    18
/**
7391
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    19
 * Compose a color based on RGBA values and the current pixel value.
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    20
 */
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    21
static inline uint ComposeColorRGBA(uint r, uint g, uint b, uint a, uint current)
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    22
{
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    23
	uint cr, cg, cb;
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    24
	cr = GB(current, 16, 8);
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    25
	cg = GB(current, 8,  8);
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    26
	cb = GB(current, 0,  8);
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    27
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    28
	return ComposeColor((r * a + cr * (255 - a)) / 255,
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    29
											(g * a + cg * (255 - a)) / 255,
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    30
											(b * a + cb * (255 - a)) / 255);
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    31
}
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    32
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    33
/**
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    34
 * Compose a color based on Pixel value, alpha value, and the current pixel value.
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    35
 */
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    36
static inline uint ComposeColorPA(uint color, uint a, uint current)
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    37
{
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    38
	uint r, g, b, cr, cg, cb;
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    39
	r  = GB(color,   16, 8);
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    40
	g  = GB(color,   8,  8);
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    41
	b  = GB(color,   0,  8);
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    42
	cr = GB(current, 16, 8);
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    43
	cg = GB(current, 8,  8);
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    44
	cb = GB(current, 0,  8);
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    45
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    46
	return ComposeColor((r * a + cr * (255 - a)) / 255,
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    47
											(g * a + cg * (255 - a)) / 255,
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    48
											(b * a + cb * (255 - a)) / 255);
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    49
}
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    50
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
    51
/**
7385
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    52
 * Make a pixel looks like it is transparent.
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    53
 * @param color the color already on the screen.
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    54
 * @param amount the amount of transparency, times 100.
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    55
 * @return the new color for the screen.
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    56
 */
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    57
static inline uint MakeTransparent(uint color, uint amount)
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    58
{
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    59
	uint r, g, b;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    60
	r = GB(color, 16, 8);
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    61
	g = GB(color, 8,  8);
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    62
	b = GB(color, 0,  8);
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    63
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    64
	return ComposeColor(r * amount / 100, g * amount / 100, b * amount / 100);
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    65
}
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    66
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    67
/**
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    68
 * Make a color grey-based.
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    69
 * @param color the color to make grey.
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    70
 * @return the new color, now grey.
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    71
 */
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    72
static inline uint MakeGrey(uint color)
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    73
{
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    74
	uint r, g, b;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    75
	r = GB(color, 16, 8);
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    76
	g = GB(color, 8,  8);
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    77
	b = GB(color, 0,  8);
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    78
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    79
	/* To avoid doubles and stuff, multiple it with a total of 65536 (16bits), then
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    80
	 *  divide by it to normalize the value to a byte again. See heightmap.cpp for
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    81
	 *  information about the formula. */
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    82
	color = ((r * 19595) + (g * 38470) + (b * 7471)) / 65536;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    83
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    84
	return ComposeColor(color, color, color);
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    85
}
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    86
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    87
void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    88
{
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    89
	const SpriteLoader::CommonPixel *src, *src_line;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    90
	uint32 *dst, *dst_line;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    91
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    92
	/* Find where to start reading in the source sprite */
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    93
	src_line = (const SpriteLoader::CommonPixel *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom);
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    94
	dst_line = (uint32 *)bp->dst + bp->top * bp->pitch + bp->left;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    95
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    96
	for (int y = 0; y < bp->height; y++) {
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    97
		dst = dst_line;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    98
		dst_line += bp->pitch;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    99
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   100
		src = src_line;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   101
		src_line += bp->sprite_width * ScaleByZoom(1, zoom);
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   102
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   103
		for (int x = 0; x < bp->width; x++) {
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   104
			switch (mode) {
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   105
				case BM_COLOUR_REMAP:
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   106
					/* In case the m-channel is zero, do not remap this pixel in any way */
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   107
					if (src->m == 0) {
7391
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
   108
						if (src->a != 0) *dst = ComposeColorRGBA(src->r, src->g, src->b, src->a, *dst);
7385
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   109
					} else {
7433
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 7391
diff changeset
   110
						if (bp->remap[src->m] != 0) *dst = ComposeColorPA(this->LookupColourInPalette(bp->remap[src->m]), src->a, *dst);
7385
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   111
					}
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   112
					break;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   113
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   114
				case BM_TRANSPARENT:
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   115
					/* TODO -- We make an assumption here that the remap in fact is transparency, not some color.
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   116
					 *  This is never a problem with the code we produce, but newgrfs can make it fail... or at least:
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   117
					 *  we produce a result the newgrf maker didn't expect ;) */
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   118
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   119
					/* Make the current color a bit more black, so it looks like this image is transparent */
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   120
					if (src->a != 0) *dst = MakeTransparent(*dst, 75);
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   121
					break;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   122
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   123
				default:
7391
1fec0c1b204f (svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
truelight
parents: 7385
diff changeset
   124
					if (src->a != 0) *dst = ComposeColorRGBA(src->r, src->g, src->b, src->a, *dst);
7385
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   125
					break;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   126
			}
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   127
			dst++;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   128
			src += ScaleByZoom(1, zoom);
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   129
		}
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   130
	}
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   131
}
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   132
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   133
void Blitter_32bppSimple::DrawColorMappingRect(void *dst, int width, int height, int pal)
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   134
{
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   135
	uint32 *udst = (uint32 *)dst;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   136
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   137
	if (pal == PALETTE_TO_TRANSPARENT) {
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   138
		do {
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   139
			for (int i = 0; i != width; i++) {
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   140
				*udst = MakeTransparent(*udst, 60);
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   141
				udst++;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   142
			}
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   143
			udst = udst - width + _screen.pitch;
7455
d6f39d44664b (svn r10215) -Fix r10214: forgot 2 cases of the same mistake
truelight
parents: 7433
diff changeset
   144
		} while (--height);
7385
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   145
		return;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   146
	}
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   147
	if (pal == PALETTE_TO_STRUCT_GREY) {
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   148
		do {
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   149
			for (int i = 0; i != width; i++) {
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   150
				*udst = MakeGrey(*udst);
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   151
				udst++;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   152
			}
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   153
			udst = udst - width + _screen.pitch;
7455
d6f39d44664b (svn r10215) -Fix r10214: forgot 2 cases of the same mistake
truelight
parents: 7433
diff changeset
   154
		} while (--height);
7385
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   155
		return;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   156
	}
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   157
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   158
	DEBUG(misc, 0, "32bpp blitter doesn't know how to draw this color table ('%d')", pal);
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   159
}
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   160
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   161
Sprite *Blitter_32bppSimple::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator)
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   162
{
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   163
	Sprite *dest_sprite;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   164
	SpriteLoader::CommonPixel *dst;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   165
	dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sprite->height * sprite->width * sizeof(SpriteLoader::CommonPixel));
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   166
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   167
	dest_sprite->height = sprite->height;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   168
	dest_sprite->width  = sprite->width;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   169
	dest_sprite->x_offs = sprite->x_offs;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   170
	dest_sprite->y_offs = sprite->y_offs;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   171
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   172
	dst = (SpriteLoader::CommonPixel *)dest_sprite->data;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   173
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   174
	memcpy(dst, sprite->data, sprite->height * sprite->width * sizeof(SpriteLoader::CommonPixel));
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   175
	for (int i = 0; i < sprite->height * sprite->width; i++) {
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   176
		if (dst[i].m != 0) {
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   177
			/* Pre-convert the mapping channel to a RGB value */
7433
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 7391
diff changeset
   178
			uint color = this->LookupColourInPalette(dst[i].m);
7385
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   179
			dst[i].r = GB(color, 16, 8);
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   180
			dst[i].g = GB(color, 8,  8);
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   181
			dst[i].b = GB(color, 0,  8);
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   182
		}
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   183
	}
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   184
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   185
	return dest_sprite;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   186
}