GithubHelp home page GithubHelp logo

rasterize's Introduction

Rasterizer

Build Status MIT License Crate API Docs

This is a fully functional 2D rasterizer and SVG path parser.

Features:

  • parsing SVG path format
  • rendering elliptic arc, lines, cubic/quadratic bezier curves
  • curve offsetting
  • linear and radial gradients

Usage example

There is a very simple binary in examples folder that can be used to render SVG path

$ cargo run --release --example rasterize -- data/squirrel.path -w 512 -o squirrel.bmp

This will produce:

squirrel

rasterize's People

Contributors

aslpavel avatar fincap avatar lnicola avatar luke-nuttall avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rasterize's Issues

Ready for production?

Hi thanks for the lib! I need to rasterize bezier curves, so I wonder whether this is ready for production? Thanks!

Missing simpler examples/documentation

I'm trying to understand this library to see if it would be suitable for drawing into a softbuffer buffer. The problem is, I can only find full-featured SVG-drawing examples, when all I want to do is draw simple primitives for UI elements. Additionally, I can't find any helpful info in the documentation.

Infinite loop and memory leak when flattening a segment that contains one or more NaN points

If any point in a Segment is NaN, then during rasterization the PathFlattenIter will get stuck in an infinite loop of splitting itself pushing both halves onto the Segment stack (which also contain NaN values). Memory usage will rapidly climb and cause severe degradation to the entire computer's performance if the process isn't killed in time.

The infinite loop occurs in this section of path.rs:

rasterize/src/path.rs

Lines 664 to 672 in f4196d7

match self.stack.pop() {
Some(segment) => {
if segment.flatness() < self.flatness {
return Some(Line::new(segment.start(), segment.end()));
}
let (s0, s1) = segment.split();
self.stack.push(s1);
self.stack.push(s0);
}

Because f64::NAN always returns false from comparisons, this loop will never break.

Steps to reproduce

(I would highly recommend having your finger on the trigger to kill the process since this caused roughly 400MB/s to leak on my machine)

  1. Modify examples/simple.rs so that any of the coordinates in squirrel_path are f64::NAN.
  2. cargo run --example=simple

Upgrading after the pipeline changes

Hi! Sorry for the support question but I have some code that renders stuff onto multiple Scenes, but with the same transform and bbox. This worked in 0.1, but broke in 0.2. One difference I noticed is that the returned Layer size was the same for each Scene, but now it's different, even (0, 0) at times.

Is it possible to get the old behaviour in 0.2? I think the output shape was determined by the bbox and transform.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.