xref: /haiku/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaPC.h (revision e81a954787e50e56a7f06f72705b7859b6ab06d1)
1 /*
2  * Copyright 2005, Stephan Aßmus <superstippi@gmx.de>. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * DrawingMode implementing B_OP_ALPHA in "Pixel Composite" mode on B_RGBA32.
6  *
7  */
8 
9 #ifndef DRAWING_MODE_ALPHA_PC_H
10 #define DRAWING_MODE_ALPHA_PC_H
11 
12 #include "DrawingMode.h"
13 
14 // BLEND_ALPHA_PC
15 #define BLEND_ALPHA_PC(d, r, g, b, a) \
16 { \
17 	BLEND_COMPOSITE16(d, r, g, b, a); \
18 }
19 
20 // ASSIGN_ALPHA_PC
21 #define ASSIGN_ALPHA_PC(d, r, g, b) \
22 { \
23 	d[0] = (b); \
24 	d[1] = (g); \
25 	d[2] = (r); \
26 	d[3] = 255; \
27 }
28 
29 // blend_pixel_alpha_pc
30 void
31 blend_pixel_alpha_pc(int x, int y, const color_type& c, uint8 cover,
32 					 agg_buffer* buffer, const PatternHandler* pattern)
33 {
34 	uint8* p = buffer->row_ptr(y) + (x << 2);
35 	rgb_color color = pattern->ColorAt(x, y);
36 	uint16 alpha = color.alpha * cover;
37 	if (alpha == 255*255) {
38 		ASSIGN_ALPHA_PC(p, color.red, color.green, color.blue);
39 	} else {
40 		BLEND_ALPHA_PC(p, color.red, color.green, color.blue, alpha);
41 	}
42 }
43 
44 // blend_hline_alpha_pc
45 void
46 blend_hline_alpha_pc(int x, int y, unsigned len,
47 					 const color_type& c, uint8 cover,
48 					 agg_buffer* buffer, const PatternHandler* pattern)
49 {
50 	uint8* p = buffer->row_ptr(y) + (x << 2);
51 	do {
52 		rgb_color color = pattern->ColorAt(x, y);
53 		uint16 alpha = color.alpha * cover;
54 		if (alpha) {
55 			if (alpha == 255 * 255) {
56 				ASSIGN_ALPHA_PC(p, color.red, color.green, color.blue);
57 			} else {
58 				BLEND_ALPHA_PC(p, color.red, color.green, color.blue, alpha);
59 			}
60 		}
61 		x++;
62 		p += 4;
63 	} while(--len);
64 }
65 
66 // blend_solid_hspan_alpha_pc
67 void
68 blend_solid_hspan_alpha_pc(int x, int y, unsigned len,
69 						   const color_type& c, const uint8* covers,
70 						   agg_buffer* buffer, const PatternHandler* pattern)
71 {
72 	uint8* p = buffer->row_ptr(y) + (x << 2);
73 	do {
74 		rgb_color color = pattern->ColorAt(x, y);
75 		uint16 alpha = color.alpha * *covers;
76 		if (alpha) {
77 			if(alpha == 255 * 255) {
78 				ASSIGN_ALPHA_PC(p, color.red, color.green, color.blue);
79 			} else {
80 				BLEND_ALPHA_PC(p, color.red, color.green, color.blue, alpha);
81 			}
82 		}
83 		covers++;
84 		p += 4;
85 		x++;
86 	} while(--len);
87 }
88 
89 // blend_solid_vspan_alpha_pc
90 void
91 blend_solid_vspan_alpha_pc(int x, int y, unsigned len,
92 						   const color_type& c, const uint8* covers,
93 						   agg_buffer* buffer, const PatternHandler* pattern)
94 {
95 	uint8* p = buffer->row_ptr(y) + (x << 2);
96 	do {
97 		rgb_color color = pattern->ColorAt(x, y);
98 		uint16 alpha = color.alpha * *covers;
99 		if (alpha) {
100 			if (alpha == 255 * 255) {
101 				ASSIGN_ALPHA_PC(p, color.red, color.green, color.blue);
102 			} else {
103 				BLEND_ALPHA_PC(p, color.red, color.green, color.blue, alpha);
104 			}
105 		}
106 		covers++;
107 		p += buffer->stride();
108 		y++;
109 	} while(--len);
110 }
111 
112 
113 // blend_color_hspan_alpha_pc
114 void
115 blend_color_hspan_alpha_pc(int x, int y, unsigned len,
116 						   const color_type* colors,
117 						   const uint8* covers, uint8 cover,
118 						   agg_buffer* buffer, const PatternHandler* pattern)
119 {
120 	uint8* p = buffer->row_ptr(y) + (x << 2);
121 	if (covers) {
122 		// non-solid opacity
123 		do {
124 			uint16 alpha = colors->a * *covers;
125 			if (alpha) {
126 				if (alpha == 255 * 255) {
127 					ASSIGN_ALPHA_PC(p, colors->r, colors->g, colors->b);
128 				} else {
129 					BLEND_ALPHA_PC(p, colors->r, colors->g, colors->b, alpha);
130 				}
131 			}
132 			covers++;
133 			p += 4;
134 			++colors;
135 		} while(--len);
136 	} else {
137 		// solid full opcacity
138 		uint16 alpha = colors->a * cover;
139 		if (alpha == 255 * 255) {
140 			do {
141 				ASSIGN_ALPHA_PC(p, colors->r, colors->g, colors->b);
142 				p += 4;
143 				++colors;
144 			} while(--len);
145 		// solid partial opacity
146 		} else if (alpha) {
147 			do {
148 				BLEND_ALPHA_PC(p, colors->r, colors->g, colors->b, alpha);
149 				p += 4;
150 				++colors;
151 			} while(--len);
152 		}
153 	}
154 }
155 
156 #endif // DRAWING_MODE_ALPHA_PC_H
157 
158