src/blitter/8bpp_debug.cpp
author truelight
Wed, 13 Jun 2007 10:31:40 +0000
changeset 7385 dc6e404283bc
parent 7374 54c06f06ecc8
child 7433 8e410e7ec0d7
permissions -rw-r--r--
(svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
-Add: added a new renderer and blitter to make room for some optimized bpp
-Fix: fill the alpha channel in the grf-spriteloader
7368
c8585746a177 (svn r10113) -Fix (r10092): Missing svn properties and some Id/@file comments
peter1138
parents: 7352
diff changeset
     1
/* $Id$ */
c8585746a177 (svn r10113) -Fix (r10092): Missing svn properties and some Id/@file comments
peter1138
parents: 7352
diff changeset
     2
c8585746a177 (svn r10113) -Fix (r10092): Missing svn properties and some Id/@file comments
peter1138
parents: 7352
diff changeset
     3
/** @file 8bpp_debug.cpp */
c8585746a177 (svn r10113) -Fix (r10092): Missing svn properties and some Id/@file comments
peter1138
parents: 7352
diff changeset
     4
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
     5
#include "../stdafx.h"
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
     6
#include "../zoom.hpp"
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
     7
#include "../gfx.h"
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
     8
#include "../functions.h"
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
     9
#include "8bpp_debug.hpp"
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    10
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    11
static FBlitter_8bppDebug iFBlitter_8bppDebug;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    12
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    13
void Blitter_8bppDebug::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    14
{
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7368
diff changeset
    15
	const uint8 *src, *src_line;
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7368
diff changeset
    16
	uint8 *dst, *dst_line;
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    17
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    18
	/* Find where to start reading in the source sprite */
7374
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7368
diff changeset
    19
	src_line = (const uint8 *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom);
54c06f06ecc8 (svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents: 7368
diff changeset
    20
	dst_line = (uint8 *)bp->dst + bp->top * bp->pitch + bp->left;
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    21
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    22
	for (int y = 0; y < bp->height; y++) {
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    23
		dst = dst_line;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    24
		dst_line += bp->pitch;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    25
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    26
		src = src_line;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    27
		src_line += bp->sprite_width * ScaleByZoom(1, zoom);
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    28
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    29
		for (int x = 0; x < bp->width; x++) {
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    30
			if (*src != 0) *dst = *src;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    31
			dst++;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    32
			src += ScaleByZoom(1, zoom);
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    33
		}
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    34
		assert(src <= src_line);
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    35
	}
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    36
}
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    37
7385
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents: 7374
diff changeset
    38
void Blitter_8bppDebug::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: 7374
diff changeset
    39
{
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents: 7374
diff changeset
    40
	const uint8 *ctab = GetNonSprite(pal) + 1;
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents: 7374
diff changeset
    41
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents: 7374
diff changeset
    42
	do {
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents: 7374
diff changeset
    43
		for (int i = 0; i != width; i++) _screen.renderer->SetPixel(dst, i, 0, ctab[((uint8 *)dst)[i]]);
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents: 7374
diff changeset
    44
		dst = _screen.renderer->MoveTo(dst, 0, 1);
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents: 7374
diff changeset
    45
	} while (height--);
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents: 7374
diff changeset
    46
}
dc6e404283bc (svn r10132) -Codechange: split out the last direct video-buffer read access to the blitter-layer
truelight
parents: 7374
diff changeset
    47
7352
e2e8432018f6 (svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight
parents: 7348
diff changeset
    48
Sprite *Blitter_8bppDebug::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator)
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    49
{
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    50
	Sprite *dest_sprite;
7352
e2e8432018f6 (svn r10096) -Fix r10092: freetype bypassed the Blitter::Encode, making fonts look weird
truelight
parents: 7348
diff changeset
    51
	dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sprite->height * sprite->width);
7348
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    52
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    53
	dest_sprite->height = sprite->height;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    54
	dest_sprite->width  = sprite->width;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    55
	dest_sprite->x_offs = sprite->x_offs;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    56
	dest_sprite->y_offs = sprite->y_offs;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    57
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    58
	/* Write a random color as sprite; this makes debugging really easy */
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    59
	uint color = InteractiveRandom() % 150 + 2;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    60
	for (int i = 0; i < sprite->height * sprite->width; i++) {
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    61
		dest_sprite->data[i] = (sprite->data[i].m == 0) ? 0 : color;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    62
	}
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    63
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    64
	return dest_sprite;
becce3f57dc7 (svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
diff changeset
    65
}