Git Product home page Git Product logo

scany's Introduction

scany

About

The scany package is a denovo implementation the CL-AA antigrain algorithm in both a single thread or multi-threaded structure by ScanS and ScanT, respectivly. Both implement the rasterx.Scanner interface, and therefore they can be used with the rasterx and oksvg. The single threaded ScanS is vitually as fast as the ScanFT structure implemented in github.com/swiley/scanFT. Benchmarks vary a bit from run to run but ScanS appears to be within 1 or 2 percent as fast as ScanFT. The difference is that ScanFT is under the Freetype license, since it is a direct port from the C implementation of Freetype. while ScanS and ScanT are under the less restrictive MIT3 license, so they can be freely incoporated in commercial as well as open source projects.

If ScanT is run using a thread count of one it is around 10% slower than ScanFT or ScanS. However, as additional threads are added it will exceed the speed of the single thread implementations. At what point this occurs, depends on the image being rendered. SVG's with gradients, for example, particularly benefit from using multiple threads. Also note that number of threads specified may exceed the number of available CPU cores and still increase speed on some machines, while on others it may max out, so experimentation to determine the optimal thread number is advised.

Instead of the Painter interface used by Freetype to translate x y coordinates and alpha values to various image formats, scanY uses the scany.Collector interface. A Collector for the image.RGBA format is provided in the scany package. Collectors for additional formats may be provided by the user.

How to use

To use the ScanS single threaded antialiaser with oksvg do the following:

img := image.NewRGBA(image.Rect(0, 0, width, height))
collector := &scany.RGBACollector{Image: img}
scanner := scany.NewScanS(width, height, collector)
raster := rasterx.NewDasher(w, h, scanner)
icon.Draw(raster, 1.0) // icon is an oksvg.Icon

Similarly to use the ScanT multi-threaded antialiaser do:

threadCount := 6
img := image.NewRGBA(image.Rect(0, 0, width, height))
collector := &scany.RGBACollector{Image: img}
scanner := scany.NewScanT(threadCount, width, height, collector)
raster := rasterx.NewDasher(w, h, scanner)
icon.Draw(raster, 1.0) // icon is an oksvg.Icon

All threads are started when the NewScanT method is called. There are three types of threads handling various steps of the CL-AA algorithm. One type breaks lines into cell sized segments, one calculates the cover and area, and places them into a linked list. Once these complete, the last type of thread sweeps the linked list scan lines, and adds the x, y alpha values to the target image format using the Collector. When a thread count of one is specified, one of each thread type is created. Similarly if a thead count of six is used, six of each type of thread are created. The threads can be shut down by executing:

scanner.Close()

For an explanation of the CL-AA algorithm, see the cl-vectors file in the docs folder taken from projects.tuxee.net. See the test files for additional examples and benchmarks.

example

Thanks to Freepik from Flaticon Licensed by Creative Commons 3.0 for the test icons used in the testdata/svg/landscapeIcons folder.

scany's People

Contributors

srwiley avatar

Watchers

 avatar  avatar

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.