Crate agg

source ·
Expand description

Anti Grain Geometry - Rust implementation

Originally derived from version 2.4 of AGG

This crate implments the drawing / painting 2D algorithms developed in the Anti Grain Geometry C++ library. Quoting from the author in the documentation:

Anti-Grain Geometry is not a solid graphic library and it’s not very easy to use. I consider AGG as a “tool to create other tools”. It means that there’s no “Graphics” object or something like that, instead, AGG consists of a number of loosely coupled algorithms that can be used together or separately. All of them have well defined interfaces and absolute minimum of implicit or explicit dependencies.

Anti-Aliasing and Subpixel Accuracy

One primary strenght of AGG are the combination of drawing with subpixel accuracy with anti-aliasing effects. There are many examples within the documentation and reproduced here.

Drawing

There are multiple ways to put / draw pixels including:

  • Scanline Renderers
    • Antialiased or Aliased (Binary)
  • Outline Renderer, possibly with Images
  • Raw Pixel Manipulation

Scanline Renderer

The multitude of renderers here include render_scanlines, render_all_paths, render_scanlines_aa_solid and render_scanlines_bin_solid

  use agg::PixelData;
  use agg::Render;
  // Create a blank image 10x10 pixels
  let pix = agg::Pixfmt::<agg::Rgb8>::new(100,100);
  let mut ren_base = agg::RenderingBase::new(pix);
  ren_base.clear(agg::Rgba8::white());
  // Draw a polygon from (10,10) - (50,90) - (90,10)
  let mut ras = agg::RasterizerScanline::new();
  ras.move_to_d(10.0, 10.0);
  ras.line_to_d(50.0, 90.0);
  ras.line_to_d(90.0, 10.0);
  // Render the line to the image
  let mut ren = agg::RenderingScanlineAASolid::with_base(&mut ren_base);
  ren.color(&agg::Rgba8::black());
  agg::render_scanlines(&mut ras, &mut ren);
  // Save the image to a file
  agg::ppm::write_ppm(&ren_base.pixeldata(), 100,100,
                      "little_black_triangle.ppm").unwrap();

Outline AntiAlias Renderer

   use agg::{Pixfmt,Rgb8,Rgba8,RenderingBase,SetColor};
   use agg::{RendererOutlineAA,RasterizerOutlineAA};
   use agg::PixelData;
   let pix = Pixfmt::<Rgb8>::new(100,100);
   let mut ren_base = agg::RenderingBase::new(pix);
   ren_base.clear( Rgba8::new(255, 255, 255, 255) );

   let mut ren = RendererOutlineAA::with_base(&mut ren_base);
   ren.color(agg::Rgba8::new(102,77,26,255));
   ren.profile.width(3.0);

   let mut path = agg::PathStorage::new();
   path.move_to(10.0, 10.0);
   path.line_to(50.0, 90.0);
   path.line_to(90.0, 10.0);

   let mut ras = RasterizerOutlineAA::with_renderer(&mut ren);
   ras.add_path(&path);
   agg::ppm::write_ppm(&ren_base.pixeldata(), 100,100,
         "outline_aa.ppm").unwrap();

Primative Renderer

Render for primative shapes: lines, rectangles, and ellipses; filled or outlined.

   use agg::{Pixfmt,Rgb8,Rgba8,RenderingBase,SetColor};
   use agg::{RendererPrimatives,RasterizerOutline};
   use agg::PixelData;
   let pix = Pixfmt::<Rgb8>::new(100,100);
   let mut ren_base = agg::RenderingBase::new(pix);
   ren_base.clear( Rgba8::new(255, 255, 255, 255) );

   let mut ren = RendererPrimatives::with_base(&mut ren_base);
   ren.line_color(agg::Rgba8::new(0,0,0,255));

   let mut path = agg::PathStorage::new();
   path.move_to(10.0, 10.0);
   path.line_to(50.0, 90.0);
   path.line_to(90.0, 10.0);

   let mut ras = RasterizerOutline::with_primative(&mut ren);
   ras.add_path(&path);
   agg::ppm::write_ppm(&ren_base.pixeldata(), 100,100,
         "primative.ppm").unwrap();

Raw Pixel Manipulation

Note: Functions here are a somewhat low level interface and probably not what you want to use.

Functions to set pixel color through Pixfmt are clear, set, copy_pixel, copy_hline, copy_vline, fill

Functions to blend colors with existing pixels through Pixfmt are copy_or_blend_pix, copy_or_blend_pix_with_cover, blend_hline, blend_vline, blend_solid_hspan, blend_solid_vspan, blend_color_hspan, blend_color_vspan

Re-exports

pub use freetype as ft;
pub use crate::path_storage::*;
pub use crate::conv_stroke::*;
pub use crate::affine_transform::*;
pub use crate::color::*;
pub use crate::pixfmt::*;
pub use crate::base::*;
pub use crate::clip::*;
pub use crate::cell::*;
pub use crate::raster::*;
pub use crate::alphamask::*;
pub use crate::render::*;
pub use crate::text::*;
pub use crate::line_interp::*;
pub use crate::outline::*;
pub use crate::outline_aa::*;

Modules

Affine Transforms
Alphamask Adapator
Rendering Base
Rendering buffer
Rendering Cells
Clipping Region
Colors
Pixel Format
Writing of PPM (Portable Pixmap Format) files
Rasterizer
Renderer
Scanlines

Structs

Enums

Traits

Access Color properties and compoents
Access raw color component data at the pixel level
Render scanlines to Image
Source of vertex points

Functions