xref: /haiku/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaPOSolid.h (revision 17889a8c70dbb3d59c1412f6431968753c767bab)
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 Overlay" mode on B_RGBA32.
6  *
7  */
8 
9 #ifndef DRAWING_MODE_ALPHA_PO_SOLID_H
10 #define DRAWING_MODE_ALPHA_PO_SOLID_H
11 
12 #include "DrawingModeAlphaPO.h"
13 
14 // blend_pixel_alpha_po_solid
15 void
16 blend_pixel_alpha_po_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 = c.a * cover;
21 	if (alpha == 255 * 255) {
22 		ASSIGN_ALPHA_PO(p, c.r, c.g, c.b);
23 	} else {
24 		BLEND_ALPHA_PO(p, c.r, c.g, c.b, alpha);
25 	}
26 }
27 
28 // blend_hline_alpha_po_solid
29 void
30 blend_hline_alpha_po_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 = c.a * 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_po_solid
66 void
67 blend_solid_hspan_alpha_po_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 	do {
73 		uint16 alpha = c.a * *covers;
74 		if (alpha) {
75 			if(alpha == 255 * 255) {
76 				ASSIGN_ALPHA_PO(p, c.r, c.g, c.b);
77 			} else {
78 				BLEND_ALPHA_PO(p, c.r, c.g, c.b, alpha);
79 			}
80 		}
81 		covers++;
82 		p += 4;
83 		x++;
84 	} while(--len);
85 }
86 
87 
88 
89 // blend_solid_vspan_alpha_po_solid
90 void
91 blend_solid_vspan_alpha_po_solid(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 		uint16 alpha = c.a * *covers;
98 		if (alpha) {
99 			if (alpha == 255 * 255) {
100 				ASSIGN_ALPHA_PO(p, c.r, c.g, c.b);
101 			} else {
102 				BLEND_ALPHA_PO(p, c.r, c.g, c.b, alpha);
103 			}
104 		}
105 		covers++;
106 		p += buffer->stride();
107 		y++;
108 	} while(--len);
109 }
110 
111 #endif // DRAWING_MODE_ALPHA_PO_SOLID_H
112 
113