Skip to content

Shared Types

WARNING

Picguin is in early development, and the public API across codecs is subject to change.
All packages will remain pre-v1.0.0 until a stable design is in place.

Codecs

All codecs export this specific shape:

luau
{
	version: string,
	decode: (source: buffer, options: DecodeOptions?) -> (Parsed?, DecodeError),
	encode: () -> (), -- TBD
}
PropertyDescription
versionThe current version of the codec package.
decodeParses a source image into a format-specific Parsed.
encode(TBD)

For decode-only formats, encode() returns an "unsupported" error.

General Types

Error<Code> Private Base

luau
{
	code: "ok",
	message: "",
} | {
	code: Code,
	message: string,
}
PropertyDescription
codeString literal representing the error. "ok" if no fatal error was encountered.
messageHuman-readable string providing more detail on the error.
  • A private base is inherited by types internally, but never exported directly from a codec.
    (e.g. PNG exports png.DecodeError, equivalent to Error<png.DecodeErrorCode>)

All public functions return a type inherited from Error<Code> to indicate success/failure.

Decode Types

Parsed Public Base

luau
{
	width: number,
	height: number,
	frames: number,

	cel: (frame: number?, target: ColorTarget?) -> (Cel?, CelError),
}
PropertyDescription
widthImage width in pixels.
heightImage height in pixels.
framesImage frame count. 1 by default if animation is unsupported.
celDecodes the image or a specified frame into a Cel.
Default parameters: (0, "rgba8")
  • A public base is always exported directly from a codec, with format-specific extensions.
    (e.g. PNG exports png.Parsed, an extension of Parsed with additional properties)

In cel(), the frame parameter wraps around the frame count, and can be negative.


ColorTarget

luau
| "rgba8"
| "rgba16"

A string literal specifying the target format for Cel.bitmap when calling Parsed.cel().


Cel

luau
{
	bitmap: buffer,
	region: BitmapRegion,
	duration: number,
}
PropertyDescription
bitmapFrame pixel data.
regionRegion to write bitmap into. Relevant when decoding APNG and GIF.
durationFrame duration. 0.0 by default if the image is not animated.

A decoded frame returned by Parsed.cel(), containing all information necessary to display the frame and progress animation.


BitmapRegion

luau
{
	size: vector,
	position: vector,
}
PropertyDescription
sizeSize of region in pixels.
positionPositional offset of region in pixels.

Represents a 2D region in pixels.

Encode Types

(TBD)

Released under the MIT License.