// Detect It Easy: detection rule file format
// Author: LinXP
// doc-ref: https://qoiformat.org/qoi-specification.pdf

init("image", "Quite OK Image (.QOI)");

function detect(bShowType, bShowVersion, bShowOptions) {
    if (Binary.getSize() >= 0x0E) {
        if (Binary.compare("'qoif'")) {
            bDetected = true;
            sOptions = sOptions.append(Binary.read_uint32(0x04, _BE) + "x" + Binary.read_uint32(0x08, _BE));
            switch (File.read_uint8(0x0C)) {
                case 3:
                    sOption("RGB");
                    break;
                case 4:
                    sOption("RGBA");
                    break;
                default:
                    bDetected = false;
            }
            switch (File.read_uint8(0x0D)) {
                case 0:
                    sOption("sRGB with linear alpha");
                    break;
                case 1:
                    sOption("all channels linear");
                    break;
                default:
                    bDetected = false;
            }
        }
    }

    return result(bShowType, bShowVersion, bShowOptions);
}