diff options
author | truelight <truelight@openttd.org> | 2007-06-11 11:50:49 +0000 |
---|---|---|
committer | truelight <truelight@openttd.org> | 2007-06-11 11:50:49 +0000 |
commit | 6b101cc177a9e689dd193041b82661ab140b817c (patch) | |
tree | 2fcb96fde1458283649c1303c0436fcfb369de55 /src/blitter/8bpp_slow.cpp | |
parent | 68c369ea98c4379c25300d055eb206ff8f4442cb (diff) | |
download | openttd-6b101cc177a9e689dd193041b82661ab140b817c.tar.xz |
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
-Add: make it possible to pick your own blitter (-b <blitter>, -h for overview)
-Add: added a new optimized 8bpp blitter (default, caches sprites of all zoom-levels)
-Add: added a debug 8bpp blitter and a very slow normal 8bpp blitter
Diffstat (limited to 'src/blitter/8bpp_slow.cpp')
-rw-r--r-- | src/blitter/8bpp_slow.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/blitter/8bpp_slow.cpp b/src/blitter/8bpp_slow.cpp new file mode 100644 index 000000000..99c43a4f5 --- /dev/null +++ b/src/blitter/8bpp_slow.cpp @@ -0,0 +1,65 @@ +#include "../stdafx.h" +#include "../zoom.hpp" +#include "../gfx.h" +#include "8bpp_slow.hpp" + +static FBlitter_8bppSimple iFBlitter_8bppSimple; + +extern void* AllocSprite(size_t); + +void Blitter_8bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) +{ + const byte *src, *src_line; + Pixel8 *dst, *dst_line; + + /* Find where to start reading in the source sprite */ + src_line = (const byte *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom); + dst_line = (Pixel8 *)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++) { + uint color = 0; + + switch (mode) { + case BM_COLOUR_REMAP: + color = bp->remap[*src]; + break; + + case BM_TRANSPARENT: + if (*src != 0) color = bp->remap[*dst]; + break; + + default: + color = *src; + break; + } + if (color != 0) *dst = color; + dst++; + src += ScaleByZoom(1, zoom); + } + } +} + +Sprite *Blitter_8bppSimple::Encode(SpriteLoader::Sprite *sprite) +{ + Sprite *dest_sprite; + dest_sprite = (Sprite *)AllocSprite(sizeof(*dest_sprite) + sprite->height * sprite->width); + + dest_sprite->height = sprite->height; + dest_sprite->width = sprite->width; + dest_sprite->x_offs = sprite->x_offs; + dest_sprite->y_offs = sprite->y_offs; + + /* Copy over only the 'remap' channel, as that is what we care about in 8bpp */ + for (int i = 0; i < sprite->height * sprite->width; i++) { + dest_sprite->data[i] = sprite->data[i].m; + } + + return dest_sprite; +} |