src/blitter/32bpp_simple.cpp
author peter1138
Tue, 29 Jan 2008 17:09:00 +0000
changeset 8941 f93c669d3ca6
parent 8760 ce0891c412ce
child 10429 1b99254f9607
permissions -rw-r--r--
(svn r12015) -Fix [FS#1716] (Revert r11422): Patch in FS#1430 avoided instead of fixed the problem. GetStringWithArgs() discards information that SCC_GENDER_LIST needs to work. Now use pointers to retrieve GRF strings, so that GetStringPtr() will work correctly. This is advantageous as now no buffer copy is made when using all GRF strings.
8587
6db234b2b897 (svn r11652) -Codechange: add the svn $ header for several files
smatz
parents: 8048
diff changeset
     1
/* $Id$ */
6db234b2b897 (svn r11652) -Codechange: add the svn $ header for several files
smatz
parents: 8048
diff changeset
     2
7385
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
     3
#include "../stdafx.h"
8619
c2434269c3eb (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8587
diff changeset
     4
#include "../gfx_func.h"
c2434269c3eb (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8587
diff changeset
     5
#include "../zoom_func.h"
7385
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
     6
#include "../debug.h"
8760
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8619
diff changeset
     7
#include "32bpp_simple.hpp"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8619
diff changeset
     8
7385
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
     9
#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
    10
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    11
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
    12
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    13
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
    14
{
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    15
	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
    16
	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
    17
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    18
	/* 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
    19
	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
    20
	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
    21
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    22
	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
    23
		dst = dst_line;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    24
		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
    25
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    26
		src = src_line;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    27
		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
    28
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    29
		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
    30
			switch (mode) {
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    31
				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
    32
					/* 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
    33
					if (src->m == 0) {
7465
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7455
diff changeset
    34
						if (src->a != 0) *dst = ComposeColourRGBA(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
    35
					} else {
7465
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7455
diff changeset
    36
						if (bp->remap[src->m] != 0) *dst = ComposeColourPA(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
    37
					}
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    38
					break;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    39
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    40
				case BM_TRANSPARENT:
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    41
					/* 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
    42
					 *  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
    43
					 *  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
    44
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    45
					/* Make the current color a bit more black, so it looks like this image is transparent */
8048
7547093f21e6 (svn r11076) -Fix: MakeTransparent of 32bpp blitter used 0..100; using 0..255 makes it much faster (frosch)
truelight
parents: 7465
diff changeset
    46
					if (src->a != 0) *dst = MakeTransparent(*dst, 192);
7385
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    47
					break;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    48
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    49
				default:
7465
6f991aac5551 (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 7455
diff changeset
    50
					if (src->a != 0) *dst = ComposeColourRGBA(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
    51
					break;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    52
			}
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    53
			dst++;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    54
			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
    55
		}
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
}
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
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
    60
{
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    61
	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
    62
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    63
	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
    64
		do {
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    65
			for (int i = 0; i != width; i++) {
8048
7547093f21e6 (svn r11076) -Fix: MakeTransparent of 32bpp blitter used 0..100; using 0..255 makes it much faster (frosch)
truelight
parents: 7465
diff changeset
    66
				*udst = MakeTransparent(*udst, 154);
7385
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    67
				udst++;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    68
			}
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    69
			udst = udst - width + _screen.pitch;
7455
d6f39d44664b (svn r10215) -Fix r10214: forgot 2 cases of the same mistake
truelight
parents: 7433
diff changeset
    70
		} while (--height);
7385
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    71
		return;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    72
	}
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    73
	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
    74
		do {
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    75
			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
    76
				*udst = MakeGrey(*udst);
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    77
				udst++;
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
			udst = udst - width + _screen.pitch;
7455
d6f39d44664b (svn r10215) -Fix r10214: forgot 2 cases of the same mistake
truelight
parents: 7433
diff changeset
    80
		} while (--height);
7385
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    81
		return;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    82
	}
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
	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
    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
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
    88
{
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    89
	Sprite *dest_sprite;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    90
	SpriteLoader::CommonPixel *dst;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    91
	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
    92
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    93
	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
    94
	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
    95
	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
    96
	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
    97
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    98
	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
    99
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   100
	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
   101
	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
   102
		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
   103
			/* 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
   104
			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
   105
			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
   106
			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
   107
			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
   108
		}
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   109
	}
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   110
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   111
	return dest_sprite;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   112
}