decoder

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package decoder provides a unified interface for decoding JPEG family formats.

This package implements decoders for modern JPEG extensions that go beyond the standard DCT-based JPEG. It provides a consistent API across all formats, making it easy to work with different JPEG variants.

Supported Formats

The decoder package supports the following formats:

  • JPEG-LS (ITU-T T.87): Lossless and near-lossless compression using context-based prediction and Golomb-Rice coding.

  • JPEG 2000 (ITU-T T.800): Wavelet-based compression with support for tiling, regions of interest, and progressive decoding.

  • JPEG XR (ITU-T T.832): HD Photo format with support for HDR, wide gamut, and lossless compression.

  • JPEG XL (ISO/IEC 18181): Next-generation format with superior compression, progressive decoding, and animation support.

  • JPEG XT (ISO/IEC 18477): HDR extension for standard JPEG using backwards-compatible APP11 markers.

  • JPEG XS (ISO/IEC 21122): Low-latency, visually lossless codec designed for professional video and real-time streaming.

Basic Usage

The simplest way to decode an image:

dec, err := decoder.NewDecoder(data)
if err != nil {
    log.Fatal(err)
}
pixels, err := dec.Decode()
if err != nil {
    log.Fatal(err)
}
info := dec.GetInfo()
fmt.Printf("Decoded %dx%d image\n", info.Width, info.Height)

Format-Specific Decoding

To decode a specific format:

dec, err := decoder.NewDecoderForFormat(data, decoder.FormatJPEG2000)
if err != nil {
    log.Fatal(err)
}
pixels, err := dec.Decode()

Streaming Decode

For large images, use streaming decode to process tiles individually:

streamDec, err := decoder.NewStreamDecoder(data)
if err != nil {
    if errors.Is(err, decoder.ErrStreamingNotSupported) {
        // Fall back to bulk decode
    }
    log.Fatal(err)
}

// Process tiles one at a time
for i := 0; i < streamDec.NumTiles(); i++ {
    tile, err := streamDec.DecodeTile(i)
    if err != nil {
        log.Fatal(err)
    }
    // Process tile...
}

Or use callback-based streaming:

err = streamDec.DecodeStream(func(tileIdx int, data []byte) error {
    // Process each tile as it's decoded
    return nil
})

HDR Decoding

For HDR images (JPEG XT, JPEG XR with HDR profiles):

dec, err := decoder.NewDecoder(data)
if err != nil {
    log.Fatal(err)
}

if hdr, ok := dec.(decoder.HDRDecoder); ok {
    hdrPixels, err := hdr.DecodeHDR()
    if err != nil {
        log.Fatal(err)
    }
    // hdrPixels contains float32 values per channel
    hdrInfo := hdr.GetHDRInfo()
    fmt.Printf("HDR range: %.1f - %.1f nits\n",
        hdrInfo.MinLuminance, hdrInfo.MaxLuminance)
}

Low-Latency Decoding

For real-time applications using JPEG XS:

dec, err := decoder.NewDecoder(data)
if err != nil {
    log.Fatal(err)
}

if ll, ok := dec.(decoder.LowLatencyDecoder); ok {
    fmt.Printf("Latency: %d lines\n", ll.GetLatencyLines())
    fmt.Printf("Memory bound: %d bytes\n", ll.GetMemoryBound())

    // Progressive line-by-line decoding
    err = ll.DecodeProgressive(func(lineNum int, data []byte) error {
        // Process each line as it's decoded
        return nil
    })
}

Pixel Data Format

All decoders return pixel data in a consistent format:

  • 8-bit images: 1 byte per channel per pixel
  • 16-bit images: 2 bytes per channel per pixel (little-endian)
  • Channels are interleaved: RGBRGB... or RGBARGBA...

Use ImageInfo to determine the pixel format:

info := dec.GetInfo()
bytesPerPixel := info.NumChannels * (info.BitDepth / 8)

Thread Safety

Decoder instances are not safe for concurrent use. Create separate decoder instances for each goroutine, or synchronize access externally.

Error Handling

The package defines specific error types:

  • ErrUnsupportedFormat: format not recognized
  • ErrInvalidData: corrupted or truncated data
  • ErrDataTooShort: insufficient data
  • ErrOutputTooLarge: decoded size exceeds limits
  • ErrStreamingNotSupported: streaming not available for format
  • ErrNoHDRData: HDR decode requested but no HDR data present

Use errors.Is() to check for specific errors:

if errors.Is(err, decoder.ErrInvalidData) {
    // Handle corrupted data
}
Example (DecoderInterface)

Example_decoderInterface demonstrates the common Decoder interface. All format-specific decoders implement this interface.

package main

import (
	"fmt"
)

func main() {
	// The Decoder interface provides:
	// - Decode() ([]byte, error)  - decode to raw pixels
	// - GetInfo() *ImageInfo      - get image metadata

	fmt.Println("Decoder interface methods:")
	fmt.Println("  - Decode() ([]byte, error)")
	fmt.Println("  - GetInfo() *ImageInfo")
}
Output:
Decoder interface methods:
  - Decode() ([]byte, error)
  - GetInfo() *ImageInfo
Example (ErrorHandling)

Example_errorHandling demonstrates handling decoder-specific errors.

package main

import (
	"fmt"

	"github.com/0verkilll/jpeg/decoder"
)

func main() {
	// The decoder package defines specific error types:
	errTypes := []struct {
		name string
		err  error
	}{
		{"ErrUnsupportedFormat", decoder.ErrUnsupportedFormat},
		{"ErrInvalidData", decoder.ErrInvalidData},
		{"ErrStreamingNotSupported", decoder.ErrStreamingNotSupported},
	}

	fmt.Println("Decoder error types:")
	for _, e := range errTypes {
		fmt.Printf("  - %s\n", e.name)
	}
}
Output:
Decoder error types:
  - ErrUnsupportedFormat
  - ErrInvalidData
  - ErrStreamingNotSupported
Example (HdrDecoderInterface)

Example_hdrDecoderInterface demonstrates the HDRDecoder interface. JPEG XT decoders implement this for floating-point HDR output.

package main

import (
	"fmt"
)

func main() {
	// The HDRDecoder interface extends Decoder with:
	// - DecodeHDR() ([]float32, error)  - decode to HDR float
	// - DecodeHDR16() ([]uint16, error) - decode to 16-bit
	// - GetHDRInfo() *HDRInfo           - get HDR metadata

	fmt.Println("HDRDecoder interface methods:")
	fmt.Println("  - DecodeHDR() ([]float32, error)")
	fmt.Println("  - DecodeHDR16() ([]uint16, error)")
	fmt.Println("  - GetHDRInfo() *HDRInfo")
}
Output:
HDRDecoder interface methods:
  - DecodeHDR() ([]float32, error)
  - DecodeHDR16() ([]uint16, error)
  - GetHDRInfo() *HDRInfo
Example (LowLatencyDecoderInterface)

Example_lowLatencyDecoderInterface demonstrates the LowLatencyDecoder interface. JPEG XS decoders support line-by-line progressive decoding.

package main

import (
	"fmt"
)

func main() {
	// The LowLatencyDecoder interface extends Decoder with:
	// - DecodeProgressive(callback) error - decode line by line
	// - GetLatencyLines() int             - decode latency in lines
	// - GetMemoryBound() int64            - memory usage bound
	// - IsLowLatency() bool               - check mode

	fmt.Println("LowLatencyDecoder for real-time video:")
	fmt.Println("  - Sub-line latency decoding")
	fmt.Println("  - Bounded memory usage")
	fmt.Println("  - Line-by-line callbacks")
}
Output:
LowLatencyDecoder for real-time video:
  - Sub-line latency decoding
  - Bounded memory usage
  - Line-by-line callbacks
Example (StreamDecoderInterface)

Example_streamDecoderInterface demonstrates the StreamDecoder interface. JPEG 2000 decoders support tile-based streaming.

package main

import (
	"fmt"
)

func main() {
	// The StreamDecoder interface extends Decoder with:
	// - NumTiles() int                    - get tile count
	// - TileInfo(idx int) *TileInfo       - get tile metadata
	// - DecodeTile(idx int) ([]byte, err) - decode single tile
	// - DecodeRow(idx int) ([]byte, err)  - decode single row
	// - DecodeStream(callback) error      - decode with callback
	// - Reset()                           - reset for re-decode

	fmt.Println("StreamDecoder enables memory-efficient processing:")
	fmt.Println("  - Decode one tile at a time")
	fmt.Println("  - Process large images with limited memory")
	fmt.Println("  - Use callbacks for streaming workflows")
}
Output:
StreamDecoder enables memory-efficient processing:
  - Decode one tile at a time
  - Process large images with limited memory
  - Use callbacks for streaming workflows

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnsupportedFormat is returned when the data format is not recognized.
	ErrUnsupportedFormat = errors.New("unsupported or unrecognized image format")

	// ErrInvalidData is returned when the image data is corrupted or truncated.
	ErrInvalidData = errors.New("invalid or corrupted image data")

	// ErrDataTooShort is returned when the data is too short to contain a valid image.
	ErrDataTooShort = errors.New("data too short for image format")

	// ErrOutputTooLarge is returned when the decoded image would exceed size limits.
	ErrOutputTooLarge = errors.New("decoded image size exceeds maximum limit")

	// ErrStreamingNotSupported is returned when streaming decode is requested
	// for a format that does not support it.
	ErrStreamingNotSupported = errors.New("streaming decode not supported for this format")

	// ErrInvalidTileIndex is returned when an invalid tile index is provided.
	ErrInvalidTileIndex = errors.New("invalid tile index")

	// ErrInvalidRowIndex is returned when an invalid row index is provided.
	ErrInvalidRowIndex = errors.New("invalid row index")

	// ErrNoHDRData is returned when HDR decoding is requested but no HDR data is present.
	ErrNoHDRData = errors.New("no HDR extension data present")
)

Common errors returned by decoders.

Functions

This section is empty.

Types

type Decoder

type Decoder interface {
	// Decode decodes the image and returns raw pixel data.
	// The pixel data format is consistent across all decoders:
	//   - 8-bit images: 1 byte per channel per pixel
	//   - 16-bit images: 2 bytes per channel per pixel (little-endian)
	//   - Channels are interleaved: RGBRGB... or RGBARGBA...
	Decode() ([]byte, error)

	// GetInfo returns metadata about the image.
	// This can be called before Decode() to get dimensions without
	// fully decoding the image.
	GetInfo() *ImageInfo
}

Decoder is the common interface for all JPEG family decoders. Each format-specific decoder implements this interface to provide consistent behavior across all formats.

func NewDecoder

func NewDecoder(data []byte) (Decoder, error)

NewDecoder creates a decoder for the given image data. It automatically detects the format and returns the appropriate decoder.

Example:

decoder, err := decoder.NewDecoder(imageData)
if err != nil {
    log.Fatal(err)
}
pixels, err := decoder.Decode()
info := decoder.GetInfo()

func NewDecoderForFormat

func NewDecoderForFormat(data []byte, format Format) (Decoder, error)

NewDecoderForFormat creates a decoder for the specified format. Use this when you already know the format and want to skip auto-detection.

Example

ExampleNewDecoderForFormat demonstrates creating a format-specific decoder. Use this when you already know the format to skip auto-detection.

package main

import (
	"fmt"

	"github.com/0verkilll/jpeg/decoder"
)

func main() {
	// In real use, this would be actual JPEG-LS encoded data
	// Here we demonstrate the pattern with error handling

	fakeData := []byte{0x00} // Invalid data for demonstration

	_, err := decoder.NewDecoderForFormat(fakeData, decoder.FormatJPEGLS)
	if err != nil {
		fmt.Println("Error creating decoder (expected with invalid data)")
	}
}
Output:
Error creating decoder (expected with invalid data)

type Format

type Format int

Format represents a JPEG family image format.

const (
	// FormatUnknown indicates the format could not be determined.
	FormatUnknown Format = iota

	// FormatJPEGLS indicates JPEG-LS format (ITU-T T.87).
	FormatJPEGLS

	// FormatJPEG2000 indicates JPEG 2000 format (ITU-T T.800).
	FormatJPEG2000

	// FormatJPEGXR indicates JPEG XR format (ITU-T T.832).
	FormatJPEGXR

	// FormatJPEGXL indicates JPEG XL format (ISO/IEC 18181).
	FormatJPEGXL

	// FormatJPEGXT indicates JPEG XT format (ISO/IEC 18477).
	// This is standard JPEG with HDR extension data in APP11 markers.
	FormatJPEGXT

	// FormatJPEGXS indicates JPEG XS format (ISO/IEC 21122).
	// This is a low-latency, visually lossless codec for professional video.
	// It uses bounded memory and sub-line latency for real-time streaming.
	FormatJPEGXS
)

func DetectFormat

func DetectFormat(data []byte) (Format, error)

DetectFormat identifies the JPEG family format from the data. It examines magic bytes at the beginning of the data to determine the format. Returns FormatUnknown if the format cannot be determined.

Example

ExampleDetectFormat demonstrates detecting the format of image data.

package main

import (
	"fmt"
	"log"

	"github.com/0verkilll/jpeg/decoder"
)

// createMinimalJPEG2000 creates a minimal JPEG 2000 codestream header.
// Note: This is a header-only stub; real JPEG 2000 files would have more data.
func createMinimalJPEG2000() []byte {
	return []byte{

		0xFF, 0x4F,

		0xFF, 0x51, 0x00, 0x2F,
		0x00, 0x00,
		0x00, 0x00, 0x00, 0x10,
		0x00, 0x00, 0x00, 0x10,
		0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x10,
		0x00, 0x00, 0x00, 0x10,
		0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00,
		0x00, 0x01,
		0x07, 0x01, 0x01,

		0xFF, 0xD9,
	}
}

func main() {
	data := createMinimalJPEG2000()

	format, err := decoder.DetectFormat(data)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Detected format: %s\n", format)
}
Output:
Detected format: JPEG 2000

func (Format) IsHDR

func (f Format) IsHDR() bool

IsHDR returns true if the format supports HDR content.

Example

ExampleFormat_IsHDR demonstrates checking if a format supports HDR. Multiple formats support HDR through different mechanisms.

package main

import (
	"fmt"

	"github.com/0verkilll/jpeg/decoder"
)

func main() {
	formats := []decoder.Format{
		decoder.FormatJPEGLS,
		decoder.FormatJPEG2000,
		decoder.FormatJPEGXR,
		decoder.FormatJPEGXL,
		decoder.FormatJPEGXT,
		decoder.FormatJPEGXS,
	}

	fmt.Println("HDR-capable formats:")
	for _, f := range formats {
		if f.IsHDR() {
			fmt.Printf("  - %s\n", f)
		}
	}
}
Output:
HDR-capable formats:
  - JPEG 2000
  - JPEG XR
  - JPEG XL
  - JPEG XT (HDR)
  - JPEG XS (Low-Latency)

func (Format) IsLowLatency

func (f Format) IsLowLatency() bool

IsLowLatency returns true if the format is designed for low-latency applications.

Example

ExampleFormat_IsLowLatency demonstrates checking for low-latency formats. JPEG XS is specifically designed for sub-line latency in video applications.

package main

import (
	"fmt"

	"github.com/0verkilll/jpeg/decoder"
)

func main() {
	formats := []decoder.Format{
		decoder.FormatJPEG2000,
		decoder.FormatJPEGXS,
		decoder.FormatJPEGXL,
	}

	fmt.Println("Low-latency formats:")
	for _, f := range formats {
		if f.IsLowLatency() {
			fmt.Printf("  - %s\n", f)
		}
	}
}
Output:
Low-latency formats:
  - JPEG XS (Low-Latency)

func (Format) String

func (f Format) String() string

String returns a human-readable name for the format.

Example

ExampleFormat_String demonstrates the Format type's String method.

package main

import (
	"fmt"

	"github.com/0verkilll/jpeg/decoder"
)

func main() {
	formats := []decoder.Format{
		decoder.FormatJPEGLS,
		decoder.FormatJPEG2000,
		decoder.FormatJPEGXR,
		decoder.FormatJPEGXL,
		decoder.FormatJPEGXT,
		decoder.FormatJPEGXS,
	}

	fmt.Println("Supported extended formats:")
	for _, f := range formats {
		fmt.Printf("  - %s\n", f)
	}
}
Output:
Supported extended formats:
  - JPEG-LS
  - JPEG 2000
  - JPEG XR
  - JPEG XL
  - JPEG XT (HDR)
  - JPEG XS (Low-Latency)

type HDRDecoder

type HDRDecoder interface {
	Decoder

	// DecodeHDR decodes the image and returns HDR pixel data as float32.
	// Each channel value is a floating-point number representing luminance.
	// The range depends on the HDR content (typically 0.0 to 10000.0+ nits).
	//
	// Returns ErrNoHDRData if the image doesn't contain HDR extension data.
	DecodeHDR() ([]float32, error)

	// DecodeHDR16 decodes the image and returns HDR pixel data as uint16.
	// This is useful for formats like JPEG XT Profile D (16-bit integer).
	//
	// Returns ErrNoHDRData if the image doesn't contain HDR extension data.
	DecodeHDR16() ([]uint16, error)

	// GetHDRInfo returns HDR-specific metadata.
	// Returns nil if the image doesn't contain HDR data.
	GetHDRInfo() *HDRInfo
}

HDRDecoder is an optional interface for decoders that support HDR output. JPEG XT decoders implement this interface to provide floating-point HDR data.

type HDRInfo

type HDRInfo struct {
	// Profile indicates the JPEG XT profile (A, B, C, or D)
	Profile string

	// MinLuminance is the minimum luminance in nits (cd/m^2)
	MinLuminance float32

	// MaxLuminance is the maximum luminance in nits (cd/m^2)
	MaxLuminance float32

	// HasToneMap indicates if tone mapping data is present
	HasToneMap bool

	// HasAlpha indicates if alpha channel extension is present
	HasAlpha bool
}

HDRInfo contains HDR-specific metadata.

type ImageInfo

type ImageInfo struct {
	// Width is the image width in pixels.
	Width int

	// Height is the image height in pixels.
	Height int

	// NumChannels is the number of color channels.
	// Common values: 1 (grayscale), 3 (RGB), 4 (RGBA)
	NumChannels int

	// BitDepth is the number of bits per sample.
	// Common values: 8 or 16
	BitDepth int

	// Format indicates which JPEG family format this image uses.
	Format Format

	// NumTilesX is the number of tiles horizontally (for tiled formats).
	// Zero or one for non-tiled images.
	NumTilesX int

	// NumTilesY is the number of tiles vertically (for tiled formats).
	// Zero or one for non-tiled images.
	NumTilesY int

	// TileWidth is the nominal tile width (for tiled formats).
	// Zero for non-tiled images.
	TileWidth int

	// TileHeight is the nominal tile height (for tiled formats).
	// Zero for non-tiled images.
	TileHeight int

	// HasHDR indicates if the image contains HDR extension data.
	HasHDR bool

	// IsLowLatency indicates if the format is designed for low-latency decoding.
	// JPEG XS is the primary low-latency format.
	IsLowLatency bool
}

ImageInfo contains metadata about a decoded image. This structure is common across all JPEG family formats and provides the essential information needed to interpret the raw pixel data.

type LowLatencyDecoder

type LowLatencyDecoder interface {
	Decoder

	// DecodeProgressive decodes the image progressively, calling the callback
	// for each decoded line. This enables low-latency streaming applications.
	DecodeProgressive(callback func(lineNumber int, data []byte) error) error

	// GetLatencyLines returns the latency in lines for progressive decoding.
	// JPEG XS is designed for sub-line latency.
	GetLatencyLines() int

	// GetMemoryBound returns the maximum memory usage in bytes.
	// JPEG XS has bounded memory requirements for real-time applications.
	GetMemoryBound() int64

	// IsLowLatency returns true if the decoder is configured for low-latency mode.
	IsLowLatency() bool
}

LowLatencyDecoder is an optional interface for decoders that support low-latency progressive decoding. JPEG XS decoders implement this interface.

func NewLowLatencyDecoder

func NewLowLatencyDecoder(data []byte) (LowLatencyDecoder, error)

NewLowLatencyDecoder creates a low-latency decoder for the given image data. It automatically detects the format and returns an appropriate decoder that implements the LowLatencyDecoder interface.

Low-latency decoders support progressive line-by-line decoding with bounded memory usage, making them suitable for real-time video applications.

Returns ErrStreamingNotSupported if the detected format does not support low-latency decode.

Currently supported formats for low-latency decoding:

  • JPEG XS (line-based progressive decoding)

Example:

llDecoder, err := decoder.NewLowLatencyDecoder(imageData)
if err != nil {
    // Handle error or fall back to regular decoder
}
err = llDecoder.DecodeProgressive(func(line int, data []byte) error {
    // Process each line as it becomes available
    return nil
})

func NewLowLatencyDecoderForFormat

func NewLowLatencyDecoderForFormat(data []byte, format Format) (LowLatencyDecoder, error)

NewLowLatencyDecoderForFormat creates a low-latency decoder for the specified format. Use this when you already know the format and want to skip auto-detection.

Returns ErrStreamingNotSupported if the format does not support low-latency decode.

type StreamDecoder

type StreamDecoder interface {
	// Decoder embeds the base decoder interface for GetInfo() access.
	Decoder

	// NumTiles returns the number of tiles in the image.
	// For non-tiled images or row-based streaming, this may represent
	// the number of rows or strips.
	NumTiles() int

	// TileInfo returns information about a specific tile.
	// Returns nil if the tile index is out of range.
	TileInfo(tileIdx int) *TileInfo

	// DecodeTile decodes a single tile and returns its raw pixel data.
	// This allows processing large images one tile at a time to limit
	// memory usage.
	//
	// The returned data is in the same format as Decode():
	//   - 8-bit images: 1 byte per channel per pixel
	//   - 16-bit images: 2 bytes per channel per pixel (little-endian)
	//   - Channels are interleaved within the tile
	DecodeTile(tileIdx int) ([]byte, error)

	// DecodeRow decodes a single row of pixels.
	// For formats that don't support row-by-row decoding, this may
	// decode the entire tile containing the row.
	//
	// Returns ErrStreamingNotSupported if row-based decoding is not available.
	DecodeRow(rowIdx int) ([]byte, error)

	// DecodeStream decodes the image using a callback for each tile.
	// This is useful for processing tiles as they are decoded without
	// storing them all in memory.
	//
	// The callback receives the tile index and its decoded pixel data.
	// If the callback returns an error, decoding stops and the error
	// is returned.
	DecodeStream(callback func(tileIdx int, data []byte) error) error

	// Reset resets the decoder state to allow re-decoding tiles.
	// This is useful when you want to decode tiles multiple times
	// or in a different order.
	Reset()
}

StreamDecoder provides streaming/progressive decode capability for memory-efficient processing of large images. This interface is optional; formats that don't support streaming will return ErrStreamingNotSupported from NewStreamDecoder.

func NewStreamDecoder

func NewStreamDecoder(data []byte) (StreamDecoder, error)

NewStreamDecoder creates a streaming decoder for the given image data. It automatically detects the format and returns an appropriate streaming decoder.

Streaming decoders allow memory-efficient processing of large images by decoding one tile or row at a time instead of the entire image at once.

Returns ErrStreamingNotSupported if the detected format does not support streaming decode.

Currently supported formats for streaming:

  • JPEG 2000 (tile-based streaming)

Example:

streamDecoder, err := decoder.NewStreamDecoder(imageData)
if err != nil {
    if errors.Is(err, decoder.ErrStreamingNotSupported) {
        // Fall back to regular decoder
        dec, _ := decoder.NewDecoder(imageData)
        pixels, _ := dec.Decode()
    }
    log.Fatal(err)
}
// Process tiles one at a time
for i := 0; i < streamDecoder.NumTiles(); i++ {
    tile, err := streamDecoder.DecodeTile(i)
    // Process tile...
}
Example

ExampleNewStreamDecoder demonstrates using streaming decode for large images. Streaming allows processing tiles without loading the entire image.

package main

import (
	"errors"
	"fmt"

	"github.com/0verkilll/jpeg/decoder"
)

func main() {
	// Note: Streaming is only supported for certain formats like JPEG 2000
	fakeData := []byte{0x00}

	_, err := decoder.NewStreamDecoder(fakeData)
	if err != nil {
		if errors.Is(err, decoder.ErrStreamingNotSupported) {
			fmt.Println("Streaming not supported for this format")
		} else {
			fmt.Println("Format detection or decoder error")
		}
	}
}
Output:
Format detection or decoder error

func NewStreamDecoderForFormat

func NewStreamDecoderForFormat(data []byte, format Format) (StreamDecoder, error)

NewStreamDecoderForFormat creates a streaming decoder for the specified format. Use this when you already know the format and want to skip auto-detection.

Returns ErrStreamingNotSupported if the format does not support streaming decode.

type TileInfo

type TileInfo struct {
	// Index is the tile index (0-based).
	Index int

	// X is the horizontal tile position (0-based).
	X int

	// Y is the vertical tile position (0-based).
	Y int

	// Width is the tile width in pixels.
	Width int

	// Height is the tile height in pixels.
	Height int

	// OffsetX is the x-offset of this tile within the full image.
	OffsetX int

	// OffsetY is the y-offset of this tile within the full image.
	OffsetY int
}

TileInfo contains information about a single tile in a tiled image.

Jump to

Keyboard shortcuts

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