#ifndef DRAWING_MODE_ALPHA_CC_H
#define DRAWING_MODE_ALPHA_CC_H
#include "DrawingMode.h"
#define BLEND_ALPHA_CC(d, r, g, b, a) \
{ \
BLEND_COMPOSITE16(d, r, g, b, a); \
}
#define ASSIGN_ALPHA_CC(d, r, g, b) \
{ \
d[0] = (b); \
d[1] = (g); \
d[2] = (r); \
d[3] = 255; \
}
void
blend_pixel_alpha_cc(int x, int y, const color_type& c, uint8 cover,
agg_buffer* buffer, const PatternHandler* pattern)
{
uint8* p = buffer->row_ptr(y) + (x << 2);
rgb_color color = pattern->ColorAt(x, y);
uint16 alpha = pattern->HighColor().alpha * cover;
if (alpha == 255 * 255) {
ASSIGN_ALPHA_CC(p, color.red, color.green, color.blue);
} else {
BLEND_ALPHA_CC(p, color.red, color.green, color.blue, alpha);
}
}
void
blend_hline_alpha_cc(int x, int y, unsigned len,
const color_type& c, uint8 cover,
agg_buffer* buffer, const PatternHandler* pattern)
{
rgb_color color = pattern->HighColor();
uint16 alpha = color.alpha * cover;
if (alpha == 255 * 255) {
uint32 vh;
uint8* p8 = (uint8*)&vh;
p8[0] = color.blue;
p8[1] = color.green;
p8[2] = color.red;
p8[3] = 255;
color = pattern->LowColor();
uint32 vl;
p8 = (uint8*)&vl;
p8[0] = color.blue;
p8[1] = color.green;
p8[2] = color.red;
p8[3] = 255;
uint32* p32 = (uint32*)(buffer->row_ptr(y)) + x;
do {
if (pattern->IsHighColor(x, y))
*p32 = vh;
else
*p32 = vl;
p32++;
x++;
} while(--len);
} else {
uint8* p = buffer->row_ptr(y) + (x << 2);
do {
rgb_color color = pattern->ColorAt(x, y);
BLEND_ALPHA_CC(p, color.red, color.green, color.blue, alpha);
x++;
p += 4;
} while(--len);
}
}
void
blend_solid_hspan_alpha_cc(int x, int y, unsigned len,
const color_type& c, const uint8* covers,
agg_buffer* buffer, const PatternHandler* pattern)
{
uint8* p = buffer->row_ptr(y) + (x << 2);
uint8 hAlpha = pattern->HighColor().alpha;
do {
rgb_color color = pattern->ColorAt(x, y);
uint16 alpha = hAlpha * *covers;
if (alpha) {
if (alpha == 255 * 255) {
ASSIGN_ALPHA_CC(p, color.red, color.green, color.blue);
} else {
BLEND_ALPHA_CC(p, color.red, color.green, color.blue, alpha);
}
}
covers++;
p += 4;
x++;
} while(--len);
}
void
blend_solid_vspan_alpha_cc(int x, int y, unsigned len,
const color_type& c, const uint8* covers,
agg_buffer* buffer, const PatternHandler* pattern)
{
uint8* p = buffer->row_ptr(y) + (x << 2);
uint8 hAlpha = pattern->HighColor().alpha;
do {
rgb_color color = pattern->ColorAt(x, y);
uint16 alpha = hAlpha * *covers;
if (alpha) {
if (alpha == 255 * 255) {
ASSIGN_ALPHA_CC(p, color.red, color.green, color.blue);
} else {
BLEND_ALPHA_CC(p, color.red, color.green, color.blue, alpha);
}
}
covers++;
p += buffer->stride();
y++;
} while(--len);
}
void
blend_color_hspan_alpha_cc(int x, int y, unsigned len,
const color_type* colors,
const uint8* covers, uint8 cover,
agg_buffer* buffer, const PatternHandler* pattern)
{
uint8* p = buffer->row_ptr(y) + (x << 2);
uint8 hAlpha = pattern->HighColor().alpha;
if (covers) {
do {
uint16 alpha = hAlpha * colors->a * *covers / 255;
if (alpha) {
if (alpha == 255 * 255) {
ASSIGN_ALPHA_CC(p, colors->r, colors->g, colors->b);
} else {
BLEND_ALPHA_CC(p, colors->r, colors->g, colors->b, alpha);
}
}
covers++;
p += 4;
++colors;
} while(--len);
} else {
uint16 alpha = hAlpha * colors->a * cover / 255;
if (alpha == 255 * 255) {
do {
ASSIGN_ALPHA_CC(p, colors->r, colors->g, colors->b);
p += 4;
++colors;
} while(--len);
} else if (alpha) {
do {
BLEND_ALPHA_CC(p, colors->r, colors->g, colors->b, alpha);
p += 4;
++colors;
} while(--len);
}
}
}
#endif