crad

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2020 License: MIT Imports: 10 Imported by: 0

README

CRAD

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

File extension .crad.

General structure

#?CRAD\n
{"width":3272,"height":1280,"depth":32,"format":"LogLuv","raster_mode":"separately","compression":"gzip"}\n
+----------------+
|                |
|     Raster     |
|                |
+----------------+

### Magic number

The magic number of the the CRAD is #?CRAD at the first line.

Header

The header is a one-line JSON string at the second line.

Raster

The raster contains all the pixels of the image.

Compression

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

Format
  • RGBE and XYZE

These formats are based on the Radiance RGBE enconding. 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


# CRAD 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"
)

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,
	}
)

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    `json:"width"`
	Height      int    `json:"height"`
	Depth       int    `json:"depth"`
	Format      string `json:"format"`
	RasterMode  string `json:"raster_mode"`
	Compression string `json:"compression"`
}

A Header handles all image properties.

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