Documentation
¶
Index ¶
- Variables
- func BytesToPixels(data []byte) []color.NRGBA
- func CalculateDimensions(numPixels int, width int) (w, h int, err error)
- func ConvertToNRGBA(img image.Image) *image.NRGBA
- func CreateImage(data []byte, width int) (*image.NRGBA, error)
- func PixelsToBytes(pixels []color.NRGBA, numBytes int) []byte
- func ReadImageBytes(img *image.NRGBA, numBytes int) ([]byte, error)
- func RequiredPixels(totalBytes int) int
- type DecodeOptions
- type EncodeOptions
- type Metadata
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
ConvertToNRGBA converts any image to an NRGBA image for consistent pixel reading.
func CreateImage ¶
CreateImage creates an NRGBA image with bytes written into pixel channels.
func PixelsToBytes ¶
PixelsToBytes extracts raw bytes from NRGBA pixels. It reads R, G, B channels in order and returns exactly numBytes bytes.
func ReadImageBytes ¶
ReadImageBytes extracts raw bytes from an NRGBA image, reading pixels in row-major order (top-to-bottom, left-to-right).
func RequiredPixels ¶
RequiredPixels computes the number of pixels needed for totalBytes bytes.
Types ¶
type DecodeOptions ¶
DecodeOptions controls the decoding behavior.
type EncodeOptions ¶
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 ¶
InspectFile reads a PixPack PNG and returns its metadata without extracting the payload.
func VerifyFile ¶
VerifyFile checks the integrity of a PixPack PNG without extracting the file. It returns the metadata and nil if the payload is intact.