Table of Contents

Class ExtendedContextExtensions

Namespace
Egami.Formats.Extended
Assembly
Egami.Formats.Extended.dll

Registers Egami.Formats.Extended's formats with an EgamiContext. Nothing registers them on their own: an app calls WithExtendedFormats(EgamiContext) for every stable format, or one method per format.

public static class ExtendedContextExtensions
Inheritance
ExtendedContextExtensions
Inherited Members

Examples

// Every stable format of Egami.Formats.Extended, once at startup before any other Egami call:
// EgamiContext.SetDefault(new EgamiContext().WithExtendedFormats());

// ...or in a context of its own.
EgamiContext context = EgamiContext.Default.WithExtendedFormats();
using Raster image = Raster.Load("duck.png", context);

// A raster saves to a path through the context it was loaded with, so the extension picks PCX.
image.Save("duck.pcx");
using Raster back = Raster.Load("duck.pcx", context);
string format = back.Metadata.FormatName!;               // "PCX"

Methods

WithCineon(EgamiContext)

Returns a copy of context that reads and writes Cineon (CineonFormat).

public static EgamiContext WithCineon(this EgamiContext context)

Parameters

context EgamiContext

The context to add the format to.

Returns

EgamiContext

The new context.

Exceptions

ArgumentNullException

context is null.

WithDds(EgamiContext)

Returns a copy of context that reads DDS textures (DdsFormat).

public static EgamiContext WithDds(this EgamiContext context)

Parameters

context EgamiContext

The context to add the format to.

Returns

EgamiContext

The new context.

Exceptions

ArgumentNullException

context is null.

WithDicom(EgamiContext)

Returns a copy of context that reads and writes DICOM (DicomFormat). In preview, so WithExtendedFormats(EgamiContext) leaves it out. DICOM is detected ahead of the other formats: the 128-byte preamble may hold another format's header (PS3.10 section 7.1 allows a TIFF one), which would otherwise be found first.

[Experimental("EGAMIX001", UrlFormat = "https://github.com/inexin/Egami/blob/main/docs/articles/formats/dicom.md")]
public static EgamiContext WithDicom(this EgamiContext context)

Parameters

context EgamiContext

The context to add the format to.

Returns

EgamiContext

The new context.

Examples

// Registered, DICOM is detected and probed: the size, the layout a load gives and the number of frames.
EgamiContext context = new EgamiContext().WithDicom();
RasterInfo info = Raster.Probe("scan.dcm", context);
Console.WriteLine($"{info.Format.Name} {info.Width}x{info.Height} {info.Layout}, {info.ImageCount} frames");

Exceptions

ArgumentNullException

context is null.

WithDpx(EgamiContext)

Returns a copy of context that reads and writes DPX (DpxFormat).

public static EgamiContext WithDpx(this EgamiContext context)

Parameters

context EgamiContext

The context to add the format to.

Returns

EgamiContext

The new context.

Exceptions

ArgumentNullException

context is null.

WithExtendedFormats(EgamiContext)

Returns a copy of context with every stable format of this package registered: PCX, SGI, Sun raster, XBM, XPM, WBMP, Farbfeld, DDS, KTX, KTX 2, JPEG-LS, camera RAW, DPX, Cineon and FITS. Formats in preview are never included; each has its own method. Call it once, for example EgamiContext.SetDefault(new EgamiContext().WithExtendedFormats()) at startup.

public static EgamiContext WithExtendedFormats(this EgamiContext context)

Parameters

context EgamiContext

The context to add the formats to.

Returns

EgamiContext

The new context, its own formats first, so this package's are detected after them.

Examples

// Every stable format of Egami.Formats.Extended, once at startup before any other Egami call:
// EgamiContext.SetDefault(new EgamiContext().WithExtendedFormats());

// ...or in a context of its own.
EgamiContext context = EgamiContext.Default.WithExtendedFormats();
using Raster image = Raster.Load("duck.png", context);

// A raster saves to a path through the context it was loaded with, so the extension picks PCX.
image.Save("duck.pcx");
using Raster back = Raster.Load("duck.pcx", context);
string format = back.Metadata.FormatName!;               // "PCX"

Exceptions

ArgumentNullException

context is null.

WithFarbfeld(EgamiContext)

Returns a copy of context that reads and writes Farbfeld (FarbfeldFormat).

public static EgamiContext WithFarbfeld(this EgamiContext context)

Parameters

context EgamiContext

The context to add the format to.

Returns

EgamiContext

The new context.

Exceptions

ArgumentNullException

context is null.

WithFits(EgamiContext)

Returns a copy of context that reads and writes FITS (FitsFormat).

public static EgamiContext WithFits(this EgamiContext context)

Parameters

context EgamiContext

The context to add the format to.

Returns

EgamiContext

The new context.

Exceptions

ArgumentNullException

context is null.

WithJpegLs(EgamiContext)

Returns a copy of context that reads and writes JPEG-LS (JpegLsFormat). JPEG-LS is detected ahead of the other formats, since a JPEG-LS file starts as a JPEG file does; without it, a .jls file fails to load as JPEG.

public static EgamiContext WithJpegLs(this EgamiContext context)

Parameters

context EgamiContext

The context to add the format to.

Returns

EgamiContext

The new context.

Examples

// JPEG-LS (.jls) is lossless or near-lossless; WithExtendedFormats() registers it too.
EgamiContext context = EgamiContext.Default.WithJpegLs();
using Raster duck = Raster.Load("duck.png", context);
duck.Save("duck.jls");

// Load gives the natural pixel type: Gray8 or Gray16, GrayAlpha, Rgb or Rgba, 8 or 16 bits as stored.
using Raster back = Raster.Load("duck.jls", context);
if (back.Metadata.FormatDetails is JpegLsDetails jls)
{
    Console.WriteLine($"NEAR {jls.Near}, {jls.Interleave}, {jls.BitsPerSample} bits, {jls.Components} components, {jls.ColorTransform}");
}

Exceptions

ArgumentNullException

context is null.

WithKtx(EgamiContext)

Returns a copy of context that reads KTX 1.1 textures (KtxFormat).

public static EgamiContext WithKtx(this EgamiContext context)

Parameters

context EgamiContext

The context to add the format to.

Returns

EgamiContext

The new context.

Exceptions

ArgumentNullException

context is null.

WithKtx2(EgamiContext)

Returns a copy of context that reads KTX 2.0 textures (Ktx2Format).

public static EgamiContext WithKtx2(this EgamiContext context)

Parameters

context EgamiContext

The context to add the format to.

Returns

EgamiContext

The new context.

Exceptions

ArgumentNullException

context is null.

WithPcx(EgamiContext)

Returns a copy of context that reads and writes PCX (PcxFormat).

public static EgamiContext WithPcx(this EgamiContext context)

Parameters

context EgamiContext

The context to add the format to.

Returns

EgamiContext

The new context.

Exceptions

ArgumentNullException

context is null.

WithRaw(EgamiContext)

Returns a copy of context that reads camera RAW files (RawFormat). RAW is detected ahead of every other format, since a DNG file is also a TIFF file; without it, a DNG opens as TIFF and only its preview pages load.

public static EgamiContext WithRaw(this EgamiContext context)

Parameters

context EgamiContext

The context to add the format to.

Returns

EgamiContext

The new context.

Examples

// RAW goes ahead of TIFF, since a DNG is a TIFF file; WithExtendedFormats() registers it too.
EgamiContext context = EgamiContext.Default.WithRaw();

// Load develops the sensor data: the camera's white balance and colour, AHD demosaicing, sRGB in Rgb16.
using Raster photo = Raster.Load("photo.dng", context);
photo.Save("photo.png");

// Probe reads the structure alone: the developed size, the camera and the embedded previews.
RasterInfo info = Raster.Probe("photo.dng", context);
Console.WriteLine($"{info.Width}×{info.Height}, {info.ImageCount} image(s)");

Exceptions

ArgumentNullException

context is null.

WithSgi(EgamiContext)

Returns a copy of context that reads and writes SGI (SgiFormat).

public static EgamiContext WithSgi(this EgamiContext context)

Parameters

context EgamiContext

The context to add the format to.

Returns

EgamiContext

The new context.

Exceptions

ArgumentNullException

context is null.

WithSunRaster(EgamiContext)

Returns a copy of context that reads and writes Sun raster (SunRasterFormat).

public static EgamiContext WithSunRaster(this EgamiContext context)

Parameters

context EgamiContext

The context to add the format to.

Returns

EgamiContext

The new context.

Exceptions

ArgumentNullException

context is null.

WithWbmp(EgamiContext)

Returns a copy of context that reads and writes WBMP (WbmpFormat).

public static EgamiContext WithWbmp(this EgamiContext context)

Parameters

context EgamiContext

The context to add the format to.

Returns

EgamiContext

The new context.

Exceptions

ArgumentNullException

context is null.

WithXbm(EgamiContext)

Returns a copy of context that reads and writes XBM (XbmFormat).

public static EgamiContext WithXbm(this EgamiContext context)

Parameters

context EgamiContext

The context to add the format to.

Returns

EgamiContext

The new context.

Exceptions

ArgumentNullException

context is null.

WithXpm(EgamiContext)

Returns a copy of context that reads and writes XPM (XpmFormat).

public static EgamiContext WithXpm(this EgamiContext context)

Parameters

context EgamiContext

The context to add the format to.

Returns

EgamiContext

The new context.

Exceptions

ArgumentNullException

context is null.