2007-12-17 01:35:45 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-06-13 10:31:40 +00:00
|
|
|
#include "../stdafx.h"
|
2007-12-23 10:56:02 +00:00
|
|
|
#include "../gfx_func.h"
|
|
|
|
#include "../zoom_func.h"
|
2007-06-13 10:31:40 +00:00
|
|
|
#include "../debug.h"
|
|
|
|
#include "32bpp_simple.hpp"
|
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "../table/sprites.h"
|
|
|
|
|
2007-06-13 10:31:40 +00:00
|
|
|
static FBlitter_32bppSimple iFBlitter_32bppSimple;
|
|
|
|
|
|
|
|
void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
|
|
|
|
{
|
|
|
|
const SpriteLoader::CommonPixel *src, *src_line;
|
|
|
|
uint32 *dst, *dst_line;
|
|
|
|
|
|
|
|
/* Find where to start reading in the source sprite */
|
|
|
|
src_line = (const SpriteLoader::CommonPixel *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom);
|
|
|
|
dst_line = (uint32 *)bp->dst + bp->top * bp->pitch + bp->left;
|
|
|
|
|
|
|
|
for (int y = 0; y < bp->height; y++) {
|
|
|
|
dst = dst_line;
|
|
|
|
dst_line += bp->pitch;
|
|
|
|
|
|
|
|
src = src_line;
|
|
|
|
src_line += bp->sprite_width * ScaleByZoom(1, zoom);
|
|
|
|
|
|
|
|
for (int x = 0; x < bp->width; x++) {
|
|
|
|
switch (mode) {
|
|
|
|
case BM_COLOUR_REMAP:
|
|
|
|
/* In case the m-channel is zero, do not remap this pixel in any way */
|
|
|
|
if (src->m == 0) {
|
2007-06-19 17:32:01 +00:00
|
|
|
if (src->a != 0) *dst = ComposeColourRGBA(src->r, src->g, src->b, src->a, *dst);
|
2007-06-13 10:31:40 +00:00
|
|
|
} else {
|
2007-06-19 17:32:01 +00:00
|
|
|
if (bp->remap[src->m] != 0) *dst = ComposeColourPA(this->LookupColourInPalette(bp->remap[src->m]), src->a, *dst);
|
2007-06-13 10:31:40 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BM_TRANSPARENT:
|
|
|
|
/* TODO -- We make an assumption here that the remap in fact is transparency, not some color.
|
|
|
|
* This is never a problem with the code we produce, but newgrfs can make it fail... or at least:
|
|
|
|
* we produce a result the newgrf maker didn't expect ;) */
|
|
|
|
|
|
|
|
/* Make the current color a bit more black, so it looks like this image is transparent */
|
2007-09-09 21:56:52 +00:00
|
|
|
if (src->a != 0) *dst = MakeTransparent(*dst, 192);
|
2007-06-13 10:31:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2007-06-19 17:32:01 +00:00
|
|
|
if (src->a != 0) *dst = ComposeColourRGBA(src->r, src->g, src->b, src->a, *dst);
|
2007-06-13 10:31:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
dst++;
|
|
|
|
src += ScaleByZoom(1, zoom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Blitter_32bppSimple::DrawColorMappingRect(void *dst, int width, int height, int pal)
|
|
|
|
{
|
|
|
|
uint32 *udst = (uint32 *)dst;
|
|
|
|
|
|
|
|
if (pal == PALETTE_TO_TRANSPARENT) {
|
|
|
|
do {
|
|
|
|
for (int i = 0; i != width; i++) {
|
2007-09-09 21:56:52 +00:00
|
|
|
*udst = MakeTransparent(*udst, 154);
|
2007-06-13 10:31:40 +00:00
|
|
|
udst++;
|
|
|
|
}
|
|
|
|
udst = udst - width + _screen.pitch;
|
2007-06-19 12:19:31 +00:00
|
|
|
} while (--height);
|
2007-06-13 10:31:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (pal == PALETTE_TO_STRUCT_GREY) {
|
|
|
|
do {
|
|
|
|
for (int i = 0; i != width; i++) {
|
|
|
|
*udst = MakeGrey(*udst);
|
|
|
|
udst++;
|
|
|
|
}
|
|
|
|
udst = udst - width + _screen.pitch;
|
2007-06-19 12:19:31 +00:00
|
|
|
} while (--height);
|
2007-06-13 10:31:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG(misc, 0, "32bpp blitter doesn't know how to draw this color table ('%d')", pal);
|
|
|
|
}
|
|
|
|
|
|
|
|
Sprite *Blitter_32bppSimple::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator)
|
|
|
|
{
|
|
|
|
Sprite *dest_sprite;
|
|
|
|
SpriteLoader::CommonPixel *dst;
|
|
|
|
dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sprite->height * sprite->width * sizeof(SpriteLoader::CommonPixel));
|
|
|
|
|
|
|
|
dest_sprite->height = sprite->height;
|
|
|
|
dest_sprite->width = sprite->width;
|
|
|
|
dest_sprite->x_offs = sprite->x_offs;
|
|
|
|
dest_sprite->y_offs = sprite->y_offs;
|
|
|
|
|
|
|
|
dst = (SpriteLoader::CommonPixel *)dest_sprite->data;
|
|
|
|
|
|
|
|
memcpy(dst, sprite->data, sprite->height * sprite->width * sizeof(SpriteLoader::CommonPixel));
|
|
|
|
for (int i = 0; i < sprite->height * sprite->width; i++) {
|
|
|
|
if (dst[i].m != 0) {
|
|
|
|
/* Pre-convert the mapping channel to a RGB value */
|
2007-06-17 20:30:28 +00:00
|
|
|
uint color = this->LookupColourInPalette(dst[i].m);
|
2007-06-13 10:31:40 +00:00
|
|
|
dst[i].r = GB(color, 16, 8);
|
|
|
|
dst[i].g = GB(color, 8, 8);
|
|
|
|
dst[i].b = GB(color, 0, 8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dest_sprite;
|
|
|
|
}
|