16 #include <agg_conv_stroke.h> 17 #include <agg_image_accessors.h> 18 #include <agg_pixfmt_rgba.h> 19 #include <agg_rasterizer_scanline_aa.h> 20 #include <agg_renderer_base.h> 21 #include <agg_renderer_scanline.h> 22 #include <agg_scanline_p.h> 23 #include <agg_span_allocator.h> 24 #include <agg_span_image_filter_rgba.h> 25 #include <agg_span_interpolator_linear.h> 36 template<
class RBaseType1,
class RBaseType2>
38 drawImage(RBaseType1& dst, RBaseType2& src,
int x,
int y,
int width,
int height)
45 const agg::rgba8 transparentWhiteColor (0xff, 0xff, 0xff, 0);
47 double srcWidth = src.width();
48 double srcHeight = src.height();
53 matrix.scale(width / srcWidth, height / srcHeight);
54 matrix.translate(x, y);
59 invertMatrix.invert();
61 InterpolatorType interpolator (invertMatrix);
62 ImageAccessorType ia (src.ren(), transparentWhiteColor);
63 SpanGeneratorType sg (ia, interpolator);
68 (double)x + width, (
double)y,
69 (double)x + width, (
double)y + height,
70 (double)x, (
double)y + height,
75 SimplePath path(rect,
sizeof(rect) /
sizeof(
double));
83 agg::render_scanlines_aa(ras, scanline, dst, sa, sg);
88 main (
int argc,
const char* argv[])
92 const int imageWidth = 400;
93 const int imageHeight = 400;
96 const int pixelSize = PixelFormat::pix_width;
102 unsigned char *imageBuffer =
new unsigned char[imageWidth * imageHeight * pixelSize];
105 renderBuffer.attach (imageBuffer, imageWidth, imageHeight, imageWidth * pixelSize);
106 pixFmt.attach(renderBuffer);
107 rBase.attach(pixFmt);
109 const agg::rgba8 transparentWhiteColor (0xff, 0xff, 0xff, 0);
110 const agg::rgba8 greenColor (0, 0xff, 0, 0x7f);
114 rBase.clear(transparentWhiteColor);
119 ras.auto_close(
false);
123 double centerSquare[] =
132 SimplePath path (centerSquare,
sizeof(centerSquare) /
sizeof(
double));
137 agg::render_scanlines_aa_solid(ras, scanline, rBase, redColor);
149 SimplePath path (square,
sizeof(square) /
sizeof(
double));
156 agg::render_scanlines_aa_solid(ras, scanline, rBase, greenColor);
165 unsigned char *layerImageBuffer =
new unsigned char[200 * 200 * pixelSize];
168 layerBuffer.attach (layerImageBuffer, 200, 200, 200 * pixelSize);
169 layerPixFmt.attach(layerBuffer);
170 layerRBase.attach(layerPixFmt);
181 SimplePath path (square,
sizeof(square) /
sizeof(
double));
186 agg::render_scanlines_aa_solid(ras, scanline, layerRBase, greenColor);
188 drawImage (rBase, layerRBase, 200, 0, 200, 200);
197 unsigned char *layerImageBuffer =
new unsigned char[200 * 200 * pixelSize];
200 layerBuffer.attach (layerImageBuffer, 200, 200, 200 * pixelSize);
201 layerPixFmt.attach(layerBuffer);
202 layerRBase.attach(layerPixFmt);
213 SimplePath path (square,
sizeof(square) /
sizeof(
double));
218 agg::render_scanlines_aa_solid(ras, scanline, layerRBase, greenColor);
220 drawImage (rBase, layerRBase, 0, 200, 200, 200);
224 char fileName[1000] = { 0 };
227 sprintf (fileName,
"%s/", argv[1]);
229 strcat(fileName,
"tutorial_layer.png");
230 writePng<RendererBaseType> (fileName, rBase);
236 printf (
"%s\n", ex.getMessage());
241 printf (
"Unknown exception detected.\n");