xref: /haiku/src/servers/app/drawing/Painter/drawing_modes/AggCompOpAdapter.h (revision 17889a8c70dbb3d59c1412f6431968753c767bab)
1 /*
2  * Copyright 2020, Kacper Kasper <kacperkasper@gmail.com>
3  * All rights reserved. Distributed under the terms of the MIT license.
4  *
5  * Copyright 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
6  */
7 
8 #ifndef AGG_COMP_OP_ADAPTER_H
9 #define AGG_COMP_OP_ADAPTER_H
10 
11 #include <stdio.h>
12 
13 #include <agg_pixfmt_rgba.h>
14 
15 #include "PatternHandler.h"
16 
17 
18 template<typename CompOp, typename RenBuf>
19 struct AggCompOpAdapter {
20 	typedef typename CompOp::color_type color_type;
21 	typedef typename CompOp::color_type::value_type value_type;
22 
23 	static void
24 	blend_pixel(int x, int y,
25 				const color_type& c,
26 				uint8 cover, RenBuf* buffer,
27 				const PatternHandler* pattern)
28 	{
29 		value_type* p = buffer->row_ptr(y) + x * sizeof(color_type);
30 		rgb_color color = pattern->ColorAt(x, y);
31 		CompOp::blend_pix(p,
32 			color.red, color.green, color.blue, color.alpha, cover);
33 	}
34 
35 	static void
36 	blend_hline(int x, int y,
37 				unsigned len,
38 				const color_type& c,
39 				uint8 cover, RenBuf* buffer,
40 				const PatternHandler* pattern)
41 	{
42 		value_type* p = buffer->row_ptr(y) + x * sizeof(color_type);
43 		do {
44 			rgb_color color = pattern->ColorAt(x, y);
45 			CompOp::blend_pix(p,
46 				color.red, color.green, color.blue, color.alpha, cover);
47 			x++;
48 			p += sizeof(color_type) / sizeof(value_type);
49 		} while(--len);
50 	}
51 
52 	static void
53 	blend_solid_hspan(int x, int y,
54 					  unsigned len,
55 					  const color_type& c,
56 					  const uint8* covers, RenBuf* buffer,
57 					  const PatternHandler* pattern)
58 	{
59 		value_type* p = buffer->row_ptr(y) + x * sizeof(color_type);
60 		do {
61 			rgb_color color = pattern->ColorAt(x, y);
62 			CompOp::blend_pix(p,
63 				color.red, color.green, color.blue, color.alpha, *covers);
64 			covers++;
65 			p += sizeof(color_type) / sizeof(value_type);
66 			x++;
67 		} while(--len);
68 	}
69 
70 	static void
71 	blend_solid_hspan_subpix(int x, int y,
72 							 unsigned len,
73 							 const color_type& c,
74 							 const uint8* covers, RenBuf* buffer,
75 							 const PatternHandler* pattern)
76 	{
77 		fprintf(stderr,
78 			"B_ALPHA_COMPOSITE_* subpixel drawing not implemented\n");
79 	}
80 
81 	static void
82 	blend_solid_vspan(int x, int y,
83 					  unsigned len,
84 					  const color_type& c,
85 					  const uint8* covers, RenBuf* buffer,
86 					  const PatternHandler* pattern)
87 	{
88 		value_type* p = buffer->row_ptr(y) + x * sizeof(color_type);
89 		do {
90 			rgb_color color = pattern->ColorAt(x, y);
91 			CompOp::blend_pix(p,
92 				color.red, color.green, color.blue, color.alpha, *covers);
93 			covers++;
94 			p += buffer->stride();
95 			y++;
96 		} while(--len);
97 	}
98 
99 	static void
100 	blend_color_hspan(int x, int y,
101 					  unsigned len,
102 					  const color_type* colors,
103 					  const uint8* covers,
104 					  uint8 cover, RenBuf* buffer,
105 					  const PatternHandler* pattern)
106 	{
107 		value_type* p = buffer->row_ptr(y) + x * sizeof(color_type);
108 		do {
109 			CompOp::blend_pix(p,
110 				colors->r, colors->g, colors->b, colors->a,
111 				covers ? *covers++ : cover);
112 			p += sizeof(color_type) / sizeof(value_type);
113 			++colors;
114 		} while(--len);
115 	}
116 };
117 
118 
119 #endif // AGG_COMP_OP_ADAPTER_H
120