00001
00002
00003
00004
00005
00006
00007
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 "../core/math_func.hpp"
00018 #include "../gfx_func.h"
00019
00021 class Blitter_32bppBase : public Blitter {
00022 public:
00023 uint8 GetScreenDepth() { return 32; }
00024 void *MoveTo(void *video, int x, int y);
00025 void SetPixel(void *video, int x, int y, uint8 colour);
00026 void DrawRect(void *video, int width, int height, uint8 colour);
00027 void CopyFromBuffer(void *video, const void *src, int width, int height);
00028 void CopyToBuffer(const void *video, void *dst, int width, int height);
00029 void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch);
00030 void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y);
00031 int BufferSize(int width, int height);
00032 void PaletteAnimate(const Palette &palette);
00033 Blitter::PaletteAnimation UsePaletteAnimation();
00034 int GetBytesPerPixel() { return 4; }
00035
00039 static inline Colour LookupColourInPalette(uint index)
00040 {
00041 return _cur_palette.palette[index];
00042 }
00043
00047 static inline Colour ComposeColourRGBANoCheck(uint r, uint g, uint b, uint a, Colour current)
00048 {
00049 uint cr = current.r;
00050 uint cg = current.g;
00051 uint cb = current.b;
00052
00053
00054 return Colour(
00055 ((int)(r - cr) * a) / 256 + cr,
00056 ((int)(g - cg) * a) / 256 + cg,
00057 ((int)(b - cb) * a) / 256 + cb);
00058 }
00059
00064 static inline Colour ComposeColourRGBA(uint r, uint g, uint b, uint a, Colour current)
00065 {
00066 if (a == 0) return current;
00067 if (a >= 255) return Colour(r, g, b);
00068
00069 return ComposeColourRGBANoCheck(r, g, b, a, current);
00070 }
00071
00075 static inline Colour ComposeColourPANoCheck(Colour colour, uint a, Colour current)
00076 {
00077 uint r = colour.r;
00078 uint g = colour.g;
00079 uint b = colour.b;
00080
00081 return ComposeColourRGBANoCheck(r, g, b, a, current);
00082 }
00083
00088 static inline Colour ComposeColourPA(Colour colour, uint a, Colour current)
00089 {
00090 if (a == 0) return current;
00091 if (a >= 255) {
00092 colour.a = 255;
00093 return colour;
00094 }
00095
00096 return ComposeColourPANoCheck(colour, a, current);
00097 }
00098
00106 static inline Colour MakeTransparent(Colour colour, uint nom, uint denom = 256)
00107 {
00108 uint r = colour.r;
00109 uint g = colour.g;
00110 uint b = colour.b;
00111
00112 return Colour(r * nom / denom, g * nom / denom, b * nom / denom);
00113 }
00114
00122 static inline uint8 MakeDark(uint8 r, uint8 g, uint8 b)
00123 {
00124
00125 return ((r * 13063) + (g * 25647) + (b * 4981)) / 65536;
00126 }
00127
00133 static inline Colour MakeGrey(Colour colour)
00134 {
00135 uint r = colour.r;
00136 uint g = colour.g;
00137 uint b = colour.b;
00138
00139
00140
00141
00142 uint grey = ((r * 19595) + (g * 38470) + (b * 7471)) / 65536;
00143
00144 return Colour(grey, grey, grey);
00145 }
00146
00147 static const int DEFAULT_BRIGHTNESS = 128;
00148
00149 static inline Colour AdjustBrightness(Colour colour, uint8 brightness)
00150 {
00151
00152 if (brightness == DEFAULT_BRIGHTNESS) return colour;
00153
00154 uint16 ob = 0;
00155 uint16 r = colour.r * brightness / DEFAULT_BRIGHTNESS;
00156 uint16 g = colour.g * brightness / DEFAULT_BRIGHTNESS;
00157 uint16 b = colour.b * brightness / DEFAULT_BRIGHTNESS;
00158
00159
00160 if (r > 255) ob += r - 255;
00161 if (g > 255) ob += g - 255;
00162 if (b > 255) ob += b - 255;
00163
00164 if (ob == 0) return Colour(r, g, b, colour.a);
00165
00166
00167 ob /= 2;
00168 return Colour(
00169 r >= 255 ? 255 : min(r + ob * (255 - r) / 256, 255),
00170 g >= 255 ? 255 : min(g + ob * (255 - g) / 256, 255),
00171 b >= 255 ? 255 : min(b + ob * (255 - b) / 256, 255),
00172 colour.a);
00173 }
00174 };
00175
00176 #endif