Table of Contents

Class JxlLayer

Namespace
Egami.Formats.Jxl
Assembly
Egami.dll
public sealed class JxlLayer : IDisposable
Inheritance
JxlLayer
Implements
Inherited Members

Examples

// An animation loads as its frames, blended onto the canvas, each with its delay.
using Raster animation = Raster.Load("sprite.jxl");
int frames = animation.FrameCount;

// The layers before blending, for an editor: each at its own size and place.
IReadOnlyList<JxlLayer> layers = JxlImage.ReadLayers("sprite.jxl");
foreach (JxlLayer layer in layers)
{
    Console.WriteLine($"{layer.Raster.Width}x{layer.Raster.Height} at {layer.X},{layer.Y}: {layer.Blend}, {layer.Duration.TotalMilliseconds} ms");
    layer.Dispose();
}

// The preview some files carry for quick display, or null.
using Raster? preview = JxlImage.ReadPreview("duck.jxl");

// A lossy still at an eighth of its size, from its LF image alone.
using Raster thumbnail = Raster.Load("duck.jxl", options: new JxlReaderOptions { MaxDownscale = 8 });

Constructors

JxlLayer(Raster, int, int, JxlLayerBlend, TimeSpan, string?)

Creates a layer to write. The layer takes the raster: disposing the layer disposes it.

public JxlLayer(Raster raster, int x = 0, int y = 0, JxlLayerBlend blend = JxlLayerBlend.Replace, TimeSpan duration = default, string? name = null)

Parameters

raster Raster

The layer's pixels, at its own size.

x int

The left edge on the canvas; it can be negative or reach past the canvas.

y int

The top edge on the canvas; it can be negative or reach past the canvas.

blend JxlLayerBlend

How the layer's color combines with the canvas below it.

duration TimeSpan

How long the canvas shows after this layer in an animation; zero for a layer that is not shown alone.

name string

The layer's name, up to 1,071 bytes of UTF-8, or null for none.

Examples

// Layers for an editor: each at its own place, blended onto the ones below, and named. ReadLayers gives them back.
using Raster<Rgba8> photo = Raster.Load<Rgba8>("duck.png");
Raster<Rgba8> badge = Raster.Create<Rgba8>(120, 60, new Rgba8(255, 200, 0, 160));
List<JxlLayer> layers =
[
    new(photo.As<Rgba8>(), name: "photo"),
    new(badge, x: -20, y: 30, blend: JxlLayerBlend.Blend, name: "badge"),
];
JxlImage.WriteLayers("layered.jxl", photo.Width, photo.Height, layers);
foreach (JxlLayer layer in layers)
{
    layer.Dispose();
}

// Load gives them blended; ReadLayers as they were written.
using Raster flat = Raster.Load("layered.jxl");
IReadOnlyList<JxlLayer> read = JxlImage.ReadLayers("layered.jxl");

Exceptions

ArgumentNullException

raster is null.

ArgumentOutOfRangeException

blend is not a defined mode, or duration is negative or longer than 2³² − 1 ms.

ArgumentException

name is longer than 1,071 bytes of UTF-8.

Properties

Blend

Gets how the layer's color combines with the canvas.

public JxlLayerBlend Blend { get; }

Property Value

JxlLayerBlend

Duration

Gets how long the canvas shows after this layer in an animation; zero for a layer that is not shown alone.

public TimeSpan Duration { get; }

Property Value

TimeSpan

Name

Gets the layer's name, or an empty string.

public string Name { get; }

Property Value

string

Raster

Gets the layer's pixels, at its own size.

public Raster Raster { get; }

Property Value

Raster

X

Gets the left edge of the layer on the canvas; it can be negative or reach past the canvas.

public int X { get; }

Property Value

int

Y

Gets the top edge of the layer on the canvas.

public int Y { get; }

Property Value

int

Methods

Dispose()

Disposes the raster.

public void Dispose()