hli

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2023 License: MIT Imports: 10 Imported by: 1

README

HLI

The HLI is an HDR image format aimed to be simple as possible.

File extension .hli.

General structure

[magic number][1-byte header-size length][variable-length header-size][variable-length header][raster]

Magic number

The magic number of the HLI format is HLi.v1 at the beginning of the file.

Header

CBOR encoded data:

type Header struct {
	Width       int               `cbor:"width"`
	Height      int               `cbor:"height"`
	Depth       int               `cbor:"depth"`
	Format      string            `cbor:"format"`
	RasterMode  string            `cbor:"raster_mode"`
	Compression string            `cbor:"compression"`
	Metadata    map[string]string `cbor:"metadata,omitempty"`
}

See consts.go for possible values for each field.

  • metadata is optional

Default options:

Mode6 = &hli.Header{
    Depth:       32,
    Format:      hli.FormatLogLuv,
    RasterMode:  hli.RasterModeSeparately,
    Compression: hli.CompressionZstd,
}
Raster

The raster contains all the pixels of the image.

Compression

The raster is compressed with the specified algorithm in the header (typically: gzip)

Supported compression:

  • gzip
  • zstd (default)
Format
  • RGBE and XYZE

These formats are based on the Radiance RGBE encoding. A pixel is stored on a 4-byte representation where three 8-bit mantissas shared a common 8-bit exponent. It offers a very compact storage of 32-bit floating points. The net result is a format that has an absolute accuracy of about 1%, covering a range of over 76 orders of magnitude.

  • RGB and XYZ

These formats are based on the representation of a 32-bit floating points in bytes. A pixel is stored on a 12-byte representation where a channel is coded on 4 bytes in little endian order. It offers a great absolute accuracy.

  • LogLuv (used as default format)

This format is based on the LogLuv Encoding for Full Gamut. A pixel is stored on a 4-byte representation where a channel is coded on 4 bytes in.

# Original LogLuv representation

 1       15           8        8
|-+---------------|--------+--------|
 S       Le           ue       ve


# HLI LogLuv representation

    8        8        8        8
|--------+---------|--------+--------|
   SLe       le       ue       ve

It offers a great compression and with an absolute accuracy of about 0.3%, covering a range of over 38 orders of magnitude.

Raster mode

Uncompressed Raster is stored in several modes:

  • normal mode

Each pixels' bytes are stored in contiguous order.

RGBE example:

rgbergbergbe
rgbergbergbe

This is the same for XYZE.

RGB example:

rrrrggggbbbbrrrrggggbbbbrrrrggggbbbb
rrrrggggbbbbrrrrggggbbbbrrrrggggbbbb

This is the same for XYZ.

LogLuv example:

SLeleueveSLeleueveSLeleueve
SLeleueveSLeleueveSLeleueve
  • separately mode

The color channels are stored separately in order to improve the compression ratio.

RGBE example:

rrrgggbbbeee
rrrgggbbbeee

This is the same for XYZE.

RGB example:

rrrrrrrrrrrrggggggggggggbbbbbbbbbbbb
rrrrrrrrrrrrggggggggggggbbbbbbbbbbbb

This is the same for XYZ.

LogLuv example:

SLeSLeSLeleleleueueueveve
SLeSLeSLeleleleueueueveve

Documentation

Index

Constants

View Source
const (
	// FormatRGBE for RGBE model
	FormatRGBE = "RGBE"
	// FormatXYZE for XYZE model
	FormatXYZE = "XYZE"
	// FormatRGB for RGB model
	FormatRGB = "RGB"
	// FormatXYZ for XYZ model
	FormatXYZ = "XYZ"
	// FormatLogLuv for LogLuv model
	FormatLogLuv = "LogLuv"

	// RasterModeNormal for normal pixel positioning
	RasterModeNormal = "normal"
	// RasterModeSeparately for separately pixel's color positioning
	RasterModeSeparately = "separately"

	// CompressionGzip for gzip compression
	CompressionGzip = "gzip"
	// CompressionZstd for Zstandard compression
	CompressionZstd = "zstd"
)

Variables

View Source
var (
	// Mode1 offers the better compression in RGBE/XYZE color model depending to
	// the provided hdr.Image implementation. (quantization steps: 1%)
	Mode1 = &Header{
		Depth:       32,
		RasterMode:  RasterModeSeparately,
		Compression: CompressionGzip,
	}
	// Mode2 offers the better compression in XYZE that covers gamut. (quantization steps: 1%)
	Mode2 = &Header{
		Depth:       32,
		Format:      FormatXYZE,
		RasterMode:  RasterModeSeparately,
		Compression: CompressionGzip,
	}
	// Mode3 offers a trade off in compression/quality in RGB. (quantization steps: 0.1%)
	Mode3 = &Header{
		Depth:       32,
		Format:      FormatRGB,
		RasterMode:  RasterModeSeparately,
		Compression: CompressionGzip,
	}
	// Mode4 offers the better quality in XYZ that covers gamut. (quantization steps: 0.1%)
	Mode4 = &Header{
		Depth:       32,
		Format:      FormatXYZ,
		RasterMode:  RasterModeSeparately,
		Compression: CompressionGzip,
	}
	// Mode5 offers the better compression and quality in LogLuv that covers gamut. (quantization steps: 0.1%)
	Mode5 = &Header{
		Depth:       32,
		Format:      FormatLogLuv,
		RasterMode:  RasterModeSeparately,
		Compression: CompressionGzip,
	}
	// Mode6 offers the better and faster compression and quality in LogLuv that covers gamut. (quantization steps: 0.1%)
	Mode6 = &Header{
		Depth:       32,
		Format:      FormatLogLuv,
		RasterMode:  RasterModeSeparately,
		Compression: CompressionZstd,
	}
)

Functions

func Decode

func Decode(r io.Reader) (img image.Image, err error)

Decode reads a HDR image from r and returns an image.Image.

func DecodeConfig

func DecodeConfig(r io.Reader) (image.Config, error)

DecodeConfig returns the color model and dimensions of a RGBE image without decoding the entire image.

func Encode

func Encode(w io.Writer, m hdr.Image) error

Encode writes the Image m to w in CRAD format.

func EncodeWithOptions

func EncodeWithOptions(w io.Writer, m hdr.Image, h *Header) error

EncodeWithOptions writes the Image m to w in CRAD format.

Types

type FormatError

type FormatError string

A FormatError reports that the input is not a valid CRAD image.

func (FormatError) Error

func (e FormatError) Error() string
type Header struct {
	Width       int               `cbor:"width"`
	Height      int               `cbor:"height"`
	Depth       int               `cbor:"depth"`
	Format      string            `cbor:"format"`
	RasterMode  string            `cbor:"raster_mode"`
	Compression string            `cbor:"compression"`
	Metadata    map[string]string `cbor:"metadata,omitempty"`
}

A Header handles all image properties.

func DecodeHeader

func DecodeHeader(r io.Reader) (Header, error)

DecodeHeader returns the Header without decoding the entire image.

type InternalError

type InternalError string

An InternalError reports that an internal error was encountered.

func (InternalError) Error

func (e InternalError) Error() string

type UnsupportedError

type UnsupportedError string

An UnsupportedError reports that the input uses a valid but unimplemented feature.

func (UnsupportedError) Error

func (e UnsupportedError) Error() string

Jump to

Keyboard shortcuts

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