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