xref: /haiku/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaPCSUBPIX.h (revision c9060eb991e10e477ece52478d6743fc7691c143)
1 /*
2  * Copyright 2005, Stephan Aßmus <superstippi@gmx.de>.
3  * Copyright 2008, Andrej Spielmann <andrej.spielmann@seh.ox.ac.uk>.
4  * All rights reserved. Distributed under the terms of the MIT License.
5  *
6  * DrawingMode implementing B_OP_ALPHA in "Pixel Composite" mode on B_RGBA32.
7  *
8  */
9 
10 #ifndef DRAWING_MODE_ALPHA_PC_SUBPIX_H
11 #define DRAWING_MODE_ALPHA_PC_SUBPIX_H
12 
13 #include "DrawingMode.h"
14 
15 // BLEND_ALPHA_PC_SUBPIX
16 #define BLEND_ALPHA_PC_SUBPIX(d, r, g, b, a1, a2, a3) \
17 { \
18 	BLEND_COMPOSITE16_SUBPIX(d, r, g, b, a1, a2, a3); \
19 }
20 
21 
22 // BLEND_ALPHA_PC
23 #define BLEND_ALPHA_PC(d, r, g, b, a) \
24 { \
25 	BLEND_COMPOSITE16(d, r, g, b, a); \
26 }
27 
28 
29 // ASSIGN_ALPHA_PC
30 #define ASSIGN_ALPHA_PC(d, r, g, b) \
31 { \
32 	d[0] = (b); \
33 	d[1] = (g); \
34 	d[2] = (r); \
35 	d[3] = 255; \
36 }
37 
38 
39 // blend_hline_alpha_pc_subpix
40 void
41 blend_hline_alpha_pc_subpix(int x, int y, unsigned len, const color_type& c,
42 	uint8 cover, agg_buffer* buffer, const PatternHandler* pattern)
43 {
44 	uint8* p = buffer->row_ptr(y) + (x << 2);
45 	do {
46 		rgb_color color = pattern->ColorAt(x, y);
47 		uint16 alpha = color.alpha * cover;
48 		if (alpha) {
49 			if (alpha == 255) {
50 				ASSIGN_ALPHA_PC(p, color.red, color.green, color.blue);
51 			} else {
52 				BLEND_ALPHA_PC(p, color.red, color.green, color.blue, alpha);
53 			}
54 		}
55 		x++;
56 		p += 4;
57 		len -= 3;
58 	} while (len);
59 }
60 
61 
62 // blend_solid_hspan_alpha_pc_subpix
63 void
64 blend_solid_hspan_alpha_pc_subpix(int x, int y, unsigned len,
65 	const color_type& c, const uint8* covers, agg_buffer* buffer,
66 	const PatternHandler* pattern)
67 {
68 	uint8* p = buffer->row_ptr(y) + (x << 2);
69 	uint16 alphaRed;
70 	uint16 alphaGreen;
71 	uint16 alphaBlue;
72 	do {
73 		rgb_color color = pattern->ColorAt(x, y);
74 		alphaRed = color.alpha * covers[0];
75 		alphaGreen = color.alpha * covers[1];
76 		alphaBlue = color.alpha * covers[2];
77 		BLEND_ALPHA_PC_SUBPIX(p, color.red, color.green, color.blue,
78 			alphaBlue, alphaGreen, alphaRed);
79 		covers += 3;
80 		p += 4;
81 		x++;
82 		len -= 3;
83 	} while (len);
84 }
85 
86 #endif // DRAWING_MODE_ALPHA_PC_SUBPIX_H
87 
88