16 #include <agg_conv_stroke.h> 17 #include <agg_conv_transform.h> 18 #include <agg_ellipse.h> 19 #include <agg_image_accessors.h> 20 #include <agg_pixfmt_rgba.h> 21 #include <agg_rasterizer_scanline_aa.h> 22 #include <agg_renderer_base.h> 23 #include <agg_renderer_scanline.h> 24 #include <agg_scanline_p.h> 25 #include <agg_span_allocator.h> 26 #include <agg_span_image_filter_rgba.h> 27 #include <agg_span_interpolator_linear.h> 43 const agg::rgba8 transparentWhiteColor (0xff, 0xff, 0xff, 0);
45 double srcWidth = src.width();
46 double srcHeight = src.height();
51 matrix.scale(width / srcWidth, height / srcHeight);
52 matrix.translate(x, y);
57 invertMatrix.invert();
59 InterpolatorType interpolator (invertMatrix);
60 ImageAccessorType ia (src.ren(), transparentWhiteColor);
61 SpanGeneratorType sg (ia, interpolator);
66 (double)x + width, (
double)y,
67 (double)x + width, (
double)y + height,
68 (double)x, (
double)y + height,
73 SimplePath path(rect,
sizeof(rect) /
sizeof(
double));
81 agg::render_scanlines_aa(ras, scanline, dst, sa, sg);
85 main (
int argc,
const char* argv[])
89 const int iconWidth = 200;
90 const int iconHeight = 200;
91 const int imageWidth = 400;
92 const int imageHeight = 400;
94 const agg::rgba8 transparentWhiteColor (0xff, 0xff, 0xff, 0);
95 const agg::rgba8 whiteColor (0xff, 0xff, 0xff, 0xff);
98 ras.auto_close(
false);
102 const int pixelSize = PixelFormat::pix_width;
108 const double PI = 3.14159265358979;
110 unsigned char *iconImageBuffer =
new unsigned char[iconWidth * iconHeight * pixelSize];
116 iconRenderBuffer.attach (iconImageBuffer, iconWidth, iconHeight, iconWidth * pixelSize);
117 iconPixFmt.attach(iconRenderBuffer);
118 iconRBase.attach(iconPixFmt);
120 iconRBase.clear(transparentWhiteColor);
126 ras.add_path(circle);
127 agg::render_scanlines_aa_solid(ras, scanline, iconRBase, whiteColor);
140 { 0xfe, 0xfe, 0x33, 0xff },
141 { 0xfb, 0x99, 0x02, 0xff },
142 { 0xfa, 0xbc, 0x02, 0xff },
143 { 0xfe, 0x27, 0x12, 0xff },
144 { 0xfd, 0x53, 0x08, 0xff },
145 { 0x86, 0x01, 0xaf, 0xff },
146 { 0xa7, 0x19, 0x4b, 0xff },
147 { 0x02, 0x47, 0xfe, 0xff },
148 { 0x3d, 0x01, 0xa4, 0xff },
149 { 0x66, 0xb0, 0x32, 0xff },
150 { 0x03, 0x91, 0xce, 0xff },
151 { 0xd0, 0xea, 0x2b, 0xff }
153 SimplePath path (triangle,
sizeof(triangle) /
sizeof(
double));
155 int numRotations =
sizeof(colors) /
sizeof(
agg::rgba8);
156 for (
int i = 0; i < numRotations; ++i)
159 matrix.rotate( PI * 2 * i / numRotations);
160 matrix.translate(100, 100);
166 agg::render_scanlines_aa_solid(ras, scanline, iconRBase, colors[i]);
173 ras.add_path(innerCircle);
174 agg::render_scanlines_aa_solid(ras, scanline, iconRBase, whiteColor);
178 char fileName[1000] = { 0 };
181 sprintf (fileName,
"%s/", argv[1]);
183 strcat(fileName,
"tutorial_image_icon.png");
184 writePng<RendererBaseType> (fileName, iconRBase);
192 unsigned char *imageBuffer =
new unsigned char[imageWidth * imageHeight * pixelSize];
195 renderBuffer.attach (imageBuffer, imageWidth, imageHeight, imageWidth * pixelSize);
196 pixFmt.attach(renderBuffer);
197 rBase.attach(pixFmt);
199 const agg::rgba8 greenColor (0, 0xff, 0, 0xff);
202 rBase.clear(greenColor);
208 drawImage (rBase, iconRBase, 0, 0, 25, 25);
209 drawImage (rBase, iconRBase, 25, 25, 50, 50);
210 drawImage (rBase, iconRBase, 75, 75, 100, 100);
211 drawImage (rBase, iconRBase, 175, 175, 200, 200);
215 char fileName[1000] = { 0 };
218 sprintf (fileName,
"%s/", argv[1]);
220 strcat(fileName,
"tutorial_image_1.png");
221 writePng<RendererBaseType> (fileName, rBase);
223 delete iconImageBuffer;
228 printf (
"%s\n", ex.getMessage());
233 printf (
"Unknown exception detected.\n");