Interface IFormatConverter
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
inputStreamThe file to convert, from its current position. It is left open.
inputFormatFormatInfoThe format
inputwas detected as.outputStreamWhere to write. The writer leaves it open.
optionsWriterOptionsHow to write.
contextEgamiContextThe context of the call: its formats, limits and diagnostics.
Returns
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;
}
}