Documentation ¶
Index ¶
- Constants
- Variables
- func DrawPathListFromSWFMorph(collection ObjectCollection, startRecords, endRecords subtypes.SHAPERECORDS, ...) (DrawPathList, DrawPathList)
- func ImageToPNG(im image.Image, fname string) error
- func IterateMorphShape(start, end Shape) (r []records.RecordPair)
- func LerpFillable(start, end any, ratio float64) any
- func NewContourFromEdges(edges []records.LineRecord) (p polyclip.Contour)
- func NewPolygonFromShape(shape Shape) (g polyclip.Polygon)
- func QuantizeBitmap(i image.Image) image.Image
- type ActivePath
- type Bitmap
- type Capper
- type ClipPath
- func (c *ClipPath) AddShape(shape Shape)
- func (c *ClipPath) ApplyMatrixTransform(transform math.MatrixTransform, applyTranslation bool) *ClipPath
- func (c *ClipPath) ClipShape(o Shape, recover bool) (r Shape)
- func (c *ClipPath) GetShape() Shape
- func (c *ClipPath) Intersect(o *ClipPath) *ClipPath
- func (c *ClipPath) Merge(o *ClipPath) *ClipPath
- type Complex
- type ComplexPolygon
- type DrawPath
- type DrawPathList
- func (l DrawPathList) ApplyColorTransform(transform math.ColorTransform) Fillable
- func (l DrawPathList) ApplyFunction(f func(p DrawPath) DrawPath) (r DrawPathList)
- func (l DrawPathList) ApplyMatrixTransform(transform math.MatrixTransform, applyTranslation bool) Fillable
- func (l DrawPathList) Fill(shape Shape) (r DrawPathList)
- func (l DrawPathList) Merge(b DrawPathList) DrawPathList
- type Ellipse
- type FillStyleRecord
- func FillStyleRecordFromSWF(collection ObjectCollection, fillType swfsubtypes.FillStyleType, ...) (r *FillStyleRecord)
- func FillStyleRecordFromSWFMORPHFILLSTYLE(collection ObjectCollection, fillStyle swfsubtypes.MORPHFILLSTYLE) (start, end *FillStyleRecord)
- func LerpFillStyle(start, end *FillStyleRecord, ratio float64) *FillStyleRecord
- type Fillable
- type Gradient
- func (g Gradient) ApplyColorTransform(transform math2.ColorTransform) Fillable
- func (g Gradient) ApplyMatrixTransform(transform math2.MatrixTransform, applyTranslation bool) Fillable
- func (g Gradient) Fill(shape Shape) DrawPathList
- func (g Gradient) GetInterpolatedDrawPaths(overlap, blur float64, gradientSlices int, bb Rectangle[float64]) DrawPathList
- func (g Gradient) GetItems() []GradientItem
- func (g Gradient) Interpolate(gradientSlices int) (result []GradientSlice)
- type GradientItem
- type GradientSlice
- type Joiner
- type LineStyleRecord
- func LerpLineStyle(start, end *LineStyleRecord, ratio float64) *LineStyleRecord
- func LineStyleRecordFromSWF(width uint16, blur float64, hasFill bool, c swftypes.Color, ...) (r *LineStyleRecord)
- func LineStyleRecordFromSWFMORPHLINESTYLE(lineStyle swfsubtypes.MORPHLINESTYLE) (start, end *LineStyleRecord)
- func LineStyleRecordFromSWFMORPHLINESTYLE2(collection ObjectCollection, lineStyle swfsubtypes.MORPHLINESTYLE2) (start, end *LineStyleRecord)
- type MedianCutQuantizer
- type ObjectCollection
- type ObjectDefinition
- type ObjectProperties
- type PathSegment
- func (s *PathSegment[T]) AddPoint(p VisitedPoint[T])
- func (s *PathSegment[T]) End() math.Vector2[T]
- func (s *PathSegment[T]) Flip()
- func (s *PathSegment[T]) GetShape() (shape Shape)
- func (s *PathSegment[T]) IsClosed() bool
- func (s *PathSegment[T]) IsEmpty() bool
- func (s *PathSegment[T]) Merge(o PathSegment[T])
- func (s *PathSegment[T]) Start() math.Vector2[T]
- func (s *PathSegment[T]) Swap(o *PathSegment[T])
- func (s *PathSegment[T]) TryMerge(o *PathSegment[T], isDirected bool) bool
- type PendingPath
- type PendingPathMap
- type RecordCorrespondence
- type Rectangle
- func (r Rectangle[T]) Area() T
- func (r Rectangle[T]) Divide(size T) Rectangle[T]
- func (r Rectangle[T]) Draw() Shape
- func (r Rectangle[T]) DrawOpen() []records.Record
- func (r Rectangle[T]) Height() T
- func (r Rectangle[T]) InBounds(pos math.Vector2[T]) bool
- func (r Rectangle[T]) Multiply(size T) Rectangle[T]
- func (r Rectangle[T]) Width() T
- type Shape
- func (s Shape) ApplyMatrixTransform(transform math.MatrixTransform, applyTranslation bool) (newShape Shape)
- func (s Shape) BoundingBox() Rectangle[float64]
- func (s Shape) End() math.Vector2[float64]
- func (s Shape) Equals(o Shape) bool
- func (s Shape) Flatten() (r Shape)
- func (s Shape) FlattenWithCorrespondence() (r Shape, ix []RecordCorrespondence)
- func (s Shape) IsClosed() bool
- func (s Shape) IsFlat() bool
- func (s Shape) Merge(o Shape) (r Shape)
- func (s Shape) Reverse() (r Shape)
- func (s Shape) Start() math.Vector2[float64]
- func (s Shape) String() (r string)
- type ShapeConverter
- func (c *ShapeConverter) Convert(elements subtypes.SHAPERECORDS) DrawPathList
- func (c *ShapeConverter) ConvertMorph(start, end subtypes.SHAPERECORDS) (startList, endList subtypes.SHAPERECORDS)
- func (c *ShapeConverter) FlushLayer()
- func (c *ShapeConverter) FlushPaths()
- func (c *ShapeConverter) HandleNode(node subtypes.SHAPERECORD)
- func (c *ShapeConverter) VisitPoint(pos math.Vector2[types.Twip], isBezierControlPoint bool)
- type StrokeConverter
- type StyleList
- type StyleRecord
- type VisitedPoint
Constants ¶
const GradientBoundsMax = -GradientBoundsMin
const GradientBoundsMin swftypes.Twip = math.MinInt16 / 2
const GradientRatioDivisor = math.MaxUint8
const PolygonSimplifyTolerance = 0.01
Variables ¶
var GradientBounds = Rectangle[float64]{ TopLeft: math2.NewVector2[float64](GradientBoundsMin.Float64(), GradientBoundsMin.Float64()), BottomRight: math2.NewVector2[float64](GradientBoundsMax.Float64(), GradientBoundsMax.Float64()), }
Functions ¶
func DrawPathListFromSWFMorph ¶
func DrawPathListFromSWFMorph(collection ObjectCollection, startRecords, endRecords subtypes.SHAPERECORDS, startStyles, endStyles StyleList) (DrawPathList, DrawPathList)
func IterateMorphShape ¶
func IterateMorphShape(start, end Shape) (r []records.RecordPair)
func LerpFillable ¶
func NewContourFromEdges ¶
func NewContourFromEdges(edges []records.LineRecord) (p polyclip.Contour)
func NewPolygonFromShape ¶
func NewPolygonFromShape(shape Shape) (g polyclip.Polygon)
Types ¶
type ActivePath ¶
type ActivePath struct { Segment PathSegment[types.Twip] StyleId int }
func NewActivePath ¶
func (*ActivePath) AddPoint ¶
func (p *ActivePath) AddPoint(point VisitedPoint[types.Twip])
func (*ActivePath) Flip ¶
func (p *ActivePath) Flip()
type Bitmap ¶
type Bitmap struct { List DrawPathList Transform math2.MatrixTransform }
func BitmapFillFromSWF ¶
func BitmapFillFromSWF(l DrawPathList, transform types.MATRIX) Bitmap
func (Bitmap) ApplyColorTransform ¶
func (b Bitmap) ApplyColorTransform(transform math2.ColorTransform) Fillable
func (Bitmap) ApplyMatrixTransform ¶
func (b Bitmap) ApplyMatrixTransform(transform math2.MatrixTransform, applyTranslation bool) Fillable
func (Bitmap) Fill ¶
func (b Bitmap) Fill(shape Shape) DrawPathList
type Capper ¶
type Capper func(from, to math.Vector2[float64]) PathSegment[float64]
var ButtCapper Capper = func(from, to math.Vector2[float64]) PathSegment[float64] { return PathSegment[float64]{ { Pos: from, IsBezierControl: false, }, { Pos: to, IsBezierControl: false, }, } }
var RoundCapper Capper = func(from, to math.Vector2[float64]) PathSegment[float64] { mid := from.AddVector(to).Divide(2) ellipseDrawQuarter(mid, from.SubVector(mid)).ToLineRecords(1) ellipseDrawQuarter(mid, to.SubVector(mid)).ToLineRecords(1) return PathSegment[float64]{ { Pos: from, IsBezierControl: false, }, { Pos: to, IsBezierControl: false, }, } }
type ClipPath ¶
type ClipPath struct {
Clip ComplexPolygon
}
func NewClipPath ¶
func (*ClipPath) ApplyMatrixTransform ¶
func (c *ClipPath) ApplyMatrixTransform(transform math.MatrixTransform, applyTranslation bool) *ClipPath
type ComplexPolygon ¶
type ComplexPolygon struct {
Pol polyclip.Polygon
}
func (ComplexPolygon) Draw ¶
func (p ComplexPolygon) Draw() Shape
func (ComplexPolygon) GetShape ¶
func (p ComplexPolygon) GetShape() (r Shape)
func (ComplexPolygon) Intersect ¶
func (p ComplexPolygon) Intersect(o ComplexPolygon) ComplexPolygon
func (ComplexPolygon) Merge ¶
func (p ComplexPolygon) Merge(o ComplexPolygon) ComplexPolygon
type DrawPath ¶
type DrawPath struct { Style StyleRecord Shape Shape }
func DrawPathFill ¶
func DrawPathFill(record *FillStyleRecord, shape Shape) DrawPath
func DrawPathStroke ¶
func DrawPathStroke(record *LineStyleRecord, shape Shape) DrawPath
func (DrawPath) ApplyColorTransform ¶
func (p DrawPath) ApplyColorTransform(transform math.ColorTransform) (r DrawPath)
func (DrawPath) ApplyMatrixTransform ¶
func (p DrawPath) ApplyMatrixTransform(transform math.MatrixTransform, applyTranslation bool) (r DrawPath)
type DrawPathList ¶
type DrawPathList []DrawPath
func ConvertBitmapBytesToDrawPathList ¶
func ConvertBitmapBytesToDrawPathList(imageData []byte, alphaData []byte) (DrawPathList, error)
func ConvertBitmapToDrawPathList ¶
func ConvertBitmapToDrawPathList(i image.Image) (r DrawPathList)
func DrawPathListFromSWF ¶
func DrawPathListFromSWF(collection ObjectCollection, records subtypes.SHAPERECORDS, styles StyleList) DrawPathList
func (DrawPathList) ApplyColorTransform ¶
func (l DrawPathList) ApplyColorTransform(transform math.ColorTransform) Fillable
func (DrawPathList) ApplyFunction ¶
func (l DrawPathList) ApplyFunction(f func(p DrawPath) DrawPath) (r DrawPathList)
func (DrawPathList) ApplyMatrixTransform ¶
func (l DrawPathList) ApplyMatrixTransform(transform math.MatrixTransform, applyTranslation bool) Fillable
func (DrawPathList) Fill ¶
func (l DrawPathList) Fill(shape Shape) (r DrawPathList)
func (DrawPathList) Merge ¶
func (l DrawPathList) Merge(b DrawPathList) DrawPathList
type FillStyleRecord ¶
type FillStyleRecord struct { // Fill can be math.Color or Fillable Fill any Border *LineStyleRecord Blur float64 // contains filtered or unexported fields }
func FillStyleRecordFromSWF ¶
func FillStyleRecordFromSWF(collection ObjectCollection, fillType swfsubtypes.FillStyleType, color swftypes.Color, gradient swfsubtypes.GRADIENT, focalGradient swfsubtypes.FOCALGRADIENT, gradientMatrix, bitmapMatrix swftypes.MATRIX, bitmapId uint16) (r *FillStyleRecord)
func FillStyleRecordFromSWFMORPHFILLSTYLE ¶
func FillStyleRecordFromSWFMORPHFILLSTYLE(collection ObjectCollection, fillStyle swfsubtypes.MORPHFILLSTYLE) (start, end *FillStyleRecord)
func LerpFillStyle ¶
func LerpFillStyle(start, end *FillStyleRecord, ratio float64) *FillStyleRecord
func (*FillStyleRecord) ApplyColorTransform ¶
func (r *FillStyleRecord) ApplyColorTransform(transform math.ColorTransform) StyleRecord
func (*FillStyleRecord) ApplyMatrixTransform ¶
func (r *FillStyleRecord) ApplyMatrixTransform(transform math.MatrixTransform, applyTranslation bool) StyleRecord
func (*FillStyleRecord) Flatten ¶
func (r *FillStyleRecord) Flatten(s Shape) DrawPathList
Flatten Creates a fill that is only composed of FillStyleRecord with Fill being math.Color
func (*FillStyleRecord) IsFlat ¶
func (r *FillStyleRecord) IsFlat() bool
type Fillable ¶
type Fillable interface { Fill(shape Shape) DrawPathList ApplyMatrixTransform(transform math.MatrixTransform, applyTranslation bool) Fillable ApplyColorTransform(transform math.ColorTransform) Fillable }
type Gradient ¶
type Gradient struct { Records []GradientItem Transform math2.MatrixTransform SpreadMode swfsubtypes.GradientSpreadMode InterpolationMode swfsubtypes.GradientInterpolationMode Interpolation func(self Gradient, overlap, blur float64, gradientSlices int, bb Rectangle[float64]) DrawPathList }
func LerpGradient ¶
func LinearGradientFromSWF ¶
func LinearGradientFromSWF(records []swfsubtypes.GRADRECORD, transform types.MATRIX, spreadMode swfsubtypes.GradientSpreadMode, interpolationMode swfsubtypes.GradientInterpolationMode) Gradient
func RadialGradientFromSWF ¶
func RadialGradientFromSWF(records []swfsubtypes.GRADRECORD, transform types.MATRIX, spreadMode swfsubtypes.GradientSpreadMode, interpolationMode swfsubtypes.GradientInterpolationMode) Gradient
func (Gradient) ApplyColorTransform ¶
func (g Gradient) ApplyColorTransform(transform math2.ColorTransform) Fillable
func (Gradient) ApplyMatrixTransform ¶
func (g Gradient) ApplyMatrixTransform(transform math2.MatrixTransform, applyTranslation bool) Fillable
func (Gradient) Fill ¶
func (g Gradient) Fill(shape Shape) DrawPathList
func (Gradient) GetInterpolatedDrawPaths ¶
func (Gradient) GetItems ¶
func (g Gradient) GetItems() []GradientItem
func (Gradient) Interpolate ¶
func (g Gradient) Interpolate(gradientSlices int) (result []GradientSlice)
type GradientItem ¶
func GradientItemFromSWF ¶
func GradientItemFromSWF(ratio uint8, color swftypes.Color) GradientItem
type GradientSlice ¶
type Joiner ¶
type Joiner func(from, to math.Vector2[float64]) PathSegment[float64]
var StraightJoiner Joiner = func(from, to math.Vector2[float64]) PathSegment[float64] { return PathSegment[float64]{ { Pos: from, IsBezierControl: false, }, { Pos: to, IsBezierControl: false, }, } }
type LineStyleRecord ¶
func LerpLineStyle ¶
func LerpLineStyle(start, end *LineStyleRecord, ratio float64) *LineStyleRecord
func LineStyleRecordFromSWF ¶
func LineStyleRecordFromSWF(width uint16, blur float64, hasFill bool, c swftypes.Color, fill *FillStyleRecord) (r *LineStyleRecord)
func LineStyleRecordFromSWFMORPHLINESTYLE ¶
func LineStyleRecordFromSWFMORPHLINESTYLE(lineStyle swfsubtypes.MORPHLINESTYLE) (start, end *LineStyleRecord)
func LineStyleRecordFromSWFMORPHLINESTYLE2 ¶
func LineStyleRecordFromSWFMORPHLINESTYLE2(collection ObjectCollection, lineStyle swfsubtypes.MORPHLINESTYLE2) (start, end *LineStyleRecord)
func (*LineStyleRecord) ApplyColorTransform ¶
func (r *LineStyleRecord) ApplyColorTransform(transform math.ColorTransform) StyleRecord
func (*LineStyleRecord) ApplyMatrixTransform ¶
func (r *LineStyleRecord) ApplyMatrixTransform(transform math.MatrixTransform, applyTranslation bool) StyleRecord
func (*LineStyleRecord) StrokeWidth ¶
func (r *LineStyleRecord) StrokeWidth(transform math.MatrixTransform) float64
type MedianCutQuantizer ¶
type MedianCutQuantizer struct {
NumColor int
}
MedianCutQuantizer constructs a palette with a maximum of NumColor colors by iteratively splitting clusters of color points mapped on a three-dimensional (RGB) Euclidian space. Once the number of clusters is within the specified bounds, the resulting color is computed by averaging those within each grouping.
type ObjectCollection ¶
type ObjectCollection map[uint16]ObjectDefinition
func (ObjectCollection) Add ¶
func (o ObjectCollection) Add(def ObjectDefinition)
func (ObjectCollection) Clone ¶
func (o ObjectCollection) Clone() ObjectCollection
func (ObjectCollection) Get ¶
func (o ObjectCollection) Get(objectId uint16) ObjectDefinition
type ObjectDefinition ¶
type ObjectDefinition interface { GetObjectId() uint16 GetSafeObject() ObjectDefinition GetShapeList(p ObjectProperties) DrawPathList }
type ObjectProperties ¶
type PathSegment ¶
type PathSegment[T ~float64 | ~int64] []VisitedPoint[T]
func NewPathSegment ¶
func NewPathSegment[T ~float64 | ~int64](start math.Vector2[T]) PathSegment[T]
func (*PathSegment[T]) AddPoint ¶
func (s *PathSegment[T]) AddPoint(p VisitedPoint[T])
func (*PathSegment[T]) End ¶
func (s *PathSegment[T]) End() math.Vector2[T]
func (*PathSegment[T]) Flip ¶
func (s *PathSegment[T]) Flip()
Flip Flips the direction of the path segment. Flash fill paths are dual-sided, with fill style 1 indicating the positive side and fill style 0 indicating the negative. We have to flip fill style 0 paths in order to link them to fill style 1 paths.
func (*PathSegment[T]) GetShape ¶
func (s *PathSegment[T]) GetShape() (shape Shape)
func (*PathSegment[T]) IsClosed ¶
func (s *PathSegment[T]) IsClosed() bool
func (*PathSegment[T]) IsEmpty ¶
func (s *PathSegment[T]) IsEmpty() bool
func (*PathSegment[T]) Merge ¶
func (s *PathSegment[T]) Merge(o PathSegment[T])
func (*PathSegment[T]) Start ¶
func (s *PathSegment[T]) Start() math.Vector2[T]
func (*PathSegment[T]) Swap ¶
func (s *PathSegment[T]) Swap(o *PathSegment[T])
func (*PathSegment[T]) TryMerge ¶
func (s *PathSegment[T]) TryMerge(o *PathSegment[T], isDirected bool) bool
type PendingPath ¶
type PendingPath[T ~float64 | ~int64] []*PathSegment[T]
func (*PendingPath[T]) GetShape ¶
func (p *PendingPath[T]) GetShape() (shape Shape)
func (*PendingPath[T]) MergePath ¶
func (p *PendingPath[T]) MergePath(newSegment *PathSegment[T], directed bool)
type PendingPathMap ¶
type PendingPathMap map[int]*PendingPath[types.Twip]
func (PendingPathMap) MergePath ¶
func (m PendingPathMap) MergePath(p *ActivePath, directed bool)
type RecordCorrespondence ¶
type Rectangle ¶
func RectangleToType ¶
type Shape ¶
func (Shape) ApplyMatrixTransform ¶
func (s Shape) ApplyMatrixTransform(transform math.MatrixTransform, applyTranslation bool) (newShape Shape)
func (Shape) BoundingBox ¶
func (Shape) Flatten ¶
Flatten Converts all non-linear records into line segments and returns a new Shape
func (Shape) FlattenWithCorrespondence ¶
func (s Shape) FlattenWithCorrespondence() (r Shape, ix []RecordCorrespondence)
type ShapeConverter ¶
type ShapeConverter struct { Collection ObjectCollection Styles StyleList FillStyle0 *ActivePath FillStyle1 *ActivePath LineStyle *ActivePath Position math.Vector2[types.Twip] Fills, Strokes PendingPathMap Commands DrawPathList Finished bool }
func NewMorphShapeConverter ¶
func NewMorphShapeConverter(collection ObjectCollection, styles StyleList) *ShapeConverter
func NewShapeConverter ¶
func NewShapeConverter(collection ObjectCollection, styles StyleList) *ShapeConverter
func (*ShapeConverter) Convert ¶
func (c *ShapeConverter) Convert(elements subtypes.SHAPERECORDS) DrawPathList
func (*ShapeConverter) ConvertMorph ¶
func (c *ShapeConverter) ConvertMorph(start, end subtypes.SHAPERECORDS) (startList, endList subtypes.SHAPERECORDS)
ConvertMorph We step through both the start records and end records, interpolating edges pairwise. Fill style/line style changes should only appear in the start records. However, StyleChangeRecord move_to can appear it both start and end records, and not necessarily in matching pairs; therefore, we have to keep track of the pen position in case one side is missing a move_to; it will implicitly use the last pen position.
func (*ShapeConverter) FlushLayer ¶
func (c *ShapeConverter) FlushLayer()
func (*ShapeConverter) FlushPaths ¶
func (c *ShapeConverter) FlushPaths()
func (*ShapeConverter) HandleNode ¶
func (c *ShapeConverter) HandleNode(node subtypes.SHAPERECORD)
func (*ShapeConverter) VisitPoint ¶
type StrokeConverter ¶
type StrokeConverter struct { HalfWidth float64 MiterLimit float64 Cap Capper Join Joiner Position math.Vector2[float64] Segment [2]PathSegment[float64] }
func (*StrokeConverter) Close ¶
func (c *StrokeConverter) Close() PathSegment[float64]
type StyleList ¶
type StyleList struct { FillStyles []*FillStyleRecord LineStyles []*LineStyleRecord }
func StyleListFromSWFItems ¶
func StyleListFromSWFItems(collection ObjectCollection, fillStyles subtypes.FILLSTYLEARRAY, lineStyles subtypes.LINESTYLEARRAY) (r StyleList)
func StyleListFromSWFMorphItems ¶
func StyleListFromSWFMorphItems(collection ObjectCollection, fillStyles subtypes.MORPHFILLSTYLEARRAY, lineStyles subtypes.MORPHLINESTYLEARRAY) (start, end StyleList)
func (StyleList) GetFillStyle ¶
func (l StyleList) GetFillStyle(i int) *FillStyleRecord
func (StyleList) GetLineStyle ¶
func (l StyleList) GetLineStyle(i int) *LineStyleRecord
type StyleRecord ¶
type StyleRecord interface { ApplyColorTransform(transform math.ColorTransform) StyleRecord ApplyMatrixTransform(transform math.MatrixTransform, applyTranslation bool) StyleRecord }
Source Files ¶
- ActivePath.go
- Bitmap.go
- BitmapConverter.go
- ClipPath.go
- ComplexPolygon.go
- DrawPath.go
- DrawPathList.go
- Gradient.go
- LineStyleRecord.go
- LinearGradient.go
- ObjectCollection.go
- ObjectDefinition.go
- PathSegment.go
- PendingPath.go
- RadialGradient.go
- Shape.go
- ShapeConverter.go
- StrokeConverter.go
- StyleList.go
- StyleRecord.go
- VisitedPoint.go
- complex.go
- ellipse.go
- lerp.go
- mediancut.go
- rectangle.go