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