Copyright | (c) 2015 Christopher Chalmers |
---|---|
License | BSD-style (see LICENSE) |
Maintainer | c.chalmers@me.com |
Safe Haskell | None |
Language | Haskell2010 |
A mid-level interface to potrace. Includes helpers for making bitmap images. This is useful for other libraries that want to implement their own tools on top of potrace (see "potrace-diagrams").
In principle this could be in a separate module but there's already three separate potrace modules and the dependencies aren't huge.
- data Curve = Curve !P2 [Segment]
- data Segment
- data P2 = P2 !Double !Double
- trace :: Bitmap -> [Curve]
- trace' :: Parameters -> Bitmap -> [Curve]
- traceForest :: Bitmap -> Forest Curve
- traceForest' :: Parameters -> Bitmap -> Forest Curve
- data Bitmap = Bitmap {
- bitmapWidth :: Int
- bitmapHeight :: Int
- bitmapDy :: Int
- bitmapData :: Vector CULong
- generate :: Int -> Int -> (Int -> Int -> Bool) -> Bitmap
- index :: Bitmap -> Int -> Int -> Bool
- data Parameters = Parameters {}
- data TurnPolicy
- = BlackTP
- | WhiteTP
- | LeftTP
- | RightTP
- | MinorityTP
- | MajorityTP
- | RandomTP
Tracing
A curve is a list of segments. The starting point is provided for convenience but this is just the final point of the last segment.
Data type representing a 2D point were the origin is at the bottom left.
trace :: Bitmap -> [Curve] Source
Trace the bitmap image to a list of curves using potrace with def
parameters.
trace' :: Parameters -> Bitmap -> [Curve] Source
Trace the bitmap image to a list of curves using potrace with given parameters.
traceForest :: Bitmap -> Forest Curve Source
Trace the bitmap image as a forest of curves using potrace with def
parameters. Each child curve is completely contained in it's
parent.
traceForest' :: Parameters -> Bitmap -> Forest Curve Source
Trace the bitmap image as a forest of curves using potrace with given parameters parameters. Each child curve is completely contained in it's parent.
Bitmaps
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
.
Bitmap | |
|
generate :: Int -> Int -> (Int -> Int -> Bool) -> Bitmap Source
Given an image and a predicate for whether a pixel is on or off, create a bit-packed image suitable for passing to potrace.
index :: Bitmap -> Int -> Int -> Bool Source
Index a pixel in a Bitmap
. This is mainly here for debugging
purposes.
Parameters
data Parameters Source
Parameters to control the tracing operation of potrace. The default parameters are
Parameters {turdSize
= 2 ,turnPolicy
=MinorityTP
,alphaMax
= 1.0 ,optTolerance
=Just
0.2 }
Parameters | |
|
data TurnPolicy Source
How to resolve ambiguities during decomposition of bitmaps into paths.
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 |