xref: /haiku/src/servers/app/drawing/Painter/drawing_modes/DrawingModeOverSolid.h (revision d3d8b26997fac34a84981e6d2b649521de2cc45a)
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_OVER on B_RGBA32.
6  *
7  */
8 
9 #ifndef DRAWING_MODE_OVER_SOLID_H
10 #define DRAWING_MODE_OVER_SOLID_H
11 
12 #include "DrawingModeOver.h"
13 
14 // blend_pixel_over_solid
15 void
16 blend_pixel_over_solid(int x, int y, const color_type& c, uint8 cover,
17 					   agg_buffer* buffer, const PatternHandler* pattern)
18 {
19 	if (pattern->IsSolidLow())
20 		return;
21 
22 	uint8* p = buffer->row(y) + (x << 2);
23 	if (cover == 255) {
24 		ASSIGN_OVER(p, c.r, c.g, c.b);
25 	} else {
26 		BLEND_OVER(p, c.r, c.g, c.b, cover);
27 	}
28 }
29 
30 // blend_hline_over_solid
31 void
32 blend_hline_over_solid(int x, int y, unsigned len,
33 					   const color_type& c, uint8 cover,
34 					   agg_buffer* buffer, const PatternHandler* pattern)
35 {
36 	if (pattern->IsSolidLow())
37 		return;
38 
39 	if (cover == 255) {
40 		uint32 v;
41 		uint8* p8 = (uint8*)&v;
42 		p8[0] = (uint8)c.b;
43 		p8[1] = (uint8)c.g;
44 		p8[2] = (uint8)c.r;
45 		p8[3] = 255;
46 		uint32* p32 = (uint32*)(buffer->row(y)) + x;
47 		do {
48 			*p32 = v;
49 			p32++;
50 			x++;
51 		} while(--len);
52 	} else {
53 		uint8* p = buffer->row(y) + (x << 2);
54 		do {
55 			BLEND_OVER(p, c.r, c.g, c.b, cover);
56 			x++;
57 			p += 4;
58 		} while(--len);
59 	}
60 }
61 
62 // blend_solid_hspan_over_solid
63 void
64 blend_solid_hspan_over_solid(int x, int y, unsigned len,
65 							 const color_type& c, const uint8* covers,
66 							 agg_buffer* buffer, const PatternHandler* pattern)
67 {
68 	if (pattern->IsSolidLow())
69 		return;
70 
71 	uint8* p = buffer->row(y) + (x << 2);
72 	do {
73 		if (*covers) {
74 			if (*covers == 255) {
75 				ASSIGN_OVER(p, c.r, c.g, c.b);
76 			} else {
77 				BLEND_OVER(p, c.r, c.g, c.b, *covers);
78 			}
79 		}
80 		covers++;
81 		p += 4;
82 		x++;
83 	} while(--len);
84 }
85 
86 
87 
88 // blend_solid_vspan_over_solid
89 void
90 blend_solid_vspan_over_solid(int x, int y, unsigned len,
91 							 const color_type& c, const uint8* covers,
92 							 agg_buffer* buffer, const PatternHandler* pattern)
93 {
94 	if (pattern->IsSolidLow())
95 		return;
96 
97 	uint8* p = buffer->row(y) + (x << 2);
98 	do {
99 		if (*covers) {
100 			if (*covers == 255) {
101 				ASSIGN_OVER(p, c.r, c.g, c.b);
102 			} else {
103 				BLEND_OVER(p, c.r, c.g, c.b, *covers);
104 			}
105 		}
106 		covers++;
107 		p += buffer->stride();
108 		y++;
109 	} while(--len);
110 }
111 
112 
113 // blend_color_hspan_over_solid
114 void
115 blend_color_hspan_over_solid(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(y) + (x << 2);
121 	if (covers) {
122 		// non-solid opacity
123 		do {
124 //				if (*covers) {
125 if (*covers && (colors->a & 0xff)) {
126 				if (*covers == 255) {
127 					ASSIGN_OVER(p, colors->r, colors->g, colors->b);
128 				} else {
129 					BLEND_OVER(p, colors->r, colors->g, colors->b, *covers);
130 				}
131 			}
132 			covers++;
133 			p += 4;
134 			++colors;
135 		} while(--len);
136 	} else {
137 		// solid full opcacity
138 		if (cover == 255) {
139 			do {
140 if (colors->a & 0xff) {
141 				ASSIGN_OVER(p, colors->r, colors->g, colors->b);
142 }
143 				p += 4;
144 				++colors;
145 			} while(--len);
146 		// solid partial opacity
147 		} else if (cover) {
148 			do {
149 				BLEND_OVER(p, colors->r, colors->g, colors->b, cover);
150 				p += 4;
151 				++colors;
152 			} while(--len);
153 		}
154 	}
155 }
156 
157 #endif // DRAWING_MODE_OVER_H
158 
159