author | rubidium |
Wed, 09 Jan 2008 18:11:12 +0000 | |
branch | noai |
changeset 9723 | eee46cb39750 |
parent 9703 | d2a6acdbd665 |
child 10249 | 58810805030e |
permissions | -rw-r--r-- |
9628 | 1 |
/* $Id$ */ |
2 |
||
3 |
/** @file 32bpp_base.hpp */ |
|
4 |
||
5 |
#ifndef BLITTER_32BPP_BASE_HPP |
|
6 |
#define BLITTER_32BPP_BASE_HPP |
|
7 |
||
8 |
#include "base.hpp" |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9703
diff
changeset
|
9 |
#include "../core/bitmath_func.hpp" |
9628 | 10 |
|
11 |
class Blitter_32bppBase : public Blitter { |
|
12 |
public: |
|
13 |
/* virtual */ uint8 GetScreenDepth() { return 32; } |
|
14 |
// /* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom); |
|
15 |
// /* virtual */ void DrawColorMappingRect(void *dst, int width, int height, int pal); |
|
16 |
// /* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator); |
|
17 |
/* virtual */ void *MoveTo(const void *video, int x, int y); |
|
18 |
/* virtual */ void SetPixel(void *video, int x, int y, uint8 color); |
|
19 |
/* virtual */ void SetPixelIfEmpty(void *video, int x, int y, uint8 color); |
|
9629 | 20 |
/* virtual */ void DrawRect(void *video, int width, int height, uint8 color); |
21 |
/* virtual */ void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 color); |
|
22 |
/* virtual */ void CopyFromBuffer(void *video, const void *src, int width, int height); |
|
23 |
/* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height); |
|
24 |
/* virtual */ void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch); |
|
25 |
/* virtual */ void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y); |
|
9628 | 26 |
/* virtual */ int BufferSize(int width, int height); |
9629 | 27 |
/* virtual */ void PaletteAnimate(uint start, uint count); |
28 |
/* virtual */ Blitter::PaletteAnimation UsePaletteAnimation(); |
|
9628 | 29 |
|
9629 | 30 |
/** |
31 |
* Compose a colour based on RGB values. |
|
32 |
*/ |
|
33 |
static inline uint ComposeColour(uint a, uint r, uint g, uint b) |
|
34 |
{ |
|
35 |
return (((a) << 24) & 0xFF000000) | (((r) << 16) & 0x00FF0000) | (((g) << 8) & 0x0000FF00) | ((b) & 0x000000FF); |
|
36 |
} |
|
37 |
||
38 |
/** |
|
39 |
* Look up the colour in the current palette. |
|
40 |
**/ |
|
41 |
static inline uint32 LookupColourInPalette(uint8 index) |
|
42 |
{ |
|
43 |
if (index == 0) return 0x00000000; // Full transparent pixel */ |
|
44 |
return ComposeColour(0xFF, _cur_palette[index].r, _cur_palette[index].g, _cur_palette[index].b); |
|
45 |
} |
|
46 |
||
47 |
/** |
|
48 |
* Compose a colour based on RGBA values and the current pixel value. |
|
49 |
*/ |
|
50 |
static inline uint ComposeColourRGBA(uint r, uint g, uint b, uint a, uint current) |
|
51 |
{ |
|
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9629
diff
changeset
|
52 |
if (a == 0) return current; |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9629
diff
changeset
|
53 |
if (a >= 255) return ComposeColour(0xFF, r, g, b); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9629
diff
changeset
|
54 |
|
9629 | 55 |
uint cr, cg, cb; |
56 |
cr = GB(current, 16, 8); |
|
57 |
cg = GB(current, 8, 8); |
|
58 |
cb = GB(current, 0, 8); |
|
59 |
||
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9629
diff
changeset
|
60 |
/* The 256 is wrong, it should be 255, but 256 is much faster... */ |
9629 | 61 |
return ComposeColour(0xFF, |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9629
diff
changeset
|
62 |
(r * a + cr * (256 - a)) / 256, |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9629
diff
changeset
|
63 |
(g * a + cg * (256 - a)) / 256, |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9629
diff
changeset
|
64 |
(b * a + cb * (256 - a)) / 256); |
9629 | 65 |
} |
66 |
||
67 |
/** |
|
68 |
* Compose a colour based on Pixel value, alpha value, and the current pixel value. |
|
69 |
*/ |
|
70 |
static inline uint ComposeColourPA(uint colour, uint a, uint current) |
|
71 |
{ |
|
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9629
diff
changeset
|
72 |
if (a == 0) return current; |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9629
diff
changeset
|
73 |
if (a >= 255) return (colour | 0xFF000000); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9629
diff
changeset
|
74 |
|
9629 | 75 |
uint r, g, b, cr, cg, cb; |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9629
diff
changeset
|
76 |
r = GB(colour, 16, 8); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9629
diff
changeset
|
77 |
g = GB(colour, 8, 8); |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9629
diff
changeset
|
78 |
b = GB(colour, 0, 8); |
9629 | 79 |
cr = GB(current, 16, 8); |
80 |
cg = GB(current, 8, 8); |
|
81 |
cb = GB(current, 0, 8); |
|
82 |
||
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9629
diff
changeset
|
83 |
/* The 256 is wrong, it should be 255, but 256 is much faster... */ |
9629 | 84 |
return ComposeColour(0xFF, |
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9629
diff
changeset
|
85 |
(r * a + cr * (256 - a)) / 256, |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9629
diff
changeset
|
86 |
(g * a + cg * (256 - a)) / 256, |
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9629
diff
changeset
|
87 |
(b * a + cb * (256 - a)) / 256); |
9629 | 88 |
} |
89 |
||
90 |
/** |
|
91 |
* Make a pixel looks like it is transparent. |
|
92 |
* @param colour the colour already on the screen. |
|
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9629
diff
changeset
|
93 |
* @param amount the amount of transparency, times 256. |
9629 | 94 |
* @return the new colour for the screen. |
95 |
*/ |
|
96 |
static inline uint MakeTransparent(uint colour, uint amount) |
|
97 |
{ |
|
98 |
uint r, g, b; |
|
99 |
r = GB(colour, 16, 8); |
|
100 |
g = GB(colour, 8, 8); |
|
101 |
b = GB(colour, 0, 8); |
|
102 |
||
9703
d2a6acdbd665
(svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents:
9629
diff
changeset
|
103 |
return ComposeColour(0xFF, r * amount / 256, g * amount / 256, b * amount / 256); |
9629 | 104 |
} |
105 |
||
106 |
/** |
|
107 |
* Make a colour grey-based. |
|
108 |
* @param colour the colour to make grey. |
|
109 |
* @return the new colour, now grey. |
|
110 |
*/ |
|
111 |
static inline uint MakeGrey(uint colour) |
|
112 |
{ |
|
113 |
uint r, g, b; |
|
114 |
r = GB(colour, 16, 8); |
|
115 |
g = GB(colour, 8, 8); |
|
116 |
b = GB(colour, 0, 8); |
|
117 |
||
118 |
/* To avoid doubles and stuff, multiple it with a total of 65536 (16bits), then |
|
119 |
* divide by it to normalize the value to a byte again. See heightmap.cpp for |
|
120 |
* information about the formula. */ |
|
121 |
colour = ((r * 19595) + (g * 38470) + (b * 7471)) / 65536; |
|
122 |
||
123 |
return ComposeColour(0xFF, colour, colour, colour); |
|
9628 | 124 |
} |
125 |
}; |
|
126 |
||
127 |
#endif /* BLITTER_32BPP_BASE_HPP */ |