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 "32bpp_simple.hpp"
00015
00016 #include "../table/sprites.h"
00017
00019 static FBlitter_32bppSimple iFBlitter_32bppSimple;
00020
00021 void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
00022 {
00023 const Blitter_32bppSimple::Pixel *src, *src_line;
00024 Colour *dst, *dst_line;
00025
00026
00027 src_line = (const Blitter_32bppSimple::Pixel *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom);
00028 dst_line = (Colour *)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->AdjustBrightness(this->LookupColourInPalette(bp->remap[src->m]), src->v), src->a, *dst);
00045 }
00046 break;
00047
00048 case BM_CRASH_REMAP:
00049 if (src->m == 0) {
00050 if (src->a != 0) {
00051 uint8 g = MakeDark(src->r, src->g, src->b);
00052 *dst = ComposeColourRGBA(g, g, g, src->a, *dst);
00053 }
00054 } else {
00055 if (bp->remap[src->m] != 0) *dst = ComposeColourPA(this->AdjustBrightness(this->LookupColourInPalette(bp->remap[src->m]), src->v), src->a, *dst);
00056 }
00057 break;
00058
00059 case BM_TRANSPARENT:
00060
00061
00062
00063
00064
00065 if (src->a != 0) *dst = MakeTransparent(*dst, 192);
00066 break;
00067
00068 default:
00069 if (src->a != 0) *dst = ComposeColourRGBA(src->r, src->g, src->b, src->a, *dst);
00070 break;
00071 }
00072 dst++;
00073 src += ScaleByZoom(1, zoom);
00074 }
00075 }
00076 }
00077
00078 void Blitter_32bppSimple::DrawColourMappingRect(void *dst, int width, int height, PaletteID pal)
00079 {
00080 Colour *udst = (Colour *)dst;
00081
00082 if (pal == PALETTE_TO_TRANSPARENT) {
00083 do {
00084 for (int i = 0; i != width; i++) {
00085 *udst = MakeTransparent(*udst, 154);
00086 udst++;
00087 }
00088 udst = udst - width + _screen.pitch;
00089 } while (--height);
00090 return;
00091 }
00092 if (pal == PALETTE_NEWSPAPER) {
00093 do {
00094 for (int i = 0; i != width; i++) {
00095 *udst = MakeGrey(*udst);
00096 udst++;
00097 }
00098 udst = udst - width + _screen.pitch;
00099 } while (--height);
00100 return;
00101 }
00102
00103 DEBUG(misc, 0, "32bpp blitter doesn't know how to draw this colour table ('%d')", pal);
00104 }
00105
00106 Sprite *Blitter_32bppSimple::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator)
00107 {
00108 Blitter_32bppSimple::Pixel *dst;
00109 Sprite *dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + (size_t)sprite->height * (size_t)sprite->width * sizeof(*dst));
00110
00111 dest_sprite->height = sprite->height;
00112 dest_sprite->width = sprite->width;
00113 dest_sprite->x_offs = sprite->x_offs;
00114 dest_sprite->y_offs = sprite->y_offs;
00115
00116 dst = (Blitter_32bppSimple::Pixel *)dest_sprite->data;
00117 SpriteLoader::CommonPixel *src = (SpriteLoader::CommonPixel *)sprite->data;
00118
00119 for (int i = 0; i < sprite->height * sprite->width; i++) {
00120 if (src->m == 0) {
00121 dst[i].r = src->r;
00122 dst[i].g = src->g;
00123 dst[i].b = src->b;
00124 dst[i].a = src->a;
00125 dst[i].m = 0;
00126 dst[i].v = 0;
00127 } else {
00128
00129 uint8 rgb_max = max(src->r, max(src->g, src->b));
00130
00131
00132 if (rgb_max == 0) rgb_max = DEFAULT_BRIGHTNESS;
00133 dst[i].v = rgb_max;
00134
00135
00136 Colour colour = this->AdjustBrightness(this->LookupColourInPalette(src->m), dst[i].v);
00137 dst[i].r = colour.r;
00138 dst[i].g = colour.g;
00139 dst[i].b = colour.b;
00140 dst[i].a = src->a;
00141 dst[i].m = src->m;
00142 }
00143 src++;
00144 }
00145
00146 return dest_sprite;
00147 }