Replaced agg pixfmts

git-svn-id: svn://ultimatepp.org/upp/trunk@751 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2009-01-15 22:25:48 +00:00
parent 845ace0cc0
commit 4d6eb322b6
21 changed files with 277 additions and 4842 deletions

View file

@ -1026,6 +1026,7 @@ void ChHostSkin()
s.sel = Rect(0, 0, 0, 4);
s.extendleft = 2;
ChGtkColor(s.text_color, 0);
}
int efm = 0;
@ -1099,6 +1100,8 @@ void ChHostSkin()
static int shadowtype;
static GtkWidget *top_item;
static GtkWidget *menu_item;
Color menu_topitemtext_color[4];
ChGtkColor(menu_topitemtext_color, 0);
if(!popup) {
gtk_widget_style_get(bar, "shadow_type", &shadowtype, NULL);
top_item = gtk_menu_item_new_with_label("M");
@ -1134,10 +1137,13 @@ void ChHostSkin()
sw = GtkInt("selected_shadow_type");
GtkCh(s.item, sw, GTK_STATE_PRELIGHT);
s.itemtext = ChGtkColor(2, menu_item);
ChGtkNew(top_item, "menuitem", GTK_BOX);
if(gtk_major_version > 2 || (gtk_major_version == 2 && gtk_minor_version >= 1))
sw = GtkInt("selected_shadow_type");
s.topitemtext[1] = s.topitemtext[0];
s.topitemtext[0] = menu_topitemtext_color[0];
s.topitemtext[1] = menu_topitemtext_color[1];
s.topitemtext[2] = menu_topitemtext_color[2];
s.topitem[1] = s.topitem[0];
GtkCh(s.topitem[2], sw, GTK_STATE_PRELIGHT);
s.topitemtext[2] = ChGtkColor(2, top_item);

View file

@ -122,8 +122,7 @@ bool BufferPainter::PathVisible(double w) const
void BufferPainter::SetRbuf()
{
rbuf.attach((agg::int8u *)~buffer, size.cx, size.cy, size.cx * 4);
pixf.attach(rbuf);
pixf.attach(buffer);
renb.attach(pixf);
renderer.attach(renb);
}

View file

@ -1,3 +1,27 @@
inline RGBA Mul8(const RGBA& s, int mul)
{
RGBA t;
t.r = (mul * s.r) >> 8;
t.g = (mul * s.g) >> 8;
t.b = (mul * s.b) >> 8;
t.a = (mul * s.a) >> 8;
return t;
}
inline RGBA MulA(const RGBA& s, int alpha)
{
return Mul8(s, alpha + (alpha >> 7));
}
inline void AlphaBlend(RGBA& t, const RGBA& c)
{
int alpha = 256 - (c.a + (c.a >> 7));
t.r = c.r + (alpha * t.r >> 8);
t.g = c.g + (alpha * t.g >> 8);
t.b = c.b + (alpha * t.b >> 8);
t.a = c.a + (alpha * t.a >> 8);
}
class BufferPainter : public Painter {
protected:
virtual void ClearOp(const RGBA& color);
@ -88,15 +112,66 @@ private:
unsigned command(int i) const { return (int)i < c.GetCount() ? c[i] : agg::path_cmd_stop; }
};
class upp_pixfmt {
Size sz;
RGBA *buffer;
public:
typedef RGBA pixel_type;
typedef RGBA color_type;
typedef byte value_type;
typedef int calc_type;
typedef agg::const_row_info<RGBA> row_data;
void attach(ImageBuffer& ib) { buffer = ib; sz = ib.GetSize(); }
int width() const { return sz.cx; }
int height() const { return sz.cy; }
int stride() const { return sz.cx; }
RGBA* row_ptr(int y) { return buffer + sz.cx * y; }
RGBA *ptr(int x, int y) { return buffer + sz.cx * y + x; }
const RGBA* row_ptr(int y) const { return buffer + sz.cx * y; }
void blend_hline(int x, int y, int len, RGBA c, byte cover);
void blend_solid_hspan(int x, int y, int len, const RGBA& c, const byte* covers);
void blend_color_hspan(int x, int y, int len, const RGBA* colors,
const byte* covers, byte cover);
};
struct upp_pixfmt_clip {
Size sz;
byte *buffer;
typedef byte pixel_type;
typedef byte color_type;
typedef byte value_type;
typedef int calc_type;
typedef agg::const_row_info<RGBA> row_data;
int width() const { return sz.cx; }
int height() const { return sz.cy; }
int stride() const { return sz.cx; }
byte* row_ptr(int y) { return buffer + sz.cx * y; }
byte *ptr(int x, int y) { return buffer + sz.cx * y + x; }
const byte* row_ptr(int y) const { return buffer + sz.cx * y; }
void blend_hline(int x, int y, int len, byte, byte cover);
void blend_solid_hspan(int x, int y, int len, byte, const byte* covers);
void blend_color_hspan(int x, int y, int len, byte *,
const byte* covers, byte cover);
};
typedef agg::path_base<vertex_upp_storage> path_storage;
typedef agg::pixfmt_rgba32_pre pixfmt;
typedef agg::rgba8 color_type;
typedef agg::renderer_base<agg::pixfmt_rgba32_pre> renderer_base;
typedef upp_pixfmt pixfmt;
typedef RGBA color_type;
typedef agg::renderer_base<pixfmt> renderer_base;
typedef agg::renderer_scanline_aa_solid<renderer_base> renderer_solid;
typedef agg::span_interpolator_linear<> interpolator_type;
typedef agg::image_accessor_clip<pixfmt> img_source_type;
typedef agg::span_image_filter_rgba_bilinear_clip<pixfmt, interpolator_type> span_gen_type;
// typedef agg::span_image_filter_rgba_bilinear_clip<pixfmt, interpolator_type> span_gen_type;
typedef agg::span_allocator<color_type> span_alloc;
typedef renderer_base::color_type x;
@ -129,12 +204,11 @@ private:
path_storage path;
bool inpath;
agg::rendering_buffer rbuf;
agg::rasterizer_scanline_aa<> rasterizer;
agg::scanline_p8 scanline_p;
renderer_base renb;
renderer_solid renderer;
agg::pixfmt_rgba32_pre pixf;
pixfmt pixf;
typedef agg::conv_curve<path_storage> Curved;
typedef agg::conv_transform<Curved> CurvedTrans;
@ -154,7 +228,7 @@ private:
Rectf PathRect() const { return pathrect; }
path_storage MakeStroke(double width);
Pointf ReadPoint(CParser& p, bool rel);
void RenderClip(byte *t, int alpha);
void RenderClip(byte *t);
void MakeGradient(RGBA *t, RGBA color1, RGBA color2, int cx);
void ColorStop0(Attr& a, double pos, const RGBA& color);
void FinishMask();

View file

@ -2,12 +2,22 @@
NAMESPACE_UPP
void BufferPainter::RenderClip(byte *t, int alpha)
void BufferPainter::upp_pixfmt_clip::blend_hline(int x, int y, int len, byte, byte cover)
{
agg::rendering_buffer mask_rbuf;
mask_rbuf.attach(t, size.cx, size.cy, size.cx);
typedef agg::renderer_base<agg::pixfmt_gray8> ren_base;
agg::pixfmt_gray8 pixf(mask_rbuf);
memset(ptr(x, y), cover, len);
}
void BufferPainter::upp_pixfmt_clip::blend_solid_hspan(int x, int y, int len, byte, const byte *covers)
{
memcpy(ptr(x, y), covers, len);
}
void BufferPainter::RenderClip(byte *t)
{
upp_pixfmt_clip pixf;
pixf.sz = size;
pixf.buffer = t;
typedef agg::renderer_base<upp_pixfmt_clip> ren_base;
ren_base rb(pixf);
agg::scanline_p8 sl;
if(inpath)
@ -16,7 +26,7 @@ void BufferPainter::RenderClip(byte *t, int alpha)
rasterizer.filling_rule(pathattr.evenodd ? agg::fill_even_odd : agg::fill_non_zero);
rasterizer.add_path(curved_trans);
agg::renderer_scanline_aa_solid<ren_base> r(rb);
r.color(agg::gray8(alpha, 255));
r.color(255);
agg::render_scanlines(rasterizer, sl, r);
rasterizer.reset();
inpath = false;
@ -27,7 +37,7 @@ void BufferPainter::ClipOp()
int l = size.cx * size.cy;
Buffer<byte> cl(l);
memset(~cl, 0, l);
RenderClip(~cl, 255);
RenderClip(~cl);
if(clip.GetCount()) {
byte *s = ~clip.Top();
for(int i = 0; i < l; i++)

View file

@ -23,7 +23,7 @@ void BufferPainter::FillOp(const RGBA& c)
mask_rbuf.attach(~clip.Top(), size.cx, size.cy, size.cx);
agg::alpha_mask_gray8 mask(mask_rbuf);
agg::scanline_u8_am<agg::alpha_mask_gray8> sl(mask);
renderer.color(*(color_type *)&color);
renderer.color(color);
agg::render_scanlines(rasterizer, sl, renderer);
}
else {
@ -58,8 +58,6 @@ struct UppImageAggSpan {
const RGBA *image;
int alpha;
void SetAlpha(int a) { alpha = a + (a >> 7); }
void SetImage(const Image& img) {
image = ~img;
cx = img.GetWidth();
@ -77,7 +75,7 @@ struct UppImageAggSpan {
x = minmax(x, 0, maxx);
else
if(hstyle == FILL_HREFLECT)
x = (x + ax) / cx & 1 ? (ax - x - 1) % cx : (x + ax) % cx;
x = (x + ax) / cx & 1 ? (x + ax) % cx : (ax - x - 1) % cx;
else
if(hstyle == FILL_HREPEAT)
x = (x + ax) % cx;
@ -85,7 +83,7 @@ struct UppImageAggSpan {
y = minmax(y, 0, maxy);
else
if(vstyle == FILL_VREFLECT)
y = (y + ay) / cy & 1 ? (ay - y - 1) % cy : (y + ay) % cy;
y = (y + ay) / cy & 1 ? (y + ay) % cy : (ay - y - 1) % cy;
else
if(vstyle == FILL_VREPEAT)
y = (y + ay) % cy;
@ -94,7 +92,8 @@ struct UppImageAggSpan {
void prepare() {}
void generate(agg::rgba8 *_span, int x, int y, unsigned len) {
void generate(RGBA *_span, int x, int y, unsigned len)
{
interpolator.begin(x + 0.5, y + 0.5, len);
RGBA *span = (RGBA *)_span;
fixed = hstyle && vstyle;
@ -182,7 +181,7 @@ void BufferPainter::FillOp(const Image& image, const Matrix2D& transsrc, dword f
m.invert();
UppImageAggSpan sg;
sg.interpolator.transformer(m);
sg.SetAlpha(int(pathattr.opacity * 255));
sg.alpha = int(pathattr.opacity * 256);
sg.SetImage(image);
sg.style = flags & 15;
sg.hstyle = flags & 3;

View file

@ -33,7 +33,7 @@ void BufferPainter::FinishMask()
s++;
t++;
}
else {
else
while(s < e) {
byte v = ((s->a + (s->a >> 7)) * (77 * s->r + 151 * s->g + 28 * s->b)) >> 16;
*t = (*cs * (v + (v >> 7))) >> 8;
@ -41,7 +41,6 @@ void BufferPainter::FinishMask()
t++;
cs++;
}
}
buffer = mask.Top();
mask.Drop();
SetRbuf();

View file

@ -223,4 +223,15 @@ void Painter::Paint(const Painting& pic)
}
}
END_UPP_NAMESPACE
Image AsImage(const Painting& p, Size sz, Size isz, Point pos)
{
ImageBuffer ib(sz);
BufferPainter sw(ib);
Sizef psz = p.GetSize();
sw.Scale(psz.cx / sz.cx, psz.cy / sz.cy);
sw.Clear(White());
sw.Paint(p);
return ib;
}
END_UPP_NAMESPACE

View file

@ -187,7 +187,7 @@ Matrix2D GetImageLineMatrix(double x1, double y1, double x2, double y2, const Im
Matrix2D m;
Size sz = image.GetSize();
m.scale(agg::calc_distance(x1, y1, x2, y2) / sz.cx);
if(abs(x2 - x1) < abs(y2 - y1) / 1e-6)
if(abs(x2 - x1) < abs(y2 - y1) * 1e-6)
m.rotate(y2 > y1 ? M_PI_2 : -M_PI_2);
else
m.rotate(atan((y2 - y1) / (x2 - x1)));
@ -243,4 +243,24 @@ void Painter::Scale(double scale)
Transform(Scale2D(scale));
}
Painter& Painter::Ellipse(double x, double y, double rx, double ry)
{
return Arc(x, y, rx, ry, 0, M_2PI);
}
Painter& Painter::Circle(double x, double y, double r)
{
return Ellipse(x, y, r, r);
}
Painter& Painter::Rectangle(double x, double y, double cx, double cy)
{
Move(x, y);
Line(x + cx, y);
Line(x + cx, y + cy);
Line(x, y + cy);
Close();
return *this;
}
END_UPP_NAMESPACE

View file

@ -9,8 +9,6 @@
#include "agg_basics.h"
#include "agg_renderer_base.h"
#include "agg_pixfmt_rgba.h"
#include "agg_pixfmt_gray.h"
#include "agg_renderer_scanline.h"
#include "agg_rasterizer_scanline_aa.h"
#include "agg_scanline_u.h"
@ -23,7 +21,6 @@
#include "agg_span_allocator.h"
#include "agg_span_interpolator_linear.h"
#include "agg_image_accessors.h"
#include "agg_span_image_filter_upp.h"
#include "agg_alpha_mask_u8.h"
NAMESPACE_UPP
@ -214,9 +211,6 @@ public:
Painter& Clip();
Painter& Arc(double x, double y, double rx, double ry,
double start_angle, double sweep_angle, bool startline = false);
Painter& Character(double x, double y, int ch, Font fnt);
Painter& Text(double x, double y, const wchar *text, Font fnt, int n = -1, double *dx = NULL);
Painter& Text(double x, double y, const WString& s, Font fnt, double *dx = NULL);
@ -250,6 +244,12 @@ public:
void Scale(double scale);
void Paint(const Painting& p);
Painter& Arc(double x, double y, double rx, double ry,
double start_angle, double sweep_angle, bool startline = false);
Painter& Ellipse(double x, double y, double rx, double ry);
Painter& Circle(double x, double y, double r);
Painter& Rectangle(double x, double y, double cx, double cy);
};
#include "BufferPainter.h"

View file

@ -1,3 +1,5 @@
description "Advanced rendering system";
optimize_speed;
file
@ -11,6 +13,7 @@ file
Text.cpp,
Path.cpp,
BufferPainter.h,
PixFmt.cpp,
BufferPainter.cpp,
Context.cpp,
Fill.cpp,
@ -27,8 +30,6 @@ file
agg_alpha_mask_u8.h,
agg_basics.h,
agg_clip_liang_barsky.h,
agg_color_rgba.h,
agg_color_gray.h,
agg_config.h,
agg_conv_adaptor_vcgen.h,
agg_conv_curve.h,
@ -45,8 +46,6 @@ file
agg_math.h,
agg_math_stroke.h,
agg_path_storage.h,
agg_pixfmt_gray.h,
agg_pixfmt_rgba.h,
agg_rasterizer_cells_aa.h,
agg_rasterizer_scanline_aa.h,
agg_rasterizer_sl_clip.h,

View file

@ -230,7 +230,19 @@ Painting PaintingPainter::GetResult()
Painting p;
p.cmd = cmd.GetResult();
p.data = data;
p.size = size;
return p;
}
void PaintingPainter::Create(double cx, double cy)
{
cmd.Create();
size.cx = cx;
size.cy = cy;
}
void PaintingPainter::Create(Sizef sz)
{
}
END_UPP_NAMESPACE

View file

@ -1,9 +1,13 @@
class Painting {
String cmd;
ValueArray data;
Sizef size;
friend class PaintingPainter;
friend class Painter;
public:
Sizef GetSize() const { return size; }
};
enum {
@ -57,6 +61,7 @@ enum {
class PaintingPainter : public Painter {
StringStream cmd;
ValueArray data;
Sizef size;
void Put(int c) { cmd.Put(c); }
void Put32(int c) { cmd.Put32(c); }
@ -121,4 +126,15 @@ protected:
public:
Painting GetResult();
operator Painting() { return GetResult(); }
void Create(double cx, double cy);
void Create(Sizef sz);
Sizef GetSize() const { return size; }
PaintingPainter() {}
PaintingPainter(double cx, double cy) { Create(cx, cy); }
PaintingPainter(Sizef sz) { Create(sz); }
};
Image AsImage(const Painting& p, Size sz);

View file

@ -14,6 +14,7 @@ Painter& Painter::Path(CParser& p)
{
while(!p.IsEof()) {
int c = p.GetChar();
p.Spaces();
bool rel = IsLower(c);
Pointf t, t1, t2;
switch(ToUpper(c)) {
@ -23,7 +24,7 @@ Painter& Painter::Path(CParser& p)
case 'L':
while(p.IsDouble()) {
t = ReadPoint(p);
Move(t.x, t.y, rel);
Line(t.x, t.y, rel);
}
break;
case 'Z':

87
uppsrc/Painter/PixFmt.cpp Normal file
View file

@ -0,0 +1,87 @@
#include "Painter.h"
NAMESPACE_UPP
void BufferPainter::upp_pixfmt::blend_hline(int x, int y, int len, RGBA c, byte cover)
{
if(c.a == 0) return;
RGBA *t = ptr(x, y);
if((c.a & cover) == 255) {
#if 1
while(len >= 16) {
t[0] = c; t[1] = c; t[2] = c; t[3] = c;
t[4] = c; t[5] = c; t[6] = c; t[7] = c;
t[8] = c; t[9] = c; t[10] = c; t[11] = c;
t[12] = c; t[13] = c; t[14] = c; t[15] = c;
t += 16;
len -= 16;
}
switch(len) {
case 15: t[14] = c;
case 14: t[13] = c;
case 13: t[12] = c;
case 12: t[11] = c;
case 11: t[10] = c;
case 10: t[9] = c;
case 9: t[8] = c;
case 8: t[7] = c;
case 7: t[6] = c;
case 6: t[5] = c;
case 5: t[4] = c;
case 4: t[3] = c;
case 3: t[2] = c;
case 2: t[1] = c;
case 1: t[0] = c;
}
#else
do
*t++ = c;
while(--len);
#endif
}
else {
if(cover != 255)
c = MulA(c, cover);
RGBA *e = t + len;
int alpha = 256 - (c.a + (c.a >> 7));
while(t < e)
AlphaBlend(*t++, c);
}
}
void BufferPainter::upp_pixfmt::blend_solid_hspan(int x, int y, int len,
const RGBA& c, const byte *covers)
{
if(c.a == 0) return;
RGBA *t = ptr(x, y);
RGBA *e = t + len;
while(t < e) {
byte cover = *covers++;
if((cover & c.a) == 255) // is it worth it?
*t++ = c;
else
AlphaBlend(*t++, MulA(c, cover));
}
}
void BufferPainter::upp_pixfmt::blend_color_hspan(int x, int y, int len, const RGBA *colors,
const byte *covers, byte cover)
{
RGBA *t = ptr(x, y);
RGBA *e = t + len;
while(t < e) {
if(covers)
cover = *covers++;
if((cover & colors->a) == 255)
*t = *colors;
else
if(cover == 255)
AlphaBlend(*t, *colors);
else
AlphaBlend(*t, MulA(*colors, cover));
colors++;
t++;
}
}
END_UPP_NAMESPACE

View file

@ -156,8 +156,9 @@ struct UppRadialSpan {
r <<= 6;
}
}
void generate(agg::rgba8 *_span, int x, int y, unsigned len) {
void generate(RGBA *_span, int x, int y, unsigned len)
{
if(r <= 0)
return;
interpolator.begin(x + 0.5, y + 0.5, len);

View file

@ -9,8 +9,6 @@ BufferPainter::path_storage BufferPainter::MakeStroke(double width)
curved.angle_tolerance(0.0);
if(width * scl > 1.0)
curved.angle_tolerance(0.2);
rasterizer.reset();
rasterizer.filling_rule(agg::fill_non_zero);
path_storage b;
if(pathattr.dash.GetCount()) {
agg::conv_dash<Curved> dashed(curved);

View file

@ -1,414 +0,0 @@
//----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.4
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://www.antigrain.com
//----------------------------------------------------------------------------
//
// Adaptation for high precision colors has been sponsored by
// Liberty Technology Systems, Inc., visit http://lib-sys.com
//
// Liberty Technology Systems, Inc. is the provider of
// PostScript and PDF technology for software developers.
//
//----------------------------------------------------------------------------
//
// color types gray8, gray16
//
//----------------------------------------------------------------------------
#ifndef AGG_COLOR_GRAY_INCLUDED
#define AGG_COLOR_GRAY_INCLUDED
#include "agg_basics.h"
#include "agg_color_rgba.h"
namespace agg
{
//===================================================================gray8
struct gray8
{
typedef int8u value_type;
typedef int32u calc_type;
typedef int32 long_type;
enum base_scale_e
{
base_shift = 8,
base_scale = 1 << base_shift,
base_mask = base_scale - 1
};
typedef gray8 self_type;
value_type v;
value_type a;
//--------------------------------------------------------------------
gray8() {}
//--------------------------------------------------------------------
gray8(unsigned v_, unsigned a_=base_mask) :
v(int8u(v_)), a(int8u(a_)) {}
//--------------------------------------------------------------------
gray8(const self_type& c, unsigned a_) :
v(c.v), a(value_type(a_)) {}
//--------------------------------------------------------------------
gray8(const rgba& c) :
v((value_type)uround((0.299*c.r + 0.587*c.g + 0.114*c.b) * double(base_mask))),
a((value_type)uround(c.a * double(base_mask))) {}
//--------------------------------------------------------------------
gray8(const rgba& c, double a_) :
v((value_type)uround((0.299*c.r + 0.587*c.g + 0.114*c.b) * double(base_mask))),
a((value_type)uround(a_ * double(base_mask))) {}
//--------------------------------------------------------------------
gray8(const rgba8& c) :
v((c.r*77 + c.g*150 + c.b*29) >> 8),
a(c.a) {}
//--------------------------------------------------------------------
gray8(const rgba8& c, unsigned a_) :
v((c.r*77 + c.g*150 + c.b*29) >> 8),
a(a_) {}
//--------------------------------------------------------------------
void clear()
{
v = a = 0;
}
//--------------------------------------------------------------------
const self_type& transparent()
{
a = 0;
return *this;
}
//--------------------------------------------------------------------
void opacity(double a_)
{
if(a_ < 0.0) a_ = 0.0;
if(a_ > 1.0) a_ = 1.0;
a = (value_type)uround(a_ * double(base_mask));
}
//--------------------------------------------------------------------
double opacity() const
{
return double(a) / double(base_mask);
}
//--------------------------------------------------------------------
const self_type& premultiply()
{
if(a == base_mask) return *this;
if(a == 0)
{
v = 0;
return *this;
}
v = value_type((calc_type(v) * a) >> base_shift);
return *this;
}
//--------------------------------------------------------------------
const self_type& premultiply(unsigned a_)
{
if(a == base_mask && a_ >= base_mask) return *this;
if(a == 0 || a_ == 0)
{
v = a = 0;
return *this;
}
calc_type v_ = (calc_type(v) * a_) / a;
v = value_type((v_ > a_) ? a_ : v_);
a = value_type(a_);
return *this;
}
//--------------------------------------------------------------------
const self_type& demultiply()
{
if(a == base_mask) return *this;
if(a == 0)
{
v = 0;
return *this;
}
calc_type v_ = (calc_type(v) * base_mask) / a;
v = value_type((v_ > base_mask) ? (value_type)base_mask : v_);
return *this;
}
//--------------------------------------------------------------------
self_type gradient(self_type c, double k) const
{
self_type ret;
calc_type ik = uround(k * base_scale);
ret.v = value_type(calc_type(v) + (((calc_type(c.v) - v) * ik) >> base_shift));
ret.a = value_type(calc_type(a) + (((calc_type(c.a) - a) * ik) >> base_shift));
return ret;
}
//--------------------------------------------------------------------
AGG_INLINE void add(const self_type& c, unsigned cover)
{
calc_type cv, ca;
if(cover == cover_mask)
{
if(c.a == base_mask)
{
*this = c;
}
else
{
cv = v + c.v; v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv;
ca = a + c.a; a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca;
}
}
else
{
cv = v + ((c.v * cover + cover_mask/2) >> cover_shift);
ca = a + ((c.a * cover + cover_mask/2) >> cover_shift);
v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv;
a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca;
}
}
//--------------------------------------------------------------------
static self_type no_color() { return self_type(0,0); }
};
//-------------------------------------------------------------gray8_pre
inline gray8 gray8_pre(unsigned v, unsigned a = gray8::base_mask)
{
return gray8(v,a).premultiply();
}
inline gray8 gray8_pre(const gray8& c, unsigned a)
{
return gray8(c,a).premultiply();
}
inline gray8 gray8_pre(const rgba& c)
{
return gray8(c).premultiply();
}
inline gray8 gray8_pre(const rgba& c, double a)
{
return gray8(c,a).premultiply();
}
inline gray8 gray8_pre(const rgba8& c)
{
return gray8(c).premultiply();
}
inline gray8 gray8_pre(const rgba8& c, unsigned a)
{
return gray8(c,a).premultiply();
}
//==================================================================gray16
struct gray16
{
typedef int16u value_type;
typedef int32u calc_type;
typedef int64 long_type;
enum base_scale_e
{
base_shift = 16,
base_scale = 1 << base_shift,
base_mask = base_scale - 1
};
typedef gray16 self_type;
value_type v;
value_type a;
//--------------------------------------------------------------------
gray16() {}
//--------------------------------------------------------------------
gray16(unsigned v_, unsigned a_=base_mask) :
v(int16u(v_)), a(int16u(a_)) {}
//--------------------------------------------------------------------
gray16(const self_type& c, unsigned a_) :
v(c.v), a(value_type(a_)) {}
//--------------------------------------------------------------------
gray16(const rgba& c) :
v((value_type)uround((0.299*c.r + 0.587*c.g + 0.114*c.b) * double(base_mask))),
a((value_type)uround(c.a * double(base_mask))) {}
//--------------------------------------------------------------------
gray16(const rgba& c, double a_) :
v((value_type)uround((0.299*c.r + 0.587*c.g + 0.114*c.b) * double(base_mask))),
a((value_type)uround(a_ * double(base_mask))) {}
//--------------------------------------------------------------------
gray16(const rgba8& c) :
v(c.r*77 + c.g*150 + c.b*29),
a((value_type(c.a) << 8) | c.a) {}
//--------------------------------------------------------------------
gray16(const rgba8& c, unsigned a_) :
v(c.r*77 + c.g*150 + c.b*29),
a((value_type(a_) << 8) | c.a) {}
//--------------------------------------------------------------------
void clear()
{
v = a = 0;
}
//--------------------------------------------------------------------
const self_type& transparent()
{
a = 0;
return *this;
}
//--------------------------------------------------------------------
void opacity(double a_)
{
if(a_ < 0.0) a_ = 0.0;
if(a_ > 1.0) a_ = 1.0;
a = (value_type)uround(a_ * double(base_mask));
}
//--------------------------------------------------------------------
double opacity() const
{
return double(a) / double(base_mask);
}
//--------------------------------------------------------------------
const self_type& premultiply()
{
if(a == base_mask) return *this;
if(a == 0)
{
v = 0;
return *this;
}
v = value_type((calc_type(v) * a) >> base_shift);
return *this;
}
//--------------------------------------------------------------------
const self_type& premultiply(unsigned a_)
{
if(a == base_mask && a_ >= base_mask) return *this;
if(a == 0 || a_ == 0)
{
v = a = 0;
return *this;
}
calc_type v_ = (calc_type(v) * a_) / a;
v = value_type((v_ > a_) ? a_ : v_);
a = value_type(a_);
return *this;
}
//--------------------------------------------------------------------
const self_type& demultiply()
{
if(a == base_mask) return *this;
if(a == 0)
{
v = 0;
return *this;
}
calc_type v_ = (calc_type(v) * base_mask) / a;
v = value_type((v_ > base_mask) ? base_mask : v_);
return *this;
}
//--------------------------------------------------------------------
self_type gradient(self_type c, double k) const
{
self_type ret;
calc_type ik = uround(k * base_scale);
ret.v = value_type(calc_type(v) + (((calc_type(c.v) - v) * ik) >> base_shift));
ret.a = value_type(calc_type(a) + (((calc_type(c.a) - a) * ik) >> base_shift));
return ret;
}
//--------------------------------------------------------------------
AGG_INLINE void add(const self_type& c, unsigned cover)
{
calc_type cv, ca;
if(cover == cover_mask)
{
if(c.a == base_mask)
{
*this = c;
}
else
{
cv = v + c.v; v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv;
ca = a + c.a; a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca;
}
}
else
{
cv = v + ((c.v * cover + cover_mask/2) >> cover_shift);
ca = a + ((c.a * cover + cover_mask/2) >> cover_shift);
v = (cv > calc_type(base_mask)) ? calc_type(base_mask) : cv;
a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca;
}
}
//--------------------------------------------------------------------
static self_type no_color() { return self_type(0,0); }
};
//------------------------------------------------------------gray16_pre
inline gray16 gray16_pre(unsigned v, unsigned a = gray16::base_mask)
{
return gray16(v,a).premultiply();
}
inline gray16 gray16_pre(const gray16& c, unsigned a)
{
return gray16(c,a).premultiply();
}
inline gray16 gray16_pre(const rgba& c)
{
return gray16(c).premultiply();
}
inline gray16 gray16_pre(const rgba& c, double a)
{
return gray16(c,a).premultiply();
}
inline gray16 gray16_pre(const rgba8& c)
{
return gray16(c).premultiply();
}
inline gray16 gray16_pre(const rgba8& c, unsigned a)
{
return gray16(c,a).premultiply();
}
}
#endif

View file

@ -1,743 +0,0 @@
//----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.4
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
//
// Adaptation for high precision colors has been sponsored by
// Liberty Technology Systems, Inc., visit http://lib-sys.com
//
// Liberty Technology Systems, Inc. is the provider of
// PostScript and PDF technology for software developers.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://www.antigrain.com
//----------------------------------------------------------------------------
#ifndef AGG_COLOR_RGBA_INCLUDED
#define AGG_COLOR_RGBA_INCLUDED
//#include <math.h>
#include "agg_basics.h"
namespace agg
{
// Supported byte orders for RGB and RGBA pixel formats
//=======================================================================
struct order_rgb { enum rgb_e { R=0, G=1, B=2, rgb_tag }; }; //----order_rgb
struct order_bgr { enum bgr_e { B=0, G=1, R=2, rgb_tag }; }; //----order_bgr
struct order_rgba { enum rgba_e { R=0, G=1, B=2, A=3, rgba_tag }; }; //----order_rgba
struct order_argb { enum argb_e { A=0, R=1, G=2, B=3, rgba_tag }; }; //----order_argb
struct order_abgr { enum abgr_e { A=0, B=1, G=2, R=3, rgba_tag }; }; //----order_abgr
struct order_bgra { enum bgra_e { B=0, G=1, R=2, A=3, rgba_tag }; }; //----order_bgra
//====================================================================rgba
struct rgba
{
typedef double value_type;
double r;
double g;
double b;
double a;
//--------------------------------------------------------------------
rgba() {}
//--------------------------------------------------------------------
rgba(double r_, double g_, double b_, double a_=1.0) :
r(r_), g(g_), b(b_), a(a_) {}
//--------------------------------------------------------------------
rgba(const rgba& c, double a_) : r(c.r), g(c.g), b(c.b), a(a_) {}
//--------------------------------------------------------------------
void clear()
{
r = g = b = a = 0;
}
//--------------------------------------------------------------------
const rgba& transparent()
{
a = 0.0;
return *this;
}
//--------------------------------------------------------------------
const rgba& opacity(double a_)
{
if(a_ < 0.0) a_ = 0.0;
if(a_ > 1.0) a_ = 1.0;
a = a_;
return *this;
}
//--------------------------------------------------------------------
double opacity() const
{
return a;
}
//--------------------------------------------------------------------
const rgba& premultiply()
{
r *= a;
g *= a;
b *= a;
return *this;
}
//--------------------------------------------------------------------
const rgba& premultiply(double a_)
{
if(a <= 0.0 || a_ <= 0.0)
{
r = g = b = a = 0.0;
return *this;
}
a_ /= a;
r *= a_;
g *= a_;
b *= a_;
a = a_;
return *this;
}
//--------------------------------------------------------------------
const rgba& demultiply()
{
if(a == 0)
{
r = g = b = 0;
return *this;
}
double a_ = 1.0 / a;
r *= a_;
g *= a_;
b *= a_;
return *this;
}
//--------------------------------------------------------------------
rgba gradient(rgba c, double k) const
{
rgba ret;
ret.r = r + (c.r - r) * k;
ret.g = g + (c.g - g) * k;
ret.b = b + (c.b - b) * k;
ret.a = a + (c.a - a) * k;
return ret;
}
//--------------------------------------------------------------------
static rgba no_color() { return rgba(0,0,0,0); }
//--------------------------------------------------------------------
static rgba from_wavelength(double wl, double gamma = 1.0);
//--------------------------------------------------------------------
explicit rgba(double wavelen, double gamma=1.0)
{
*this = from_wavelength(wavelen, gamma);
}
};
//----------------------------------------------------------------rgba_pre
inline rgba rgba_pre(double r, double g, double b, double a=1.0)
{
return rgba(r, g, b, a).premultiply();
}
inline rgba rgba_pre(const rgba& c)
{
return rgba(c).premultiply();
}
inline rgba rgba_pre(const rgba& c, double a)
{
return rgba(c, a).premultiply();
}
//------------------------------------------------------------------------
inline rgba rgba::from_wavelength(double wl, double gamma)
{
rgba t(0.0, 0.0, 0.0);
if(wl >= 380.0 && wl <= 440.0)
{
t.r = -1.0 * (wl - 440.0) / (440.0 - 380.0);
t.b = 1.0;
}
else
if(wl >= 440.0 && wl <= 490.0)
{
t.g = (wl - 440.0) / (490.0 - 440.0);
t.b = 1.0;
}
else
if(wl >= 490.0 && wl <= 510.0)
{
t.g = 1.0;
t.b = -1.0 * (wl - 510.0) / (510.0 - 490.0);
}
else
if(wl >= 510.0 && wl <= 580.0)
{
t.r = (wl - 510.0) / (580.0 - 510.0);
t.g = 1.0;
}
else
if(wl >= 580.0 && wl <= 645.0)
{
t.r = 1.0;
t.g = -1.0 * (wl - 645.0) / (645.0 - 580.0);
}
else
if(wl >= 645.0 && wl <= 780.0)
{
t.r = 1.0;
}
double s = 1.0;
if(wl > 700.0) s = 0.3 + 0.7 * (780.0 - wl) / (780.0 - 700.0);
else if(wl < 420.0) s = 0.3 + 0.7 * (wl - 380.0) / (420.0 - 380.0);
t.r = pow(t.r * s, gamma);
t.g = pow(t.g * s, gamma);
t.b = pow(t.b * s, gamma);
return t;
}
//===================================================================rgba8
struct rgba8
{
typedef int8u value_type;
typedef int32u calc_type;
typedef int32 long_type;
enum base_scale_e
{
base_shift = 8,
base_scale = 1 << base_shift,
base_mask = base_scale - 1
};
typedef rgba8 self_type;
value_type r;
value_type g;
value_type b;
value_type a;
//--------------------------------------------------------------------
rgba8() {}
//--------------------------------------------------------------------
rgba8(unsigned r_, unsigned g_, unsigned b_, unsigned a_=base_mask) :
r(value_type(r_)),
g(value_type(g_)),
b(value_type(b_)),
a(value_type(a_)) {}
//--------------------------------------------------------------------
rgba8(const rgba& c, double a_) :
r((value_type)uround(c.r * double(base_mask))),
g((value_type)uround(c.g * double(base_mask))),
b((value_type)uround(c.b * double(base_mask))),
a((value_type)uround(a_ * double(base_mask))) {}
//--------------------------------------------------------------------
rgba8(const self_type& c, unsigned a_) :
r(c.r), g(c.g), b(c.b), a(value_type(a_)) {}
//--------------------------------------------------------------------
rgba8(const rgba& c) :
r((value_type)uround(c.r * double(base_mask))),
g((value_type)uround(c.g * double(base_mask))),
b((value_type)uround(c.b * double(base_mask))),
a((value_type)uround(c.a * double(base_mask))) {}
//--------------------------------------------------------------------
void clear()
{
r = g = b = a = 0;
}
//--------------------------------------------------------------------
const self_type& transparent()
{
a = 0;
return *this;
}
//--------------------------------------------------------------------
const self_type& opacity(double a_)
{
if(a_ < 0.0) a_ = 0.0;
if(a_ > 1.0) a_ = 1.0;
a = (value_type)uround(a_ * double(base_mask));
return *this;
}
//--------------------------------------------------------------------
double opacity() const
{
return double(a) / double(base_mask);
}
//--------------------------------------------------------------------
AGG_INLINE const self_type& premultiply()
{
if(a == base_mask) return *this;
if(a == 0)
{
r = g = b = 0;
return *this;
}
r = value_type((calc_type(r) * a) >> base_shift);
g = value_type((calc_type(g) * a) >> base_shift);
b = value_type((calc_type(b) * a) >> base_shift);
return *this;
}
//--------------------------------------------------------------------
AGG_INLINE const self_type& premultiply(unsigned a_)
{
if(a == base_mask && a_ >= base_mask) return *this;
if(a == 0 || a_ == 0)
{
r = g = b = a = 0;
return *this;
}
calc_type r_ = (calc_type(r) * a_) / a;
calc_type g_ = (calc_type(g) * a_) / a;
calc_type b_ = (calc_type(b) * a_) / a;
r = value_type((r_ > a_) ? a_ : r_);
g = value_type((g_ > a_) ? a_ : g_);
b = value_type((b_ > a_) ? a_ : b_);
a = value_type(a_);
return *this;
}
//--------------------------------------------------------------------
AGG_INLINE const self_type& demultiply()
{
if(a == base_mask) return *this;
if(a == 0)
{
r = g = b = 0;
return *this;
}
calc_type r_ = (calc_type(r) * base_mask) / a;
calc_type g_ = (calc_type(g) * base_mask) / a;
calc_type b_ = (calc_type(b) * base_mask) / a;
r = value_type((r_ > calc_type(base_mask)) ? calc_type(base_mask) : r_);
g = value_type((g_ > calc_type(base_mask)) ? calc_type(base_mask) : g_);
b = value_type((b_ > calc_type(base_mask)) ? calc_type(base_mask) : b_);
return *this;
}
//--------------------------------------------------------------------
AGG_INLINE self_type gradient(const self_type& c, double k) const
{
self_type ret;
calc_type ik = uround(k * base_scale);
ret.r = value_type(calc_type(r) + (((calc_type(c.r) - r) * ik) >> base_shift));
ret.g = value_type(calc_type(g) + (((calc_type(c.g) - g) * ik) >> base_shift));
ret.b = value_type(calc_type(b) + (((calc_type(c.b) - b) * ik) >> base_shift));
ret.a = value_type(calc_type(a) + (((calc_type(c.a) - a) * ik) >> base_shift));
return ret;
}
//--------------------------------------------------------------------
AGG_INLINE void add(const self_type& c, unsigned cover)
{
calc_type cr, cg, cb, ca;
if(cover == cover_mask)
{
if(c.a == base_mask)
{
*this = c;
}
else
{
cr = r + c.r; r = (cr > calc_type(base_mask)) ? calc_type(base_mask) : cr;
cg = g + c.g; g = (cg > calc_type(base_mask)) ? calc_type(base_mask) : cg;
cb = b + c.b; b = (cb > calc_type(base_mask)) ? calc_type(base_mask) : cb;
ca = a + c.a; a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca;
}
}
else
{
cr = r + ((c.r * cover + cover_mask/2) >> cover_shift);
cg = g + ((c.g * cover + cover_mask/2) >> cover_shift);
cb = b + ((c.b * cover + cover_mask/2) >> cover_shift);
ca = a + ((c.a * cover + cover_mask/2) >> cover_shift);
r = (cr > calc_type(base_mask)) ? calc_type(base_mask) : cr;
g = (cg > calc_type(base_mask)) ? calc_type(base_mask) : cg;
b = (cb > calc_type(base_mask)) ? calc_type(base_mask) : cb;
a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca;
}
}
//--------------------------------------------------------------------
template<class GammaLUT>
AGG_INLINE void apply_gamma_dir(const GammaLUT& gamma)
{
r = gamma.dir(r);
g = gamma.dir(g);
b = gamma.dir(b);
}
//--------------------------------------------------------------------
template<class GammaLUT>
AGG_INLINE void apply_gamma_inv(const GammaLUT& gamma)
{
r = gamma.inv(r);
g = gamma.inv(g);
b = gamma.inv(b);
}
//--------------------------------------------------------------------
static self_type no_color() { return self_type(0,0,0,0); }
//--------------------------------------------------------------------
static self_type from_wavelength(double wl, double gamma = 1.0)
{
return self_type(rgba::from_wavelength(wl, gamma));
}
};
//-------------------------------------------------------------rgba8_pre
inline rgba8 rgba8_pre(unsigned r, unsigned g, unsigned b,
unsigned a = rgba8::base_mask)
{
return rgba8(r,g,b,a).premultiply();
}
inline rgba8 rgba8_pre(const rgba8& c)
{
return rgba8(c).premultiply();
}
inline rgba8 rgba8_pre(const rgba8& c, unsigned a)
{
return rgba8(c,a).premultiply();
}
inline rgba8 rgba8_pre(const rgba& c)
{
return rgba8(c).premultiply();
}
inline rgba8 rgba8_pre(const rgba& c, double a)
{
return rgba8(c,a).premultiply();
}
//-------------------------------------------------------------rgb8_packed
inline rgba8 rgb8_packed(unsigned v)
{
return rgba8((v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF);
}
//-------------------------------------------------------------bgr8_packed
inline rgba8 bgr8_packed(unsigned v)
{
return rgba8(v & 0xFF, (v >> 8) & 0xFF, (v >> 16) & 0xFF);
}
//------------------------------------------------------------argb8_packed
inline rgba8 argb8_packed(unsigned v)
{
return rgba8((v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF, v >> 24);
}
//---------------------------------------------------------rgba8_gamma_dir
template<class GammaLUT>
rgba8 rgba8_gamma_dir(rgba8 c, const GammaLUT& gamma)
{
return rgba8(gamma.dir(c.r), gamma.dir(c.g), gamma.dir(c.b), c.a);
}
//---------------------------------------------------------rgba8_gamma_inv
template<class GammaLUT>
rgba8 rgba8_gamma_inv(rgba8 c, const GammaLUT& gamma)
{
return rgba8(gamma.inv(c.r), gamma.inv(c.g), gamma.inv(c.b), c.a);
}
//==================================================================rgba16
struct rgba16
{
typedef int16u value_type;
typedef int32u calc_type;
typedef int64 long_type;
enum base_scale_e
{
base_shift = 16,
base_scale = 1 << base_shift,
base_mask = base_scale - 1
};
typedef rgba16 self_type;
value_type r;
value_type g;
value_type b;
value_type a;
//--------------------------------------------------------------------
rgba16() {}
//--------------------------------------------------------------------
rgba16(unsigned r_, unsigned g_, unsigned b_, unsigned a_=base_mask) :
r(value_type(r_)),
g(value_type(g_)),
b(value_type(b_)),
a(value_type(a_)) {}
//--------------------------------------------------------------------
rgba16(const self_type& c, unsigned a_) :
r(c.r), g(c.g), b(c.b), a(value_type(a_)) {}
//--------------------------------------------------------------------
rgba16(const rgba& c) :
r((value_type)uround(c.r * double(base_mask))),
g((value_type)uround(c.g * double(base_mask))),
b((value_type)uround(c.b * double(base_mask))),
a((value_type)uround(c.a * double(base_mask))) {}
//--------------------------------------------------------------------
rgba16(const rgba& c, double a_) :
r((value_type)uround(c.r * double(base_mask))),
g((value_type)uround(c.g * double(base_mask))),
b((value_type)uround(c.b * double(base_mask))),
a((value_type)uround(a_ * double(base_mask))) {}
//--------------------------------------------------------------------
rgba16(const rgba8& c) :
r(value_type((value_type(c.r) << 8) | c.r)),
g(value_type((value_type(c.g) << 8) | c.g)),
b(value_type((value_type(c.b) << 8) | c.b)),
a(value_type((value_type(c.a) << 8) | c.a)) {}
//--------------------------------------------------------------------
rgba16(const rgba8& c, unsigned a_) :
r(value_type((value_type(c.r) << 8) | c.r)),
g(value_type((value_type(c.g) << 8) | c.g)),
b(value_type((value_type(c.b) << 8) | c.b)),
a(value_type(( a_ << 8) | c.a)) {}
//--------------------------------------------------------------------
void clear()
{
r = g = b = a = 0;
}
//--------------------------------------------------------------------
const self_type& transparent()
{
a = 0;
return *this;
}
//--------------------------------------------------------------------
AGG_INLINE const self_type& opacity(double a_)
{
if(a_ < 0.0) a_ = 0.0;
if(a_ > 1.0) a_ = 1.0;
a = (value_type)uround(a_ * double(base_mask));
return *this;
}
//--------------------------------------------------------------------
double opacity() const
{
return double(a) / double(base_mask);
}
//--------------------------------------------------------------------
AGG_INLINE const self_type& premultiply()
{
if(a == base_mask) return *this;
if(a == 0)
{
r = g = b = 0;
return *this;
}
r = value_type((calc_type(r) * a) >> base_shift);
g = value_type((calc_type(g) * a) >> base_shift);
b = value_type((calc_type(b) * a) >> base_shift);
return *this;
}
//--------------------------------------------------------------------
AGG_INLINE const self_type& premultiply(unsigned a_)
{
if(a == base_mask && a_ >= base_mask) return *this;
if(a == 0 || a_ == 0)
{
r = g = b = a = 0;
return *this;
}
calc_type r_ = (calc_type(r) * a_) / a;
calc_type g_ = (calc_type(g) * a_) / a;
calc_type b_ = (calc_type(b) * a_) / a;
r = value_type((r_ > a_) ? a_ : r_);
g = value_type((g_ > a_) ? a_ : g_);
b = value_type((b_ > a_) ? a_ : b_);
a = value_type(a_);
return *this;
}
//--------------------------------------------------------------------
AGG_INLINE const self_type& demultiply()
{
if(a == base_mask) return *this;
if(a == 0)
{
r = g = b = 0;
return *this;
}
calc_type r_ = (calc_type(r) * base_mask) / a;
calc_type g_ = (calc_type(g) * base_mask) / a;
calc_type b_ = (calc_type(b) * base_mask) / a;
r = value_type((r_ > calc_type(base_mask)) ? calc_type(base_mask) : r_);
g = value_type((g_ > calc_type(base_mask)) ? calc_type(base_mask) : g_);
b = value_type((b_ > calc_type(base_mask)) ? calc_type(base_mask) : b_);
return *this;
}
//--------------------------------------------------------------------
AGG_INLINE self_type gradient(const self_type& c, double k) const
{
self_type ret;
calc_type ik = uround(k * base_scale);
ret.r = value_type(calc_type(r) + (((calc_type(c.r) - r) * ik) >> base_shift));
ret.g = value_type(calc_type(g) + (((calc_type(c.g) - g) * ik) >> base_shift));
ret.b = value_type(calc_type(b) + (((calc_type(c.b) - b) * ik) >> base_shift));
ret.a = value_type(calc_type(a) + (((calc_type(c.a) - a) * ik) >> base_shift));
return ret;
}
//--------------------------------------------------------------------
AGG_INLINE void add(const self_type& c, unsigned cover)
{
calc_type cr, cg, cb, ca;
if(cover == cover_mask)
{
if(c.a == base_mask)
{
*this = c;
}
else
{
cr = r + c.r; r = (cr > calc_type(base_mask)) ? calc_type(base_mask) : cr;
cg = g + c.g; g = (cg > calc_type(base_mask)) ? calc_type(base_mask) : cg;
cb = b + c.b; b = (cb > calc_type(base_mask)) ? calc_type(base_mask) : cb;
ca = a + c.a; a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca;
}
}
else
{
cr = r + ((c.r * cover + cover_mask) >> cover_shift);
cg = g + ((c.g * cover + cover_mask) >> cover_shift);
cb = b + ((c.b * cover + cover_mask) >> cover_shift);
ca = a + ((c.a * cover + cover_mask) >> cover_shift);
r = (cr > calc_type(base_mask)) ? calc_type(base_mask) : cr;
g = (cg > calc_type(base_mask)) ? calc_type(base_mask) : cg;
b = (cb > calc_type(base_mask)) ? calc_type(base_mask) : cb;
a = (ca > calc_type(base_mask)) ? calc_type(base_mask) : ca;
}
}
//--------------------------------------------------------------------
template<class GammaLUT>
AGG_INLINE void apply_gamma_dir(const GammaLUT& gamma)
{
r = gamma.dir(r);
g = gamma.dir(g);
b = gamma.dir(b);
}
//--------------------------------------------------------------------
template<class GammaLUT>
AGG_INLINE void apply_gamma_inv(const GammaLUT& gamma)
{
r = gamma.inv(r);
g = gamma.inv(g);
b = gamma.inv(b);
}
//--------------------------------------------------------------------
static self_type no_color() { return self_type(0,0,0,0); }
//--------------------------------------------------------------------
static self_type from_wavelength(double wl, double gamma = 1.0)
{
return self_type(rgba::from_wavelength(wl, gamma));
}
};
//--------------------------------------------------------------rgba16_pre
inline rgba16 rgba16_pre(unsigned r, unsigned g, unsigned b,
unsigned a = rgba16::base_mask)
{
return rgba16(r,g,b,a).premultiply();
}
inline rgba16 rgba16_pre(const rgba16& c, unsigned a)
{
return rgba16(c,a).premultiply();
}
inline rgba16 rgba16_pre(const rgba& c)
{
return rgba16(c).premultiply();
}
inline rgba16 rgba16_pre(const rgba& c, double a)
{
return rgba16(c,a).premultiply();
}
inline rgba16 rgba16_pre(const rgba8& c)
{
return rgba16(c).premultiply();
}
inline rgba16 rgba16_pre(const rgba8& c, unsigned a)
{
return rgba16(c,a).premultiply();
}
//------------------------------------------------------rgba16_gamma_dir
template<class GammaLUT>
rgba16 rgba16_gamma_dir(rgba16 c, const GammaLUT& gamma)
{
return rgba16(gamma.dir(c.r), gamma.dir(c.g), gamma.dir(c.b), c.a);
}
//------------------------------------------------------rgba16_gamma_inv
template<class GammaLUT>
rgba16 rgba16_gamma_inv(rgba16 c, const GammaLUT& gamma)
{
return rgba16(gamma.inv(c.r), gamma.inv(c.g), gamma.inv(c.b), c.a);
}
}
#endif

View file

@ -1,670 +0,0 @@
//----------------------------------------------------------------------------
// Anti-Grain Geometry - Version 2.4
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: mcseem@antigrain.com
// mcseemagg@yahoo.com
// http://www.antigrain.com
//----------------------------------------------------------------------------
//
// Adaptation for high precision colors has been sponsored by
// Liberty Technology Systems, Inc., visit http://lib-sys.com
//
// Liberty Technology Systems, Inc. is the provider of
// PostScript and PDF technology for software developers.
//
//----------------------------------------------------------------------------
#ifndef AGG_PIXFMT_GRAY_INCLUDED
#define AGG_PIXFMT_GRAY_INCLUDED
#include <string.h>
#include "agg_basics.h"
#include "agg_color_gray.h"
#include "agg_rendering_buffer.h"
namespace agg
{
//============================================================blender_gray
template<class ColorT> struct blender_gray
{
typedef ColorT color_type;
typedef typename color_type::value_type value_type;
typedef typename color_type::calc_type calc_type;
enum base_scale_e { base_shift = color_type::base_shift };
static AGG_INLINE void blend_pix(value_type* p, unsigned cv,
unsigned alpha, unsigned cover=0)
{
*p = (value_type)((((cv - calc_type(*p)) * alpha) + (calc_type(*p) << base_shift)) >> base_shift);
}
};
//======================================================blender_gray_pre
template<class ColorT> struct blender_gray_pre
{
typedef ColorT color_type;
typedef typename color_type::value_type value_type;
typedef typename color_type::calc_type calc_type;
enum base_scale_e { base_shift = color_type::base_shift };
static AGG_INLINE void blend_pix(value_type* p, unsigned cv,
unsigned alpha, unsigned cover)
{
alpha = color_type::base_mask - alpha;
cover = (cover + 1) << (base_shift - 8);
*p = (value_type)((*p * alpha + cv * cover) >> base_shift);
}
static AGG_INLINE void blend_pix(value_type* p, unsigned cv,
unsigned alpha)
{
*p = (value_type)(((*p * (color_type::base_mask - alpha)) >> base_shift) + cv);
}
};
//=====================================================apply_gamma_dir_gray
template<class ColorT, class GammaLut> class apply_gamma_dir_gray
{
public:
typedef typename ColorT::value_type value_type;
apply_gamma_dir_gray(const GammaLut& gamma) : m_gamma(gamma) {}
AGG_INLINE void operator () (value_type* p)
{
*p = m_gamma.dir(*p);
}
private:
const GammaLut& m_gamma;
};
//=====================================================apply_gamma_inv_gray
template<class ColorT, class GammaLut> class apply_gamma_inv_gray
{
public:
typedef typename ColorT::value_type value_type;
apply_gamma_inv_gray(const GammaLut& gamma) : m_gamma(gamma) {}
AGG_INLINE void operator () (value_type* p)
{
*p = m_gamma.inv(*p);
}
private:
const GammaLut& m_gamma;
};
//=================================================pixfmt_alpha_blend_gray
template<class Blender, class RenBuf, unsigned Step=1, unsigned Offset=0>
class pixfmt_alpha_blend_gray
{
public:
typedef RenBuf rbuf_type;
typedef typename rbuf_type::row_data row_data;
typedef Blender blender_type;
typedef typename blender_type::color_type color_type;
typedef int order_type; // A fake one
typedef typename color_type::value_type value_type;
typedef typename color_type::calc_type calc_type;
enum base_scale_e
{
base_shift = color_type::base_shift,
base_scale = color_type::base_scale,
base_mask = color_type::base_mask,
pix_width = sizeof(value_type),
pix_step = Step,
pix_offset = Offset
};
private:
//--------------------------------------------------------------------
static AGG_INLINE void copy_or_blend_pix(value_type* p,
const color_type& c,
unsigned cover)
{
if (c.a)
{
calc_type alpha = (calc_type(c.a) * (cover + 1)) >> 8;
if(alpha == base_mask)
{
*p = c.v;
}
else
{
Blender::blend_pix(p, c.v, alpha, cover);
}
}
}
static AGG_INLINE void copy_or_blend_pix(value_type* p,
const color_type& c)
{
if (c.a)
{
if(c.a == base_mask)
{
*p = c.v;
}
else
{
Blender::blend_pix(p, c.v, c.a);
}
}
}
public:
//--------------------------------------------------------------------
explicit pixfmt_alpha_blend_gray(rbuf_type& rb) :
m_rbuf(&rb)
{}
void attach(rbuf_type& rb) { m_rbuf = &rb; }
//--------------------------------------------------------------------
template<class PixFmt>
bool attach(PixFmt& pixf, int x1, int y1, int x2, int y2)
{
rect_i r(x1, y1, x2, y2);
if(r.clip(rect_i(0, 0, pixf.width()-1, pixf.height()-1)))
{
int stride = pixf.stride();
m_rbuf->attach(pixf.pix_ptr(r.x1, stride < 0 ? r.y2 : r.y1),
(r.x2 - r.x1) + 1,
(r.y2 - r.y1) + 1,
stride);
return true;
}
return false;
}
//--------------------------------------------------------------------
AGG_INLINE unsigned width() const { return m_rbuf->width(); }
AGG_INLINE unsigned height() const { return m_rbuf->height(); }
AGG_INLINE int stride() const { return m_rbuf->stride(); }
//--------------------------------------------------------------------
int8u* row_ptr(int y) { return m_rbuf->row_ptr(y); }
const int8u* row_ptr(int y) const { return m_rbuf->row_ptr(y); }
row_data row(int y) const { return m_rbuf->row(y); }
const int8u* pix_ptr(int x, int y) const
{
return m_rbuf->row_ptr(y) + x * Step + Offset;
}
int8u* pix_ptr(int x, int y)
{
return m_rbuf->row_ptr(y) + x * Step + Offset;
}
//--------------------------------------------------------------------
AGG_INLINE static void make_pix(int8u* p, const color_type& c)
{
*(value_type*)p = c.v;
}
//--------------------------------------------------------------------
AGG_INLINE color_type pixel(int x, int y) const
{
value_type* p = (value_type*)m_rbuf->row_ptr(y) + x * Step + Offset;
return color_type(*p);
}
//--------------------------------------------------------------------
AGG_INLINE void copy_pixel(int x, int y, const color_type& c)
{
*((value_type*)m_rbuf->row_ptr(x, y, 1) + x * Step + Offset) = c.v;
}
//--------------------------------------------------------------------
AGG_INLINE void blend_pixel(int x, int y, const color_type& c, int8u cover)
{
copy_or_blend_pix((value_type*)
m_rbuf->row_ptr(x, y, 1) + x * Step + Offset,
c,
cover);
}
//--------------------------------------------------------------------
AGG_INLINE void copy_hline(int x, int y,
unsigned len,
const color_type& c)
{
value_type* p = (value_type*)
m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
do
{
*p = c.v;
p += Step;
}
while(--len);
}
//--------------------------------------------------------------------
AGG_INLINE void copy_vline(int x, int y,
unsigned len,
const color_type& c)
{
do
{
value_type* p = (value_type*)
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
*p = c.v;
}
while(--len);
}
//--------------------------------------------------------------------
void blend_hline(int x, int y,
unsigned len,
const color_type& c,
int8u cover)
{
if (c.a)
{
value_type* p = (value_type*)
m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
calc_type alpha = (calc_type(c.a) * (cover + 1)) >> 8;
if(alpha == base_mask)
{
do
{
*p = c.v;
p += Step;
}
while(--len);
}
else
{
do
{
Blender::blend_pix(p, c.v, alpha, cover);
p += Step;
}
while(--len);
}
}
}
//--------------------------------------------------------------------
void blend_vline(int x, int y,
unsigned len,
const color_type& c,
int8u cover)
{
if (c.a)
{
value_type* p;
calc_type alpha = (calc_type(c.a) * (cover + 1)) >> 8;
if(alpha == base_mask)
{
do
{
p = (value_type*)
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
*p = c.v;
}
while(--len);
}
else
{
do
{
p = (value_type*)
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
Blender::blend_pix(p, c.v, alpha, cover);
}
while(--len);
}
}
}
//--------------------------------------------------------------------
void blend_solid_hspan(int x, int y,
unsigned len,
const color_type& c,
const int8u* covers)
{
if (c.a)
{
value_type* p = (value_type*)
m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
do
{
calc_type alpha = (calc_type(c.a) * (calc_type(*covers) + 1)) >> 8;
if(alpha == base_mask)
{
*p = c.v;
}
else
{
Blender::blend_pix(p, c.v, alpha, *covers);
}
p += Step;
++covers;
}
while(--len);
}
}
//--------------------------------------------------------------------
void blend_solid_vspan(int x, int y,
unsigned len,
const color_type& c,
const int8u* covers)
{
if (c.a)
{
do
{
calc_type alpha = (calc_type(c.a) * (calc_type(*covers) + 1)) >> 8;
value_type* p = (value_type*)
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
if(alpha == base_mask)
{
*p = c.v;
}
else
{
Blender::blend_pix(p, c.v, alpha, *covers);
}
++covers;
}
while(--len);
}
}
//--------------------------------------------------------------------
void copy_color_hspan(int x, int y,
unsigned len,
const color_type* colors)
{
value_type* p = (value_type*)
m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
do
{
*p = colors->v;
p += Step;
++colors;
}
while(--len);
}
//--------------------------------------------------------------------
void copy_color_vspan(int x, int y,
unsigned len,
const color_type* colors)
{
do
{
value_type* p = (value_type*)
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
*p = colors->v;
++colors;
}
while(--len);
}
//--------------------------------------------------------------------
void blend_color_hspan(int x, int y,
unsigned len,
const color_type* colors,
const int8u* covers,
int8u cover)
{
value_type* p = (value_type*)
m_rbuf->row_ptr(x, y, len) + x * Step + Offset;
if(covers)
{
do
{
copy_or_blend_pix(p, *colors++, *covers++);
p += Step;
}
while(--len);
}
else
{
if(cover == 255)
{
do
{
if(colors->a == base_mask)
{
*p = colors->v;
}
else
{
copy_or_blend_pix(p, *colors);
}
p += Step;
++colors;
}
while(--len);
}
else
{
do
{
copy_or_blend_pix(p, *colors++, cover);
p += Step;
}
while(--len);
}
}
}
//--------------------------------------------------------------------
void blend_color_vspan(int x, int y,
unsigned len,
const color_type* colors,
const int8u* covers,
int8u cover)
{
value_type* p;
if(covers)
{
do
{
p = (value_type*)
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
copy_or_blend_pix(p, *colors++, *covers++);
}
while(--len);
}
else
{
if(cover == 255)
{
do
{
p = (value_type*)
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
if(colors->a == base_mask)
{
*p = colors->v;
}
else
{
copy_or_blend_pix(p, *colors);
}
++colors;
}
while(--len);
}
else
{
do
{
p = (value_type*)
m_rbuf->row_ptr(x, y++, 1) + x * Step + Offset;
copy_or_blend_pix(p, *colors++, cover);
}
while(--len);
}
}
}
//--------------------------------------------------------------------
template<class Function> void for_each_pixel(Function f)
{
unsigned y;
for(y = 0; y < height(); ++y)
{
row_data r = m_rbuf->row(y);
if(r.ptr)
{
unsigned len = r.x2 - r.x1 + 1;
value_type* p = (value_type*)
m_rbuf->row_ptr(r.x1, y, len) + r.x1 * Step + Offset;
do
{
f(p);
p += Step;
}
while(--len);
}
}
}
//--------------------------------------------------------------------
template<class GammaLut> void apply_gamma_dir(const GammaLut& g)
{
for_each_pixel(apply_gamma_dir_gray<color_type, GammaLut>(g));
}
//--------------------------------------------------------------------
template<class GammaLut> void apply_gamma_inv(const GammaLut& g)
{
for_each_pixel(apply_gamma_inv_gray<color_type, GammaLut>(g));
}
//--------------------------------------------------------------------
template<class RenBuf2>
void copy_from(const RenBuf2& from,
int xdst, int ydst,
int xsrc, int ysrc,
unsigned len)
{
const int8u* p = from.row_ptr(ysrc);
if(p)
{
memmove(m_rbuf->row_ptr(xdst, ydst, len) + xdst * pix_width,
p + xsrc * pix_width,
len * pix_width);
}
}
//--------------------------------------------------------------------
template<class SrcPixelFormatRenderer>
void blend_from_color(const SrcPixelFormatRenderer& from,
const color_type& color,
int xdst, int ydst,
int xsrc, int ysrc,
unsigned len,
int8u cover)
{
typedef typename SrcPixelFormatRenderer::value_type src_value_type;
const src_value_type* psrc = (src_value_type*)from.row_ptr(ysrc);
if(psrc)
{
value_type* pdst =
(value_type*)m_rbuf->row_ptr(xdst, ydst, len) + xdst;
do
{
copy_or_blend_pix(pdst,
color,
(*psrc * cover + base_mask) >> base_shift);
++psrc;
++pdst;
}
while(--len);
}
}
//--------------------------------------------------------------------
template<class SrcPixelFormatRenderer>
void blend_from_lut(const SrcPixelFormatRenderer& from,
const color_type* color_lut,
int xdst, int ydst,
int xsrc, int ysrc,
unsigned len,
int8u cover)
{
typedef typename SrcPixelFormatRenderer::value_type src_value_type;
const src_value_type* psrc = (src_value_type*)from.row_ptr(ysrc);
if(psrc)
{
value_type* pdst =
(value_type*)m_rbuf->row_ptr(xdst, ydst, len) + xdst;
do
{
copy_or_blend_pix(pdst, color_lut[*psrc], cover);
++psrc;
++pdst;
}
while(--len);
}
}
private:
rbuf_type* m_rbuf;
};
typedef blender_gray<gray8> blender_gray8;
typedef blender_gray_pre<gray8> blender_gray8_pre;
typedef blender_gray<gray16> blender_gray16;
typedef blender_gray_pre<gray16> blender_gray16_pre;
typedef pixfmt_alpha_blend_gray<blender_gray8, rendering_buffer> pixfmt_gray8; //----pixfmt_gray8
typedef pixfmt_alpha_blend_gray<blender_gray8_pre, rendering_buffer> pixfmt_gray8_pre; //----pixfmt_gray8_pre
typedef pixfmt_alpha_blend_gray<blender_gray16, rendering_buffer> pixfmt_gray16; //----pixfmt_gray16
typedef pixfmt_alpha_blend_gray<blender_gray16_pre, rendering_buffer> pixfmt_gray16_pre; //----pixfmt_gray16_pre
}
#endif

File diff suppressed because it is too large Load diff

View file

@ -143,7 +143,7 @@ bool Sqlite3Connection::Execute() {
return false;
}
got_first_row = got_row_data = (retcode==SQLITE_ROW);
if (got_row_data) {
// if (got_row_data) { // By WebChaot, 2009-01-15
int numfields = sqlite3_column_count(current_stmt);
info.SetCount(numfields);
for (int i = 0; i < numfields; ++i) {
@ -177,7 +177,7 @@ bool Sqlite3Connection::Execute() {
break;
}
}
}
// }
return true;
}