Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a315e3a9 authored by Vignesh Venkatasubramanian's avatar Vignesh Venkatasubramanian Committed by Android (Google) Code Review
Browse files

Merge "Add AVIF sniffing to ExifInterface"

parents 93f4464b 78b19db5
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -79,7 +79,8 @@ import java.util.zip.CRC32;
/**
 * This is a class for reading and writing Exif tags in various image file formats.
 * <p>
 * Supported for reading: JPEG, PNG, WebP, HEIF, DNG, CR2, NEF, NRW, ARW, RW2, ORF, PEF, SRW, RAF.
 * Supported for reading: JPEG, PNG, WebP, HEIF, DNG, CR2, NEF, NRW, ARW, RW2, ORF, PEF, SRW, RAF,
 * AVIF.
 * <p>
 * Supported for writing: JPEG, PNG, WebP.
 * <p>
@@ -543,6 +544,8 @@ public class ExifInterface {
    private static final byte[] HEIF_TYPE_FTYP = new byte[] {'f', 't', 'y', 'p'};
    private static final byte[] HEIF_BRAND_MIF1 = new byte[] {'m', 'i', 'f', '1'};
    private static final byte[] HEIF_BRAND_HEIC = new byte[] {'h', 'e', 'i', 'c'};
    private static final byte[] HEIF_BRAND_AVIF = new byte[] {'a', 'v', 'i', 'f'};
    private static final byte[] HEIF_BRAND_AVIS = new byte[] {'a', 'v', 'i', 's'};

    // See http://fileformats.archiveteam.org/wiki/Olympus_ORF
    private static final short ORF_SIGNATURE_1 = 0x4f52;
@@ -2662,6 +2665,7 @@ public class ExifInterface {
            byte[] brand = new byte[4];
            boolean isMif1 = false;
            boolean isHeic = false;
            boolean isAvif = false;
            for (long i = 0; i < chunkDataSize / 4;  ++i) {
                if (signatureInputStream.read(brand) != brand.length) {
                    return false;
@@ -2674,8 +2678,11 @@ public class ExifInterface {
                    isMif1 = true;
                } else if (Arrays.equals(brand, HEIF_BRAND_HEIC)) {
                    isHeic = true;
                } else if (Arrays.equals(brand, HEIF_BRAND_AVIF)
                        || Arrays.equals(brand, HEIF_BRAND_AVIS)) {
                    isAvif = true;
                }
                if (isMif1 && isHeic) {
                if (isMif1 && (isHeic || isAvif)) {
                    return true;
                }
            }