32bpp_simple.cpp

Go to the documentation of this file.
00001 /* $Id: 32bpp_simple.cpp 15428 2009-02-09 02:57:15Z rubidium $ */
00002 
00005 #include "../stdafx.h"
00006 #include "../gfx_func.h"
00007 #include "../zoom_func.h"
00008 #include "32bpp_simple.hpp"
00009 
00010 #include "../table/sprites.h"
00011 
00012 static FBlitter_32bppSimple iFBlitter_32bppSimple;
00013 
00014 void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
00015 {
00016   const SpriteLoader::CommonPixel *src, *src_line;
00017   uint32 *dst, *dst_line;
00018 
00019   /* Find where to start reading in the source sprite */
00020   src_line = (const SpriteLoader::CommonPixel *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom);
00021   dst_line = (uint32 *)bp->dst + bp->top * bp->pitch + bp->left;
00022 
00023   for (int y = 0; y < bp->height; y++) {
00024     dst = dst_line;
00025     dst_line += bp->pitch;
00026 
00027     src = src_line;
00028     src_line += bp->sprite_width * ScaleByZoom(1, zoom);
00029 
00030     for (int x = 0; x < bp->width; x++) {
00031       switch (mode) {
00032         case BM_COLOUR_REMAP:
00033           /* In case the m-channel is zero, do not remap this pixel in any way */
00034           if (src->m == 0) {
00035             if (src->a != 0) *dst = ComposeColourRGBA(src->r, src->g, src->b, src->a, *dst);
00036           } else {
00037             if (bp->remap[src->m] != 0) *dst = ComposeColourPA(this->LookupColourInPalette(bp->remap[src->m]), src->a, *dst);
00038           }
00039           break;
00040 
00041         case BM_TRANSPARENT:
00042           /* TODO -- We make an assumption here that the remap in fact is transparency, not some colour.
00043            *  This is never a problem with the code we produce, but newgrfs can make it fail... or at least:
00044            *  we produce a result the newgrf maker didn't expect ;) */
00045 
00046           /* Make the current colour a bit more black, so it looks like this image is transparent */
00047           if (src->a != 0) *dst = MakeTransparent(*dst, 192);
00048           break;
00049 
00050         default:
00051           if (src->a != 0) *dst = ComposeColourRGBA(src->r, src->g, src->b, src->a, *dst);
00052           break;
00053       }
00054       dst++;
00055       src += ScaleByZoom(1, zoom);
00056     }
00057   }
00058 }
00059 
00060 void Blitter_32bppSimple::DrawColourMappingRect(void *dst, int width, int height, int pal)
00061 {
00062   uint32 *udst = (uint32 *)dst;
00063 
00064   if (pal == PALETTE_TO_TRANSPARENT) {
00065     do {
00066       for (int i = 0; i != width; i++) {
00067         *udst = MakeTransparent(*udst, 154);
00068         udst++;
00069       }
00070       udst = udst - width + _screen.pitch;
00071     } while (--height);
00072     return;
00073   }
00074   if (pal == PALETTE_TO_STRUCT_GREY) {
00075     do {
00076       for (int i = 0; i != width; i++) {
00077         *udst = MakeGrey(*udst);
00078         udst++;
00079       }
00080       udst = udst - width + _screen.pitch;
00081     } while (--height);
00082     return;
00083   }
00084 
00085   DEBUG(misc, 0, "32bpp blitter doesn't know how to draw this colour table ('%d')", pal);
00086 }
00087 
00088 Sprite *Blitter_32bppSimple::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator)
00089 {
00090   Sprite *dest_sprite;
00091   SpriteLoader::CommonPixel *dst;
00092   dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sprite->height * sprite->width * sizeof(SpriteLoader::CommonPixel));
00093 
00094   dest_sprite->height = sprite->height;
00095   dest_sprite->width  = sprite->width;
00096   dest_sprite->x_offs = sprite->x_offs;
00097   dest_sprite->y_offs = sprite->y_offs;
00098 
00099   dst = (SpriteLoader::CommonPixel *)dest_sprite->data;
00100 
00101   memcpy(dst, sprite->data, sprite->height * sprite->width * sizeof(SpriteLoader::CommonPixel));
00102   for (int i = 0; i < sprite->height * sprite->width; i++) {
00103     if (dst[i].m != 0) {
00104       /* Pre-convert the mapping channel to a RGB value */
00105       uint colour = this->LookupColourInPalette(dst[i].m);
00106       dst[i].r = GB(colour, 16, 8);
00107       dst[i].g = GB(colour, 8,  8);
00108       dst[i].b = GB(colour, 0,  8);
00109     }
00110   }
00111 
00112   return dest_sprite;
00113 }

Generated on Sun Mar 15 22:49:45 2009 for openttd by  doxygen 1.5.6