xref: /haiku/src/servers/app/drawing/Painter/drawing_modes/DrawingModeSubtractSUBPIX.h (revision 59e13a3f06eedbc797f797da71c6810634b22cd4)
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_SUBTRACT on B_RGBA32.
7  *
8  */
9 
10 #ifndef DRAWING_MODE_SUBTRACT_SUBPIX_H
11 #define DRAWING_MODE_SUBTRACT_SUBPIX_H
12 
13 #include "DrawingMode.h"
14 #include "GlobalSubpixelSettings.h"
15 
16 // BLEND_SUBTRACT_SUBPIX
17 #define BLEND_SUBTRACT_SUBPIX(d, r, g, b, a1, a2, a3) \
18 { \
19 	pixel32 _p; \
20 	_p.data32 = *(uint32*)d; \
21 	uint8 rt = max_c(0, _p.data8[2] - (r)); \
22 	uint8 gt = max_c(0, _p.data8[1] - (g)); \
23 	uint8 bt = max_c(0, _p.data8[0] - (b)); \
24 	BLEND_SUBPIX(d, rt, gt, bt, a1, a2, a3); \
25 }
26 
27 
28 // blend_solid_hspan_subtract_subpix
29 void
blend_solid_hspan_subtract_subpix(int x,int y,unsigned len,const color_type & c,const uint8 * covers,agg_buffer * buffer,const PatternHandler * pattern)30 blend_solid_hspan_subtract_subpix(int x, int y, unsigned len,
31 	const color_type& c, const uint8* covers, agg_buffer* buffer,
32 	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_SUBTRACT_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 #endif // DRAWING_MODE_SUBTRACT_SUBPIX_H
50 
51