32bpp_base.hpp

Go to the documentation of this file.
00001 /* $Id: 32bpp_base.hpp 18809 2010-01-15 16:41:15Z rubidium $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00012 #ifndef BLITTER_32BPP_BASE_HPP
00013 #define BLITTER_32BPP_BASE_HPP
00014 
00015 #include "base.hpp"
00016 #include "../core/bitmath_func.hpp"
00017 #include "../gfx_func.h"
00018 
00019 class Blitter_32bppBase : public Blitter {
00020 public:
00021   /* virtual */ uint8 GetScreenDepth() { return 32; }
00022 //  /* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
00023 //  /* virtual */ void DrawColourMappingRect(void *dst, int width, int height, int pal);
00024 //  /* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator);
00025   /* virtual */ void *MoveTo(const void *video, int x, int y);
00026   /* virtual */ void SetPixel(void *video, int x, int y, uint8 colour);
00027   /* virtual */ void SetPixelIfEmpty(void *video, int x, int y, uint8 colour);
00028   /* virtual */ void DrawRect(void *video, int width, int height, uint8 colour);
00029   /* virtual */ void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour);
00030   /* virtual */ void CopyFromBuffer(void *video, const void *src, int width, int height);
00031   /* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height);
00032   /* virtual */ void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch);
00033   /* virtual */ void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y);
00034   /* virtual */ int BufferSize(int width, int height);
00035   /* virtual */ void PaletteAnimate(uint start, uint count);
00036   /* virtual */ Blitter::PaletteAnimation UsePaletteAnimation();
00037   /* virtual */ int GetBytesPerPixel() { return 4; }
00038 
00042   static inline uint32 ComposeColour(uint a, uint r, uint g, uint b)
00043   {
00044     return (((a) << 24) & 0xFF000000) | (((r) << 16) & 0x00FF0000) | (((g) << 8) & 0x0000FF00) | ((b) & 0x000000FF);
00045   }
00046 
00050   static inline uint32 LookupColourInPalette(uint index)
00051   {
00052     return _cur_palette[index].data;
00053   }
00054 
00058   static inline uint32 ComposeColourRGBANoCheck(uint r, uint g, uint b, uint a, uint32 current)
00059   {
00060     uint cr = GB(current, 16, 8);
00061     uint cg = GB(current, 8,  8);
00062     uint cb = GB(current, 0,  8);
00063 
00064     /* The 256 is wrong, it should be 255, but 256 is much faster... */
00065     return ComposeColour(0xFF,
00066               ((int)(r - cr) * a) / 256 + cr,
00067               ((int)(g - cg) * a) / 256 + cg,
00068               ((int)(b - cb) * a) / 256 + cb);
00069   }
00070 
00075   static inline uint32 ComposeColourRGBA(uint r, uint g, uint b, uint a, uint32 current)
00076   {
00077     if (a == 0) return current;
00078     if (a >= 255) return ComposeColour(0xFF, r, g, b);
00079 
00080     return ComposeColourRGBANoCheck(r, g, b, a, current);
00081   }
00082 
00086   static inline uint32 ComposeColourPANoCheck(uint32 colour, uint a, uint32 current)
00087   {
00088     uint r  = GB(colour,  16, 8);
00089     uint g  = GB(colour,  8,  8);
00090     uint b  = GB(colour,  0,  8);
00091 
00092     return ComposeColourRGBANoCheck(r, g, b, a, current);
00093   }
00094 
00099   static inline uint32 ComposeColourPA(uint32 colour, uint a, uint32 current)
00100   {
00101     if (a == 0) return current;
00102     if (a >= 255) return (colour | 0xFF000000);
00103 
00104     return ComposeColourPANoCheck(colour, a, current);
00105   }
00106 
00114   static inline uint32 MakeTransparent(uint32 colour, uint nom, uint denom = 256)
00115   {
00116     uint r = GB(colour, 16, 8);
00117     uint g = GB(colour, 8,  8);
00118     uint b = GB(colour, 0,  8);
00119 
00120     return ComposeColour(0xFF, r * nom / denom, g * nom / denom, b * nom / denom);
00121   }
00122 
00128   static inline uint32 MakeGrey(uint32 colour)
00129   {
00130     uint r = GB(colour, 16, 8);
00131     uint g = GB(colour, 8,  8);
00132     uint b = GB(colour, 0,  8);
00133 
00134     /* To avoid doubles and stuff, multiple it with a total of 65536 (16bits), then
00135      *  divide by it to normalize the value to a byte again. See heightmap.cpp for
00136      *  information about the formula. */
00137     colour = ((r * 19595) + (g * 38470) + (b * 7471)) / 65536;
00138 
00139     return ComposeColour(0xFF, colour, colour, colour);
00140   }
00141 };
00142 
00143 #endif /* BLITTER_32BPP_BASE_HPP */

Generated on Wed Jan 20 23:38:34 2010 for OpenTTD by  doxygen 1.5.6