32bpp_simple.cpp
Go to the documentation of this file.00001
00002
00005 #include "../stdafx.h"
00006 #include "../gfx_func.h"
00007 #include "../zoom_func.h"
00008 #include "../debug.h"
00009 #include "32bpp_simple.hpp"
00010
00011 #include "../table/sprites.h"
00012
00013 static FBlitter_32bppSimple iFBlitter_32bppSimple;
00014
00015 void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
00016 {
00017 const SpriteLoader::CommonPixel *src, *src_line;
00018 uint32 *dst, *dst_line;
00019
00020
00021 src_line = (const SpriteLoader::CommonPixel *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom);
00022 dst_line = (uint32 *)bp->dst + bp->top * bp->pitch + bp->left;
00023
00024 for (int y = 0; y < bp->height; y++) {
00025 dst = dst_line;
00026 dst_line += bp->pitch;
00027
00028 src = src_line;
00029 src_line += bp->sprite_width * ScaleByZoom(1, zoom);
00030
00031 for (int x = 0; x < bp->width; x++) {
00032 switch (mode) {
00033 case BM_COLOUR_REMAP:
00034
00035 if (src->m == 0) {
00036 if (src->a != 0) *dst = ComposeColourRGBA(src->r, src->g, src->b, src->a, *dst);
00037 } else {
00038 if (bp->remap[src->m] != 0) *dst = ComposeColourPA(this->LookupColourInPalette(bp->remap[src->m]), src->a, *dst);
00039 }
00040 break;
00041
00042 case BM_TRANSPARENT:
00043
00044
00045
00046
00047
00048 if (src->a != 0) *dst = MakeTransparent(*dst, 192);
00049 break;
00050
00051 default:
00052 if (src->a != 0) *dst = ComposeColourRGBA(src->r, src->g, src->b, src->a, *dst);
00053 break;
00054 }
00055 dst++;
00056 src += ScaleByZoom(1, zoom);
00057 }
00058 }
00059 }
00060
00061 void Blitter_32bppSimple::DrawColorMappingRect(void *dst, int width, int height, int pal)
00062 {
00063 uint32 *udst = (uint32 *)dst;
00064
00065 if (pal == PALETTE_TO_TRANSPARENT) {
00066 do {
00067 for (int i = 0; i != width; i++) {
00068 *udst = MakeTransparent(*udst, 154);
00069 udst++;
00070 }
00071 udst = udst - width + _screen.pitch;
00072 } while (--height);
00073 return;
00074 }
00075 if (pal == PALETTE_TO_STRUCT_GREY) {
00076 do {
00077 for (int i = 0; i != width; i++) {
00078 *udst = MakeGrey(*udst);
00079 udst++;
00080 }
00081 udst = udst - width + _screen.pitch;
00082 } while (--height);
00083 return;
00084 }
00085
00086 DEBUG(misc, 0, "32bpp blitter doesn't know how to draw this color table ('%d')", pal);
00087 }
00088
00089 Sprite *Blitter_32bppSimple::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator)
00090 {
00091 Sprite *dest_sprite;
00092 SpriteLoader::CommonPixel *dst;
00093 dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sprite->height * sprite->width * sizeof(SpriteLoader::CommonPixel));
00094
00095 dest_sprite->height = sprite->height;
00096 dest_sprite->width = sprite->width;
00097 dest_sprite->x_offs = sprite->x_offs;
00098 dest_sprite->y_offs = sprite->y_offs;
00099
00100 dst = (SpriteLoader::CommonPixel *)dest_sprite->data;
00101
00102 memcpy(dst, sprite->data, sprite->height * sprite->width * sizeof(SpriteLoader::CommonPixel));
00103 for (int i = 0; i < sprite->height * sprite->width; i++) {
00104 if (dst[i].m != 0) {
00105
00106 uint color = this->LookupColourInPalette(dst[i].m);
00107 dst[i].r = GB(color, 16, 8);
00108 dst[i].g = GB(color, 8, 8);
00109 dst[i].b = GB(color, 0, 8);
00110 }
00111 }
00112
00113 return dest_sprite;
00114 }