xref: /haiku/src/servers/app/drawing/Painter/drawing_modes/DrawingModeBlendSUBPIX.h (revision 21258e2674226d6aa732321b6f8494841895af5f)
1 /*
2  * Copyright 2005, Stephan Aßmus <superstippi@gmx.de>.
3  * Copyright 2008, Andrej Spielmann <andrej.spielmann@seh.ox.ac.uk>.
4  * All rights reserved. Distributed under the terms of the MIT License.
5  *
6  * DrawingMode implementing B_OP_ADD on B_RGBA32.
7  *
8  */
9 
10 #ifndef DRAWING_MODE_BLEND_SUBPIX_H
11 #define DRAWING_MODE_BLEND_SUBPIX_H
12 
13 #include "DrawingMode.h"
14 #include "GlobalSubpixelSettings.h"
15 
16 
17 // BLEND_BLEND_SUBPIX
18 #define BLEND_BLEND_SUBPIX(d, r, g, b, a1, a2, a3) \
19 { \
20 	pixel32 _p; \
21 	_p.data32 = *(uint32*)d; \
22 	uint8 bt = (_p.data8[0] + (b)) >> 1; \
23 	uint8 gt = (_p.data8[1] + (g)) >> 1; \
24 	uint8 rt = (_p.data8[2] + (r)) >> 1; \
25 	BLEND_SUBPIX(d, rt, gt, bt, a1, a2, a3); \
26 }
27 
28 
29 // blend_solid_hspan_blend_subpix
30 void
31 blend_solid_hspan_blend_subpix(int x, int y, unsigned len, const color_type& c,
32 	const uint8* covers, agg_buffer* buffer, const PatternHandler* pattern)
33 {
34 	uint8* p = buffer->row_ptr(y) + (x << 2);
35 	const int subpixelL = gSubpixelOrderingRGB ? 2 : 0;
36 	const int subpixelM = 1;
37 	const int subpixelR = gSubpixelOrderingRGB ? 0 : 2;
38 	do {
39 		rgb_color color = pattern->ColorAt(x, y);
40 		BLEND_BLEND_SUBPIX(p, color.red, color.green, color.blue,
41 			covers[subpixelL], covers[subpixelM], covers[subpixelR]);
42 		covers += 3;
43 		p += 4;
44 		x++;
45 		len -= 3;
46 	} while (len);
47 }
48 
49 
50 #endif // DRAWING_MODE_BLEND_SUBPIX_H
51 
52