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