lowlevel

package
v0.0.0-...-054d748 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package lowlevel provides a low-level decoder for the IconVG file format.

IconVG is specified at https://github.com/google/iconvg/blob/main/spec/iconvg-spec.md

Index

Constants

This section is empty.

Variables

View Source
var DefaultPalette = Palette{
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x00, 0x00, 0x00, 0xff},
}

DefaultPalette is the default Palette. Its values should not be modified.

View Source
var DefaultViewBox = Rectangle{
	Min: f32.Vec2{-32, -32},
	Max: f32.Vec2{+32, +32},
}

DefaultViewBox is the default ViewBox. Its values should not be modified.

Functions

func Decode

func Decode(dst Destination, src []byte, opts *DecodeOptions) error

Decode decodes an IconVG graphic.

opts may be nil, which means to use the default options.

func Disassemble

func Disassemble(w io.Writer, src []byte) error

Disassemble writes src's disassembly to w.

See https://github.com/google/iconvg/blob/main/spec/iconvg-spec.md#example (look for the text "annotated disassembly") or test/data/*.ivg.disassembly for example output.

Types

type Color

type Color struct {
	// contains filtered or unexported fields
}

Color is an IconVG color, whose RGBA values can depend on context. Some Colors are direct RGBA values. Other Colors are indirect, referring to an index of the custom palette, a color register of the decoder virtual machine, or a blend of two other Colors.

See the "Colors" section in the specification for details.

func BlendColor

func BlendColor(t, c0, c1 uint8) Color

BlendColor returns an indirect Color that blends two other Colors. Those two other Colors must both be encodable as a 1 byte color.

To blend a Color that is not encodable as a 1 byte color, first load that Color into a CREG color register, then call CRegColor to produce a Color that is encodable as a 1 byte color. See testdata/favicon.ivg for an example.

See the "Colors" section in the specification for details.

TODO: update this for FFV1.

func CRegColor

func CRegColor(i uint8) Color

CRegColor returns an indirect Color referring to a color register of the decoder virtual machine.

func PaletteIndexColor

func PaletteIndexColor(i uint8) Color

PaletteIndexColor returns an indirect Color referring to an index of the custom palette.

func RGBAColor

func RGBAColor(c color.RGBA) Color

RGBAColor returns a direct Color.

func (Color) Resolve

func (c Color) Resolve(pal *Palette, cReg *[64]color.RGBA) color.RGBA

Resolve resolves the Color's RGBA value, given its context: the custom palette and the color registers of the decoder virtual machine.

type DecodeOptions

type DecodeOptions struct {
	// Palette is an optional 64 color palette. If one isn't provided, the
	// IconVG graphic's suggested palette will be used.
	Palette *Palette
}

DecodeOptions are the optional parameters to the Decode function.

type Destination

type Destination interface {
	Reset(m Metadata)

	// QueryLevelOfDetail returns whether the height-in-pixels H satisfies
	// ((lod0 <= H) && (H < lod1)).
	QueryLevelOfDetail(lod0, lod1 float32) bool

	ClosePathMoveTo(x, y float32)
	LineTo(x, y float32)
	QuadTo(x1, y1, x, y float32)
	CubeTo(x1, y1, x2, y2, x, y float32)
	Ellipse(nQuarters uint32, x1, y1, x2, y2, x, y float32)
	Parallelogram(x1, y1, x2, y2, x, y float32)

	ClosePathFill() // TODO.
}

Destination handles the actions decoded from an IconVG graphic's byte code.

When passed to Decode, the first method called (if any) will be Reset. No methods will be called at all if an error is encountered in the encoded form before the metadata is fully decoded.

type Metadata

type Metadata struct {
	ViewBox Rectangle

	// Palette is a 64 color palette. When encoding, it is the suggested
	// palette to place within the IconVG graphic. When decoding, it is either
	// the optional palette passed to Decode, or if no optional palette was
	// given, the suggested palette within the IconVG graphic.
	Palette Palette
}

Metadata is an IconVG's metadata.

func DecodeMetadata

func DecodeMetadata(src []byte) (m Metadata, retErr error)

DecodeMetadata decodes only the metadata in an IconVG graphic.

type Palette

type Palette [64]color.RGBA

Palette is an IconVG palette.

type Rectangle

type Rectangle struct {
	Min, Max f32.Vec2
}

Rectangle is defined by its minimum and maximum coordinates.

func (*Rectangle) AspectRatio

func (r *Rectangle) AspectRatio() (dx, dy float32)

AspectRatio returns the Rectangle's aspect ratio. An IconVG graphic is scalable; these dimensions do not necessarily map 1:1 to pixels.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL