src/blitter/32bpp_simple.cpp
author bjarni
Thu, 19 Jun 2008 17:54:23 +0000
changeset 9561 f236daaaf93a
parent 9111 48ce04029fe4
permissions -rw-r--r--
(svn r13584) -Fix: [OSX] Fixed issue where 10.5 failed to switch to fullscreen
This is done by selecting the 32bpp-anim blitter by default as it seems Apple removed some 8bpp support
Since this is done at runtime the same binary will still select 8bpp on 10.3 and 10.4
8091
674be8638d74 (svn r11652) -Codechange: add the svn $ header for several files
smatz
parents: 7552
diff changeset
     1
/* $Id$ */
674be8638d74 (svn r11652) -Codechange: add the svn $ header for several files
smatz
parents: 7552
diff changeset
     2
9111
48ce04029fe4 (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: 8264
diff changeset
     3
/** @file 32bpp_simple.cpp Implementation of the simple 32 bpp blitter. */
48ce04029fe4 (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: 8264
diff changeset
     4
6889
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
     5
#include "../stdafx.h"
8123
ce31d2843a95 (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8091
diff changeset
     6
#include "../gfx_func.h"
ce31d2843a95 (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8091
diff changeset
     7
#include "../zoom_func.h"
6889
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
     8
#include "../debug.h"
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8123
diff changeset
     9
#include "32bpp_simple.hpp"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8123
diff changeset
    10
6889
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    11
#include "../table/sprites.h"
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    12
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    13
static FBlitter_32bppSimple iFBlitter_32bppSimple;
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    14
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    15
void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    16
{
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    17
	const SpriteLoader::CommonPixel *src, *src_line;
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    18
	uint32 *dst, *dst_line;
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    19
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    20
	/* Find where to start reading in the source sprite */
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    21
	src_line = (const SpriteLoader::CommonPixel *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom);
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    22
	dst_line = (uint32 *)bp->dst + bp->top * bp->pitch + bp->left;
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    23
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    24
	for (int y = 0; y < bp->height; y++) {
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    25
		dst = dst_line;
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    26
		dst_line += bp->pitch;
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    27
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    28
		src = src_line;
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    29
		src_line += bp->sprite_width * ScaleByZoom(1, zoom);
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    30
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    31
		for (int x = 0; x < bp->width; x++) {
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    32
			switch (mode) {
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    33
				case BM_COLOUR_REMAP:
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    34
					/* In case the m-channel is zero, do not remap this pixel in any way */
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    35
					if (src->m == 0) {
6969
3d6722f0e3bd (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 6959
diff changeset
    36
						if (src->a != 0) *dst = ComposeColourRGBA(src->r, src->g, src->b, src->a, *dst);
6889
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    37
					} else {
6969
3d6722f0e3bd (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 6959
diff changeset
    38
						if (bp->remap[src->m] != 0) *dst = ComposeColourPA(this->LookupColourInPalette(bp->remap[src->m]), src->a, *dst);
6889
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    39
					}
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    40
					break;
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    41
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    42
				case BM_TRANSPARENT:
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    43
					/* TODO -- We make an assumption here that the remap in fact is transparency, not some color.
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    44
					 *  This is never a problem with the code we produce, but newgrfs can make it fail... or at least:
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    45
					 *  we produce a result the newgrf maker didn't expect ;) */
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    46
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    47
					/* Make the current color a bit more black, so it looks like this image is transparent */
7552
56aa62dba204 (svn r11076) -Fix: MakeTransparent of 32bpp blitter used 0..100; using 0..255 makes it much faster (frosch)
truelight
parents: 6969
diff changeset
    48
					if (src->a != 0) *dst = MakeTransparent(*dst, 192);
6889
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    49
					break;
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    50
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    51
				default:
6969
3d6722f0e3bd (svn r10225) -Codechange: move common Colour routines for 32bpp to the base class (and nick it colour, not color)
truelight
parents: 6959
diff changeset
    52
					if (src->a != 0) *dst = ComposeColourRGBA(src->r, src->g, src->b, src->a, *dst);
6889
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    53
					break;
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    54
			}
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    55
			dst++;
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    56
			src += ScaleByZoom(1, zoom);
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    57
		}
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    58
	}
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    59
}
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    60
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    61
void Blitter_32bppSimple::DrawColorMappingRect(void *dst, int width, int height, int pal)
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    62
{
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    63
	uint32 *udst = (uint32 *)dst;
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    64
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    65
	if (pal == PALETTE_TO_TRANSPARENT) {
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    66
		do {
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    67
			for (int i = 0; i != width; i++) {
7552
56aa62dba204 (svn r11076) -Fix: MakeTransparent of 32bpp blitter used 0..100; using 0..255 makes it much faster (frosch)
truelight
parents: 6969
diff changeset
    68
				*udst = MakeTransparent(*udst, 154);
6889
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    69
				udst++;
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    70
			}
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    71
			udst = udst - width + _screen.pitch;
6959
8c5ef1825831 (svn r10215) -Fix r10214: forgot 2 cases of the same mistake
truelight
parents: 6937
diff changeset
    72
		} while (--height);
6889
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    73
		return;
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    74
	}
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    75
	if (pal == PALETTE_TO_STRUCT_GREY) {
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    76
		do {
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    77
			for (int i = 0; i != width; i++) {
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    78
				*udst = MakeGrey(*udst);
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    79
				udst++;
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    80
			}
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    81
			udst = udst - width + _screen.pitch;
6959
8c5ef1825831 (svn r10215) -Fix r10214: forgot 2 cases of the same mistake
truelight
parents: 6937
diff changeset
    82
		} while (--height);
6889
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    83
		return;
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    84
	}
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    85
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    86
	DEBUG(misc, 0, "32bpp blitter doesn't know how to draw this color table ('%d')", pal);
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    87
}
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    88
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    89
Sprite *Blitter_32bppSimple::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator)
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    90
{
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    91
	Sprite *dest_sprite;
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    92
	SpriteLoader::CommonPixel *dst;
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    93
	dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sprite->height * sprite->width * sizeof(SpriteLoader::CommonPixel));
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    94
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    95
	dest_sprite->height = sprite->height;
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    96
	dest_sprite->width  = sprite->width;
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    97
	dest_sprite->x_offs = sprite->x_offs;
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    98
	dest_sprite->y_offs = sprite->y_offs;
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
    99
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   100
	dst = (SpriteLoader::CommonPixel *)dest_sprite->data;
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   101
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   102
	memcpy(dst, sprite->data, sprite->height * sprite->width * sizeof(SpriteLoader::CommonPixel));
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   103
	for (int i = 0; i < sprite->height * sprite->width; i++) {
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   104
		if (dst[i].m != 0) {
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   105
			/* Pre-convert the mapping channel to a RGB value */
6937
40c760fcf1f6 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 6895
diff changeset
   106
			uint color = this->LookupColourInPalette(dst[i].m);
6889
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   107
			dst[i].r = GB(color, 16, 8);
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   108
			dst[i].g = GB(color, 8,  8);
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   109
			dst[i].b = GB(color, 0,  8);
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   110
		}
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   111
	}
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   112
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   113
	return dest_sprite;
2160bf28040b (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents:
diff changeset
   114
}