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