xref: /haiku/src/servers/app/drawing/Painter/drawing_modes/DrawingModeCopySolid.h (revision 93aeb8c3bc3f13cb1f282e3e749258a23790d947)
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 "DrawingModeCopySolid.h"
13 
14 template<class Order>
15 class DrawingModeCopySolid : public DrawingMode {
16  public:
17 	// constructor
18 	DrawingModeCopySolid()
19 		: DrawingMode()
20 	{
21 	}
22 
23 	// blend_pixel
24 	virtual	void blend_pixel(int x, int y, const color_type& c, uint8 cover)
25 	{
26 		uint8* p = fBuffer->row(y) + (x << 2);
27 		if (cover == 255) {
28 			ASSIGN_COPY(p[Order::R], p[Order::G], p[Order::B], p[Order::A],
29 						c.r, c.g, c.b);
30 		} else {
31 			rgb_color l = fPatternHandler->LowColor().GetColor32();
32 			BLEND_COPY(p[Order::R], p[Order::G], p[Order::B], p[Order::A],
33 					   c.r, c.g, c.b, cover,
34 					   l.red, l.green, l.blue);
35 		}
36 	}
37 
38 	// blend_hline
39 	virtual	void blend_hline(int x, int y, unsigned len,
40 							 const color_type& c, uint8 cover)
41 	{
42 		if(cover == 255) {
43 			// cache the color as 32bit value
44 			uint32 v;
45 			uint8* p8 = (uint8*)&v;
46 			p8[Order::R] = (uint8)c.r;
47 			p8[Order::G] = (uint8)c.g;
48 			p8[Order::B] = (uint8)c.b;
49 			p8[Order::A] = 255;
50 			// row offset as 32bit pointer
51 			uint32* p32 = (uint32*)(fBuffer->row(y)) + x;
52 			do {
53 				*p32 = v;
54 				p32++;
55 			} while(--len);
56 		} else {
57 			uint8* p = fBuffer->row(y) + (x << 2);
58 			rgb_color l = fPatternHandler->LowColor().GetColor32();
59 			do {
60 				BLEND_COPY(p[Order::R], p[Order::G], p[Order::B], p[Order::A],
61 						   c.r, c.g, c.b, cover,
62 						   l.red, l.green, l.blue);
63 				p += 4;
64 			} while(--len);
65 		}
66 	}
67 
68 	// blend_vline
69 	virtual	void blend_vline(int x, int y, unsigned len,
70 							 const color_type& c, uint8 cover)
71 	{
72 printf("DrawingModeCopySolid::blend_vline()\n");
73 	}
74 
75 	// blend_solid_hspan
76 	virtual	void blend_solid_hspan(int x, int y, unsigned len,
77 								   const color_type& c, const uint8* covers)
78 	{
79 		uint8* p = fBuffer->row(y) + (x << 2);
80 		rgb_color l = fPatternHandler->LowColor().GetColor32();
81 		do {
82 			if (*covers) {
83 				if(*covers == 255) {
84 					ASSIGN_COPY(p[Order::R], p[Order::G], p[Order::B], p[Order::A],
85 								c.r, c.g, c.b);
86 				} else {
87 					BLEND_COPY(p[Order::R], p[Order::G], p[Order::B], p[Order::A],
88 							   c.r, c.g, c.b, *covers,
89 							   l.red, l.green, l.blue);
90 				}
91 			}
92 			covers++;
93 			p += 4;
94 		} while(--len);
95 	}
96 
97 
98 
99 	// blend_solid_vspan
100 	virtual	void blend_solid_vspan(int x, int y, unsigned len,
101 								   const color_type& c, const uint8* covers)
102 	{
103 		uint8* p = fBuffer->row(y) + (x << 2);
104 		rgb_color l = fPatternHandler->LowColor().GetColor32();
105 		do {
106 			if (*covers) {
107 				if (*covers == 255) {
108 					ASSIGN_COPY(p[Order::R], p[Order::G], p[Order::B], p[Order::A],
109 								c.r, c.g, c.b);
110 				} else {
111 					BLEND_COPY(p[Order::R], p[Order::G], p[Order::B], p[Order::A],
112 							   c.r, c.g, c.b, *covers,
113 							   l.red, l.green, l.blue);
114 				}
115 			}
116 			covers++;
117 			p += fBuffer->stride();
118 		} while(--len);
119 	}
120 
121 
122 	// blend_color_hspan
123 	virtual	void blend_color_hspan(int x, int y, unsigned len,
124 								   const color_type* colors,
125 								   const uint8* covers,
126 								   uint8 cover)
127 	{
128 		uint8* p = fBuffer->row(y) + (x << 2);
129 		rgb_color l = fPatternHandler->LowColor().GetColor32();
130 		if (covers) {
131 			// non-solid opacity
132 			do {
133 				if(*covers) {
134 					if(*covers == 255) {
135 						ASSIGN_COPY(p[Order::R], p[Order::G], p[Order::B], p[Order::A],
136 									colors->r, colors->g, colors->b);
137 					} else {
138 						BLEND_COPY(p[Order::R], p[Order::G], p[Order::B], p[Order::A],
139 								   colors->r, colors->g, colors->b, *covers,
140 								   l.red, l.green, l.blue);
141 					}
142 				}
143 				covers++;
144 				p += 4;
145 				++colors;
146 			} while(--len);
147 		} else {
148 			// solid full opcacity
149 			if (cover == 255) {
150 				do {
151 					ASSIGN_COPY(p[Order::R], p[Order::G], p[Order::B], p[Order::A],
152 								colors->r, colors->g, colors->b);
153 					p += 4;
154 					++colors;
155 				} while(--len);
156 			// solid partial opacity
157 			} else if (cover) {
158 				do {
159 					BLEND_COPY(p[Order::R], p[Order::G], p[Order::B], p[Order::A],
160 							   colors->r, colors->g, colors->b, cover,
161 							   l.red, l.green, l.blue);
162 					p += 4;
163 					++colors;
164 				} while(--len);
165 			}
166 		}
167 	}
168 
169 
170 	// blend_color_vspan
171 	virtual	void blend_color_vspan(int x, int y, unsigned len,
172 								   const color_type* colors,
173 								   const uint8* covers,
174 								   uint8 cover)
175 	{
176 printf("DrawingModeCopySolid::blend_color_vspan()\n");
177 	}
178 
179 };
180 
181 typedef DrawingModeCopySolid<agg::order_rgba32> DrawingModeRGBA32CopySolid;
182 typedef DrawingModeCopySolid<agg::order_argb32> DrawingModeARGB32CopySolid;
183 typedef DrawingModeCopySolid<agg::order_abgr32> DrawingModeABGR32CopySolid;
184 typedef DrawingModeCopySolid<agg::order_bgra32> DrawingModeBGRA32CopySolid;
185 
186 #endif // DRAWING_MODE_COPY_SOLID_H
187 
188