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
00120 static inline Colour MakeGrey(Colour colour)
00121 {
00122 uint r = colour.r;
00123 uint g = colour.g;
00124 uint b = colour.b;
00125
00126
00127
00128
00129 uint grey = ((r * 19595) + (g * 38470) + (b * 7471)) / 65536;
00130
00131 return Colour(grey, grey, grey);
00132 }
00133
00134 static const int DEFAULT_BRIGHTNESS = 64;
00135
00136 static inline Colour AdjustBrightness(Colour colour, uint8 brightness)
00137 {
00138
00139 if (brightness == DEFAULT_BRIGHTNESS) return colour;
00140
00141 uint16 ob = 0;
00142 uint16 r = colour.r * brightness / DEFAULT_BRIGHTNESS;
00143 uint16 g = colour.g * brightness / DEFAULT_BRIGHTNESS;
00144 uint16 b = colour.b * brightness / DEFAULT_BRIGHTNESS;
00145
00146
00147 if (r > 255) ob += r - 255;
00148 if (g > 255) ob += g - 255;
00149 if (b > 255) ob += b - 255;
00150
00151 if (ob == 0) return Colour(r, g, b, colour.a);
00152
00153
00154 ob /= 2;
00155 return Colour(
00156 r >= 255 ? 255 : min(r + ob * (255 - r) / 256, 255),
00157 g >= 255 ? 255 : min(g + ob * (255 - g) / 256, 255),
00158 b >= 255 ? 255 : min(b + ob * (255 - b) / 256, 255),
00159 colour.a);
00160 }
00161 };
00162
00163 #endif