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

Commit 78b19db5 authored by Vignesh Venkatasubramanian's avatar Vignesh Venkatasubramanian
Browse files

Add AVIF sniffing to ExifInterface

The exif metadata extraction process for AVIF is similar to HEIC.
Adding AVIF sniffing so that avif files can be used wit
ExifInterface.

CTS tests for this feature will come in a separate CL as there are
still some CLs in flight to finish AVIF support.

Test: ExifInterfaceTest still passes.
Bug: 141654151
Change-Id: I5546a4f81e928a29d46f6c4b9db77032a09a8350
parent aa42b854
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;
                }
            }