QOI

edit

QOI (the "Quite OK Image" format) stores one lossless 8-bit RGB or RGBA still image, and nothing else: no animation and no metadata. QoiEncoder keeps every sample, including the colors of fully transparent pixels, and its output is byte-identical to the one of the reference encoder.

What is read and written

ReadingWriting
Pixels3 channels (loaded as Rgb24) or 4 channels (loaded as Rgba32)4 channels for pixel formats with alpha, 3 otherwise; gray images are stored as RGB
Colorspace fieldReported as Metadata.TransferFunctionWritten from Metadata.TransferFunction
MetadataNoneNone

Save a QOI file

public static void SaveQoi(string inputPath, string qoiPath, string linearQoiPath, string pngPath)
{
    using var image = Image.Load(inputPath);
    var frame = image.Frames[0]; // QOI stores one still image
    frame.Save(qoiPath, new QoiEncoder { AllowBitDepthReduction = true });

    // A QOI colorspace of 1 (linear samples) is reported as a label, never applied: other formats cannot store it, so
    // saving the pixels elsewhere requires an explicit decision instead of silently relabeling them as sRGB
    using var linear = Image.Load(linearQoiPath);
    if (linear.Metadata.TransferFunction == ColorTransferFunction.Linear)
    {
        linear.Save(pngPath, new PngEncoder { MetadataHandling = MetadataHandling.DiscardUnsupported });
    }
}

Options

OptionWhat it doesDefault
AllowBitDepthReductionLets 16-bit pixel formats be rounded to 8 bitsfalse
MetadataHandlingWhat to do with metadata, which QOI cannot storeStrict

Pitfalls