Table of Contents

Interface IFormatConverter

Namespace
Egami.Formats
Assembly
Egami.dll

A writer that can convert a file of another format to its own without decoding it to pixels first, such as camera RAW data copied into a DNG unchanged. Transcode(string, string, Action<RasterOps>?, ReaderOptions?, WriterOptions?, EgamiContext?) asks the output format's writer when there are no operations and the reader options ask for nothing beyond the format's defaults; a writer that declines is used as usual.

public interface IFormatConverter

Examples

/// <summary>Writes RAW8 files; a RAW8 file transcoded to RAW8 with no operations is copied as it is, without decoding it.</summary>
public sealed class CopyingRaw8Writer : IFormatWriter, IFormatConverter
{
    public void Write<TPixel>(Raster<TPixel> raster, Stream output, WriterOptions options)
        where TPixel : unmanaged, IPixelType<TPixel>
    {
        Raw8Format.Info.Writer!.Write(raster, output, options);
    }

    public bool TryConvert(Stream input, FormatInfo inputFormat, Stream output, WriterOptions options, EgamiContext context)
    {
        if (inputFormat.Name != Raw8Format.Info.Name)
        {
            return false;
        }

        input.CopyTo(output);
        return true;
    }
}

Methods

TryConvert(Stream, FormatInfo, Stream, WriterOptions, EgamiContext)

Converts input, a file of inputFormat, to this writer's format, or declines, by the format alone, before reading or writing anything.

bool TryConvert(Stream input, FormatInfo inputFormat, Stream output, WriterOptions options, EgamiContext context)

Parameters

input Stream

The file to convert, from its current position. It is left open.

inputFormat FormatInfo

The format input was detected as.

output Stream

Where to write. The writer leaves it open.

options WriterOptions

How to write.

context EgamiContext

The context of the call: its formats, limits and diagnostics.

Returns

bool

true when the file was converted; false, with nothing read or written, to decode it as usual.

Examples

/// <summary>Writes RAW8 files; a RAW8 file transcoded to RAW8 with no operations is copied as it is, without decoding it.</summary>
public sealed class CopyingRaw8Writer : IFormatWriter, IFormatConverter
{
    public void Write<TPixel>(Raster<TPixel> raster, Stream output, WriterOptions options)
        where TPixel : unmanaged, IPixelType<TPixel>
    {
        Raw8Format.Info.Writer!.Write(raster, output, options);
    }

    public bool TryConvert(Stream input, FormatInfo inputFormat, Stream output, WriterOptions options, EgamiContext context)
    {
        if (inputFormat.Name != Raw8Format.Info.Name)
        {
            return false;
        }

        input.CopyTo(output);
        return true;
    }
}