antigrain refactors, need an intermediate checkin

This commit is contained in:
zeromus 2009-07-11 04:27:03 +00:00
parent 11983ace12
commit e2a29f6c3e
6 changed files with 3240 additions and 373 deletions

704
desmume/src/agg2d.h Normal file
View File

@ -0,0 +1,704 @@
//----------------------------------------------------------------------------
// Agg2D - Version 1.0
// Based on Anti-Grain Geometry
// Copyright (C) 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
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
//
// 25 Jan 2007 - Ported to AGG 2.4 Jerry Evans (jerry@novadsp.com)
//
//----------------------------------------------------------------------------
#ifndef AGG2D_INCLUDED
#define AGG2D_INCLUDED
// With this define uncommented you can use FreeType font engine
#ifdef UNDER_CE
#define AGG2D_USE_FREETYPE
#endif
#pragma warning(disable: 4786)
// JME
#include "agg_basics.h"
#include "agg_math_stroke.h"
#include "agg_trans_affine.h"
#include "agg_trans_viewport.h"
#include "agg_path_storage.h"
#include "agg_conv_stroke.h"
#include "agg_conv_transform.h"
#include "agg_conv_curve.h"
#include "agg_rendering_buffer.h"
#include "agg_renderer_base.h"
#include "agg_renderer_scanline.h"
#include "agg_span_gradient.h"
#include "agg_span_image_filter_rgba.h"
//#include "agg_span_image_resample_rgba.h"
//+ JME
#include "agg_span_allocator.h"
#include "agg_span_converter.h"
#include "agg_span_interpolator_linear.h"
#include "agg_rasterizer_scanline_aa.h"
#include "agg_gamma_functions.h"
#include "agg_scanline_u.h"
#include "agg_bezier_arc.h"
#include "agg_rounded_rect.h"
#include "agg_font_cache_manager.h"
#ifdef AGG2D_USE_FREETYPE
#include "../font_freetype/agg_font_freetype.h"
#else
#include "../font_win32_tt/agg_font_win32_tt.h"
#endif
#include "agg_pixfmt_rgba.h"
//+ JME
#include "agg_image_accessors.h"
#define AGG2D_TEMPLATE template<typename PixFormat>
#define AGG2D_TEMPLATE_ARG <PixFormat>
class Agg2DBase
{
public:
// JME
//typedef agg::rect Rect;
typedef agg::rect_i Rect;
typedef agg::rect_d RectD;
typedef agg::trans_affine Affine;
enum LineJoin
{
JOIN_MITER = agg::miter_join,
JOIN_ROUND = agg::round_join,
JOIN_BEVEL = agg::bevel_join
};
enum LineCap
{
CAP_BUTT = agg::butt_cap,
CAP_SQUARE = agg::square_cap,
CAP_ROUND = agg::round_cap
};
enum TextAlignment
{
AlignLeft,
AlignRight,
AlignCenter,
AlignBaseline,
AlignTop = AlignRight,
AlignBottom = AlignLeft
};
enum DrawPathFlag
{
FillOnly,
StrokeOnly,
FillAndStroke,
FillWithLineColor
};
enum ViewportOption
{
Anisotropic,
XMinYMin,
XMidYMin,
XMaxYMin,
XMinYMid,
XMidYMid,
XMaxYMid,
XMinYMax,
XMidYMax,
XMaxYMax
};
enum WindowFitLogic
{
WindowFitLogic_meet,
WindowFitLogic_slice
};
struct Transformations
{
double affineMatrix[6];
};
struct Image
{
agg::rendering_buffer renBuf;
Image() {}
Image(unsigned char* buf, unsigned width, unsigned height, int stride) :
renBuf(buf, width, height, stride) {}
void attach(unsigned char* buf, unsigned width, unsigned height, int stride)
{
renBuf.attach(buf, width, height, stride);
}
int width() const { return renBuf.width(); }
int height() const { return renBuf.height(); }
AGG2D_TEMPLATE void premultiply();
AGG2D_TEMPLATE void demultiply();
};
enum ImageFilter
{
NoFilter,
Bilinear,
Hanning,
Hermite,
Quadric,
Bicubic,
Catrom,
Spline16,
Spline36,
Blackman144
};
enum ImageResample
{
NoResample,
ResampleAlways,
ResampleOnZoomOut
};
enum FontCacheType
{
RasterFontCache,
VectorFontCache
};
enum BlendMode
{
BlendAlpha = agg::end_of_comp_op_e,
BlendClear = agg::comp_op_clear,
BlendSrc = agg::comp_op_src,
BlendDst = agg::comp_op_dst,
BlendSrcOver = agg::comp_op_src_over,
BlendDstOver = agg::comp_op_dst_over,
BlendSrcIn = agg::comp_op_src_in,
BlendDstIn = agg::comp_op_dst_in,
BlendSrcOut = agg::comp_op_src_out,
BlendDstOut = agg::comp_op_dst_out,
BlendSrcAtop = agg::comp_op_src_atop,
BlendDstAtop = agg::comp_op_dst_atop,
BlendXor = agg::comp_op_xor,
BlendAdd = agg::comp_op_plus,
BlendSub = agg::comp_op_minus,
BlendMultiply = agg::comp_op_multiply,
BlendScreen = agg::comp_op_screen,
BlendOverlay = agg::comp_op_overlay,
BlendDarken = agg::comp_op_darken,
BlendLighten = agg::comp_op_lighten,
BlendColorDodge = agg::comp_op_color_dodge,
BlendColorBurn = agg::comp_op_color_burn,
BlendHardLight = agg::comp_op_hard_light,
BlendSoftLight = agg::comp_op_soft_light,
BlendDifference = agg::comp_op_difference,
BlendExclusion = agg::comp_op_exclusion,
BlendContrast = agg::comp_op_contrast
};
enum Direction
{
CW, CCW
};
};
AGG2D_TEMPLATE class Agg2D : public Agg2DBase
{
public:
typedef agg::order_bgra ComponentOrder; // Platform dependent!
typedef agg::rgba8 ColorType;
typedef agg::blender_rgba<ColorType, ComponentOrder> Blender;
typedef agg::comp_op_adaptor_rgba<ColorType, ComponentOrder> BlenderComp;
typedef agg::blender_rgba_pre<ColorType, ComponentOrder> BlenderPre;
typedef agg::comp_op_adaptor_rgba_pre<ColorType, ComponentOrder> BlenderCompPre;
// JME
//typedef agg::pixel_formats_rgba<Blender, agg::pixel32_type> PixFormat;
//typedef agg::pixfmt_bgra32 PixFormat;
// JME
//typedef agg::pixfmt_custom_blend_rgba<BlenderComp,> PixFormatComp;
typedef agg::pixfmt_custom_blend_rgba<BlenderComp,agg::rendering_buffer> PixFormatComp;
// JME
//typedef agg::pixel_formats_rgba<BlenderPre, agg::pixel32_type> PixFormatPre;
typedef agg::pixfmt_bgra32_pre PixFormatPre;
// JME
//typedef agg::pixfmt_custom_blend_rgba<BlenderCompPre> PixFormatCompPre;
typedef agg::pixfmt_custom_blend_rgba<BlenderCompPre,agg::rendering_buffer> PixFormatCompPre;
typedef agg::renderer_base<PixFormat> RendererBase;
typedef agg::renderer_base<PixFormatComp> RendererBaseComp;
typedef agg::renderer_base<PixFormatPre> RendererBasePre;
typedef agg::renderer_base<PixFormatCompPre> RendererBaseCompPre;
typedef agg::renderer_scanline_aa_solid<RendererBase> RendererSolid;
typedef agg::renderer_scanline_aa_solid<RendererBaseComp> RendererSolidComp;
typedef agg::span_allocator<ColorType> SpanAllocator;
typedef agg::pod_auto_array<ColorType, 256> GradientArray;
typedef agg::span_gradient<ColorType, agg::span_interpolator_linear<>, agg::gradient_x, GradientArray> LinearGradientSpan;
typedef agg::span_gradient<ColorType, agg::span_interpolator_linear<>, agg::gradient_circle, GradientArray> RadialGradientSpan;
#ifdef AGG2D_USE_FREETYPE
typedef agg::font_engine_freetype_int32 FontEngine;
#else
typedef agg::font_engine_win32_tt_int32 FontEngine;
#endif
typedef agg::font_cache_manager<FontEngine> FontCacheManager;
typedef FontCacheManager::gray8_adaptor_type FontRasterizer;
typedef FontCacheManager::gray8_scanline_type FontScanline;
typedef agg::conv_curve<agg::path_storage> ConvCurve;
typedef agg::conv_stroke<ConvCurve> ConvStroke;
typedef agg::conv_transform<ConvCurve> PathTransform;
typedef agg::conv_transform<ConvStroke> StrokeTransform;
enum Gradient
{
Solid,
Linear,
Radial
};
public:
AGG2D_TEMPLATE friend class Agg2DRenderer;
typedef ColorType Color;
struct State
{
RectD m_clipBox;
BlendMode m_blendMode;
BlendMode m_imageBlendMode;
Color m_imageBlendColor;
double m_masterAlpha;
double m_antiAliasGamma;
Color m_fillColor;
Color m_lineColor;
GradientArray m_fillGradient;
GradientArray m_lineGradient;
LineCap m_lineCap;
LineJoin m_lineJoin;
Gradient m_fillGradientFlag;
Gradient m_lineGradientFlag;
agg::trans_affine m_fillGradientMatrix;
agg::trans_affine m_lineGradientMatrix;
double m_fillGradientD1;
double m_lineGradientD1;
double m_fillGradientD2;
double m_lineGradientD2;
double m_textAngle;
TextAlignment m_textAlignX;
TextAlignment m_textAlignY;
bool m_textHints;
double m_fontHeight;
double m_fontAscent;
double m_fontDescent;
FontCacheType m_fontCacheType;
double m_lineWidth;
bool m_evenOddFlag;
agg::trans_affine m_transform;
agg::trans_affine m_affine;
};
~Agg2D();
Agg2D();
// Setup
//-----------------------
void attach(unsigned char* buf, unsigned width, unsigned height, int stride);
void attach(Image& img);
void clipBox(double x1, double y1, double x2, double y2);
RectD clipBox() const;
void clearAll(Color c);
void clearAll(unsigned r, unsigned g, unsigned b, unsigned a = 255);
void clearClipBox(Color c);
void clearClipBox(unsigned r, unsigned g, unsigned b, unsigned a = 255);
unsigned width() const { return m_rbuf.width(); }
unsigned height() const { return m_rbuf.height(); }
// Conversions
//-----------------------
void worldToScreen(double& x, double& y) const;
void screenToWorld(double& x, double& y) const;
double worldToScreen(double scalar) const;
double screenToWorld(double scalar) const;
void alignPoint(double& x, double& y) const;
bool inBox(double worldX, double worldY) const;
// General Attributes
//-----------------------
void blendMode(BlendMode m);
BlendMode blendMode() const;
void imageBlendMode(BlendMode m);
BlendMode imageBlendMode() const;
void imageBlendColor(Color c);
void imageBlendColor(unsigned r, unsigned g, unsigned b, unsigned a = 255);
Color imageBlendColor() const;
void masterAlpha(double a);
double masterAlpha() const;
void antiAliasGamma(double g);
double antiAliasGamma() const;
void fillColor(Color c);
void fillColor(unsigned r, unsigned g, unsigned b, unsigned a = 255);
void noFill();
void lineColor(Color c);
void lineColor(unsigned r, unsigned g, unsigned b, unsigned a = 255);
void noLine();
Color fillColor() const;
Color lineColor() const;
void fillLinearGradient(double x1, double y1, double x2, double y2, Color c1, Color c2, double profile=1.0);
void lineLinearGradient(double x1, double y1, double x2, double y2, Color c1, Color c2, double profile=1.0);
void fillRadialGradient(double x, double y, double r, Color c1, Color c2, double profile=1.0);
void lineRadialGradient(double x, double y, double r, Color c1, Color c2, double profile=1.0);
void fillRadialGradient(double x, double y, double r, Color c1, Color c2, Color c3);
void lineRadialGradient(double x, double y, double r, Color c1, Color c2, Color c3);
void fillRadialGradient(double x, double y, double r);
void lineRadialGradient(double x, double y, double r);
void lineWidth(double w);
double lineWidth(double w) const;
void lineCap(LineCap cap);
LineCap lineCap() const;
void lineJoin(LineJoin join);
LineJoin lineJoin() const;
void fillEvenOdd(bool evenOddFlag);
bool fillEvenOdd() const;
// Transformations
//-----------------------
Transformations transformations() const;
void transformations(const Transformations& tr);
const Affine& affine() const;
void affine(const Affine&);
void resetTransformations();
void matrix(const Affine& tr);
void matrix(const Transformations& tr);
void rotate(double angle);
void rotate(double angle, double cx, double cy);
void scale(double s);
void scale(double sx, double sy);
void skew(double sx, double sy);
void translate(double x, double y);
void parallelogram(double x1, double y1, double x2, double y2, const double* para);
void viewport(double worldX1, double worldY1, double worldX2, double worldY2,
double screenX1, double screenY1, double screenX2, double screenY2,
ViewportOption opt=XMidYMid, WindowFitLogic fl = WindowFitLogic_meet);
// Basic Shapes
//-----------------------
void line(double x1, double y1, double x2, double y2);
void triangle(double x1, double y1, double x2, double y2, double x3, double y3);
void rectangle(double x1, double y1, double x2, double y2);
void roundedRect(double x1, double y1, double x2, double y2, double r);
void roundedRect(double x1, double y1, double x2, double y2, double rx, double ry);
void roundedRect(double x1, double y1, double x2, double y2,
double rxBottom, double ryBottom,
double rxTop, double ryTop);
void ellipse(double cx, double cy, double rx, double ry);
void arc(double cx, double cy, double rx, double ry, double start, double sweep);
void star(double cx, double cy, double r1, double r2, double startAngle, int numRays);
void curve(double x1, double y1, double x2, double y2, double x3, double y3);
void curve(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4);
void polygon(double* xy, int numPoints);
void polyline(double* xy, int numPoints);
// Text
//-----------------------
void flipText(bool flip);
void font(const char* fileName, double height,
bool bold = false,
bool italic = false,
FontCacheType ch = RasterFontCache,
double angle = 0.0);
double fontHeight() const;
double fontAscent() const;
void textAlignment(TextAlignment alignX, TextAlignment alignY);
bool textHints() const;
void textHints(bool hints);
double textWidth(const char* str, unsigned int len);
double textWidth(const wchar_t* str, unsigned int len);
void text(double x, double y, const char* str, unsigned int len, bool roundOff=false, double dx=0.0, double dy=0.0);
void text(double x, double y, const wchar_t* str, unsigned int len, bool roundOff=false, double dx=0.0, double dy=0.0);
double textWidth(const char* str);
void text(double x, double y, const char* str, bool roundOff=false, double dx=0.0, double dy=0.0);
// Path commands
//-----------------------
void resetPath();
void moveTo(double x, double y);
void moveRel(double dx, double dy);
void lineTo(double x, double y);
void lineRel(double dx, double dy);
void horLineTo(double x);
void horLineRel(double dx);
void verLineTo(double y);
void verLineRel(double dy);
void arcTo(double rx, double ry,
double angle,
bool largeArcFlag,
bool sweepFlag,
double x, double y);
void arcRel(double rx, double ry,
double angle,
bool largeArcFlag,
bool sweepFlag,
double dx, double dy);
void quadricCurveTo(double xCtrl, double yCtrl,
double xTo, double yTo);
void quadricCurveRel(double dxCtrl, double dyCtrl,
double dxTo, double dyTo);
void quadricCurveTo(double xTo, double yTo);
void quadricCurveRel(double dxTo, double dyTo);
void cubicCurveTo(double xCtrl1, double yCtrl1,
double xCtrl2, double yCtrl2,
double xTo, double yTo);
void cubicCurveRel(double dxCtrl1, double dyCtrl1,
double dxCtrl2, double dyCtrl2,
double dxTo, double dyTo);
void cubicCurveTo(double xCtrl2, double yCtrl2,
double xTo, double yTo);
void cubicCurveRel(double xCtrl2, double yCtrl2,
double xTo, double yTo);
void addEllipse(double cx, double cy, double rx, double ry, Direction dir);
void closePolygon();
void drawPath(DrawPathFlag flag = FillAndStroke);
void drawPathNoTransform(DrawPathFlag flag = FillAndStroke);
// Image Transformations
//-----------------------
void imageFilter(ImageFilter f);
ImageFilter imageFilter() const;
void imageResample(ImageResample f);
ImageResample imageResample() const;
void transformImage(const Image& img,
int imgX1, int imgY1, int imgX2, int imgY2,
double dstX1, double dstY1, double dstX2, double dstY2);
void transformImage(const Image& img,
double dstX1, double dstY1, double dstX2, double dstY2);
void transformImage(const Image& img,
int imgX1, int imgY1, int imgX2, int imgY2,
const double* parallelogram);
void transformImage(const Image& img, const double* parallelogram);
void transformImagePath(const Image& img,
int imgX1, int imgY1, int imgX2, int imgY2,
double dstX1, double dstY1, double dstX2, double dstY2);
void transformImagePath(const Image& img,
double dstX1, double dstY1, double dstX2, double dstY2);
void transformImagePath(const Image& img,
int imgX1, int imgY1, int imgX2, int imgY2,
const double* parallelogram);
void transformImagePath(const Image& img, const double* parallelogram);
// Image Blending (no transformations available)
void blendImage(Image& img,
int imgX1, int imgY1, int imgX2, int imgY2,
double dstX, double dstY, unsigned alpha=255);
void blendImage(Image& img, double dstX, double dstY, unsigned alpha=255);
// Copy image directly, together with alpha-channel
void copyImage(Image& img,
int imgX1, int imgY1, int imgX2, int imgY2,
double dstX, double dstY);
void copyImage(Image& img, double dstX, double dstY);
// State
//-----------------------
void saveStateTo(State& st);
void restoreStateFrom(const State& st);
// Auxiliary
//-----------------------
static double pi() { return agg::pi; }
static double deg2Rad(double v) { return v * agg::pi / 180.0; }
static double rad2Deg(double v) { return v * 180.0 / agg::pi; }
PixFormat & pixFormat() { return m_pixFormat; }
private:
void render(bool fillColor);
#if !defined( UNDER_CE )
void render(FontRasterizer& ras, FontScanline& sl);
#endif
void addLine(double x1, double y1, double x2, double y2);
void updateRasterizerGamma();
void renderImage(const Image& img, int x1, int y1, int x2, int y2, const double* parl);
void updateTransformations();
agg::rendering_buffer m_rbuf;
PixFormat m_pixFormat;
PixFormatComp m_pixFormatComp;
PixFormatPre m_pixFormatPre;
PixFormatCompPre m_pixFormatCompPre;
RendererBase m_renBase;
RendererBaseComp m_renBaseComp;
RendererBasePre m_renBasePre;
RendererBaseCompPre m_renBaseCompPre;
RendererSolid m_renSolid;
RendererSolidComp m_renSolidComp;
SpanAllocator m_allocator;
RectD m_clipBox;
BlendMode m_blendMode;
BlendMode m_imageBlendMode;
Color m_imageBlendColor;
agg::scanline_u8 m_scanline;
agg::rasterizer_scanline_aa<> m_rasterizer;
double m_masterAlpha;
double m_antiAliasGamma;
Color m_fillColor;
Color m_lineColor;
GradientArray m_fillGradient;
GradientArray m_lineGradient;
LineCap m_lineCap;
LineJoin m_lineJoin;
Gradient m_fillGradientFlag;
Gradient m_lineGradientFlag;
agg::trans_affine m_fillGradientMatrix;
agg::trans_affine m_lineGradientMatrix;
double m_fillGradientD1;
double m_lineGradientD1;
double m_fillGradientD2;
double m_lineGradientD2;
double m_textAngle;
TextAlignment m_textAlignX;
TextAlignment m_textAlignY;
bool m_textHints;
double m_fontHeight;
double m_fontAscent;
double m_fontDescent;
FontCacheType m_fontCacheType;
ImageFilter m_imageFilter;
ImageResample m_imageResample;
agg::image_filter_lut m_imageFilterLut;
agg::span_interpolator_linear<> m_fillGradientInterpolator;
agg::span_interpolator_linear<> m_lineGradientInterpolator;
agg::gradient_x m_linearGradientFunction;
agg::gradient_circle m_radialGradientFunction;
double m_lineWidth;
bool m_evenOddFlag;
double m_start_x;
double m_start_y;
agg::path_storage m_path;
agg::trans_affine m_transform;
agg::trans_affine m_viewport;
agg::trans_affine m_affine;
ConvCurve m_convCurve;
ConvStroke m_convStroke;
PathTransform m_pathTransform;
StrokeTransform m_strokeTransform;
#ifndef AGG2D_USE_FREETYPE
HDC m_fontDC;
#endif
FontEngine m_fontEngine;
FontCacheManager m_fontCacheManager;
};
#include "agg2d.inl"
#endif

2471
desmume/src/agg2d.inl Normal file

File diff suppressed because it is too large Load Diff

View File

@ -66,62 +66,6 @@
typedef std::map<std::string, const agg::int8u*> TAgg_Font_Table;
static TAgg_Font_Table font_table;
const agg::int8u* AggDrawTarget::lookupFont(const std::string& name)
{
TAgg_Font_Table::iterator it(font_table.find(name));
if(it == font_table.end()) return NULL;
else return it->second;
}
void Agg_init_fonts()
{
struct font_type
{
const agg::int8u* font;
const char* name;
}
fonts[] =
{
{ agg::gse4x6, "gse4x6" },
{ agg::gse4x8, "gse4x8" },
{ agg::gse5x7, "gse5x7" },
{ agg::gse5x9, "gse5x9" },
{ agg::gse6x9, "gse6x9" },
{ agg::gse6x12, "gse6x12" },
{ agg::gse7x11, "gse7x11" },
{ agg::gse7x11_bold, "gse7x11_bold" },
{ agg::gse7x15, "gse7x15" },
{ agg::gse7x15_bold, "gse7x15_bold" },
{ agg::gse8x16, "gse8x16" },
{ agg::gse8x16_bold, "gse8x16_bold" },
{ agg::mcs11_prop, "mcs11_prop" },
{ agg::mcs11_prop_condensed, "mcs11_prop_condensed" },
{ agg::mcs12_prop, "mcs12_prop" },
{ agg::mcs13_prop, "mcs13_prop" },
{ agg::mcs5x10_mono, "mcs5x10_mono" },
{ agg::mcs5x11_mono, "mcs5x11_mono" },
{ agg::mcs6x10_mono, "mcs6x10_mono" },
{ agg::mcs6x11_mono, "mcs6x11_mono" },
{ agg::mcs7x12_mono_high, "mcs7x12_mono_high" },
{ agg::mcs7x12_mono_low, "mcs7x12_mono_low" },
{ agg::verdana12, "verdana12" },
{ agg::verdana12_bold, "verdana12_bold" },
{ agg::verdana13, "verdana13" },
{ agg::verdana13_bold, "verdana13_bold" },
{ agg::verdana14, "verdana14" },
{ agg::verdana14_bold, "verdana14_bold" },
{ agg::verdana16, "verdana16" },
{ agg::verdana16_bold, "verdana16_bold" },
{ agg::verdana17, "verdana17" },
{ agg::verdana17_bold, "verdana17_bold" },
{ agg::verdana18, "verdana18" },
{ agg::verdana18_bold, "verdana18_bold" },
};
for(int i=0;i<ARRAY_SIZE(fonts);i++)
font_table[fonts[i].name] = fonts[i].font;
}
AggDraw_Desmume aggDraw;
typedef AggDrawTargetImplementation<agg::pixfmt_rgb555> T_AGG_RGB555;
@ -139,7 +83,7 @@ static AggDrawTarget* targets[] = {
void Agg_init()
{
Agg_init_fonts();
//Agg_init_fonts();
aggDraw.target = targets[0];
}
@ -155,9 +99,10 @@ void AggDraw_Desmume::composite(void* dest)
agg::rendering_buffer rBuf;
rBuf.attach((u8*)dest, 256, 384, 1024);
typedef agg::image_accessor_clip<T_AGG_RGBA::pixfmt> img_source_type;
img_source_type img_src(agg_targetLua.pixf, T_AGG_RGBA::pixfmt::color_type(0,255,0,0));
img_source_type img_src(agg_targetLua.pixFormat(), T_AGG_RGBA::pixfmt::color_type(0,255,0,0));
agg::trans_affine img_mtx;
typedef agg::span_interpolator_linear<> interpolator_type;
@ -188,174 +133,42 @@ void AggDraw_Desmume::composite(void* dest)
agg::render_scanlines_bin(ras, sl, rbase, sa, sg);
}
static int ctr=0;
//temporary, just for testing the lib
//
//static int ctr=0;
//
////temporary, just for testing the lib
void AGGDraw() {
//
aggDraw.setTarget(AggTarget_Lua);
//
// aggDraw.target->clear();
//
// ctr++;
//
aggDraw.target->clear();
ctr++;
aggDraw.target->set_color(0, 255, 0, 128);
int add = (int)(40*cos((double)ctr/20.0f));
aggDraw.target->solid_rectangle(100 +add , 100, 200 + add, 200);
aggDraw.target->set_gamma(99999);
aggDraw.target->set_color(255, 64, 64, 128);
aggDraw.target->solid_triangle(0, 60, 200, 170, 100, 310);
aggDraw.target->set_color(255, 0, 0, 128);
aggDraw.target->solid_ellipse(70, 80, 50, 50);
aggDraw.target->set_font("verdana18_bold");
aggDraw.target->set_color(255, 0, 255, 255);
aggDraw.target->render_text(60,60, "testing testing testing");
aggDraw.target->line(60, 90, 100, 100, 4);
aggDraw.target->marker(200, 200, 40, 4);
aggDraw.target->marker(100, 300, 40, 3);
//
//agg_draw_line_pattern(64, 19, 14, 126, 118, 266, 19, 265, .76, 4.69, "C:\\7.bmp");
aggDraw.target->lineColor(0, 255, 0, 128);
aggDraw.target->noFill();
// int add = (int)(40*cos((double)ctr/20.0f));
aggDraw.target->roundedRect(0.5, 0.5, 600-0.5, 600-0.5, 20.0);
//
// aggDraw.target->set_gamma(99999);
// aggDraw.target->set_color(255, 64, 64, 128);
// aggDraw.target->solid_triangle(0, 60, 200, 170, 100, 310);
//
// aggDraw.target->set_color(255, 0, 0, 128);
// aggDraw.target->solid_ellipse(70, 80, 50, 50);
//
// aggDraw.target->set_font("verdana18_bold");
// aggDraw.target->set_color(255, 0, 255, 255);
// aggDraw.target->render_text(60,60, "testing testing testing");
//
// aggDraw.target->line(60, 90, 100, 100, 4);
//
// aggDraw.target->marker(200, 200, 40, 4);
// aggDraw.target->marker(100, 300, 40, 3);
// //
// //agg_draw_line_pattern(64, 19, 14, 126, 118, 266, 19, 265, .76, 4.69, "C:\\7.bmp");
}
//static agg::int8u brightness_to_alpha[256 * 3] =
//{
// 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
// 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
// 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
// 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
// 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
// 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
// 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
// 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
// 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
// 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 254, 254, 254, 254, 254,
// 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
// 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
// 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
// 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
// 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
// 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
// 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
// 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
// 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
// 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
// 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
// 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
// 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
// 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 253, 253,
// 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 252,
// 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 251, 251, 251, 251, 251,
// 251, 251, 251, 251, 250, 250, 250, 250, 250, 250, 250, 250, 249, 249, 249, 249,
// 249, 249, 249, 248, 248, 248, 248, 248, 248, 248, 247, 247, 247, 247, 247, 246,
// 246, 246, 246, 246, 246, 245, 245, 245, 245, 245, 244, 244, 244, 244, 243, 243,
// 243, 243, 243, 242, 242, 242, 242, 241, 241, 241, 241, 240, 240, 240, 239, 239,
// 239, 239, 238, 238, 238, 238, 237, 237, 237, 236, 236, 236, 235, 235, 235, 234,
// 234, 234, 233, 233, 233, 232, 232, 232, 231, 231, 230, 230, 230, 229, 229, 229,
// 228, 228, 227, 227, 227, 226, 226, 225, 225, 224, 224, 224, 223, 223, 222, 222,
// 221, 221, 220, 220, 219, 219, 219, 218, 218, 217, 217, 216, 216, 215, 214, 214,
// 213, 213, 212, 212, 211, 211, 210, 210, 209, 209, 208, 207, 207, 206, 206, 205,
// 204, 204, 203, 203, 202, 201, 201, 200, 200, 199, 198, 198, 197, 196, 196, 195,
// 194, 194, 193, 192, 192, 191, 190, 190, 189, 188, 188, 187, 186, 186, 185, 184,
// 183, 183, 182, 181, 180, 180, 179, 178, 177, 177, 176, 175, 174, 174, 173, 172,
// 171, 171, 170, 169, 168, 167, 166, 166, 165, 164, 163, 162, 162, 161, 160, 159,
// 158, 157, 156, 156, 155, 154, 153, 152, 151, 150, 149, 148, 148, 147, 146, 145,
// 144, 143, 142, 141, 140, 139, 138, 137, 136, 135, 134, 133, 132, 131, 130, 129,
// 128, 128, 127, 125, 124, 123, 122, 121, 120, 119, 118, 117, 116, 115, 114, 113,
// 112, 111, 110, 109, 108, 107, 106, 105, 104, 102, 101, 100, 99, 98, 97, 96,
// 95, 94, 93, 91, 90, 89, 88, 87, 86, 85, 84, 82, 81, 80, 79, 78,
// 77, 75, 74, 73, 72, 71, 70, 69, 67, 66, 65, 64, 63, 61, 60, 59,
// 58, 57, 56, 54, 53, 52, 51, 50, 48, 47, 46, 45, 44, 42, 41, 40,
// 39, 37, 36, 35, 34, 33, 31, 30, 29, 28, 27, 25, 24, 23, 22, 20,
// 19, 18, 17, 15, 14, 13, 12, 11, 9, 8, 7, 6, 4, 3, 2, 1
//};
//
//template<class Pattern,class Rasterizer,class Renderer,class PatternSource,class VertexSource>
//void draw_curve(Pattern& patt,Rasterizer& ras,Renderer& ren,PatternSource& src,VertexSource& vs, double scale, double start)
//{
// patt.create(src);
// ren.scale_x(scale);
// ren.start_x(start);
// ras.add_path(vs);
//}
//
//class pattern_src_brightness_to_alpha_rgba8
//{
//public:
// pattern_src_brightness_to_alpha_rgba8(agg::rendering_buffer& rb) :
// m_rb(&rb), m_pf(*m_rb) {}
//
// unsigned width() const { return m_pf.width(); }
// unsigned height() const { return m_pf.height(); }
// agg::rgba8 pixel(int x, int y) const
// {
// agg::rgba8 c = m_pf.pixel(x, y);
// c.a = brightness_to_alpha[c.r + c.g + c.b];
// return c;
// }
//
//private:
// agg::rendering_buffer* m_rb;
// pixfmt m_pf;
//};
//
// void agg_draw_line_pattern(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, double scale, double start, char* filename){
//
// int flipy = 0;
//
// agg::platform_support platsup(agg::pix_format_rgb555, flipy);
//
// platsup.load_img(0, filename);
//
// agg::bezier_ctrl<agg::rgba8> m_curve1;
//
// typedef agg::rasterizer_scanline_aa<> rasterizer_scanline;
// typedef agg::scanline_p8 scanline;
//
// m_curve1.curve(x1, y1, x2, y2, x3, y3, x4, y4);
// m_curve1.no_transform();
//
// rBuf.attach(GPU_tempScreen, width, height, stride);
//
// pixfmt pixf(rBuf);
// RendererBase ren_base(pixf);
// RendererSolid ren(ren_base);
//
// rasterizer_scanline ras;
// scanline sl;
//
// // Pattern source. Must have an interface:
// // width() const
// // height() const
// // pixel(int x, int y) const
// // Any agg::renderer_base<> or derived
// // is good for the use as a source.
// //-----------------------------------
// pattern_src_brightness_to_alpha_rgba8 p1(platsup.rbuf_img(0));
//
// agg::pattern_filter_bilinear_rgba8 fltr; // Filtering functor
//
// // agg::line_image_pattern is the main container for the patterns. It creates
// // a copy of the patterns extended according to the needs of the filter.
// // agg::line_image_pattern can operate with arbitrary image width, but if the
// // width of the pattern is power of 2, it's better to use the modified
// // version agg::line_image_pattern_pow2 because it works about 15-25 percent
// // faster than agg::line_image_pattern (because of using simple masking instead
// // of expensive '%' operation).
// typedef agg::line_image_pattern<agg::pattern_filter_bilinear_rgba8> pattern_type;
// typedef agg::renderer_base<pixfmt> base_ren_type;
// typedef agg::renderer_outline_image<base_ren_type, pattern_type> renderer_type;
// typedef agg::rasterizer_outline_aa<renderer_type> rasterizer_type;
//
// //-- Create uninitialized and set the source
// pattern_type patt(fltr);
// renderer_type ren_img(ren_base, patt);
// rasterizer_type ras_img(ren_img);
//
// draw_curve(patt, ras_img, ren_img, p1, m_curve1.curve(), scale, start);
// }

View File

@ -39,172 +39,47 @@
#include "agg_renderer_outline_aa.h"
#include "agg_renderer_markers.h"
#include "agg2d.h"
class AggDrawTarget
{
public:
virtual void set_color(int r, int g, int b, int a) = 0;
virtual void set_gamma(int gamma) = 0;
virtual void set_font(const std::string& name) = 0;
virtual void set_pixel(int x, int y) = 0;
virtual void clear() = 0;
virtual void render_text(int x, int y, const std::string& str) = 0;
virtual void solid_ellipse(int x, int y, int rx, int ry) = 0;
virtual void solid_rectangle(int x1, int y1, int x2, int y2) = 0;
virtual void solid_triangle(int x1, int y1, int x2, int y2, int x3, int y3) = 0;
virtual void line(int x1, int y1, int x2, int y2, double w) = 0;
virtual void marker(int x, int y, int size, int type) = 0;
static const agg::int8u* lookupFont(const std::string& name);
virtual void lineColor(unsigned r, unsigned g, unsigned b, unsigned a) = 0;
virtual void noFill() = 0;
virtual void roundedRect(double x1, double y1, double x2, double y2,double rx_bottom, double ry_bottom,double rx_top, double ry_top) = 0;
virtual void roundedRect(double x1, double y1, double x2, double y2, double r) = 0;
virtual void roundedRect(double x1, double y1, double x2, double y2, double rx, double ry) = 0;
};
template<typename PIXFMT>
class AggDrawTargetImplementation : public AggDrawTarget
class AggDrawTargetImplementation : public AggDrawTarget, public Agg2D<PIXFMT>
{
public:
public:
typedef PIXFMT pixfmt;
// The AGG base
typedef agg::renderer_base<pixfmt> RendererBase;
// The AGG primitives renderer
typedef agg::renderer_primitives<RendererBase> RendererPrimitives;
// The AGG solid renderer
typedef agg::renderer_scanline_aa_solid<RendererBase> RendererSolid;
//the order of declaration matters in order to make these variables get setup correctly
agg::rendering_buffer rBuf;
pixfmt pixf;
RendererBase rbase;
RendererPrimitives rprim;
AggDrawTargetImplementation(agg::int8u* buf, int width, int height, int stride)
: rBuf(buf,width,height,stride)
, pixf(rBuf)
, rbase(pixf)
, rprim(rbase)
{
}
typedef typename pixfmt::color_type color_type;
struct TRenderState
{
TRenderState()
: color(0,0,0,255)
, gamma(99999)
, font(NULL)
{}
color_type color;
int gamma;
const agg::int8u* font;
} renderState;
virtual void set_color(int r, int g, int b, int a) { renderState.color = color_type(r,g,b,a); }
virtual void set_gamma(int gamma) { renderState.gamma = gamma; }
virtual void set_font(const std::string& name) { renderState.font = lookupFont(name); }
virtual void set_pixel(int x, int y)
typedef Agg2D<PIXFMT> BASE;
AggDrawTargetImplementation(agg::int8u* buf, int width, int height, int stride)
{
pixf.copy_pixel(x, y, renderState.color);
attach(buf,width,height,stride);
BASE::viewport(0, 0, 600, 600,
0, 0, width, height,
//TAGG2D::Anisotropic);
XMidYMid);
}
virtual void clear()
virtual void lineColor(unsigned r, unsigned g, unsigned b, unsigned a) { BASE::lineColor(r,g,b,a); }
virtual void noFill() { BASE::noFill(); }
virtual void roundedRect(double x1, double y1, double x2, double y2,double rx_bottom, double ry_bottom,double rx_top,double ry_top)
{
static color_type transparentBlack(0,0,0,0);
rbase.clear(transparentBlack);
BASE::roundedRect(x1,y1,x2,y2,rx_bottom,ry_bottom,rx_top,ry_top);
}
virtual void render_text(int x, int y, const std::string& str)
{
typedef agg::renderer_base<pixfmt> ren_base;
typedef agg::glyph_raster_bin<agg::rgba8> glyph_gen;
glyph_gen glyph(0);
ren_base rb(pixf);
agg::renderer_raster_htext_solid<ren_base, glyph_gen> rt(rb, glyph);
rt.color(renderState.color);
glyph.font(renderState.font);
rt.render_text(x, y, str.c_str(), true); //flipy
}
virtual void solid_ellipse(int x, int y, int rx, int ry)
{
rprim.fill_color(renderState.color);
rprim.solid_ellipse(x, y, rx, ry);
}
virtual void solid_rectangle(int x1, int y1, int x2, int y2)
{
rprim.fill_color(renderState.color);
rprim.solid_rectangle(x1, y1, x2, y2);
}
virtual void solid_triangle(int x1, int y1, int x2, int y2, int x3, int y3)
{
RendererSolid ren_aa(rbase);
agg::rasterizer_scanline_aa<> m_ras;
agg::scanline_p8 m_sl_p8;
agg::path_storage path;
path.move_to(x1, y1);
path.line_to(x2, y2);
path.line_to(x3, y3);
path.close_polygon();
ren_aa.color(renderState.color);
m_ras.gamma(agg::gamma_power(renderState.gamma * 2.0));
m_ras.add_path(path);
agg::render_scanlines(m_ras, m_sl_p8, ren_aa);
}
virtual void line(int x1, int y1, int x2, int y2, double w)
{
agg::line_profile_aa profile;
profile.width(w);
typedef agg::renderer_mclip<pixfmt> base_ren_type;
typedef agg::renderer_outline_aa<base_ren_type> renderer_type;
base_ren_type r(pixf);
renderer_type ren(r, profile);
agg::rasterizer_outline_aa<renderer_type> ras(ren);
ras.round_cap(true);
ren.color(renderState.color);
ras.move_to_d(x1, y1);
ras.line_to_d(x2, y2);
ras.render(false);
}
virtual void marker(int x, int y, int size, int type)
{
typedef agg::renderer_mclip<pixfmt> base_ren_type;
base_ren_type r(pixf);
agg::renderer_scanline_aa_solid<base_ren_type> rs(r);
agg::renderer_markers<base_ren_type> m(r);
m.line_color(renderState.color);
m.fill_color(renderState.color);
m.marker(x, y, size, agg::marker_e(type % agg::end_of_markers));
}
virtual void roundedRect(double x1, double y1, double x2, double y2, double r) { BASE::roundedRect(x1,y1,x2,y2,r); }
virtual void roundedRect(double x1, double y1, double x2, double y2, double rx, double ry) { BASE::roundedRect(x1,y1,x2,y2,rx,ry); }
};
class AggDraw
{
public:

View File

@ -86,6 +86,7 @@
#include "directx/ddraw.h"
#include "aggdraw.h"
#include "agg2d.h"
using namespace std;
@ -776,8 +777,8 @@ void Display()
ddsd.dwFlags=DDSD_ALL;
res = lpBackSurface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
extern void AGGDraw();
AGGDraw();
//extern void AGGDraw(); AGGDraw();
if (res == DD_OK)
{
@ -893,6 +894,9 @@ void Display()
break;
}
//extern void AGGDraw(unsigned char * buffer); AGGDraw((unsigned char*) ddsd.lpSurface);
lpBackSurface->Unlock((LPRECT)ddsd.lpSurface);
// Main screen