codec

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrOutputExists      = errors.New("output file already exists (use --overwrite to replace)")
	ErrInputIsDir        = errors.New("input is a directory, not a regular file")
	ErrFileTooLarge      = errors.New("file too large for the format")
	ErrTruncatedPayload  = errors.New("truncated payload: image contains fewer bytes than declared")
	ErrChecksumMismatch  = errors.New("integrity check failed: payload checksum does not match")
	ErrNotPixPackImage   = errors.New("not a PixPack image")
	ErrUnsupportedImage  = errors.New("unsupported or corrupted PixPack image")
	ErrPNGDecodeFailed   = errors.New("failed to decode PNG image")
	ErrPNGEncodeFailed   = errors.New("failed to encode PNG image")
	ErrInvalidDimensions = errors.New("invalid image dimensions")
	ErrFilenameUnsafe    = errors.New("stored filename is unsafe or contains directory traversal elements")
)

Functions

func BytesToPixels

func BytesToPixels(data []byte) []color.NRGBA

BytesToPixels converts a byte slice into NRGBA pixels. Each pixel stores 3 bytes (R, G, B); alpha is always 255. The final pixel is padded with zero bytes if needed.

func CalculateDimensions

func CalculateDimensions(numPixels int, width int) (w, h int, err error)

CalculateDimensions computes the image width and height needed to hold the given number of pixels. If width is 0, a near-square is computed.

func ConvertToNRGBA

func ConvertToNRGBA(img image.Image) *image.NRGBA

ConvertToNRGBA converts any image to an NRGBA image for consistent pixel reading.

func CreateImage

func CreateImage(data []byte, width int) (*image.NRGBA, error)

CreateImage creates an NRGBA image with bytes written into pixel channels.

func PixelsToBytes

func PixelsToBytes(pixels []color.NRGBA, numBytes int) []byte

PixelsToBytes extracts raw bytes from NRGBA pixels. It reads R, G, B channels in order and returns exactly numBytes bytes.

func ReadImageBytes

func ReadImageBytes(img *image.NRGBA, numBytes int) ([]byte, error)

ReadImageBytes extracts raw bytes from an NRGBA image, reading pixels in row-major order (top-to-bottom, left-to-right).

func RequiredPixels

func RequiredPixels(totalBytes int) int

RequiredPixels computes the number of pixels needed for totalBytes bytes.

Types

type DecodeOptions

type DecodeOptions struct {
	OutputPath string
	Overwrite  bool
}

DecodeOptions controls the decoding behavior.

type EncodeOptions

type EncodeOptions struct {
	Width     int
	Overwrite bool
}

EncodeOptions controls the encoding behavior.

type Metadata

type Metadata struct {
	Version     uint8
	Flags       uint8
	Filename    string
	PayloadSize uint64
	Width       int
	Height      int
	SHA256      [sha256.Size]byte
}

Metadata describes a PixPack encoded image.

func DecodeFile

func DecodeFile(inputPath string, opts DecodeOptions) (*Metadata, error)

DecodeFile reads a PixPack PNG and restores the original file.

func EncodeFile

func EncodeFile(inputPath, outputPath string, opts EncodeOptions) (*Metadata, error)

EncodeFile reads inputPath, creates a PixPack PNG at outputPath, and returns metadata.

func InspectFile

func InspectFile(inputPath string) (*Metadata, error)

InspectFile reads a PixPack PNG and returns its metadata without extracting the payload.

func VerifyFile

func VerifyFile(inputPath string) (*Metadata, error)

VerifyFile checks the integrity of a PixPack PNG without extracting the file. It returns the metadata and nil if the payload is intact.

Jump to

Keyboard shortcuts

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