# 32bpp_base.hpp

Go to the documentation of this file.

    00001 /* $Id: 32bpp_base.hpp 15711 2009-03-14 18:16:29Z 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 DrawColourMappingRect(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 colour);
    00019   /* virtual */ void SetPixelIfEmpty(void *video, int x, int y, uint8 colour);
    00020   /* virtual */ void DrawRect(void *video, int width, int height, uint8 colour);
    00021   /* virtual */ void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour);
    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   /* virtual */ int GetBytesPerPixel() { return 4; }
    00030
    00034   static inline uint32 ComposeColour(uint a, uint r, uint g, uint b)
    00035   {
    00036     return (((a) << 24) & 0xFF000000) | (((r) << 16) & 0x00FF0000) | (((g) << 8) & 0x0000FF00) | ((b) & 0x000000FF);
    00037   }
    00038
    00042   static inline uint32 LookupColourInPalette(uint index)
    00043   {
    00044     return _cur_palette[index];
    00045   }
    00046
    00050   static inline uint32 ComposeColourRGBANoCheck(uint r, uint g, uint b, uint a, uint32 current)
    00051   {
    00052     uint cr = GB(current, 16, 8);
    00053     uint cg = GB(current, 8,  8);
    00054     uint cb = GB(current, 0,  8);
    00055
    00056     /* The 256 is wrong, it should be 255, but 256 is much faster... */
    00057     return ComposeColour(0xFF,
    00058               ((int)(r - cr) * a) / 256 + cr,
    00059               ((int)(g - cg) * a) / 256 + cg,
    00060               ((int)(b - cb) * a) / 256 + cb);
    00061   }
    00062
    00067   static inline uint32 ComposeColourRGBA(uint r, uint g, uint b, uint a, uint32 current)
    00068   {
    00069     if (a == 0) return current;
    00070     if (a >= 255) return ComposeColour(0xFF, r, g, b);
    00071
    00072     return ComposeColourRGBANoCheck(r, g, b, a, current);
    00073   }
    00074
    00078   static inline uint32 ComposeColourPANoCheck(uint32 colour, uint a, uint32 current)
    00079   {
    00080     uint r  = GB(colour,  16, 8);
    00081     uint g  = GB(colour,  8,  8);
    00082     uint b  = GB(colour,  0,  8);
    00083
    00084     return ComposeColourRGBANoCheck(r, g, b, a, current);
    00085   }
    00086
    00091   static inline uint32 ComposeColourPA(uint32 colour, uint a, uint32 current)
    00092   {
    00093     if (a == 0) return current;
    00094     if (a >= 255) return (colour | 0xFF000000);
    00095
    00096     return ComposeColourPANoCheck(colour, a, current);
    00097   }
    00098
    00106   static inline uint32 MakeTransparent(uint32 colour, uint nom, uint denom = 256)
    00107   {
    00108     uint r = GB(colour, 16, 8);
    00109     uint g = GB(colour, 8,  8);
    00110     uint b = GB(colour, 0,  8);
    00111
    00112     return ComposeColour(0xFF, r * nom / denom, g * nom / denom, b * nom / denom);
    00113   }
    00114
    00120   static inline uint32 MakeGrey(uint32 colour)
    00121   {
    00122     uint r = GB(colour, 16, 8);
    00123     uint g = GB(colour, 8,  8);
    00124     uint b = GB(colour, 0,  8);
    00125
    00126     /* To avoid doubles and stuff, multiple it with a total of 65536 (16bits), then
    00127      *  divide by it to normalize the value to a byte again. See heightmap.cpp for
    00128      *  information about the formula. */
    00129     colour = ((r * 19595) + (g * 38470) + (b * 7471)) / 65536;
    00130
    00131     return ComposeColour(0xFF, colour, colour, colour);
    00132   }
    00133 };
    00134
    00135 #endif /* BLITTER_32BPP_BASE_HPP */