17 #include <agg_conv_stroke.h> 18 #include <agg_conv_transform.h> 19 #include <agg_ellipse.h> 20 #include <agg_alpha_mask_u8.h> 21 #include <agg_pixfmt_amask_adaptor.h> 22 #include <agg_pixfmt_rgba.h> 23 #include <agg_rasterizer_scanline_aa.h> 24 #include <agg_renderer_base.h> 25 #include <agg_renderer_scanline.h> 26 #include <agg_scanline_p.h> 27 #include <agg_scanline_u.h> 28 #include <agg_span_allocator.h> 29 #include <agg_span_interpolator_linear.h> 30 #include <agg_span_gradient.h> 39 template<
class SrcPixelFormat>
41 drawIcon(SrcPixelFormat& pixFmt,
int x,
int y,
int width,
int height)
44 SrcPixelFormat dstPixFmt (renBuffer);
45 dstPixFmt.attach (pixFmt, x, y , x + width - 1, y + height - 1);
49 ras.auto_close(
false);
58 double strokeWidth = 10.0;
59 strokePath.width(strokeWidth);
60 strokePath.line_cap(agg::butt_cap);
61 strokePath.line_join(agg::miter_join);
62 strokePath.miter_limit(strokeWidth);
65 ras.add_path(strokePath);
66 const agg::rgba8 purpleColor (0xee, 0, 0xcc, 0xcc);
67 agg::render_scanlines_aa_solid(ras, scanline, rBase, purpleColor);
80 ColorFunctionType> SpanGradientType;
84 GradientFunctionType gradientFunction;
86 matrix.translate (70, 70);
89 invertMatrix.invert();
90 InterpolatorType interpolator (invertMatrix);
92 ColorFunctionType colorFunction (agg::rgba8 (0xff, 0xd7, 0, 0xff),
93 agg::rgba8 (0xff, 0, 0, 0xff),
96 SpanGradientType sg (interpolator, gradientFunction, colorFunction, 0.0, 60.0);
103 agg::render_scanlines_aa(ras, scanline, rBase, sa, sg);
107 template<
class PixelFormat,
class Path,
class AlphaMaskType>
109 drawAMPath(
PixelFormat& pixFmt, Path& path,
const agg::rgba8& color, AlphaMaskType &alphaMask,
int x,
int y,
int width,
int height)
113 subPixFmt.attach (pixFmt, x, y , x + width - 1, y + height - 1);
118 AMPixelFormat amPixFmt (subPixFmt, alphaMask);
119 AMRendererBaseType amRBase (amPixFmt);
124 ras.auto_close(
false);
129 agg::render_scanlines(ras, scanline, amrs);
132 template<
class PixFormat,
class BlurType>
134 blurImage(PixFormat& pixFmt,
int x,
int y,
int width,
int height, BlurType& blur,
double radius)
137 PixFormat subPixFmt (renBuffer);
138 subPixFmt.attach (pixFmt, x, y , x + width - 1, y + height - 1);
139 blur.blur (subPixFmt, radius);
143 main (
int argc,
const char* argv[])
147 const int imageWidth = 800;
148 const int imageHeight = 200;
149 const int iconWidth = 200;
150 const int iconHeight = 200;
153 ras.auto_close(
false);
157 const int pixelSize = PixelFormat::pix_width;
159 const double PI = 3.14159265358979;
160 const agg::rgba8 blackColor(0, 0, 0, 0xff);
161 const agg::rgba8 whiteColor (0xff, 0xff, 0xff, 0xff);
162 const agg::rgba8 transparentWhiteColor (0xff, 0xff, 0xff, 0);
164 unsigned char *imageBuffer =
new unsigned char[imageWidth * imageHeight * pixelSize];
168 rBase.clear(whiteColor);
170 unsigned char *iconBuffer =
new unsigned char[iconWidth * iconHeight * pixelSize];
174 iconRBase.clear(transparentWhiteColor);
184 SimplePath path (square,
sizeof(square) /
sizeof(
double));
187 drawIcon (pixFmt, 0, 0, 200, 200);
189 drawIcon (iconPixFmt, 0, 0, 200, 200);
193 AlphaMaskType alphaMask (iconRenderBuffer);
196 drawAMPath (pixFmt, path, blackColor, alphaMask, 200, 0, 200, 200);
200 drawAMPath (pixFmt, path, blackColor, alphaMask, 400, 0, 200, 200);
202 blurImage (pixFmt, 400, 0, 200, 200, blur, 10);
206 drawAMPath (pixFmt, path, blackColor, alphaMask, 600 + 5, 0 + 5, 200, 200);
208 blurImage (pixFmt, 600 + 5, 0 + 5, 200, 200, blur, 10);
209 drawIcon (pixFmt, 600, 0, 200, 200);
214 char fileName[1000] = { 0 };
217 sprintf (fileName,
"%s/", argv[1]);
219 strcat(fileName,
"tutorial_alphamask.png");
220 writePng<RendererBaseType> (fileName, rBase);
226 printf (
"%s\n", ex.getMessage());
231 printf (
"Unknown exception detected.\n");