potrace-diagrams-0.1.0.0: Potrace bindings for the diagrams library

Copyright(c) 2015 Christopher Chalmers
LicenseBSD-style (see LICENSE)
Maintainerc.chalmers@me.com
Safe HaskellNone
LanguageHaskell2010

Diagrams.Potrace

Contents

Description

Trace bitmap images into paths using the potrace library. This module also provides helpers for turning JuicyPixel images to bitmap.

Synopsis

Tracing

tracePath :: Bitmap -> Path V2 Double Source

Trace the bitmap image to a path using potrace with def parameters.

tracePath' :: Parameters -> Bitmap -> Path V2 Double Source

Trace the bitmap image to a path curves using potrace with given parameters.

Bitmaps

data Bitmap :: *

Data type to represent a bit packed image. This can be passed to potrace via trace. The constructor is exported by Base but be aware the underlying vector has a host dependant form. You are advised to use generate to create a Bitmap.

generate :: Int -> Int -> (Int -> Int -> Bool) -> Bitmap

Given an image and a predicate for whether a pixel is on or off, create a bit-packed image suitable for passing to potrace.

fromImage :: Pixel a => Image a -> (a -> Bool) -> Bitmap

Generate a bitmap by apply the predicate function to each pixel. True corresponds to a black pixel or "on". False corresponds to white or "off".

lumaThreshold :: DynamicImage -> Double -> Bitmap

Generate a bitmap choosing pixels according to their luma plane for a threshold given between 0 and 1. Anything below the threshold is white or "off". Anything above the threshold is black, or "on". Throws an error for CMYK images.

Parameters

data Parameters :: *

Parameters to control the tracing operation of potrace. The default parameters are

Parameters
  { turdSize     = 2
  , turnPolicy   = MinorityTP
  , alphaMax     = 1.0
  , optTolerance = 0.2
  }

Instances

data TurnPolicy :: *

How to resolve ambiguities during decomposition of bitmaps into paths.

Constructors

BlackTP

Prefers to connect black (foreground) components

WhiteTP

Prefers to connect white (background) components.

LeftTP

Always take a left turn.

RightTP

Always take a right turn.

MinorityTP

Prefers to connect the color (black or white) that occurs least frequently in a local neighborhood of the current position.

MajorityTP

Prefers to connect the color (black or white) that occurs most frequently in a local neighborhood of the current position. (default)

RandomTP

Choose pseudo-randomly

Lenses

turdSize :: Lens' Parameters Int

The turdSize parameter can be used to “despeckle” the bitmap to be traced, by removing all curves whose enclosed area is below the given threshold.

Default is 2.

turnPolicy :: Lens' Parameters TurnPolicy

The TurnPolicy parameter determines how to resolve ambiguities during decomposition of bitmaps into paths.

Default is MinorityTP.

alphaMax :: Lens' Parameters Double

The alphamax parameter is a threshold for the detection of corners. It controls the smoothness of the traced curve.The useful range of this parameter is from 0.0 (polygon) to 1.3334 (no corners).

Default is 1.0.

optTolerance :: Lens' Parameters (Maybe Double)

The optTolerance parameter defines the amount of error allowed in this simplification. Larger values tend to decrease the number of segments, at the expense of less accuracy. The useful range is from 0 to infinity, although in practice one would hardly choose values greater than 1 or so. For most purposes, the default value is a good trade off between space and accuracy. Nothing turns simplification off.

Default is Just 1.0.

Misc