Table of Contents

Class CubeFile

Namespace
Egami.Operations
Assembly
Egami.dll

Reads and writes .cube LUT files: the Adobe Cube LUT Specification 1.0 (a 1D or a 3D table, with TITLE, DOMAIN_MIN and DOMAIN_MAX), and DaVinci Resolve's variant with a 1D shaper before the 3D table (LUT_1D_INPUT_RANGE and LUT_3D_INPUT_RANGE).

public static class CubeFile
Inheritance
CubeFile
Inherited Members

Examples

// Export a grade for DaVinci Resolve or Premiere, then load a .cube file and apply it at 70%.
ColorFilter grade = ColorFilter.Curves(ToneCurve.FromPoints([(0, 0), (0.25f, 0.2f), (0.75f, 0.82f), (1, 1)]))
    .Then(ColorFilter.Saturation(1.1f));
CubeFile.Write("my-grade.cube", grade.ToLut3D(size: 33), title: "My grade");

Lut3D lut = CubeFile.Read("my-grade.cube");
raster.Apply(o => o.ApplyFilter(ColorFilter.Lerp(ColorFilter.Identity, ColorFilter.FromLut(lut), 0.7f)), Ct);

// Tables can also be built from a function, and read at any color.
Lut3D warm = Lut3D.FromFunction(c => new Vector3(c.X, c.Y * 0.97f, c.Z * 0.9f), size: 17);
Vector3 gray = warm.Evaluate(new Vector3(0.5f), LutInterpolation.Tetrahedral);

Remarks

The reader is strict: every number must parse and be finite, the counts must match the sizes exactly, LUT_3D_SIZE may be at most 256 and LUT_1D_SIZE at most 65,536, and the table is checked against MaxTotalBytes before it is allocated. Anything else throws CorruptDataException naming the line.

Methods

Read(Stream, EgamiContext?)

Reads a .cube file from a stream, which is left open.

public static Lut3D Read(Stream stream, EgamiContext? context = null)

Parameters

stream Stream

The stream, read from its current position to its end.

context EgamiContext

The context whose limits apply, or null for Default.

Returns

Lut3D

The table.

Exceptions

ArgumentNullException

stream is null.

CorruptDataException

The data breaks the format; the message names the line.

LimitExceededException

The table would exceed the context's limits.

Read(string, EgamiContext?)

Reads a .cube file. A 1D-only file becomes a table whose grid changes nothing, behind its 1D table as the shaper.

public static Lut3D Read(string path, EgamiContext? context = null)

Parameters

path string

The file.

context EgamiContext

The context whose limits apply, or null for Default.

Returns

Lut3D

The table.

Exceptions

ArgumentNullException

path is null.

CorruptDataException

The file breaks the format; the message names the line.

LimitExceededException

The table would exceed the context's limits.

Write(Stream, Lut3D, string?)

Writes a table as a .cube file to a stream, which is left open.

public static void Write(Stream stream, Lut3D lut, string? title = null)

Parameters

stream Stream

The stream.

lut Lut3D

The table.

title string

The TITLE line, or null for none. It may not hold quotes or line breaks.

Exceptions

ArgumentNullException

stream or lut is null.

ArgumentException

title holds a quote or a line break.

InvalidOperationException

The table has a shaper whose input range differs per channel from its grid's, which a .cube file cannot hold.

Write(string, Lut3D, string?)

Writes a table as a .cube file: a 3D table with nine significant digits, behind its shaper as a 1D table when it has one, or an Adobe 1D-only file when the grid changes nothing. Reading the file back gives the same values.

public static void Write(string path, Lut3D lut, string? title = null)

Parameters

path string

The file, created or replaced.

lut Lut3D

The table.

title string

The TITLE line, or null for none. It may not hold quotes or line breaks.

Exceptions

ArgumentNullException

path or lut is null.

ArgumentException

title holds a quote or a line break.

InvalidOperationException

The table has a shaper whose input range differs per channel from its grid's, which a .cube file cannot hold.