1/*
2 * Copyright 2006, 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 for text on B_RGBA32.
6 *
7 */
8
9#ifndef DRAWING_MODE_COPY_TEXT_H
10#define DRAWING_MODE_COPY_TEXT_H
11
12#include "DrawingModeCopy.h"
13
14// blend_pixel_copy_text
15void
16blend_pixel_copy_text(int x, int y, const color_type& c, uint8 cover,
17					   agg_buffer* buffer, const PatternHandler* pattern)
18{
19	uint8* p = buffer->row_ptr(y) + (x << 2);
20	if (cover == 255) {
21		ASSIGN_COPY(p, c.r, c.g, c.b, c.a);
22	} else {
23		rgb_color l = pattern->LowColor();
24		BLEND_COPY(p, c.r, c.g, c.b, cover,
25				   l.red, l.green, l.blue);
26	}
27}
28
29// blend_hline_copy_text
30void
31blend_hline_copy_text(int x, int y, unsigned len,
32					   const color_type& c, uint8 cover,
33					   agg_buffer* buffer, const PatternHandler* pattern)
34{
35	if (cover == 255) {
36		// cache the color as 32bit value
37		uint32 v;
38		uint8* p8 = (uint8*)&v;
39		p8[0] = (uint8)c.b;
40		p8[1] = (uint8)c.g;
41		p8[2] = (uint8)c.r;
42		p8[3] = 255;
43		// row offset as 32bit pointer
44		uint32* p32 = (uint32*)(buffer->row_ptr(y)) + x;
45		do {
46			*p32 = v;
47			p32++;
48		} while(--len);
49	} else {
50		uint8* p = buffer->row_ptr(y) + (x << 2);
51		rgb_color l = pattern->LowColor();
52		do {
53			BLEND_COPY(p, c.r, c.g, c.b, cover,
54					   l.red, l.green, l.blue);
55			p += 4;
56		} while(--len);
57	}
58}
59
60// blend_solid_hspan_copy_text
61void
62blend_solid_hspan_copy_text(int x, int y, unsigned len,
63							 const color_type& c, const uint8* covers,
64							 agg_buffer* buffer,
65							 const PatternHandler* pattern)
66{
67//printf("blend_solid_hspan_copy_text(%d, %d)\n", x, len);
68//	uint8* p = buffer->row_ptr(y) + (x << 2);
69	uint32* p = (uint32*)(buffer->row_ptr(y) + (x << 2));
70	const uint32* cache = (const uint32*)pattern->OpCopyColorCache();
71//	rgb_color l = pattern->LowColor();
72	do {
73//		if (*covers) {
74			*p = cache[*covers];
75//			if(*covers == 255) {
76//				ASSIGN_COPY(p, c.r, c.g, c.b, c.a);
77//			} else {
78//				BLEND_COPY(p, c.r, c.g, c.b, *covers,
79//						   l.red, l.green, l.blue);
80//			}
81//		}
82		covers++;
83		p++;
84//		p += 4;
85	} while(--len);
86}
87
88
89
90// blend_solid_vspan_copy_text
91void
92blend_solid_vspan_copy_text(int x, int y, unsigned len,
93							 const color_type& c, const uint8* covers,
94							 agg_buffer* buffer,
95							 const PatternHandler* pattern)
96{
97	uint8* p = buffer->row_ptr(y) + (x << 2);
98	rgb_color l = pattern->LowColor();
99	do {
100		if (*covers) {
101			if (*covers == 255) {
102				ASSIGN_COPY(p, c.r, c.g, c.b, c.a);
103			} else {
104				BLEND_COPY(p, c.r, c.g, c.b, *covers,
105						   l.red, l.green, l.blue);
106			}
107		}
108		covers++;
109		p += buffer->stride();
110	} while(--len);
111}
112
113
114// blend_color_hspan_copy_text
115void
116blend_color_hspan_copy_text(int x, int y, unsigned len,
117							 const color_type* colors, const uint8* covers,
118							 uint8 cover,
119							 agg_buffer* buffer,
120							 const PatternHandler* pattern)
121{
122	uint8* p = buffer->row_ptr(y) + (x << 2);
123	rgb_color l = pattern->LowColor();
124	if (covers) {
125		// non-solid opacity
126		do {
127			if(*covers) {
128				if(*covers == 255) {
129					ASSIGN_COPY(p, colors->r, colors->g, colors->b, colors->a);
130				} else {
131					BLEND_COPY(p, colors->r, colors->g, colors->b, *covers,
132							   l.red, l.green, l.blue);
133				}
134			}
135			covers++;
136			p += 4;
137			++colors;
138		} while(--len);
139	} else {
140		// solid full opcacity
141		if (cover == 255) {
142			do {
143				ASSIGN_COPY(p, colors->r, colors->g, colors->b, colors->a);
144				p += 4;
145				++colors;
146			} while(--len);
147		// solid partial opacity
148		} else if (cover) {
149			do {
150				BLEND_COPY(p, colors->r, colors->g, colors->b, cover,
151						   l.red, l.green, l.blue);
152				p += 4;
153				++colors;
154			} while(--len);
155		}
156	}
157}
158
159#endif // DRAWING_MODE_COPY_TEXT_H
160
161