Documentation
¶
Overview ¶
Package okage is a port of the Rust crate tiny-skia 0.12.0, a tiny subset of Skia (https://skia.org/).
The API of okage is a bit unconventional. It does not look like cairo, QPainter (Qt), HTML Canvas or even Skia itself. Instead, okage gives a set of low-level drawing APIs, and a user manages the world transform, the clipping mask and the style manually.
The package path holds the paths and the geometry types. okage declares a type alias for each type of path that tiny-skia exports again, so that a user needs one import.
The renderer gives the same bytes as the scalar build of tiny-skia (D16). A multiply that is followed by an add is written as float32(x*y) + z, so that the Go compiler cannot fuse the two operations.
Example (Fill) ¶
This example ports tiny-skia examples/fill.rs. It fills two paths, one with anti-aliasing and one without.
package main
import (
"fmt"
"github.com/xo/okage"
)
// printPixel prints the premultiplied RGBA value of the pixel at x, y.
func printPixel(pixmap *okage.Pixmap, x, y uint32) {
c, _ := pixmap.Pixel(x, y)
fmt.Println(c.Red(), c.Green(), c.Blue(), c.Alpha())
}
func main() {
paint1 := okage.DefaultPaint()
paint1.SetColorRGBA8(50, 127, 150, 200)
paint1.AntiAlias = true
paint2 := okage.DefaultPaint()
paint2.SetColorRGBA8(220, 140, 75, 180)
paint2.AntiAlias = false
pb := okage.NewPathBuilder()
pb.MoveTo(60, 60)
pb.LineTo(160, 940)
pb.CubicTo(380, 840, 660, 800, 940, 800)
pb.CubicTo(740, 460, 440, 160, 60, 60)
pb.Close()
path1, _ := pb.Finish()
pb = okage.NewPathBuilder()
pb.MoveTo(940, 60)
pb.LineTo(840, 940)
pb.CubicTo(620, 840, 340, 800, 60, 800)
pb.CubicTo(260, 460, 560, 160, 940, 60)
pb.Close()
path2, _ := pb.Finish()
pixmap, _ := okage.NewPixmap(1000, 1000)
pixmap.FillPath(
path1,
&paint1,
okage.FillRuleWinding,
okage.IdentityTransform(),
nil,
)
pixmap.FillPath(
path2,
&paint2,
okage.FillRuleWinding,
okage.IdentityTransform(),
nil,
)
printPixel(pixmap, 500, 600)
}
Output: 167 129 88 239
Example (Gamma) ¶
This example ports tiny-skia examples/gamma.rs. It strokes the same lines in each color space.
package main
import (
"fmt"
"github.com/xo/okage"
)
// printPixel prints the premultiplied RGBA value of the pixel at x, y.
func printPixel(pixmap *okage.Pixmap, x, y uint32) {
c, _ := pixmap.Pixel(x, y)
fmt.Println(c.Red(), c.Green(), c.Blue(), c.Alpha())
}
func main() {
paint := okage.DefaultPaint()
paint.Shader = okage.SolidColor(okage.ColorFromRGBA8(255, 100, 20, 255))
paint.AntiAlias = true
stroke := okage.DefaultStroke()
pixmap, _ := okage.NewPixmap(1000, 1000)
pixmap.Fill(okage.ColorBlack)
pb := okage.NewPathBuilder()
for i := range 10 {
pb.MoveTo(50, 45+float32(i)*20)
pb.LineTo(450, 45+float32(i)*21)
}
path, _ := pb.Finish()
colors := []okage.ColorSpace{
okage.ColorSpaceLinear,
okage.ColorSpaceGamma2,
okage.ColorSpaceSimpleSRGB,
okage.ColorSpaceFullSRGBGamma,
}
for i, color := range colors {
paint.Colorspace = color
xf := okage.IdentityTransform()
xf = xf.PreTranslate(0, 240*float32(i))
pixmap.StrokePath(path, &paint, &stroke, xf, nil)
// Move down 0.5 pixel so lines start in the middle of the pixel, not the edge
xf = xf.PreTranslate(500, 0.5)
pixmap.StrokePath(path, &paint, &stroke, xf, nil)
}
printPixel(pixmap, 250, 285)
}
Output: 181 71 14 255
Example (Hairline) ¶
This example ports tiny-skia examples/hairline.rs.
This example demonstrates thin paths rendering.
package main
import (
"fmt"
"github.com/xo/okage"
)
// printPixel prints the premultiplied RGBA value of the pixel at x, y.
func printPixel(pixmap *okage.Pixmap, x, y uint32) {
c, _ := pixmap.Pixel(x, y)
fmt.Println(c.Red(), c.Green(), c.Blue(), c.Alpha())
}
func main() {
pb := okage.NewPathBuilder()
pb.MoveTo(50, 100)
pb.CubicTo(130, 20, 390, 120, 450, 30)
path, _ := pb.Finish()
paint := okage.DefaultPaint()
paint.SetColorRGBA8(50, 127, 150, 200)
paint.AntiAlias = true
pixmap, _ := okage.NewPixmap(500, 500)
transform := okage.IdentityTransform()
for i := range 20 {
stroke := okage.DefaultStroke()
stroke.Width = 2 - (float32(i) / 10)
pixmap.StrokePath(path, &paint, &stroke, transform, nil)
transform = transform.PreTranslate(0, 20)
}
printPixel(pixmap, 50, 100)
}
Output: 13 32 37 63
Example (ImageOnImage) ¶
This example ports tiny-skia examples/image_on_image.rs. It draws a pixmap on another pixmap with a transform.
Upstream also prints the time that the drawing takes. This example does not, because the time is different on each run.
package main
import (
"fmt"
"github.com/xo/okage"
)
// printPixel prints the premultiplied RGBA value of the pixel at x, y.
func printPixel(pixmap *okage.Pixmap, x, y uint32) {
c, _ := pixmap.Pixel(x, y)
fmt.Println(c.Red(), c.Green(), c.Blue(), c.Alpha())
}
func main() {
triangle := createTriangle()
pixmap, _ := okage.NewPixmap(400, 400)
paint := okage.DefaultPixmapPaint()
paint.Quality = okage.FilterQualityBicubic
pixmap.DrawPixmap(
20,
20,
triangle.AsRef(),
&paint,
okage.TransformFromRow(1.2, 0.5, 0.5, 1.2, 0, 0),
nil,
)
printPixel(pixmap, 200, 200)
}
// createTriangle is create_triangle in tiny-skia examples/image_on_image.rs.
func createTriangle() *okage.Pixmap {
paint := okage.DefaultPaint()
paint.SetColorRGBA8(50, 127, 150, 200)
paint.AntiAlias = true
pb := okage.NewPathBuilder()
pb.MoveTo(0, 200)
pb.LineTo(200, 200)
pb.LineTo(100, 0)
pb.Close()
path, _ := pb.Finish()
pixmap, _ := okage.NewPixmap(200, 200)
pixmap.FillPath(
path,
&paint,
okage.FillRuleWinding,
okage.IdentityTransform(),
nil,
)
rect, _ := okage.RectFromLTRB(0, 0, 200, 200)
path = okage.PathFromRect(rect)
stroke := okage.DefaultStroke()
paint.SetColorRGBA8(200, 0, 0, 220)
pixmap.StrokePath(path, &paint, &stroke, okage.IdentityTransform(), nil)
return pixmap
}
Output: 39 100 118 200
Example (LargeImage) ¶
This example ports tiny-skia examples/large_image.rs.
This example will crate a 20_000x20_000px image, which can take a while in a debug mode. This example is used mainly to tests that our tiling algorithm actually works and doesn't panic.
The pixmap and the mask need about 2 GB of memory, so this example has no Output comment, and go test compiles it but does not run it.
package main
import (
"github.com/xo/okage"
)
func main() { //nolint:testableexamples // It needs about 2 GB of memory, so go test must not run it.
pb := okage.NewPathBuilder()
pb.MoveTo(1200, 1200)
pb.LineTo(3200, 18800)
pb.CubicTo(7600, 16800, 13200, 16000, 18800, 16000)
pb.CubicTo(14800, 9200, 8800, 3200, 1200, 1200)
pb.Close()
path1, _ := pb.Finish()
pb = okage.NewPathBuilder()
pb.MoveTo(18800, 1200)
pb.LineTo(16800, 18800)
pb.CubicTo(12400, 16800, 6800, 16000, 1200, 16000)
pb.CubicTo(5200, 9200, 11200, 3200, 18800, 1200)
pb.Close()
path2, _ := pb.Finish()
pixmap, _ := okage.NewPixmap(20000, 20000)
pb = okage.NewPathBuilder()
pb.PushCircle(10000, 10000, 7000)
clipPath, _ := pb.Finish()
mask, _ := okage.NewMask(20000, 20000)
mask.FillPath(clipPath, okage.FillRuleWinding, true, okage.DefaultTransform())
paint := okage.DefaultPaint()
paint.SetColorRGBA8(90, 175, 100, 150)
paint.AntiAlias = true
largeRect, _ := okage.RectFromXYWH(500, 500, 19000, 19000)
pixmap.FillRect(largeRect, &paint, okage.IdentityTransform(), nil)
paint.SetColorRGBA8(50, 127, 150, 200)
paint.AntiAlias = true
pixmap.FillPath(
path1,
&paint,
okage.FillRuleWinding,
okage.DefaultTransform(),
mask,
)
paint.SetColorRGBA8(220, 140, 75, 180)
paint.AntiAlias = false
pixmap.FillPath(
path2,
&paint,
okage.FillRuleWinding,
okage.DefaultTransform(),
nil,
)
paint.SetColorRGBA8(255, 10, 15, 180)
paint.AntiAlias = true
stroke := okage.DefaultStroke()
stroke.Width = 0.8 // hairline
pixmap.StrokePath(path2, &paint, &stroke, okage.DefaultTransform(), nil)
}
Output:
Example (LinearGradient) ¶
This example ports tiny-skia examples/linear_gradient.rs. It fills a path with a linear gradient.
package main
import (
"fmt"
"github.com/xo/okage"
)
// printPixel prints the premultiplied RGBA value of the pixel at x, y.
func printPixel(pixmap *okage.Pixmap, x, y uint32) {
c, _ := pixmap.Pixel(x, y)
fmt.Println(c.Red(), c.Green(), c.Blue(), c.Alpha())
}
func main() {
paint := okage.DefaultPaint()
paint.AntiAlias = false
paint.Shader, _ = okage.NewLinearGradient(
okage.PointFromXY(100, 100),
okage.PointFromXY(900, 900),
[]okage.GradientStop{
okage.NewGradientStop(0, okage.ColorFromRGBA8(50, 127, 150, 200)),
okage.NewGradientStop(1, okage.ColorFromRGBA8(220, 140, 75, 180)),
},
okage.SpreadModePad,
okage.IdentityTransform(),
)
pb := okage.NewPathBuilder()
pb.MoveTo(60, 60)
pb.LineTo(160, 940)
pb.CubicTo(380, 840, 660, 800, 940, 800)
pb.CubicTo(740, 460, 440, 160, 60, 60)
pb.Close()
path, _ := pb.Finish()
pixmap, _ := okage.NewPixmap(1000, 1000)
pixmap.FillPath(
path,
&paint,
okage.FillRuleWinding,
okage.IdentityTransform(),
nil,
)
printPixel(pixmap, 400, 600)
}
Output: 101 100 84 190
Example (Mask) ¶
This example ports tiny-skia examples/mask.rs. It fills a rectangle through a mask of two circles.
package main
import (
"fmt"
"github.com/xo/okage"
)
// printPixel prints the premultiplied RGBA value of the pixel at x, y.
func printPixel(pixmap *okage.Pixmap, x, y uint32) {
c, _ := pixmap.Pixel(x, y)
fmt.Println(c.Red(), c.Green(), c.Blue(), c.Alpha())
}
func main() {
pb := okage.NewPathBuilder()
pb.PushCircle(250, 250, 200)
pb.PushCircle(250, 250, 100)
clipPath, _ := pb.Finish()
clipPath, _ = clipPath.Transform(okage.TransformFromRow(1, -0.3, 0, 1, 0, 75))
mask, _ := okage.NewMask(500, 500)
mask.FillPath(clipPath, okage.FillRuleEvenOdd, true, okage.DefaultTransform())
paint := okage.DefaultPaint()
paint.AntiAlias = false
paint.SetColorRGBA8(50, 127, 150, 200)
pixmap, _ := okage.NewPixmap(500, 500)
rect, _ := okage.RectFromXYWH(0, 0, 500, 500)
pixmap.FillRect(
rect,
&paint,
okage.IdentityTransform(),
mask,
)
printPixel(pixmap, 250, 100)
}
Output: 39 100 118 200
Example (Pattern) ¶
This example ports tiny-skia examples/pattern.rs. It fills a circle with a pattern of a small pixmap. The function create_triangle of the example is the same as crate_triangle of tests/integration/pattern.rs, so the example calls crateTriangle of pattern_integration_test.go.
triangle := crateTriangle() paint := okage.DefaultPaint() paint.AntiAlias = true paint.Shader = okage.NewPattern( triangle.AsRef(), okage.SpreadModeRepeat, okage.FilterQualityBicubic, 1, okage.TransformFromRow(1.5, -0.4, 0, -0.8, 5, 1), ) path, _ := okage.PathFromCircle(200, 200, 180) pixmap, _ := okage.NewPixmap(400, 400) pixmap.FillPath( path, &paint, okage.FillRuleWinding, okage.IdentityTransform(), nil, ) printPixel(pixmap, 200, 200)
Output: 39 100 118 200
Example (Stroke) ¶
This example ports tiny-skia examples/stroke.rs. It strokes a star with a dash and round caps.
Based on https://fiddle.skia.org/c/@compose_path
package main
import (
"fmt"
"math"
"github.com/xo/okage"
)
// printPixel prints the premultiplied RGBA value of the pixel at x, y.
func printPixel(pixmap *okage.Pixmap, x, y uint32) {
c, _ := pixmap.Pixel(x, y)
fmt.Println(c.Red(), c.Green(), c.Blue(), c.Alpha())
}
func main() {
paint := okage.DefaultPaint()
paint.SetColorRGBA8(0, 127, 0, 200)
paint.AntiAlias = true
const radius float32 = 250
const center float32 = 250
pb := okage.NewPathBuilder()
pb.MoveTo(center+radius, center)
for i := 1; i < 8; i++ {
a := 2.6927937 * float32(i)
// Rust calls cosf and sinf of the C library. The functions of the
// package math can give another last bit for a rare input.
cos := float32(math.Cos(float64(a)))
sin := float32(math.Sin(float64(a)))
pb.LineTo(center+float32(radius*cos), center+float32(radius*sin))
}
path, _ := pb.Finish()
stroke := okage.DefaultStroke()
stroke.Width = 6
stroke.LineCap = okage.LineCapRound
stroke.Dash, _ = okage.NewStrokeDash([]float32{20, 40}, 0)
pixmap, _ := okage.NewPixmap(500, 500)
pixmap.StrokePath(path, &paint, &stroke, okage.IdentityTransform(), nil)
printPixel(pixmap, 497, 250)
}
Output: 0 100 0 200
Index ¶
- Constants
- Variables
- func ComputeResolutionScale(ts Transform) float32
- type BlendMode
- type Color
- func (c Color) Alpha() float32
- func (c *Color) ApplyOpacity(opacity float32)
- func (c Color) Blue() float32
- func (c Color) Green() float32
- func (c Color) IsOpaque() bool
- func (c Color) Premultiply() PremultipliedColor
- func (c Color) Red() float32
- func (c *Color) SetAlpha(v float32)
- func (c *Color) SetBlue(v float32)
- func (c *Color) SetGreen(v float32)
- func (c *Color) SetRed(v float32)
- func (c Color) ToColorU8() ColorU8
- type ColorSpace
- type ColorU8
- type Error
- type FillRule
- type FilterQuality
- type GradientStop
- type IntRect
- type IntSize
- type LineCap
- type LineJoin
- type LinearGradient
- type Mask
- func DecodeMaskPNG(data []byte, opts ...Option) (*Mask, error)
- func LoadMaskPNG(name string, opts ...Option) (*Mask, error)
- func MaskFromPixmap(pixmap PixmapRef, maskType MaskType, opts ...Option) *Mask
- func MaskFromVec(data []byte, size path.IntSize, opts ...Option) (*Mask, bool)
- func NewMask(width, height uint32, opts ...Option) (*Mask, bool)
- func (m *Mask) Clear()
- func (m *Mask) Clone() *Mask
- func (m *Mask) Data() []byte
- func (m *Mask) DataMut() []byte
- func (m *Mask) EncodePNG() ([]byte, error)
- func (m *Mask) FillPath(p *Path, fillRule FillRule, antiAlias bool, transform Transform)
- func (m *Mask) Height() uint32
- func (m *Mask) IntersectPath(p *Path, fillRule FillRule, antiAlias bool, transform Transform)
- func (m *Mask) Invert()
- func (m *Mask) SavePNG(name string) error
- func (m *Mask) Size() path.IntSize
- func (m *Mask) String() string
- func (m *Mask) Take() []byte
- func (m *Mask) Width() uint32
- type MaskType
- type NonZeroRect
- type Option
- type Paint
- type Path
- type PathBuilder
- type PathSegment
- type PathSegmentKind
- type PathSegmentsIter
- type PathStroker
- type Pattern
- type PixelSlice
- type Pixmap
- func (p *Pixmap) ApplyMask(mask *Mask)
- func (p *Pixmap) AsMut() PixmapMut
- func (p *Pixmap) AsRGBA() *image.RGBA
- func (p *Pixmap) AsRef() PixmapRef
- func (p *Pixmap) At(x, y int) color.Color
- func (p *Pixmap) Bounds() image.Rectangle
- func (p *Pixmap) Clone() *Pixmap
- func (p *Pixmap) CloneRect(rect IntRect) (*Pixmap, bool)
- func (p *Pixmap) ColorModel() color.Model
- func (p *Pixmap) Data() []byte
- func (p *Pixmap) DataMut() []byte
- func (p *Pixmap) DrawPixmap(x, y int32, pixmap PixmapRef, paint *PixmapPaint, transform Transform, ...)
- func (p *Pixmap) EncodePNG() ([]byte, error)
- func (p *Pixmap) Fill(color Color)
- func (p *Pixmap) FillPath(pa *Path, paint *Paint, fillRule FillRule, transform Transform, mask *Mask)
- func (p *Pixmap) FillRect(rect Rect, paint *Paint, transform Transform, mask *Mask)
- func (p *Pixmap) Height() uint32
- func (p *Pixmap) Pixel(x, y uint32) (PremultipliedColorU8, bool)
- func (p *Pixmap) Pixels() PixelSlice
- func (p *Pixmap) PixelsMut() PixelSlice
- func (p *Pixmap) SavePNG(name string) error
- func (p *Pixmap) Set(x, y int, c color.Color)
- func (p *Pixmap) Size() path.IntSize
- func (p *Pixmap) StrokePath(pa *Path, paint *Paint, stroke *Stroke, transform Transform, mask *Mask)
- func (p *Pixmap) Take() []byte
- func (p *Pixmap) TakeDemultiplied() []byte
- func (p *Pixmap) Width() uint32
- type PixmapMut
- func (m *PixmapMut) ApplyMask(mask *Mask)
- func (m *PixmapMut) AsRef() PixmapRef
- func (m *PixmapMut) DataMut() []byte
- func (m *PixmapMut) DrawPixmap(x, y int32, pixmap PixmapRef, paint *PixmapPaint, transform Transform, ...)
- func (m *PixmapMut) Fill(color Color)
- func (m *PixmapMut) FillPath(p *Path, paint *Paint, fillRule FillRule, transform Transform, mask *Mask)
- func (m *PixmapMut) FillRect(rect Rect, paint *Paint, transform Transform, mask *Mask)
- func (m *PixmapMut) Height() uint32
- func (m *PixmapMut) PixelsMut() PixelSlice
- func (m *PixmapMut) Size() path.IntSize
- func (m *PixmapMut) StrokePath(p *Path, paint *Paint, stroke *Stroke, transform Transform, mask *Mask)
- func (m *PixmapMut) ToOwned() *Pixmap
- func (m *PixmapMut) Width() uint32
- type PixmapPaint
- type PixmapRef
- func (r PixmapRef) CloneRect(rect IntRect) (*Pixmap, bool)
- func (r PixmapRef) Data() []byte
- func (r PixmapRef) EncodePNG() ([]byte, error)
- func (r PixmapRef) Height() uint32
- func (r PixmapRef) Pixel(x, y uint32) (PremultipliedColorU8, bool)
- func (r PixmapRef) Pixels() PixelSlice
- func (r PixmapRef) SavePNG(name string) error
- func (r PixmapRef) Size() path.IntSize
- func (r PixmapRef) ToOwned() *Pixmap
- func (r PixmapRef) Width() uint32
- type Point
- type PremultipliedColor
- type PremultipliedColorU8
- type RadialGradient
- type Rect
- type Shader
- func NewLinearGradient(start Point, end Point, stops []GradientStop, mode SpreadMode, ...) (Shader, bool)
- func NewPattern(pixmap PixmapRef, spreadMode SpreadMode, quality FilterQuality, ...) Shader
- func NewRadialGradient(startPoint Point, startRadius float32, endPoint Point, endRadius float32, ...) (Shader, bool)
- func NewSweepGradient(center Point, startAngle float32, endAngle float32, stops []GradientStop, ...) (Shader, bool)
- type Size
- type SolidColor
- type SpreadMode
- type Stroke
- type StrokeDash
- type SweepGradient
- type Transform
- func DefaultTransform() Transform
- func IdentityTransform() Transform
- func TransformFromBBox(bbox NonZeroRect) Transform
- func TransformFromRotate(angle float32) Transform
- func TransformFromRotateAt(angle, tx, ty float32) Transform
- func TransformFromRow(sx, ky, kx, sy, tx, ty float32) Transform
- func TransformFromScale(sx, sy float32) Transform
- func TransformFromSkew(kx, ky float32) Transform
- func TransformFromTranslate(tx, ty float32) Transform
Examples ¶
Constants ¶
const ( // LineCapButt is LineCap::Butt. LineCapButt = path.LineCapButt // LineCapRound is LineCap::Round. LineCapRound = path.LineCapRound // LineCapSquare is LineCap::Square. LineCapSquare = path.LineCapSquare // LineJoinMiter is LineJoin::Miter. LineJoinMiter = path.LineJoinMiter // LineJoinMiterClip is LineJoin::MiterClip. LineJoinMiterClip = path.LineJoinMiterClip // LineJoinRound is LineJoin::Round. LineJoinRound = path.LineJoinRound // LineJoinBevel is LineJoin::Bevel. LineJoinBevel = path.LineJoinBevel // PathSegmentMoveTo is PathSegment::MoveTo. PathSegmentMoveTo = path.PathSegmentMoveTo // PathSegmentLineTo is PathSegment::LineTo. PathSegmentLineTo = path.PathSegmentLineTo // PathSegmentQuadTo is PathSegment::QuadTo. PathSegmentQuadTo = path.PathSegmentQuadTo // PathSegmentCubicTo is PathSegment::CubicTo. PathSegmentCubicTo = path.PathSegmentCubicTo // PathSegmentClose is PathSegment::Close. PathSegmentClose = path.PathSegmentClose )
The constants below are the variants of the enums that tiny-skia src/lib.rs re-exports. In Rust, a variant comes with its enum.
const AlphaOpaque = path.NormalizedF32One
AlphaOpaque is ALPHA_OPAQUE in tiny-skia src/color.rs. It represents a fully opaque alpha value.
const AlphaTransparent = path.NormalizedF32Zero
AlphaTransparent is ALPHA_TRANSPARENT in tiny-skia src/color.rs. It represents a fully transparent alpha value.
const AlphaU8Opaque uint8 = 0xFF
AlphaU8Opaque is ALPHA_U8_OPAQUE in tiny-skia src/color.rs. It represents a fully opaque AlphaU8 value.
const AlphaU8Transparent uint8 = 0x00
AlphaU8Transparent is ALPHA_U8_TRANSPARENT in tiny-skia src/color.rs. It represents a fully transparent AlphaU8 value.
const BytesPerPixel = 4
BytesPerPixel is BYTES_PER_PIXEL in tiny-skia src/pixmap.rs. It is the number of bytes per pixel.
Variables ¶
var ColorBlack = Color{/* contains filtered or unexported fields */}
ColorBlack is Color::BLACK in tiny-skia src/color.rs. It is a black color.
var ColorTransparent = Color{/* contains filtered or unexported fields */}
ColorTransparent is Color::TRANSPARENT in tiny-skia src/color.rs. It is a transparent color.
var ColorWhite = Color{/* contains filtered or unexported fields */}
ColorWhite is Color::WHITE in tiny-skia src/color.rs. It is a white color.
var PremultipliedColorU8Transparent = premultipliedColorU8FromRGBAUnchecked(0, 0, 0, 0)
PremultipliedColorU8Transparent is PremultipliedColorU8::TRANSPARENT in tiny-skia src/color.rs. It is a transparent color.
Functions ¶
func ComputeResolutionScale ¶
ComputeResolutionScale is PathStroker::compute_resolution_scale. It calls path.ComputeResolutionScale.
Types ¶
type BlendMode ¶
type BlendMode uint8
BlendMode is BlendMode in tiny-skia src/blend_mode.rs. It is a blending mode.
const ( // BlendModeClear is BlendMode::Clear. It replaces destination with zero: // fully transparent. BlendModeClear BlendMode = iota // BlendModeSource is BlendMode::Source. It replaces destination. BlendModeSource // BlendModeDestination is BlendMode::Destination. It preserves // destination. BlendModeDestination // BlendModeSourceOver is BlendMode::SourceOver, the default. It draws // source over destination. BlendModeSourceOver // BlendModeDestinationOver is BlendMode::DestinationOver. It draws // destination over source. BlendModeDestinationOver // BlendModeSourceIn is BlendMode::SourceIn. It keeps the source inside // destination. BlendModeSourceIn // BlendModeDestinationIn is BlendMode::DestinationIn. It keeps the // destination inside source. BlendModeDestinationIn // BlendModeSourceOut is BlendMode::SourceOut. It keeps the source // outside destination. BlendModeSourceOut // BlendModeDestinationOut is BlendMode::DestinationOut. It keeps the // destination outside source. BlendModeDestinationOut // BlendModeSourceAtop is BlendMode::SourceAtop. It blends the source // inside destination with destination. BlendModeSourceAtop // BlendModeDestinationAtop is BlendMode::DestinationAtop. It blends the // destination inside source with source. BlendModeDestinationAtop // BlendModeXor is BlendMode::Xor. It keeps each of source and // destination outside the other. BlendModeXor // BlendModePlus is BlendMode::Plus. It is the sum of colors. BlendModePlus // BlendModeModulate is BlendMode::Modulate. It is the product of // premultiplied colors. It darkens destination. BlendModeModulate // BlendModeScreen is BlendMode::Screen. It multiplies the inverse of the // pixels and inverts the result. It brightens destination. BlendModeScreen // BlendModeOverlay is BlendMode::Overlay. It multiplies or screens, // depending on destination. BlendModeOverlay // BlendModeDarken is BlendMode::Darken. It keeps the darker of source // and destination. BlendModeDarken // BlendModeLighten is BlendMode::Lighten. It keeps the lighter of source // and destination. BlendModeLighten // BlendModeColorDodge is BlendMode::ColorDodge. It brightens destination // to reflect source. BlendModeColorDodge // BlendModeColorBurn is BlendMode::ColorBurn. It darkens destination to // reflect source. BlendModeColorBurn // BlendModeHardLight is BlendMode::HardLight. It multiplies or screens, // depending on source. BlendModeHardLight // BlendModeSoftLight is BlendMode::SoftLight. It lightens or darkens, // depending on source. BlendModeSoftLight // BlendModeDifference is BlendMode::Difference. It subtracts the darker // from the lighter with higher contrast. BlendModeDifference // BlendModeExclusion is BlendMode::Exclusion. It subtracts the darker // from the lighter with lower contrast. BlendModeExclusion // BlendModeMultiply is BlendMode::Multiply. It multiplies source with // destination, which darkens the image. BlendModeMultiply // BlendModeHue is BlendMode::Hue. It takes the hue of source with the // saturation and luminosity of destination. BlendModeHue // BlendModeSaturation is BlendMode::Saturation. It takes the saturation // of source with the hue and luminosity of destination. BlendModeSaturation // BlendModeColor is BlendMode::Color. It takes the hue and saturation of // source with the luminosity of destination. BlendModeColor // BlendModeLuminosity is BlendMode::Luminosity. It takes the luminosity // of source with the hue and saturation of destination. BlendModeLuminosity )
The values of BlendMode, in the order of the Rust enum.
type Color ¶
type Color struct {
// contains filtered or unexported fields
}
Color is Color in tiny-skia src/color.rs. It is an RGBA color value that holds four floating point components.
All values are in the range 0..=1.
func ColorFromRGBA ¶
ColorFromRGBA is Color::from_rgba in tiny-skia src/color.rs. It creates a new color from 4 components.
All values must be in the range 0..=1. If not, it returns false.
func ColorFromRGBA8 ¶
ColorFromRGBA8 is Color::from_rgba8 in tiny-skia src/color.rs. It creates a new color from 4 components.
Each uint8 is divided by 255 to get the float component.
func ColorFromRGBAUnchecked ¶
ColorFromRGBAUnchecked is Color::from_rgba_unchecked in tiny-skia src/color.rs. It creates a new color from 4 components.
All values must be in the range 0..=1. It does not check them.
func (Color) Alpha ¶
Alpha is Color::alpha in tiny-skia src/color.rs. It returns the alpha component of the color.
The value is guaranteed to be in the range 0..=1.
func (*Color) ApplyOpacity ¶
ApplyOpacity is Color::apply_opacity in tiny-skia src/color.rs. It shifts the opacity of the color.
It multiplies the alpha of the color by opacity. opacity is clamped to the range 0..=1 first. The final alpha is also clamped.
func (Color) Blue ¶
Blue is Color::blue in tiny-skia src/color.rs. It returns the blue component of the color.
The value is guaranteed to be in the range 0..=1.
func (Color) Green ¶
Green is Color::green in tiny-skia src/color.rs. It returns the green component of the color.
The value is guaranteed to be in the range 0..=1.
func (Color) IsOpaque ¶
IsOpaque is Color::is_opaque in tiny-skia src/color.rs. It returns true if the alpha is 1.0.
func (Color) Premultiply ¶
func (c Color) Premultiply() PremultipliedColor
Premultiply is Color::premultiply in tiny-skia src/color.rs. It converts the color into a premultiplied color.
func (Color) Red ¶
Red is Color::red in tiny-skia src/color.rs. It returns the red component of the color.
The value is guaranteed to be in the range 0..=1.
func (*Color) SetAlpha ¶
SetAlpha is Color::set_alpha in tiny-skia src/color.rs. It sets the alpha component.
The new value is clipped to the range 0..=1.
func (*Color) SetBlue ¶
SetBlue is Color::set_blue in tiny-skia src/color.rs. It sets the blue component.
The new value is clipped to the range 0..=1.
func (*Color) SetGreen ¶
SetGreen is Color::set_green in tiny-skia src/color.rs. It sets the green component.
The new value is clipped to the range 0..=1.
type ColorSpace ¶
type ColorSpace uint8
ColorSpace is ColorSpace in tiny-skia src/color.rs. It is the color space that is used to interpret the values of pixels.
This is a very limited subset of SkColorSpace.
const ( // ColorSpaceLinear is linear RGB, the default. It assumes that #7f7f7f // is half as bright as #ffffff. ColorSpaceLinear ColorSpace = iota // ColorSpaceGamma2 applies a gamma factor of 2. // // This is the fastest gamma correction to apply, and it produces // reasonable quality blending. ColorSpaceGamma2 // ColorSpaceSimpleSRGB applies a gamma factor of 2.2. // // This is also known as "simple sRGB". It is very close to the actual // gamma function that the sRGB color space specifies, but much faster to // compute. ColorSpaceSimpleSRGB // ColorSpaceFullSRGBGamma applies the full sRGB gamma function. // // This does not convert the RGB colors to CIE XYZ for blending. It only // applies the (full) gamma function. ColorSpaceFullSRGBGamma )
func (ColorSpace) String ¶
func (cs ColorSpace) String() string
String satisfies the fmt.Stringer interface. It returns the name of the Rust variant.
type ColorU8 ¶
type ColorU8 struct {
// contains filtered or unexported fields
}
ColorU8 is ColorU8 in tiny-skia src/color.rs. It is a 32-bit RGBA color value.
Byte order: RGBA.
func ColorU8FromRGBA ¶
ColorU8FromRGBA is ColorU8::from_rgba in tiny-skia src/color.rs. It creates a new color.
func (ColorU8) Alpha ¶
Alpha is ColorU8::alpha in tiny-skia src/color.rs. It returns the alpha component of the color.
func (ColorU8) Blue ¶
Blue is ColorU8::blue in tiny-skia src/color.rs. It returns the blue component of the color.
func (ColorU8) Green ¶
Green is ColorU8::green in tiny-skia src/color.rs. It returns the green component of the color.
func (ColorU8) IsOpaque ¶
IsOpaque is ColorU8::is_opaque in tiny-skia src/color.rs. It returns true if the alpha is 255.
func (ColorU8) Premultiply ¶
func (c ColorU8) Premultiply() PremultipliedColorU8
Premultiply is ColorU8::premultiply in tiny-skia src/color.rs. It converts the color into a premultiplied color.
type Error ¶
type Error string
Error is an error of okage. Each sentinel error of okage is a constant of this type, so that a caller can compare it with errors.Is.
const ( // ErrDecodingPNG is the error of DecodePNG, LoadPNG, DecodeMaskPNG and // LoadMaskPNG when the package image/png, or the file system, returns an // error. okage wraps that error with this one. Upstream returns the error // of the crate png. ErrDecodingPNG Error = "decoding png" // ErrEncodingPNG is the error of EncodePNG and SavePNG of a Pixmap and of // a Mask when the package image/png, or the file system, returns an // error. okage wraps that error with this one. Upstream returns the error // of the crate png. ErrEncodingPNG Error = "encoding png" // ErrUnsupportedPNG is the error of DecodePNG and DecodeMaskPNG for a PNG // image that tiny-skia does not support. Upstream gives "unsupported bit // depth", "indexed PNG is not supported" and "only grayscale masks are // supported". ErrUnsupportedPNG Error = "decoding png: unsupported image" // ErrInvalidImageSize is the error of DecodePNG and DecodeMaskPNG for an // image with a zero width or height. Upstream gives "invalid image size". ErrInvalidImageSize Error = "decoding png: invalid image size" // ErrImageTooBig is the error of DecodePNG for an image that is larger // than a Pixmap can hold. Upstream gives "image is too big". ErrImageTooBig Error = "decoding png: image is too big" // ErrCreatingPixmap is the error of DecodePNG when the decoded pixels do // not make a Pixmap. Upstream gives "failed to create a pixmap". ErrCreatingPixmap Error = "decoding png: creating a pixmap" // ErrCreatingMask is the error of DecodeMaskPNG when the decoded values do // not make a Mask. Upstream gives "failed to create a mask". ErrCreatingMask Error = "decoding png: creating a mask" )
The sentinel errors of okage.
const ( // ErrXMLInvalidXMLPrefixURI is Error::InvalidXmlPrefixUri of roxmltree. // The `xmlns:xml` attribute must have an // <http://www.w3.org/XML/1998/namespace> URI. ErrXMLInvalidXMLPrefixURI Error = "parsing xml: 'xml' namespace prefix mapped to wrong URI" // ErrXMLUnexpectedXMLURI is Error::UnexpectedXmlUri of roxmltree. Only // the `xmlns:xml` attribute can have the // <http://www.w3.org/XML/1998/namespace> URI. ErrXMLUnexpectedXMLURI Error = "parsing xml: the 'xml' namespace URI is used for not 'xml' prefix" // ErrXMLUnexpectedXMLNSURI is Error::UnexpectedXmlnsUri of roxmltree. // The <http://www.w3.org/2000/xmlns/> URI must not be declared. ErrXMLUnexpectedXMLNSURI Error = "parsing xml: the 'xmlns' URI is used, but it must not be declared" // ErrXMLInvalidElementNamePrefix is Error::InvalidElementNamePrefix of // roxmltree. `xmlns` can not be used as an element prefix. ErrXMLInvalidElementNamePrefix Error = "parsing xml: the 'xmlns' prefix is used, but it must not be" // ErrXMLDuplicatedNamespace is Error::DuplicatedNamespace of roxmltree. // A namespace was already defined on this element. ErrXMLDuplicatedNamespace Error = "parsing xml: namespace is already defined" // ErrXMLUnknownNamespace is Error::UnknownNamespace of roxmltree. An // element or an attribute has an unknown qualified name prefix. ErrXMLUnknownNamespace Error = "parsing xml: an unknown namespace prefix" // ErrXMLUnexpectedCloseTag is Error::UnexpectedCloseTag of roxmltree. // The tree structure is not correct. ErrXMLUnexpectedCloseTag Error = "parsing xml: unexpected close tag name" // ErrXMLUnexpectedEntityCloseTag is Error::UnexpectedEntityCloseTag of // roxmltree. An entity value starts with a close tag. ErrXMLUnexpectedEntityCloseTag Error = "parsing xml: unexpected close tag" // ErrXMLUnknownEntityReference is Error::UnknownEntityReference of // roxmltree. A reference names an entity that the DTD does not define. ErrXMLUnknownEntityReference Error = "parsing xml: unknown entity reference" // ErrXMLMalformedEntityReference is Error::MalformedEntityReference of // roxmltree. A `&` character inside an attribute value or text does not // start a correct reference. ErrXMLMalformedEntityReference Error = "parsing xml: malformed entity reference" // ErrXMLEntityReferenceLoop is Error::EntityReferenceLoop of roxmltree. // The depth limit of entities is 10, and an entity can expand 255 // references at most. ErrXMLEntityReferenceLoop Error = "parsing xml: a possible entity reference loop is detected" // ErrXMLInvalidAttributeValue is Error::InvalidAttributeValue of // roxmltree. An attribute value cannot have a `<` character. ErrXMLInvalidAttributeValue Error = "parsing xml: unescaped '<' found" // ErrXMLDuplicatedAttribute is Error::DuplicatedAttribute of roxmltree. // An element has a duplicated attribute, after namespaces are resolved. ErrXMLDuplicatedAttribute Error = "parsing xml: attribute is already defined" // ErrXMLNoRootNode is Error::NoRootNode of roxmltree. The XML document // must have at least one element. ErrXMLNoRootNode Error = "parsing xml: the document does not have a root node" // ErrXMLUnclosedRootNode is Error::UnclosedRootNode of roxmltree. The // root node was opened but never closed. ErrXMLUnclosedRootNode Error = "parsing xml: the root node was opened but never closed" // ErrXMLUnexpectedDeclaration is Error::UnexpectedDeclaration of // roxmltree. An XML document can have only one XML declaration, at its // start. ErrXMLUnexpectedDeclaration Error = "parsing xml: unexpected XML declaration" // ErrXMLDTDDetected is Error::DtdDetected of roxmltree. The document has // a DTD and the option AllowDTD is false. ErrXMLDTDDetected Error = "parsing xml: XML with DTD detected" // ErrXMLNodesLimitReached is Error::NodesLimitReached of roxmltree. The // document has more nodes than the option NodesLimit allows. ErrXMLNodesLimitReached Error = "parsing xml: nodes limit reached" // ErrXMLAttributesLimitReached is Error::AttributesLimitReached of // roxmltree. The document has too many attributes. ErrXMLAttributesLimitReached Error = "parsing xml: more than 2^32 attributes were parsed" // ErrXMLNamespacesLimitReached is Error::NamespacesLimitReached of // roxmltree. The document has too many namespaces. ErrXMLNamespacesLimitReached Error = "parsing xml: more than 2^16 unique namespaces were parsed" // ErrXMLInvalidName is Error::InvalidName of roxmltree. ErrXMLInvalidName Error = "parsing xml: invalid name token" // ErrXMLNonXMLChar is Error::NonXmlChar of roxmltree. The valid // characters are those of <https://www.w3.org/TR/xml/#char32>. ErrXMLNonXMLChar Error = "parsing xml: a non-XML character found" // ErrXMLInvalidChar is Error::InvalidChar of roxmltree. A byte is not // the one that was expected. ErrXMLInvalidChar Error = "parsing xml: unexpected character" // ErrXMLInvalidChar2 is Error::InvalidChar2 of roxmltree. A byte is not // of the kind that was expected. ErrXMLInvalidChar2 Error = "parsing xml: unexpected character kind" // ErrXMLInvalidString is Error::InvalidString of roxmltree. A string is // not the one that was expected. ErrXMLInvalidString Error = "parsing xml: unexpected string" // ErrXMLInvalidExternalID is Error::InvalidExternalID of roxmltree. The // DTD has an ExternalID that is not correct. ErrXMLInvalidExternalID Error = "parsing xml: invalid ExternalID" // ErrXMLEntityResolver is Error::EntityResolver of roxmltree. The entity // resolver returned an error. ErrXMLEntityResolver Error = "parsing xml: entity resolver failed" // ErrXMLInvalidComment is Error::InvalidComment of roxmltree. A comment // cannot contain `--` or end with `-`. ErrXMLInvalidComment Error = "parsing xml: comment contains '--'" // ErrXMLInvalidCharacterData is Error::InvalidCharacterData of // roxmltree. Character data cannot contain `]]>`. ErrXMLInvalidCharacterData Error = "parsing xml: ']]>' is not allowed inside a character data" // ErrXMLUnknownToken is Error::UnknownToken of roxmltree. ErrXMLUnknownToken Error = "parsing xml: unknown token" //nolint:gosec // G101: an error message, not a credential. // ErrXMLUnexpectedEndOfStream is Error::UnexpectedEndOfStream of // roxmltree. The stream ended earlier than expected. ErrXMLUnexpectedEndOfStream Error = "parsing xml: unexpected end of stream" )
The sentinel errors of internal/roxmltree.
const ( // ErrCSSUnexpectedEndOfStream is Error::UnexpectedEndOfStream in // simplecss src/lib.rs. The stream ended earlier than the parser // expected. Upstream gives "unexpected end of stream". ErrCSSUnexpectedEndOfStream Error = "parsing css: unexpected end of stream" // ErrCSSInvalidIdent is Error::InvalidIdent in simplecss src/lib.rs. // Upstream gives "invalid ident at <row>:<col>". ErrCSSInvalidIdent Error = "parsing css: invalid ident" // ErrCSSInvalidComment is Error::InvalidComment in simplecss src/lib.rs, // for a comment that is not closed. Upstream gives "invalid comment at // <row>:<col>". ErrCSSInvalidComment Error = "parsing css: invalid comment" // ErrCSSInvalidValue is Error::InvalidValue in simplecss src/lib.rs, for // an invalid value of a declaration. Upstream gives "invalid value at // <row>:<col>". ErrCSSInvalidValue Error = "parsing css: invalid value" // ErrCSSInvalidByte is Error::InvalidByte in simplecss src/lib.rs. // Upstream gives "expected '<byte>' not '<byte>' at <row>:<col>". ErrCSSInvalidByte Error = "parsing css: invalid byte" // ErrCSSSelectorMissing is Error::SelectorMissing in simplecss // src/lib.rs. Upstream gives "selector missing". ErrCSSSelectorMissing Error = "parsing css: selector missing" // ErrCSSUnexpectedSelector is Error::UnexpectedSelector in simplecss // src/lib.rs. Upstream gives "unexpected selector". ErrCSSUnexpectedSelector Error = "parsing css: unexpected selector" // ErrCSSUnexpectedCombinator is Error::UnexpectedCombinator in simplecss // src/lib.rs. Upstream gives "unexpected combinator". ErrCSSUnexpectedCombinator Error = "parsing css: unexpected combinator" // ErrCSSInvalidAttributeSelector is Error::InvalidAttributeSelector in // simplecss src/lib.rs, for an invalid or unsupported attribute // selector. Upstream gives "invalid or unsupported attribute selector". ErrCSSInvalidAttributeSelector Error = "parsing css: invalid or unsupported attribute selector" // ErrCSSInvalidLanguagePseudoClass is Error::InvalidLanguagePseudoClass // in simplecss src/lib.rs. Upstream gives "invalid language // pseudo-class". ErrCSSInvalidLanguagePseudoClass Error = "parsing css: invalid language pseudo-class" )
The sentinel errors of internal/simplecss.
const ( // ErrSVGTypesUnexpectedEndOfStream is Error::UnexpectedEndOfStream in // svgtypes src/error.rs. An input data ended earlier than expected. ErrSVGTypesUnexpectedEndOfStream Error = "parsing svg value: unexpected end of stream" // ErrSVGTypesUnexpectedData is Error::UnexpectedData in svgtypes // src/error.rs. An input text contains unknown data. The error wraps it // with the position. ErrSVGTypesUnexpectedData Error = "parsing svg value: unexpected data" // ErrSVGTypesInvalidValue is Error::InvalidValue in svgtypes src/error.rs. // A provided string does not have a valid data. ErrSVGTypesInvalidValue Error = "parsing svg value: invalid value" // ErrSVGTypesInvalidIdent is Error::InvalidIdent in svgtypes src/error.rs. // An invalid CSS ident. ErrSVGTypesInvalidIdent Error = "parsing svg value: invalid ident" // ErrSVGTypesInvalidChar is Error::InvalidChar in svgtypes src/error.rs. // An invalid or unexpected character. The error wraps it with the actual // character, the expected characters and the position. ErrSVGTypesInvalidChar Error = "parsing svg value: invalid char" // ErrSVGTypesInvalidString is Error::InvalidString in svgtypes // src/error.rs. An unexpected string. The error wraps it with the actual // string, the expected strings and the position. ErrSVGTypesInvalidString Error = "parsing svg value: invalid string" // ErrSVGTypesInvalidNumber is Error::InvalidNumber in svgtypes // src/error.rs. An invalid number. The error wraps it with the position. ErrSVGTypesInvalidNumber Error = "parsing svg value: invalid number" )
The sentinel errors of the enum Error in svgtypes src/error.rs.
const ( // ErrSVGTypesViewBoxInvalidNumber is ViewBoxError::InvalidNumber in // svgtypes src/viewbox.rs. One of the numbers is invalid. ErrSVGTypesViewBoxInvalidNumber Error = "parsing svg value: viewBox contains an invalid number" // ErrSVGTypesViewBoxInvalidSize is ViewBoxError::InvalidSize in svgtypes // src/viewbox.rs. The viewBox has a negative or zero size. ErrSVGTypesViewBoxInvalidSize Error = "parsing svg value: viewBox has a negative or zero size" )
The sentinel errors of the enum ViewBoxError in svgtypes src/viewbox.rs.
const ( // ErrSVGTypesTransformOriginMissingParameters is // TransformOriginError::MissingParameters in svgtypes // src/transform_origin.rs. ErrSVGTypesTransformOriginMissingParameters Error = "parsing svg value: transform origin doesn't have enough parameters" // ErrSVGTypesTransformOriginInvalidParameters is // TransformOriginError::InvalidParameters in svgtypes // src/transform_origin.rs. One of the parameters is invalid. ErrSVGTypesTransformOriginInvalidParameters Error = "parsing svg value: transform origin has invalid parameters" // ErrSVGTypesTransformOriginZIndexIsPercentage is // TransformOriginError::ZIndexIsPercentage in svgtypes // src/transform_origin.rs. The z offset is a percentage. ErrSVGTypesTransformOriginZIndexIsPercentage Error = "parsing svg value: z-index cannot be a percentage" )
The sentinel errors of the enum TransformOriginError in svgtypes src/transform_origin.rs.
const ( // ErrSVGTypesFilterPercentageValue is // FilterValueListParserError::PercentageValue in svgtypes // src/filter_functions.rs. A length has a percentage value. ErrSVGTypesFilterPercentageValue Error = "parsing svg value: a percentage value detected" // ErrSVGTypesFilterNegativeValue is // FilterValueListParserError::NegativeValue in svgtypes // src/filter_functions.rs. A value is negative. ErrSVGTypesFilterNegativeValue Error = "parsing svg value: a negative value detected" // ErrSVGTypesFilterInvalidAngle is // FilterValueListParserError::InvalidAngle in svgtypes // src/filter_functions.rs. ErrSVGTypesFilterInvalidAngle Error = "parsing svg value: an invalid angle" // ErrSVGTypesFilterMissingDropShadowOffset is // FilterValueListParserError::MissingDropShadowOffset in svgtypes // src/filter_functions.rs. The offset values of drop-shadow are not set. ErrSVGTypesFilterMissingDropShadowOffset Error = "parsing svg value: drop-shadow offset values are expected" // ErrSVGTypesFilterInvalidURL is FilterValueListParserError::InvalidUrl // in svgtypes src/filter_functions.rs. Usually an empty url. ErrSVGTypesFilterInvalidURL Error = "parsing svg value: an invalid url" )
The sentinel errors of the enum FilterValueListParserError in svgtypes src/filter_functions.rs. Each one wraps the position. The case StreamErrors holds an Error of src/error.rs, and okage returns that error as it is.
const ( // ErrSVGNotAnUTF8Str is Error::NotAnUtf8Str in usvg src/parser/mod.rs. // Only UTF-8 content are supported. ErrSVGNotAnUTF8Str Error = "parsing svg: provided data has not an UTF-8 encoding" // ErrSVGMalformedGZip is Error::MalformedGZip in usvg // src/parser/mod.rs. Compressed SVG must use the GZip algorithm. ErrSVGMalformedGZip Error = "parsing svg: provided data has a malformed GZip content" // ErrSVGElementsLimitReached is Error::ElementsLimitReached in usvg // src/parser/mod.rs. usvg does not allow SVG with more than 1_000_000 // elements for security reasons. ErrSVGElementsLimitReached Error = "parsing svg: the maximum number of SVG elements has been reached" // ErrSVGInvalidSize is Error::InvalidSize in usvg src/parser/mod.rs. SVG // does not have a valid size. It occurs when width and/or height are // <= 0, and also if width, height and viewBox are not set. ErrSVGInvalidSize Error = "parsing svg: SVG has an invalid size" // ErrSVGParsingFailed is Error::ParsingFailed in usvg // src/parser/mod.rs. It failed to parse an SVG data. The error wraps // the error of internal/roxmltree. Upstream gives "SVG data parsing // failed cause " and the error of roxmltree. ErrSVGParsingFailed Error = "parsing svg: SVG data parsing failed" )
The sentinel errors of the enum Error in usvg src/parser/mod.rs. The case SvgzFeatureNotEnabled has no port, because okage always reads SVGZ data.
type FillRule ¶
type FillRule uint8
FillRule is FillRule in tiny-skia src/painter.rs. It is a path filling rule.
const ( // FillRuleWinding is FillRule::Winding, the default. It specifies that // "inside" is computed by a non-zero sum of signed edge crossings. FillRuleWinding FillRule = iota // FillRuleEvenOdd is FillRule::EvenOdd. It specifies that "inside" is // computed by an odd number of edge crossings. FillRuleEvenOdd )
type FilterQuality ¶
type FilterQuality uint8
FilterQuality is FilterQuality in tiny-skia src/shaders/pattern.rs. It controls how much filtering to be done when transforming images.
const ( // FilterQualityNearest is FilterQuality::Nearest. It is // nearest-neighbor: low quality, but fastest. FilterQualityNearest FilterQuality = iota // FilterQualityBilinear is FilterQuality::Bilinear. FilterQualityBilinear // FilterQualityBicubic is FilterQuality::Bicubic: high quality, but // slow. FilterQualityBicubic )
The values of FilterQuality, in the order of the Rust enum.
func (FilterQuality) String ¶
func (q FilterQuality) String() string
String satisfies the fmt.Stringer interface. It returns the name of the Rust variant.
type GradientStop ¶
type GradientStop struct {
// contains filtered or unexported fields
}
GradientStop is GradientStop in tiny-skia src/shaders/gradient.rs. It is a gradient point.
func NewGradientStop ¶
func NewGradientStop(position float32, color Color) GradientStop
NewGradientStop is GradientStop::new in tiny-skia src/shaders/gradient.rs. It creates a new gradient point.
position is clamped to a 0..=1 range.
type IntRect ¶
IntRect is the re-export of tiny_skia_path::IntRect in tiny-skia src/lib.rs. It is an integer rectangle.
func IntRectFromLTRB ¶
IntRectFromLTRB is IntRect::from_ltrb. It calls path.IntRectFromLTRB.
type IntSize ¶
IntSize is the re-export of tiny_skia_path::IntSize in tiny-skia src/lib.rs. It is an integer size.
func IntSizeFromWH ¶
IntSizeFromWH is IntSize::from_wh. It calls path.IntSizeFromWH.
type LineCap ¶
LineCap is the re-export of tiny_skia_path::LineCap in tiny-skia src/lib.rs. It is what a stroke draws at the ends of an open contour.
type LineJoin ¶
LineJoin is the re-export of tiny_skia_path::LineJoin in tiny-skia src/lib.rs. It is what a stroke draws at the corners of a path.
type LinearGradient ¶
type LinearGradient struct {
// contains filtered or unexported fields
}
LinearGradient is LinearGradient in tiny-skia src/shaders/linear_gradient.rs. It is a linear gradient shader.
func (LinearGradient) ApplyOpacity ¶
func (g LinearGradient) ApplyOpacity(opacity float32) Shader
ApplyOpacity is the arm Shader::LinearGradient of Shader::apply_opacity in tiny-skia src/shaders/mod.rs.
func (LinearGradient) IsOpaque ¶
func (g LinearGradient) IsOpaque() bool
IsOpaque is LinearGradient::is_opaque in tiny-skia src/shaders/linear_gradient.rs, and the arm Shader::LinearGradient of Shader::is_opaque in tiny-skia src/shaders/mod.rs.
func (LinearGradient) Transform ¶
func (g LinearGradient) Transform(ts Transform) Shader
Transform is the arm Shader::LinearGradient of Shader::transform in tiny-skia src/shaders/mod.rs.
type Mask ¶
type Mask struct {
// contains filtered or unexported fields
}
Mask is Mask in tiny-skia src/mask.rs. It is a mask.
During drawing over Pixmap, mask's black (0) "pixels" block rendering and white (255) allow it. Anything in between is used for gradual masking and anti-aliasing.
Unlike Skia, we are using just a simple 8bit alpha mask. It is way slower, but easier to implement.
Port: logger is the logger of D20, which FillPath logs to. The option WithLogger sets it. A nil logger logs nothing.
func DecodeMaskPNG ¶
DecodeMaskPNG is Mask::decode_png in tiny-skia src/mask.rs. It loads a PNG file into a Mask.
Only grayscale images are supported.
Port: upstream decodes with the crate png and asks it to expand a gray image with fewer than 8 bits and to strip 16 bits to 8 bits. The package image/png decodes the image here (D7). It gives an image.Gray for a gray image of 8 bits or fewer, with the same values, and an image.Gray16 for one of 16 bits, whose high byte is kept. opts configure the mask, as D20 says.
func LoadMaskPNG ¶
LoadMaskPNG is Mask::load_png in tiny-skia src/mask.rs. It loads a PNG file into a Mask.
Only grayscale images are supported.
Port: opts configure the mask, as D20 says.
func MaskFromPixmap ¶
MaskFromPixmap is Mask::from_pixmap in tiny-skia src/mask.rs. It creates a new mask from a PixmapRef.
Port: opts configure the mask, as D20 says.
func MaskFromVec ¶
MaskFromVec is Mask::from_vec in tiny-skia src/mask.rs. It creates a new mask by taking ownership over a mask buffer.
The size needs to match the data provided.
Port: Rust takes ownership of data. Go keeps data in the mask, so the caller does not use data after the call. opts configure the mask, as D20 says.
func NewMask ¶
NewMask is Mask::new in tiny-skia src/mask.rs. It creates a new mask, allocating a buffer of the given size.
Port: opts configure the mask, as D20 says. Upstream has no options.
func (*Mask) Clear ¶
func (m *Mask) Clear()
Clear is Mask::clear in tiny-skia src/mask.rs. It clears the mask.
It zero-fills the internal data buffer.
func (*Mask) Clone ¶
Clone is the derived Clone impl of Mask in tiny-skia src/mask.rs. It returns a copy of the mask with its own data.
func (*Mask) DataMut ¶
DataMut is Mask::data_mut in tiny-skia src/mask.rs. It returns the mutable internal data.
func (*Mask) EncodePNG ¶
EncodePNG is Mask::encode_png in tiny-skia src/mask.rs. It encodes the mask into PNG data.
Port: upstream encodes with the crate png, as 8-bit grayscale. The package image/png encodes here (D7), also as 8-bit grayscale. The bytes of the file can differ from upstream, and the decoded values are the same.
func (*Mask) FillPath ¶
FillPath is Mask::fill_path in tiny-skia src/mask.rs. It draws a filled path onto the mask.
It is almost a direct copy of PixmapMut.FillPath.
In terms of RGB (no alpha) image, it draws a white path on top of black mask.
It does not reset the existing mask content and draws the path on top of existing data.
If the above behavior is undesired, call Mask.Clear first.
This method is intended to be used for simple cases. For more complex masks prefer MaskFromPixmap.
Port: upstream logs a warning with log::warn!. Go logs it to the logger of the mask, as D20 says.
func (*Mask) IntersectPath ¶
IntersectPath is Mask::intersect_path in tiny-skia src/mask.rs. It intersects the provided path with the current clipping path.
A temporary mask with the same size as the current one is created.
func (*Mask) Invert ¶
func (m *Mask) Invert()
Invert is Mask::invert in tiny-skia src/mask.rs. It inverts the mask.
func (*Mask) SavePNG ¶
SavePNG is Mask::save_png in tiny-skia src/mask.rs. It saves the mask as a PNG file.
func (*Mask) Size ¶
Size is Mask::size in tiny-skia src/mask.rs. It returns mask's size.
Port: upstream makes it public in the crate only. Go exports it, as Pixmap.Size does.
func (*Mask) String ¶
String is the Debug impl of Mask in tiny-skia src/mask.rs. It satisfies the fmt.Stringer interface.
type MaskType ¶
type MaskType uint8
MaskType is MaskType in tiny-skia src/mask.rs. It is a mask type.
const ( // MaskTypeAlpha is MaskType::Alpha. It transfers only the Alpha channel // from Pixmap to Mask. MaskTypeAlpha MaskType = iota // MaskTypeLuminance is MaskType::Luminance. It transfers RGB channels as // luminance from Pixmap to Mask. // // Formula: Y = 0.2126 * R + 0.7152 * G + 0.0722 * B. MaskTypeLuminance )
The values of MaskType, in the order of the Rust enum.
type NonZeroRect ¶
type NonZeroRect = path.NonZeroRect
NonZeroRect is the re-export of tiny_skia_path::NonZeroRect in tiny-skia src/lib.rs. It is a rectangle with a width and a height above zero.
func NonZeroRectFromLTRB ¶
func NonZeroRectFromLTRB(left, top, right, bottom float32) (NonZeroRect, bool)
NonZeroRectFromLTRB is NonZeroRect::from_ltrb. It calls path.NonZeroRectFromLTRB.
func NonZeroRectFromXYWH ¶
func NonZeroRectFromXYWH(x, y, w, h float32) (NonZeroRect, bool)
NonZeroRectFromXYWH is NonZeroRect::from_xywh. It calls path.NonZeroRectFromXYWH.
type Option ¶
type Option func(*options)
Option is an option of a constructor of okage, such as NewPixmap or NewMask. It changes the configuration of the value that the constructor makes.
func WithLogger ¶
WithLogger is an option that sets the logger of a Pixmap or a Mask. The warnings that tiny-skia logs with log::warn! go to l, with the text of upstream. Without this option, okage logs nothing.
type Paint ¶
type Paint struct {
// Shader is the paint shader.
//
// Default: black color
Shader Shader
// BlendMode is the paint blending mode.
//
// Default: SourceOver
BlendMode BlendMode
// AntiAlias enables anti-aliased painting.
//
// Default: true
AntiAlias bool
// Colorspace is the colorspace for blending.
//
// This enables gamma correction during the blend operation. While skia
// supports full color-space conversions, we only support a few (simple)
// cases. Note that any color space other than Linear forces using the
// high-quality pipeline.
//
// Default: Linear
Colorspace ColorSpace
// ForceHQPipeline forces the high quality/precision rendering pipeline.
//
// tiny-skia, just like Skia, has two rendering pipelines: one uses f32
// and another one uses u16. The u16 one is usually way faster, but less
// precise. Which can lead to slight differences.
//
// By default, tiny-skia chooses the pipeline automatically, depending on
// a blending mode and other parameters. But you can force the high
// quality one using this flag.
//
// This feature is especially useful during testing.
//
// Unlike the high quality pipeline, the low quality one does not support
// all rendering stages, therefore we cannot force it like the hq one.
//
// Default: false
ForceHQPipeline bool
}
Paint is Paint in tiny-skia src/painter.rs. It controls how a shape is painted.
Port: the zero Paint is not the default of upstream. Its Shader is nil, its BlendMode is Clear and AntiAlias is false. Use DefaultPaint to get the default of upstream. A nil Shader is not valid, and drawing with it panics.
func DefaultPaint ¶
func DefaultPaint() Paint
DefaultPaint is the Default impl of Paint in tiny-skia src/painter.rs. It returns the default paint: solid black, SourceOver, anti-aliased, linear.
func (*Paint) IsSolidColor ¶
IsSolidColor is Paint::is_solid_color in tiny-skia src/painter.rs. It checks that the paint source is a solid color.
func (*Paint) SetColor ¶
SetColor is Paint::set_color in tiny-skia src/painter.rs. It sets a paint source to a solid color.
func (*Paint) SetColorRGBA8 ¶
SetColorRGBA8 is Paint::set_color_rgba8 in tiny-skia src/painter.rs. It sets a paint source to a solid color.
It is a shorthand for p.Shader = SolidColor(ColorFromRGBA8(r, g, b, a)).
type Path ¶
Path is the re-export of tiny_skia_path::Path in tiny-skia src/lib.rs. It is a Bezier path.
func PathFromCircle ¶
PathFromCircle is PathBuilder::from_circle. It calls path.PathFromCircle.
func PathFromOval ¶
PathFromOval is PathBuilder::from_oval. It calls path.PathFromOval.
func PathFromRect ¶
PathFromRect is PathBuilder::from_rect. It calls path.PathFromRect.
type PathBuilder ¶
type PathBuilder = path.PathBuilder
PathBuilder is the re-export of tiny_skia_path::PathBuilder in tiny-skia src/lib.rs. It builds a Path.
func NewPathBuilder ¶
func NewPathBuilder() *PathBuilder
NewPathBuilder is PathBuilder::new. It calls path.NewPathBuilder.
func NewPathBuilderWithCapacity ¶
func NewPathBuilderWithCapacity(verbsCapacity, pointsCapacity int) *PathBuilder
NewPathBuilderWithCapacity is PathBuilder::with_capacity. It calls path.NewPathBuilderWithCapacity.
type PathSegment ¶
type PathSegment = path.PathSegment
PathSegment is the re-export of tiny_skia_path::PathSegment in tiny-skia src/lib.rs. It is a segment of a path.
type PathSegmentKind ¶
type PathSegmentKind = path.PathSegmentKind
PathSegmentKind is the kind of a PathSegment. In Rust, it is the variant of the enum PathSegment, which tiny-skia src/lib.rs re-exports.
type PathSegmentsIter ¶
type PathSegmentsIter = path.PathSegmentsIter
PathSegmentsIter is the re-export of tiny_skia_path::PathSegmentsIter in tiny-skia src/lib.rs. It is an iterator over the segments of a path.
type PathStroker ¶
type PathStroker = path.PathStroker
PathStroker is the re-export of tiny_skia_path::PathStroker in tiny-skia src/lib.rs. It makes the outline of a stroke.
func NewPathStroker ¶
func NewPathStroker() *PathStroker
NewPathStroker is PathStroker::new. It calls path.NewPathStroker.
type Pattern ¶
type Pattern struct {
// contains filtered or unexported fields
}
Pattern is Pattern in tiny-skia src/shaders/pattern.rs. It is a pattern shader.
Essentially a SkImageShader.
Unlike Skia, we do not support FilterQuality::Medium, because it involves mipmap generation, which adds too much complexity.
func (Pattern) ApplyOpacity ¶
ApplyOpacity is the arm Shader::Pattern of Shader::apply_opacity in tiny-skia src/shaders/mod.rs.
type PixelSlice ¶
type PixelSlice []byte
PixelSlice is the Go form of the Rust slices &PremultipliedColorU8 and &mut PremultipliedColorU8, which tiny-skia src/pixmap.rs makes from the bytes of a pixmap with bytemuck. It ports no upstream item.
Go cannot view a []byte as a slice of colors without the package unsafe (D25), so a PixelSlice holds the bytes and reads or writes one pixel at a time. It shares the bytes of the pixmap. Its length is a multiple of BytesPerPixel.
func (PixelSlice) At ¶
func (s PixelSlice) At(i int) PremultipliedColorU8
At returns the pixel at index i. It panics if i is out of range.
func (PixelSlice) Set ¶
func (s PixelSlice) Set(i int, c PremultipliedColorU8)
Set sets the pixel at index i to c. It panics if i is out of range.
type Pixmap ¶
type Pixmap struct {
// contains filtered or unexported fields
}
Pixmap is Pixmap in tiny-skia src/pixmap.rs. It is a container that owns premultiplied RGBA pixels.
The data is not aligned, therefore width == stride.
Port: logger is the logger of D20, which the painter logs to. The option WithLogger sets it. A nil logger logs nothing.
func DecodePNG ¶
DecodePNG is Pixmap::decode_png in tiny-skia src/pixmap.rs. It decodes PNG data into a Pixmap.
Only 8-bit images are supported. Index PNGs are not supported.
Port: upstream decodes with the crate png, and asks it to expand a palette, a gray image with fewer than 8 bits and the tRNS chunk, and to strip 16 bits to 8 bits. The package image/png decodes the image here (D7). The conversion keeps the high byte of a 16-bit value and expands the other formats as the crate png does, so that the same pixels come out. Before it decodes the pixels, it reads the size of the image and makes the size checks of upstream, so that it does not allocate a huge image that upstream rejects later. opts configure the pixmap, as D20 says.
func LoadPNG ¶
LoadPNG is Pixmap::load_png in tiny-skia src/pixmap.rs. It loads a PNG file into a Pixmap.
Only 8-bit images are supported. Index PNGs are not supported.
Port: opts configure the pixmap, as D20 says.
func NewPixmap ¶
NewPixmap is Pixmap::new in tiny-skia src/pixmap.rs. It allocates a new pixmap.
A pixmap is filled with transparent black by default, aka (0, 0, 0, 0).
A zero size is an error, and NewPixmap returns false.
The width of a pixmap is limited by i32::MAX/4.
Port: opts configure the pixmap, as D20 says. Upstream has no options.
func PixmapFromVec ¶
PixmapFromVec is Pixmap::from_vec in tiny-skia src/pixmap.rs. It creates a new pixmap by taking ownership over an image buffer (premultiplied RGBA pixels).
The size needs to match the data provided.
The width of a pixmap is limited by i32::MAX/4.
Port: Rust takes ownership of data. Go keeps data in the pixmap, so the caller does not use data after the call. opts configure the pixmap, as D20 says.
func (*Pixmap) ApplyMask ¶
ApplyMask is Pixmap::apply_mask in tiny-skia src/painter.rs. It applies a mask.
See PixmapMut.ApplyMask for details.
func (*Pixmap) AsMut ¶
AsMut is Pixmap::as_mut in tiny-skia src/pixmap.rs. It returns a container that references the data of the pixmap.
func (*Pixmap) AsRGBA ¶
AsRGBA returns an *image.RGBA that shares the bytes of the pixmap. A change to one is a change to the other. Its bounds start at (0, 0).
func (*Pixmap) AsRef ¶
AsRef is Pixmap::as_ref in tiny-skia src/pixmap.rs. It returns a container that references the data of the pixmap.
func (*Pixmap) At ¶
At satisfies the image.Image interface. It returns the premultiplied color of the pixel at (x, y) as a color.RGBA. It returns a transparent color for a position outside the bounds.
func (*Pixmap) Clone ¶
Clone is the derived Clone impl of Pixmap in tiny-skia src/pixmap.rs. It returns a copy of the pixmap with its own data.
func (*Pixmap) CloneRect ¶
CloneRect is Pixmap::clone_rect in tiny-skia src/pixmap.rs. It returns a copy of the part of the pixmap that intersects rect.
It returns false when the rect of the pixmap does not contain rect.
func (*Pixmap) ColorModel ¶
ColorModel satisfies the image.Image interface. It returns color.RGBAModel, because the pixels are premultiplied 8-bit RGBA.
func (*Pixmap) Data ¶
Data is Pixmap::data in tiny-skia src/pixmap.rs. It returns the internal data.
Byte order: RGBA.
func (*Pixmap) DataMut ¶
DataMut is Pixmap::data_mut in tiny-skia src/pixmap.rs. It returns the mutable internal data.
Byte order: RGBA.
func (*Pixmap) DrawPixmap ¶
func (p *Pixmap) DrawPixmap( x, y int32, pixmap PixmapRef, paint *PixmapPaint, transform Transform, mask *Mask, )
DrawPixmap is Pixmap::draw_pixmap in tiny-skia src/painter.rs. It draws a Pixmap on top of the current Pixmap.
See PixmapMut.DrawPixmap for details. A nil mask is the Rust None.
func (*Pixmap) EncodePNG ¶
EncodePNG is Pixmap::encode_png in tiny-skia src/pixmap.rs. It encodes the pixmap into PNG data.
func (*Pixmap) Fill ¶
Fill is Pixmap::fill in tiny-skia src/pixmap.rs. It fills the entire pixmap with the given color.
func (*Pixmap) FillPath ¶
func (p *Pixmap) FillPath( pa *Path, paint *Paint, fillRule FillRule, transform Transform, mask *Mask, )
FillPath is Pixmap::fill_path in tiny-skia src/painter.rs. It draws a filled path onto the pixmap.
See PixmapMut.FillPath for details. A nil mask is the Rust None.
func (*Pixmap) FillRect ¶
FillRect is Pixmap::fill_rect in tiny-skia src/painter.rs. It draws a filled rectangle onto the pixmap.
See PixmapMut.FillRect for details. A nil mask is the Rust None.
func (*Pixmap) Height ¶
Height is Pixmap::height in tiny-skia src/pixmap.rs. It returns the height of the pixmap.
func (*Pixmap) Pixel ¶
func (p *Pixmap) Pixel(x, y uint32) (PremultipliedColorU8, bool)
Pixel is Pixmap::pixel in tiny-skia src/pixmap.rs. It returns the color of a pixel.
It returns false when the position is out of bounds.
func (*Pixmap) Pixels ¶
func (p *Pixmap) Pixels() PixelSlice
Pixels is Pixmap::pixels in tiny-skia src/pixmap.rs. It returns a slice of pixels.
func (*Pixmap) PixelsMut ¶
func (p *Pixmap) PixelsMut() PixelSlice
PixelsMut is Pixmap::pixels_mut in tiny-skia src/pixmap.rs. It returns a mutable slice of pixels.
func (*Pixmap) SavePNG ¶
SavePNG is Pixmap::save_png in tiny-skia src/pixmap.rs. It saves the pixmap as a PNG file.
func (*Pixmap) Set ¶
Set satisfies the draw.Image interface. It converts c to a premultiplied color.RGBA and stores it at (x, y). It does nothing for a position outside the bounds.
func (*Pixmap) Size ¶
Size is Pixmap::size in tiny-skia src/pixmap.rs. It returns the size of the pixmap.
Port: upstream makes it public in the crate only. Go exports it, because the method of PixmapRef has the same name.
func (*Pixmap) StrokePath ¶
func (p *Pixmap) StrokePath( pa *Path, paint *Paint, stroke *Stroke, transform Transform, mask *Mask, )
StrokePath is Pixmap::stroke_path in tiny-skia src/painter.rs. It strokes a path.
See PixmapMut.StrokePath for details. A nil mask is the Rust None.
func (*Pixmap) Take ¶
Take is Pixmap::take in tiny-skia src/pixmap.rs. It consumes the internal data.
Byte order: RGBA.
Port: Rust consumes the pixmap. Go returns the data, and the caller does not use p after the call.
func (*Pixmap) TakeDemultiplied ¶
TakeDemultiplied is Pixmap::take_demultiplied in tiny-skia src/pixmap.rs. It consumes the pixmap and returns the internal data as demultiplied RGBA bytes.
Byte order: RGBA.
Port: Rust consumes the pixmap. Go changes the data in place and returns it, and the caller does not use p after the call.
type PixmapMut ¶
type PixmapMut struct {
// contains filtered or unexported fields
}
PixmapMut is PixmapMut in tiny-skia src/pixmap.rs. It is a container that references mutable premultiplied RGBA pixels.
It can be created from a Pixmap or from data that the user gives.
The data is not aligned, therefore width == stride.
Port: logger is the logger of D20, which the painter logs to.
func PixmapMutFromBytes ¶
PixmapMutFromBytes is PixmapMut::from_bytes in tiny-skia src/pixmap.rs. It creates a new PixmapMut from bytes.
The size must be at least width * height * BytesPerPixel. A zero size is an error. The width is limited by i32::MAX/4.
The data is assumed to have premultiplied RGBA pixels (byte order: RGBA).
Port: opts configure the PixmapMut, as D20 says.
func (*PixmapMut) ApplyMask ¶
ApplyMask is PixmapMut::apply_mask in tiny-skia src/painter.rs. It applies a mask.
When a Mask is passed to drawing methods, it is used to mask-out content we are about to draw. This method masks-out an already drawn content. It is not as fast, but can be useful when a mask is not available during drawing.
This method is similar to filling the whole pixmap with another, mask-like pixmap using the DestinationOut blend mode.
The Mask must have the same size as the Pixmap. No transform or offset are allowed.
Port: upstream logs a warning with log::warn!. Go logs it to the logger of the pixmap, as D20 says.
func (*PixmapMut) AsRef ¶
AsRef is PixmapMut::as_ref in tiny-skia src/pixmap.rs. It returns a container that references the data of the pixmap.
func (*PixmapMut) DataMut ¶
DataMut is PixmapMut::data_mut in tiny-skia src/pixmap.rs. It returns the mutable internal data.
Byte order: RGBA.
func (*PixmapMut) DrawPixmap ¶
func (m *PixmapMut) DrawPixmap( x, y int32, pixmap PixmapRef, paint *PixmapPaint, transform Transform, mask *Mask, )
DrawPixmap is PixmapMut::draw_pixmap in tiny-skia src/painter.rs. It draws a Pixmap on top of the current Pixmap.
It is the same as filling a rectangle with a pixmap pattern.
A nil mask is the Rust None.
func (*PixmapMut) Fill ¶
Fill is PixmapMut::fill in tiny-skia src/pixmap.rs. It fills the entire pixmap with the given color.
func (*PixmapMut) FillPath ¶
func (m *PixmapMut) FillPath( p *Path, paint *Paint, fillRule FillRule, transform Transform, mask *Mask, )
FillPath is PixmapMut::fill_path in tiny-skia src/painter.rs. It draws a filled path onto the pixmap.
A nil mask is the Rust None.
Port: upstream logs a warning with log::warn!. Go logs it to the logger of the pixmap, as D20 says.
func (*PixmapMut) FillRect ¶
FillRect is PixmapMut::fill_rect in tiny-skia src/painter.rs. It draws a filled rectangle onto the pixmap.
This function is usually slower than filling a rectangular path, but it produces better results. Mainly it does not suffer from weird clipping of horizontal/vertical edges.
It is used mainly to render a pixmap onto a pixmap.
A nil mask is the Rust None.
func (*PixmapMut) Height ¶
Height is PixmapMut::height in tiny-skia src/pixmap.rs. It returns the height of the pixmap.
func (*PixmapMut) PixelsMut ¶
func (m *PixmapMut) PixelsMut() PixelSlice
PixelsMut is PixmapMut::pixels_mut in tiny-skia src/pixmap.rs. It returns a mutable slice of pixels.
func (*PixmapMut) Size ¶
Size is PixmapMut::size in tiny-skia src/pixmap.rs. It returns the size of the pixmap.
Port: upstream makes it public in the crate only. Go exports it, so that a later port, such as the painter, can call it.
func (*PixmapMut) StrokePath ¶
func (m *PixmapMut) StrokePath( p *Path, paint *Paint, stroke *Stroke, transform Transform, mask *Mask, )
StrokePath is PixmapMut::stroke_path in tiny-skia src/painter.rs. It strokes a path.
Stroking is implemented using two separate algorithms:
- If a stroke width is wider than 1px (after applying the transformation), a path is converted into a stroked path and then filled using FillPath. Which means that we have to allocate a separate Path, that can be 2-3x larger than the original path.
- If a stroke width is thinner than 1px (after applying the transformation), we use hairline stroking, which does not involve a separate path allocation.
Also, if a stroke has a dash array, then the path is converted into a dashed path first and then stroked. Which means yet another allocation.
A nil mask is the Rust None.
Port: upstream logs a warning with log::warn!. Go logs it to the logger of the pixmap, as D20 says.
type PixmapPaint ¶
type PixmapPaint struct {
// Opacity is the pixmap opacity.
//
// Must be in 0..=1 range.
//
// Default: 1.0
Opacity float32
// BlendMode is the pixmap blending mode.
//
// Default: SourceOver
BlendMode BlendMode
// Quality specifies how much filtering to be done when transforming
// images.
//
// Default: Nearest
Quality FilterQuality
}
PixmapPaint is PixmapPaint in tiny-skia src/shaders/pattern.rs. It controls how a pixmap is blended.
It is like Paint, but for Pixmap.
func DefaultPixmapPaint ¶
func DefaultPixmapPaint() PixmapPaint
DefaultPixmapPaint is the Default impl of PixmapPaint in tiny-skia src/shaders/pattern.rs.
type PixmapRef ¶
type PixmapRef struct {
// contains filtered or unexported fields
}
PixmapRef is PixmapRef in tiny-skia src/pixmap.rs. It is a container that references premultiplied RGBA pixels.
It can be created from a Pixmap or from data that the user gives.
The data is not aligned, therefore width == stride.
Port: logger is the logger of D20. A Pixmap that ToOwned or CloneRect makes takes it.
func PixmapRefFromBytes ¶
PixmapRefFromBytes is PixmapRef::from_bytes in tiny-skia src/pixmap.rs. It creates a new PixmapRef from bytes.
The size must be at least width * height * BytesPerPixel. A zero size is an error. The width is limited by i32::MAX/4.
The data is assumed to have premultiplied RGBA pixels (byte order: RGBA).
Port: opts configure the PixmapRef, as D20 says.
func (PixmapRef) CloneRect ¶
CloneRect is PixmapRef::clone_rect in tiny-skia src/pixmap.rs. It returns a copy of the part of the pixmap that intersects rect.
It returns false when the rect of the pixmap does not contain rect.
func (PixmapRef) Data ¶
Data is PixmapRef::data in tiny-skia src/pixmap.rs. It returns the internal data.
Byte order: RGBA.
func (PixmapRef) EncodePNG ¶
EncodePNG is PixmapRef::encode_png in tiny-skia src/pixmap.rs. It encodes the pixmap into PNG data.
Port: upstream encodes with the crate png, as 8-bit RGBA. The package image/png encodes here (D7). It writes 8-bit RGB when every pixel is opaque. The bytes of the file differ from upstream, and the decoded pixels are the same.
func (PixmapRef) Height ¶
Height is PixmapRef::height in tiny-skia src/pixmap.rs. It returns the height of the pixmap.
func (PixmapRef) Pixel ¶
func (r PixmapRef) Pixel(x, y uint32) (PremultipliedColorU8, bool)
Pixel is PixmapRef::pixel in tiny-skia src/pixmap.rs. It returns the color of a pixel.
It returns false when the position is out of bounds.
func (PixmapRef) Pixels ¶
func (r PixmapRef) Pixels() PixelSlice
Pixels is PixmapRef::pixels in tiny-skia src/pixmap.rs. It returns a slice of pixels.
func (PixmapRef) SavePNG ¶
SavePNG is PixmapRef::save_png in tiny-skia src/pixmap.rs. It saves the pixmap as a PNG file.
func (PixmapRef) Size ¶
Size is PixmapRef::size in tiny-skia src/pixmap.rs. It returns the size of the pixmap.
Port: upstream makes it public in the crate only. Go exports it, so that a later port, such as the pipeline, can call it.
type Point ¶
Point is the re-export of tiny_skia_path::Point in tiny-skia src/lib.rs. It is a point.
func PointFromXY ¶
PointFromXY is Point::from_xy. It calls path.PointFromXY.
type PremultipliedColor ¶
type PremultipliedColor struct {
// contains filtered or unexported fields
}
PremultipliedColor is PremultipliedColor in tiny-skia src/color.rs. It is a premultiplied RGBA color value that holds four floating point components.
All values are in the range 0..=1, and the RGB components are <= A.
func (PremultipliedColor) Alpha ¶
func (c PremultipliedColor) Alpha() float32
Alpha is PremultipliedColor::alpha in tiny-skia src/color.rs. It returns the alpha component of the color.
The value is guaranteed to be in the range 0..=1.
func (PremultipliedColor) Blue ¶
func (c PremultipliedColor) Blue() float32
Blue is PremultipliedColor::blue in tiny-skia src/color.rs. It returns the blue component of the color.
The value is guaranteed to be in the range 0..=1, and it is <= alpha.
func (PremultipliedColor) Demultiply ¶
func (c PremultipliedColor) Demultiply() Color
Demultiply is PremultipliedColor::demultiply in tiny-skia src/color.rs. It returns a demultiplied color.
func (PremultipliedColor) Green ¶
func (c PremultipliedColor) Green() float32
Green is PremultipliedColor::green in tiny-skia src/color.rs. It returns the green component of the color.
The value is guaranteed to be in the range 0..=1, and it is <= alpha.
func (PremultipliedColor) Red ¶
func (c PremultipliedColor) Red() float32
Red is PremultipliedColor::red in tiny-skia src/color.rs. It returns the red component of the color.
The value is guaranteed to be in the range 0..=1, and it is <= alpha.
func (PremultipliedColor) ToColorU8 ¶
func (c PremultipliedColor) ToColorU8() PremultipliedColorU8
ToColorU8 is PremultipliedColor::to_color_u8 in tiny-skia src/color.rs. It converts the color into a PremultipliedColorU8.
type PremultipliedColorU8 ¶
type PremultipliedColorU8 struct {
// contains filtered or unexported fields
}
PremultipliedColorU8 is PremultipliedColorU8 in tiny-skia src/color.rs. It is a 32-bit premultiplied RGBA color value.
Byte order: RGBA.
func PremultipliedColorU8FromRGBA ¶
func PremultipliedColorU8FromRGBA(r, g, b, a uint8) (PremultipliedColorU8, bool)
PremultipliedColorU8FromRGBA is PremultipliedColorU8::from_rgba in tiny-skia src/color.rs. It creates a new premultiplied color.
The RGB components must be <= alpha. If not, it returns false.
func (PremultipliedColorU8) Alpha ¶
func (c PremultipliedColorU8) Alpha() uint8
Alpha is PremultipliedColorU8::alpha in tiny-skia src/color.rs. It returns the alpha component of the color.
func (PremultipliedColorU8) Blue ¶
func (c PremultipliedColorU8) Blue() uint8
Blue is PremultipliedColorU8::blue in tiny-skia src/color.rs. It returns the blue component of the color.
The value is <= alpha.
func (PremultipliedColorU8) Demultiply ¶
func (c PremultipliedColorU8) Demultiply() ColorU8
Demultiply is PremultipliedColorU8::demultiply in tiny-skia src/color.rs. It returns a demultiplied color.
func (PremultipliedColorU8) Green ¶
func (c PremultipliedColorU8) Green() uint8
Green is PremultipliedColorU8::green in tiny-skia src/color.rs. It returns the green component of the color.
The value is <= alpha.
func (PremultipliedColorU8) IsOpaque ¶
func (c PremultipliedColorU8) IsOpaque() bool
IsOpaque is PremultipliedColorU8::is_opaque in tiny-skia src/color.rs. It returns true if the alpha is 255.
func (PremultipliedColorU8) Red ¶
func (c PremultipliedColorU8) Red() uint8
Red is PremultipliedColorU8::red in tiny-skia src/color.rs. It returns the red component of the color.
The value is <= alpha.
type RadialGradient ¶
type RadialGradient struct {
// contains filtered or unexported fields
}
RadialGradient is RadialGradient in tiny-skia src/shaders/radial_gradient.rs. It is a 2-point conical gradient shader.
func (RadialGradient) ApplyOpacity ¶
func (g RadialGradient) ApplyOpacity(opacity float32) Shader
ApplyOpacity is the arm Shader::RadialGradient of Shader::apply_opacity in tiny-skia src/shaders/mod.rs.
func (RadialGradient) IsOpaque ¶
func (g RadialGradient) IsOpaque() bool
IsOpaque is the arm Shader::RadialGradient of Shader::is_opaque in tiny-skia src/shaders/mod.rs.
A radial gradient can have points that are "undefined" so we just assume that it is not opaque.
func (RadialGradient) Transform ¶
func (g RadialGradient) Transform(ts Transform) Shader
Transform is the arm Shader::RadialGradient of Shader::transform in tiny-skia src/shaders/mod.rs.
type Rect ¶
Rect is the re-export of tiny_skia_path::Rect in tiny-skia src/lib.rs. It is a rectangle.
func RectFromLTRB ¶
RectFromLTRB is Rect::from_ltrb. It calls path.RectFromLTRB.
func RectFromPoints ¶
RectFromPoints is Rect::from_points. It calls path.RectFromPoints.
func RectFromXYWH ¶
RectFromXYWH is Rect::from_xywh. It calls path.RectFromXYWH.
type Shader ¶
type Shader interface {
// IsOpaque is Shader::is_opaque. It checks if the shader is guaranteed
// to produce only opaque colors.
IsOpaque() bool
// Transform is Shader::transform. It returns the shader transformed by
// ts.
Transform(ts Transform) Shader
// ApplyOpacity is Shader::apply_opacity. It returns the shader with its
// opacity shifted by opacity.
//
// opacity is clamped to the 0..=1 range.
//
// This is roughly the same as Skia's SkPaint::setAlpha.
//
// Unlike Skia, we do not support global alpha/opacity, which in Skia is
// set via the alpha channel of the SkPaint::fColor4f. Instead, you can
// shift the opacity of the shader to whatever value you need.
//
// - For SolidColor this function multiplies color.alpha by opacity.
// - For gradients this function multiplies all colors by opacity.
// - For Pattern this function multiplies Pattern::opacity by opacity.
ApplyOpacity(opacity float32) Shader
// contains filtered or unexported methods
}
Shader is Shader in tiny-skia src/shaders/mod.rs. A shader specifies the source color(s) for what is being drawn.
If a paint has no shader, then the paint's color is used. If the paint has a shader, then the shader's color(s) are used instead, but they are modulated by the paint's alpha. This makes it easy to create a shader once (e.g. bitmap tiling or gradient) and then change its transparency without having to modify the original shader. Only the paint's alpha needs to be modified.
Port: Shader is a Rust enum with data. In Go it is an interface with one type for each variant: SolidColor, LinearGradient, RadialGradient, SweepGradient and Pattern. Each type is a value type. A type switch on a Shader takes the place of a match on the enum. The unexported method keeps other types out. Transform and ApplyOpacity change a Rust shader in place. In Go they return the changed shader and leave the receiver as it was, so that a copy of a Paint does not share its shader with the original, as the clone of a Rust Paint does.
func NewLinearGradient ¶
func NewLinearGradient( start Point, end Point, stops []GradientStop, mode SpreadMode, transform Transform, ) (Shader, bool)
NewLinearGradient is LinearGradient::new in tiny-skia src/shaders/linear_gradient.rs. It creates a new linear gradient shader.
It returns a SolidColor when:
- len(stops) == 1
- start and end are very close
It returns false when:
- stops is empty
- start == end
- transform is not invertible
func NewPattern ¶
func NewPattern( pixmap PixmapRef, spreadMode SpreadMode, quality FilterQuality, opacity float32, transform Transform, ) Shader
NewPattern is Pattern::new in tiny-skia src/shaders/pattern.rs. It creates a new pattern shader.
opacity is clamped to the 0..=1 range.
func NewRadialGradient ¶
func NewRadialGradient( startPoint Point, startRadius float32, endPoint Point, endRadius float32, stops []GradientStop, mode SpreadMode, transform Transform, ) (Shader, bool)
NewRadialGradient is RadialGradient::new in tiny-skia src/shaders/radial_gradient.rs. It creates a new two-point conical gradient shader.
A two-point conical gradient (also known as a radial gradient) interpolates colors between two circles defined by their center points and radii.
It returns a SolidColor when:
- len(stops) == 1
It returns false when:
- stops is empty
- startRadius < 0 or endRadius < 0
- transform is not invertible
- The gradient is degenerate (both radii and centers are equal, except in specific pad mode cases)
func NewSweepGradient ¶
func NewSweepGradient( center Point, startAngle float32, endAngle float32, stops []GradientStop, mode SpreadMode, transform Transform, ) (Shader, bool)
NewSweepGradient is SweepGradient::new in tiny-skia src/shaders/sweep_gradient.rs. It creates a new sweep gradient shader.
It returns false when an angle is not finite, when startAngle is larger than endAngle, when stops is empty, when transform is not invertible, and for most degenerate gradients.
type Size ¶
Size is the re-export of tiny_skia_path::Size in tiny-skia src/lib.rs. It is a size.
func SizeFromWH ¶
SizeFromWH is Size::from_wh. It calls path.SizeFromWH.
type SolidColor ¶
type SolidColor Color
SolidColor is Shader::SolidColor in tiny-skia src/shaders/mod.rs. It is a solid color shader.
Unlike Skia, we do not have is_constant, because we do not have Color shaders.
func (SolidColor) ApplyOpacity ¶
func (c SolidColor) ApplyOpacity(opacity float32) Shader
ApplyOpacity is the arm Shader::SolidColor of Shader::apply_opacity in tiny-skia src/shaders/mod.rs.
func (SolidColor) IsOpaque ¶
func (c SolidColor) IsOpaque() bool
IsOpaque is the arm Shader::SolidColor of Shader::is_opaque in tiny-skia src/shaders/mod.rs.
func (SolidColor) Transform ¶
func (c SolidColor) Transform(_ Transform) Shader
Transform is the arm Shader::SolidColor of Shader::transform in tiny-skia src/shaders/mod.rs. It returns c.
type SpreadMode ¶
type SpreadMode uint8
SpreadMode is SpreadMode in tiny-skia src/shaders/mod.rs. It is a shader spreading mode.
const ( // SpreadModePad is SpreadMode::Pad, the default. It replicates the edge // color if the shader draws outside of its original bounds. SpreadModePad SpreadMode = iota // SpreadModeReflect is SpreadMode::Reflect. It repeats the shader's image // horizontally and vertically, alternating mirror images so that adjacent // images always seam. SpreadModeReflect // SpreadModeRepeat is SpreadMode::Repeat. It repeats the shader's image // horizontally and vertically. SpreadModeRepeat )
The values of SpreadMode, in the order of the Rust enum.
func (SpreadMode) String ¶
func (m SpreadMode) String() string
String satisfies the fmt.Stringer interface. It returns the name of the Rust variant.
type Stroke ¶
Stroke is the re-export of tiny_skia_path::Stroke in tiny-skia src/lib.rs. It holds the properties of a stroke.
func DefaultStroke ¶
func DefaultStroke() Stroke
DefaultStroke is Stroke::default. It calls path.DefaultStroke.
type StrokeDash ¶
type StrokeDash = path.StrokeDash
StrokeDash is the re-export of tiny_skia_path::StrokeDash in tiny-skia src/lib.rs. It is a dash of a stroke.
func NewStrokeDash ¶
func NewStrokeDash(dashArray []float32, dashOffset float32) (*StrokeDash, bool)
NewStrokeDash is StrokeDash::new. It calls path.NewStrokeDash.
type SweepGradient ¶
type SweepGradient struct {
// contains filtered or unexported fields
}
SweepGradient is SweepGradient in tiny-skia src/shaders/sweep_gradient.rs. It is a sweep gradient shader.
func (SweepGradient) ApplyOpacity ¶
func (g SweepGradient) ApplyOpacity(opacity float32) Shader
ApplyOpacity is the arm Shader::SweepGradient of Shader::apply_opacity in tiny-skia src/shaders/mod.rs.
func (SweepGradient) IsOpaque ¶
func (g SweepGradient) IsOpaque() bool
IsOpaque is SweepGradient::is_opaque in tiny-skia src/shaders/sweep_gradient.rs, and the arm Shader::SweepGradient of Shader::is_opaque in tiny-skia src/shaders/mod.rs.
func (SweepGradient) Transform ¶
func (g SweepGradient) Transform(ts Transform) Shader
Transform is the arm Shader::SweepGradient of Shader::transform in tiny-skia src/shaders/mod.rs.
type Transform ¶
Transform is the re-export of tiny_skia_path::Transform in tiny-skia src/lib.rs. It is an affine transform.
func DefaultTransform ¶
func DefaultTransform() Transform
DefaultTransform is Transform::default. It calls path.DefaultTransform.
func IdentityTransform ¶
func IdentityTransform() Transform
IdentityTransform is Transform::identity. It calls path.IdentityTransform.
func TransformFromBBox ¶
func TransformFromBBox(bbox NonZeroRect) Transform
TransformFromBBox is Transform::from_bbox. It calls path.TransformFromBBox.
func TransformFromRotate ¶
TransformFromRotate is Transform::from_rotate. It calls path.TransformFromRotate.
func TransformFromRotateAt ¶
TransformFromRotateAt is Transform::from_rotate_at. It calls path.TransformFromRotateAt.
func TransformFromRow ¶
TransformFromRow is Transform::from_row. It calls path.TransformFromRow.
func TransformFromScale ¶
TransformFromScale is Transform::from_scale. It calls path.TransformFromScale.
func TransformFromSkew ¶
TransformFromSkew is Transform::from_skew. It calls path.TransformFromSkew.
func TransformFromTranslate ¶
TransformFromTranslate is Transform::from_translate. It calls path.TransformFromTranslate.
Source Files
¶
- alpha_runs.go
- blend_mode.go
- blitter.go
- color.go
- doc.go
- edge.go
- edge_builder.go
- edge_clipper.go
- errors.go
- fixed_point.go
- geom.go
- image.go
- line_clipper.go
- mask.go
- math.go
- okage.go
- options.go
- painter.go
- path64.go
- path64_cubic64.go
- path64_line_cubic_intersections.go
- path64_point64.go
- path64_quad64.go
- path_geometry.go
- pipeline.go
- pipeline_blitter.go
- pipeline_highp.go
- pipeline_lowp.go
- pixmap.go
- scan.go
- scan_hairline.go
- scan_hairline_aa.go
- scan_path.go
- scan_path_aa.go
- shaders.go
- shaders_gradient.go
- shaders_linear_gradient.go
- shaders_pattern.go
- shaders_radial_gradient.go
- shaders_sweep_gradient.go
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
crmath
Package crmath gives correctly rounded results of the math functions that tiny-skia, kurbo, svgtypes and resvg call from the C library: acos, cos, sin, tan, atan2, pow, ln and log2 for an f64, and acos, cos, sin, tan, atan2, pow and hypot for an f32.
|
Package crmath gives correctly rounded results of the math functions that tiny-skia, kurbo, svgtypes and resvg call from the C library: acos, cos, sin, tan, atan2, pow, ln and log2 for an f64, and acos, cos, sin, tan, atan2, pow and hypot for an f32. |
|
kurbo
Package kurbo is a port of a subset of the Rust crate kurbo 0.13.1, a 2D curves library, at the commit 838b69ef.
|
Package kurbo is a port of a subset of the Rust crate kurbo 0.13.1, a 2D curves library, at the commit 838b69ef. |
|
roxmltree
Package roxmltree is a port of the Rust crate roxmltree 0.21.1.
|
Package roxmltree is a port of the Rust crate roxmltree 0.21.1. |
|
simplecss
Package simplecss is a port of the Rust crate simplecss 0.2.2, a simple CSS 2.1 parser and selector.
|
Package simplecss is a port of the Rust crate simplecss 0.2.2, a simple CSS 2.1 parser and selector. |
|
svgtypes
Package svgtypes is a port of the Rust crate svgtypes 0.16.1, a collection of parsers for SVG types, at the commit fa62387a.
|
Package svgtypes is a port of the Rust crate svgtypes 0.16.1, a collection of parsers for SVG types, at the commit fa62387a. |
|
wide
Package wide holds the vector types of tiny-skia, a port of src/wide, and the conversions from a float to an integer that give the result of Rust.
|
Package wide holds the vector types of tiny-skia, a port of src/wide, and the conversions from a float to an integer that give the result of Rust. |
|
wide/internal/widegen
command
Command widegen writes the generated files of the package wide.
|
Command widegen writes the generated files of the package wide. |
|
xmlwriter
Package xmlwriter is a port of the Rust crate xmlwriter 0.1.0, a simple, streaming, partially-validating XML writer that writes XML data into an internal buffer.
|
Package xmlwriter is a port of the Rust crate xmlwriter 0.1.0, a simple, streaming, partially-validating XML writer that writes XML data into an internal buffer. |
|
Package path is a port of the Rust crate tiny-skia-path 0.12.0, a Bezier path of tiny-skia, and of the crate strict-num 0.1.1, which holds the checked float types.
|
Package path is a port of the Rust crate tiny-skia-path 0.12.0, a Bezier path of tiny-skia, and of the crate strict-num 0.1.1, which holds the checked float types. |
|
Package svg is a port of the Rust crates usvg 0.49.0 and resvg 0.49.0, in one package (D5).
|
Package svg is a port of the Rust crates usvg 0.49.0 and resvg 0.49.0, in one package (D5). |