32bpp_base.hpp

Go to the documentation of this file.
00001 /* $Id: 32bpp_base.hpp 11674 2007-12-21 19:21:21Z rubidium $ */
00002 
00005 #ifndef BLITTER_32BPP_BASE_HPP
00006 #define BLITTER_32BPP_BASE_HPP
00007 
00008 #include "base.hpp"
00009 #include "../core/bitmath_func.hpp"
00010 
00011 class Blitter_32bppBase : public Blitter {
00012 public:
00013   /* virtual */ uint8 GetScreenDepth() { return 32; }
00014 //  /* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
00015 //  /* virtual */ void DrawColorMappingRect(void *dst, int width, int height, int pal);
00016 //  /* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator);
00017   /* virtual */ void *MoveTo(const void *video, int x, int y);
00018   /* virtual */ void SetPixel(void *video, int x, int y, uint8 color);
00019   /* virtual */ void SetPixelIfEmpty(void *video, int x, int y, uint8 color);
00020   /* virtual */ void DrawRect(void *video, int width, int height, uint8 color);
00021   /* virtual */ void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 color);
00022   /* virtual */ void CopyFromBuffer(void *video, const void *src, int width, int height);
00023   /* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height);
00024   /* virtual */ void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch);
00025   /* virtual */ void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y);
00026   /* virtual */ int BufferSize(int width, int height);
00027   /* virtual */ void PaletteAnimate(uint start, uint count);
00028   /* virtual */ Blitter::PaletteAnimation UsePaletteAnimation();
00029 
00033   static inline uint ComposeColour(uint a, uint r, uint g, uint b)
00034   {
00035     return (((a) << 24) & 0xFF000000) | (((r) << 16) & 0x00FF0000) | (((g) << 8) & 0x0000FF00) | ((b) & 0x000000FF);
00036   }
00037 
00041   static inline uint32 LookupColourInPalette(uint8 index)
00042   {
00043     if (index == 0) return 0x00000000; // Full transparent pixel */
00044     return ComposeColour(0xFF, _cur_palette[index].r, _cur_palette[index].g, _cur_palette[index].b);
00045   }
00046 
00050   static inline uint ComposeColourRGBA(uint r, uint g, uint b, uint a, uint current)
00051   {
00052     if (a == 0) return current;
00053     if (a >= 255) return ComposeColour(0xFF, r, g, b);
00054 
00055     uint cr, cg, cb;
00056     cr = GB(current, 16, 8);
00057     cg = GB(current, 8,  8);
00058     cb = GB(current, 0,  8);
00059 
00060     /* The 256 is wrong, it should be 255, but 256 is much faster... */
00061     return ComposeColour(0xFF,
00062                         (r * a + cr * (256 - a)) / 256,
00063                         (g * a + cg * (256 - a)) / 256,
00064                         (b * a + cb * (256 - a)) / 256);
00065   }
00066 
00070   static inline uint ComposeColourPA(uint colour, uint a, uint current)
00071   {
00072     if (a == 0) return current;
00073     if (a >= 255) return (colour | 0xFF000000);
00074 
00075     uint r, g, b, cr, cg, cb;
00076     r  = GB(colour,  16, 8);
00077     g  = GB(colour,  8,  8);
00078     b  = GB(colour,  0,  8);
00079     cr = GB(current, 16, 8);
00080     cg = GB(current, 8,  8);
00081     cb = GB(current, 0,  8);
00082 
00083     /* The 256 is wrong, it should be 255, but 256 is much faster... */
00084     return ComposeColour(0xFF,
00085                         (r * a + cr * (256 - a)) / 256,
00086                         (g * a + cg * (256 - a)) / 256,
00087                         (b * a + cb * (256 - a)) / 256);
00088   }
00089 
00096   static inline uint MakeTransparent(uint colour, uint amount)
00097   {
00098     uint r, g, b;
00099     r = GB(colour, 16, 8);
00100     g = GB(colour, 8,  8);
00101     b = GB(colour, 0,  8);
00102 
00103     return ComposeColour(0xFF, r * amount / 256, g * amount / 256, b * amount / 256);
00104   }
00105 
00111   static inline uint MakeGrey(uint colour)
00112   {
00113     uint r, g, b;
00114     r = GB(colour, 16, 8);
00115     g = GB(colour, 8,  8);
00116     b = GB(colour, 0,  8);
00117 
00118     /* To avoid doubles and stuff, multiple it with a total of 65536 (16bits), then
00119     *  divide by it to normalize the value to a byte again. See heightmap.cpp for
00120     *  information about the formula. */
00121     colour = ((r * 19595) + (g * 38470) + (b * 7471)) / 65536;
00122 
00123     return ComposeColour(0xFF, colour, colour, colour);
00124   }
00125 };
00126 
00127 #endif /* BLITTER_32BPP_BASE_HPP */

Generated on Wed Oct 1 17:03:20 2008 for openttd by  doxygen 1.5.6