2009-08-21 22:21:05 +02:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 17:11:33 +02:00
|
|
|
/** @file 32bpp_simple.cpp Implementation of the simple 32 bpp blitter. */
|
|
|
|
|
2007-06-13 12:31:40 +02:00
|
|
|
#include "../stdafx.h"
|
2007-12-23 11:56:02 +01:00
|
|
|
#include "../zoom_func.h"
|
2023-12-22 17:01:33 +01:00
|
|
|
#include "../palette_func.h"
|
2007-06-13 12:31:40 +02:00
|
|
|
#include "32bpp_simple.hpp"
|
|
|
|
|
2008-01-13 02:21:35 +01:00
|
|
|
#include "../table/sprites.h"
|
|
|
|
|
2014-04-23 22:13:33 +02:00
|
|
|
#include "../safeguards.h"
|
|
|
|
|
2011-05-01 12:15:33 +02:00
|
|
|
/** Instantiation of the simple 32bpp blitter factory. */
|
2007-06-13 12:31:40 +02:00
|
|
|
static FBlitter_32bppSimple iFBlitter_32bppSimple;
|
|
|
|
|
|
|
|
void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
|
|
|
|
{
|
2011-12-25 00:33:45 +01:00
|
|
|
const Blitter_32bppSimple::Pixel *src, *src_line;
|
2012-04-10 22:16:51 +02:00
|
|
|
Colour *dst, *dst_line;
|
2007-06-13 12:31:40 +02:00
|
|
|
|
|
|
|
/* Find where to start reading in the source sprite */
|
2011-12-25 00:33:45 +01:00
|
|
|
src_line = (const Blitter_32bppSimple::Pixel *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom);
|
2012-04-10 22:16:51 +02:00
|
|
|
dst_line = (Colour *)bp->dst + bp->top * bp->pitch + bp->left;
|
2007-06-13 12:31:40 +02:00
|
|
|
|
|
|
|
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 19:32:01 +02:00
|
|
|
if (src->a != 0) *dst = ComposeColourRGBA(src->r, src->g, src->b, src->a, *dst);
|
2007-06-13 12:31:40 +02:00
|
|
|
} else {
|
2011-12-25 00:33:45 +01:00
|
|
|
if (bp->remap[src->m] != 0) *dst = ComposeColourPA(this->AdjustBrightness(this->LookupColourInPalette(bp->remap[src->m]), src->v), src->a, *dst);
|
2007-06-13 12:31:40 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-04-13 21:22:23 +02:00
|
|
|
case BM_CRASH_REMAP:
|
|
|
|
if (src->m == 0) {
|
|
|
|
if (src->a != 0) {
|
2023-05-08 19:01:06 +02:00
|
|
|
uint8_t g = MakeDark(src->r, src->g, src->b);
|
2014-04-13 21:22:23 +02:00
|
|
|
*dst = ComposeColourRGBA(g, g, g, src->a, *dst);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (bp->remap[src->m] != 0) *dst = ComposeColourPA(this->AdjustBrightness(this->LookupColourInPalette(bp->remap[src->m]), src->v), src->a, *dst);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-10-06 20:45:51 +02:00
|
|
|
case BM_BLACK_REMAP:
|
|
|
|
if (src->a != 0) {
|
|
|
|
*dst = Colour(0, 0, 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-06-13 12:31:40 +02:00
|
|
|
case BM_TRANSPARENT:
|
2009-02-09 03:57:15 +01:00
|
|
|
/* Make the current colour a bit more black, so it looks like this image is transparent */
|
2023-12-22 17:01:33 +01:00
|
|
|
if (src->a != 0) {
|
|
|
|
*dst = MakeTransparent(*dst, 192);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BM_TRANSPARENT_REMAP:
|
|
|
|
/* Apply custom transparency remap. */
|
|
|
|
if (src->a != 0) {
|
|
|
|
*dst = this->LookupColourInPalette(bp->remap[GetNearestColourIndex(*dst)]);
|
|
|
|
}
|
2007-06-13 12:31:40 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2007-06-19 19:32:01 +02:00
|
|
|
if (src->a != 0) *dst = ComposeColourRGBA(src->r, src->g, src->b, src->a, *dst);
|
2007-06-13 12:31:40 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
dst++;
|
|
|
|
src += ScaleByZoom(1, zoom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-21 02:44:51 +01:00
|
|
|
void Blitter_32bppSimple::DrawColourMappingRect(void *dst, int width, int height, PaletteID pal)
|
2007-06-13 12:31:40 +02:00
|
|
|
{
|
2012-04-10 22:16:51 +02:00
|
|
|
Colour *udst = (Colour *)dst;
|
2007-06-13 12:31:40 +02:00
|
|
|
|
|
|
|
if (pal == PALETTE_TO_TRANSPARENT) {
|
|
|
|
do {
|
|
|
|
for (int i = 0; i != width; i++) {
|
2007-09-09 23:56:52 +02:00
|
|
|
*udst = MakeTransparent(*udst, 154);
|
2007-06-13 12:31:40 +02:00
|
|
|
udst++;
|
|
|
|
}
|
|
|
|
udst = udst - width + _screen.pitch;
|
2007-06-19 14:19:31 +02:00
|
|
|
} while (--height);
|
2007-06-13 12:31:40 +02:00
|
|
|
return;
|
|
|
|
}
|
2011-04-29 22:47:36 +02:00
|
|
|
if (pal == PALETTE_NEWSPAPER) {
|
2007-06-13 12:31:40 +02:00
|
|
|
do {
|
|
|
|
for (int i = 0; i != width; i++) {
|
|
|
|
*udst = MakeGrey(*udst);
|
|
|
|
udst++;
|
|
|
|
}
|
|
|
|
udst = udst - width + _screen.pitch;
|
2007-06-19 14:19:31 +02:00
|
|
|
} while (--height);
|
2007-06-13 12:31:40 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-12 09:10:17 +02:00
|
|
|
Debug(misc, 0, "32bpp blitter doesn't know how to draw this colour table ('{}')", pal);
|
2007-06-13 12:31:40 +02:00
|
|
|
}
|
|
|
|
|
2023-12-20 21:38:21 +01:00
|
|
|
Sprite *Blitter_32bppSimple::Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator)
|
2007-06-13 12:31:40 +02:00
|
|
|
{
|
2011-12-25 00:33:45 +01:00
|
|
|
Blitter_32bppSimple::Pixel *dst;
|
2024-04-19 21:34:36 +02:00
|
|
|
Sprite *dest_sprite = static_cast<Sprite *>(allocator(sizeof(*dest_sprite) + static_cast<size_t>(sprite[ZOOM_LVL_MIN].height) * static_cast<size_t>(sprite[ZOOM_LVL_MIN].width) * sizeof(*dst)));
|
2007-06-13 12:31:40 +02:00
|
|
|
|
2024-04-04 19:49:37 +02:00
|
|
|
dest_sprite->height = sprite[ZOOM_LVL_MIN].height;
|
|
|
|
dest_sprite->width = sprite[ZOOM_LVL_MIN].width;
|
|
|
|
dest_sprite->x_offs = sprite[ZOOM_LVL_MIN].x_offs;
|
|
|
|
dest_sprite->y_offs = sprite[ZOOM_LVL_MIN].y_offs;
|
2007-06-13 12:31:40 +02:00
|
|
|
|
2011-12-25 00:33:45 +01:00
|
|
|
dst = (Blitter_32bppSimple::Pixel *)dest_sprite->data;
|
2024-04-04 19:49:37 +02:00
|
|
|
SpriteLoader::CommonPixel *src = (SpriteLoader::CommonPixel *)sprite[ZOOM_LVL_MIN].data;
|
2007-06-13 12:31:40 +02:00
|
|
|
|
2024-04-04 19:49:37 +02:00
|
|
|
for (int i = 0; i < sprite[ZOOM_LVL_MIN].height * sprite[ZOOM_LVL_MIN].width; i++) {
|
2011-12-25 00:33:45 +01:00
|
|
|
if (src->m == 0) {
|
|
|
|
dst[i].r = src->r;
|
|
|
|
dst[i].g = src->g;
|
|
|
|
dst[i].b = src->b;
|
|
|
|
dst[i].a = src->a;
|
|
|
|
dst[i].m = 0;
|
|
|
|
dst[i].v = 0;
|
|
|
|
} else {
|
|
|
|
/* Get brightest value */
|
2023-05-08 19:01:06 +02:00
|
|
|
uint8_t rgb_max = std::max({src->r, src->g, src->b});
|
2011-12-25 00:33:45 +01:00
|
|
|
|
|
|
|
/* Black pixel (8bpp or old 32bpp image), so use default value */
|
|
|
|
if (rgb_max == 0) rgb_max = DEFAULT_BRIGHTNESS;
|
|
|
|
dst[i].v = rgb_max;
|
|
|
|
|
2007-06-13 12:31:40 +02:00
|
|
|
/* Pre-convert the mapping channel to a RGB value */
|
2012-04-10 22:16:51 +02:00
|
|
|
Colour colour = this->AdjustBrightness(this->LookupColourInPalette(src->m), dst[i].v);
|
|
|
|
dst[i].r = colour.r;
|
|
|
|
dst[i].g = colour.g;
|
|
|
|
dst[i].b = colour.b;
|
2011-12-25 00:33:45 +01:00
|
|
|
dst[i].a = src->a;
|
|
|
|
dst[i].m = src->m;
|
2007-06-13 12:31:40 +02:00
|
|
|
}
|
2011-12-25 00:33:45 +01:00
|
|
|
src++;
|
2007-06-13 12:31:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return dest_sprite;
|
|
|
|
}
|