xref: /haiku/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaCOSolid.h (revision 1e60bdeab63fa7a57bc9a55b032052e95a18bd2c)
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 "Constant Overlay" mode on B_RGBA32.
6  *
7  */
8 
9 #ifndef DRAWING_MODE_ALPHA_CO_SOLID_H
10 #define DRAWING_MODE_ALPHA_CO_SOLID_H
11 
12 #include "DrawingModeAlphaCO.h"
13 
14 // blend_pixel_alpha_co_solid
15 void
16 blend_pixel_alpha_co_solid(int x, int y, const color_type& c, uint8 cover,
17 						   agg_buffer* buffer, const PatternHandler* pattern)
18 {
19 	uint8* p = buffer->row_ptr(y) + (x << 2);
20 	uint16 alpha = pattern->HighColor().alpha * cover;
21 	if (alpha == 255 * 255) {
22 		ASSIGN_ALPHA_CO(p, c.r, c.g, c.b);
23 	} else {
24 		BLEND_ALPHA_CO(p, c.r, c.g, c.b, alpha);
25 	}
26 }
27 
28 // blend_hline_alpha_co_solid
29 void
30 blend_hline_alpha_co_solid(int x, int y, unsigned len,
31 						   const color_type& c, uint8 cover,
32 						   agg_buffer* buffer, const PatternHandler* pattern)
33 {
34 	uint16 alpha = pattern->HighColor().alpha * cover;
35 	if (alpha == 255 * 255) {
36 		// cache the color as 32bit values
37 		uint32 v;
38 		uint8* p8 = (uint8*)&v;
39 		p8[0] = c.b;
40 		p8[1] = c.g;
41 		p8[2] = c.r;
42 		p8[3] = 255;
43 		// row offset as 32bit pointer
44 		uint32* p32 = (uint32*)(buffer->row_ptr(y)) + x;
45 		do {
46 			*p32 = v;
47 			p32++;
48 			x++;
49 		} while(--len);
50 	} else {
51 		uint8* p = buffer->row_ptr(y) + (x << 2);
52 		if (len < 4) {
53 			do {
54 				BLEND_ALPHA_CO(p, c.r, c.g, c.b, alpha);
55 				x++;
56 				p += 4;
57 			} while(--len);
58 		} else {
59 			alpha = alpha >> 8;
60 			blend_line32(p, len, c.r, c.g, c.b, alpha);
61 		}
62 	}
63 }
64 
65 // blend_solid_hspan_alpha_co_solid
66 void
67 blend_solid_hspan_alpha_co_solid(int x, int y, unsigned len,
68 								 const color_type& c, const uint8* covers,
69 								 agg_buffer* buffer, const PatternHandler* pattern)
70 {
71 	uint8* p = buffer->row_ptr(y) + (x << 2);
72 	uint8 hAlpha = pattern->HighColor().alpha;
73 	do {
74 		uint16 alpha = hAlpha * *covers;
75 		if (alpha) {
76 			if (alpha == 255 * 255) {
77 				ASSIGN_ALPHA_CO(p, c.r, c.g, c.b);
78 			} else {
79 				BLEND_ALPHA_CO(p, c.r, c.g, c.b, alpha);
80 			}
81 		}
82 		covers++;
83 		p += 4;
84 		x++;
85 	} while(--len);
86 }
87 
88 
89 
90 // blend_solid_vspan_alpha_co_solid
91 void
92 blend_solid_vspan_alpha_co_solid(int x, int y, unsigned len,
93 								 const color_type& c, const uint8* covers,
94 								 agg_buffer* buffer, const PatternHandler* pattern)
95 {
96 	uint8* p = buffer->row_ptr(y) + (x << 2);
97 	uint8 hAlpha = pattern->HighColor().alpha;
98 	do {
99 		uint16 alpha = hAlpha * *covers;
100 		if (alpha) {
101 			if (alpha == 255 * 255) {
102 				ASSIGN_ALPHA_CO(p, c.r, c.g, c.b);
103 			} else {
104 				BLEND_ALPHA_CO(p, c.r, c.g, c.b, alpha);
105 			}
106 		}
107 		covers++;
108 		p += buffer->stride();
109 		y++;
110 	} while(--len);
111 }
112 
113 #endif // DRAWING_MODE_ALPHA_CO_SOLID_H
114 
115