8bpp_simple.cpp
Go to the documentation of this file.00001
00002
00005 #include "../stdafx.h"
00006 #include "../zoom_func.h"
00007 #include "8bpp_simple.hpp"
00008
00009 static FBlitter_8bppSimple iFBlitter_8bppSimple;
00010
00011 void Blitter_8bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
00012 {
00013 const uint8 *src, *src_line;
00014 uint8 *dst, *dst_line;
00015
00016
00017 src_line = (const uint8 *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom);
00018 dst_line = (uint8 *)bp->dst + bp->top * bp->pitch + bp->left;
00019
00020 for (int y = 0; y < bp->height; y++) {
00021 dst = dst_line;
00022 dst_line += bp->pitch;
00023
00024 src = src_line;
00025 src_line += bp->sprite_width * ScaleByZoom(1, zoom);
00026
00027 for (int x = 0; x < bp->width; x++) {
00028 uint color = 0;
00029
00030 switch (mode) {
00031 case BM_COLOUR_REMAP:
00032 color = bp->remap[*src];
00033 break;
00034
00035 case BM_TRANSPARENT:
00036 if (*src != 0) color = bp->remap[*dst];
00037 break;
00038
00039 default:
00040 color = *src;
00041 break;
00042 }
00043 if (color != 0) *dst = color;
00044 dst++;
00045 src += ScaleByZoom(1, zoom);
00046 }
00047 }
00048 }
00049
00050 Sprite *Blitter_8bppSimple::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator)
00051 {
00052 Sprite *dest_sprite;
00053 dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sprite->height * sprite->width);;
00054
00055 dest_sprite->height = sprite->height;
00056 dest_sprite->width = sprite->width;
00057 dest_sprite->x_offs = sprite->x_offs;
00058 dest_sprite->y_offs = sprite->y_offs;
00059
00060
00061 for (int i = 0; i < sprite->height * sprite->width; i++) {
00062 dest_sprite->data[i] = sprite->data[i].m;
00063 }
00064
00065 return dest_sprite;
00066 }