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