44 } |
44 } |
45 |
45 |
46 /** |
46 /** |
47 * Compose a colour based on RGBA values and the current pixel value. |
47 * Compose a colour based on RGBA values and the current pixel value. |
48 */ |
48 */ |
49 static inline uint ComposeColourRGBA(uint r, uint g, uint b, uint a, uint current) |
49 static inline uint32 ComposeColourRGBANoCheck(uint r, uint g, uint b, uint a, uint32 current) |
|
50 { |
|
51 uint cr = GB(current, 16, 8); |
|
52 uint cg = GB(current, 8, 8); |
|
53 uint cb = GB(current, 0, 8); |
|
54 |
|
55 /* The 256 is wrong, it should be 255, but 256 is much faster... */ |
|
56 return ComposeColour(0xFF, |
|
57 (r * a + cr * (256 - a)) / 256, |
|
58 (g * a + cg * (256 - a)) / 256, |
|
59 (b * a + cb * (256 - a)) / 256); |
|
60 } |
|
61 |
|
62 /** |
|
63 * Compose a colour based on RGBA values and the current pixel value. |
|
64 * Handles fully transparent and solid pixels in a special (faster) way. |
|
65 */ |
|
66 static inline uint32 ComposeColourRGBA(uint r, uint g, uint b, uint a, uint32 current) |
50 { |
67 { |
51 if (a == 0) return current; |
68 if (a == 0) return current; |
52 if (a >= 255) return ComposeColour(0xFF, r, g, b); |
69 if (a >= 255) return ComposeColour(0xFF, r, g, b); |
53 |
70 |
54 uint cr, cg, cb; |
71 return ComposeColourRGBANoCheck(r, g, b, a, current); |
55 cr = GB(current, 16, 8); |
72 } |
56 cg = GB(current, 8, 8); |
73 |
57 cb = GB(current, 0, 8); |
74 /** |
|
75 * Compose a colour based on Pixel value, alpha value, and the current pixel value. |
|
76 */ |
|
77 static inline uint32 ComposeColourPANoCheck(uint32 colour, uint a, uint32 current) |
|
78 { |
|
79 uint r = GB(colour, 16, 8); |
|
80 uint g = GB(colour, 8, 8); |
|
81 uint b = GB(colour, 0, 8); |
|
82 uint cr = GB(current, 16, 8); |
|
83 uint cg = GB(current, 8, 8); |
|
84 uint cb = GB(current, 0, 8); |
58 |
85 |
59 /* The 256 is wrong, it should be 255, but 256 is much faster... */ |
86 /* The 256 is wrong, it should be 255, but 256 is much faster... */ |
60 return ComposeColour(0xFF, |
87 return ComposeColour(0xFF, |
61 (r * a + cr * (256 - a)) / 256, |
88 (r * a + cr * (256 - a)) / 256, |
62 (g * a + cg * (256 - a)) / 256, |
89 (g * a + cg * (256 - a)) / 256, |
63 (b * a + cb * (256 - a)) / 256); |
90 (b * a + cb * (256 - a)) / 256); |
64 } |
91 } |
65 |
92 |
66 /** |
93 /** |
67 * Compose a colour based on Pixel value, alpha value, and the current pixel value. |
94 * Compose a colour based on Pixel value, alpha value, and the current pixel value. |
68 */ |
95 * Handles fully transparent and solid pixels in a special (faster) way. |
69 static inline uint ComposeColourPA(uint colour, uint a, uint current) |
96 */ |
|
97 static inline uint32 ComposeColourPA(uint32 colour, uint a, uint32 current) |
70 { |
98 { |
71 if (a == 0) return current; |
99 if (a == 0) return current; |
72 if (a >= 255) return (colour | 0xFF000000); |
100 if (a >= 255) return (colour | 0xFF000000); |
73 |
101 |
74 uint r, g, b, cr, cg, cb; |
102 return ComposeColourPANoCheck(colour, a, current); |
75 r = GB(colour, 16, 8); |
|
76 g = GB(colour, 8, 8); |
|
77 b = GB(colour, 0, 8); |
|
78 cr = GB(current, 16, 8); |
|
79 cg = GB(current, 8, 8); |
|
80 cb = GB(current, 0, 8); |
|
81 |
|
82 /* The 256 is wrong, it should be 255, but 256 is much faster... */ |
|
83 return ComposeColour(0xFF, |
|
84 (r * a + cr * (256 - a)) / 256, |
|
85 (g * a + cg * (256 - a)) / 256, |
|
86 (b * a + cb * (256 - a)) / 256); |
|
87 } |
103 } |
88 |
104 |
89 /** |
105 /** |
90 * Make a pixel looks like it is transparent. |
106 * Make a pixel looks like it is transparent. |
91 * @param colour the colour already on the screen. |
107 * @param colour the colour already on the screen. |
92 * @param amount the amount of transparency, times 256. |
108 * @param nom the amount of transparency, nominator, makes colour lighter. |
|
109 * @param denom denominator, makes colour darker. |
93 * @return the new colour for the screen. |
110 * @return the new colour for the screen. |
94 */ |
111 */ |
95 static inline uint MakeTransparent(uint colour, uint amount) |
112 static inline uint32 MakeTransparent(uint32 colour, uint nom, uint denom = 256) |
96 { |
113 { |
97 uint r, g, b; |
114 uint r = GB(colour, 16, 8); |
98 r = GB(colour, 16, 8); |
115 uint g = GB(colour, 8, 8); |
99 g = GB(colour, 8, 8); |
116 uint b = GB(colour, 0, 8); |
100 b = GB(colour, 0, 8); |
|
101 |
117 |
102 return ComposeColour(0xFF, r * amount / 256, g * amount / 256, b * amount / 256); |
118 return ComposeColour(0xFF, r * nom / denom, g * nom / denom, b * nom / denom); |
103 } |
119 } |
104 |
120 |
105 /** |
121 /** |
106 * Make a colour grey - based. |
122 * Make a colour grey - based. |
107 * @param colour the colour to make grey. |
123 * @param colour the colour to make grey. |
108 * @return the new colour, now grey. |
124 * @return the new colour, now grey. |
109 */ |
125 */ |
110 static inline uint MakeGrey(uint colour) |
126 static inline uint32 MakeGrey(uint32 colour) |
111 { |
127 { |
112 uint r, g, b; |
128 uint r = GB(colour, 16, 8); |
113 r = GB(colour, 16, 8); |
129 uint g = GB(colour, 8, 8); |
114 g = GB(colour, 8, 8); |
130 uint b = GB(colour, 0, 8); |
115 b = GB(colour, 0, 8); |
|
116 |
131 |
117 /* To avoid doubles and stuff, multiple it with a total of 65536 (16bits), then |
132 /* To avoid doubles and stuff, multiple it with a total of 65536 (16bits), then |
118 * divide by it to normalize the value to a byte again. See heightmap.cpp for |
133 * divide by it to normalize the value to a byte again. See heightmap.cpp for |
119 * information about the formula. */ |
134 * information about the formula. */ |
120 colour = ((r * 19595) + (g * 38470) + (b * 7471)) / 65536; |
135 colour = ((r * 19595) + (g * 38470) + (b * 7471)) / 65536; |