Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.modules.fresco

import com.facebook.imageutils.HeifExifUtil
import java.io.ByteArrayInputStream
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner

/**
* Fresco reads a HEIF image's EXIF orientation with `androidx.exifinterface`, which it does not
* declare as a dependency. ReactAndroid declares it, and this test fails with a
* `NoClassDefFoundError` if that dependency is removed.
*/
@RunWith(RobolectricTestRunner::class)
class HeifExifOrientationTest {

@Test
fun heifExifUtil_readsTheOrientationWithExifInterface() {
assertThat(HeifExifUtil.getOrientation(ByteArrayInputStream(EXIF_ROTATED_90))).isEqualTo(6)
}

private companion object {
// An EXIF block whose only tag is Orientation (0x0112) = 6, "rotate 90 CW", in the smallest
// file ExifInterface reads: a JPEG with no image data. HeifExifUtil passes the stream to
// ExifInterface without checking its format.
private val EXIF_ROTATED_90 =
byteArrayOf(
// SOI
0xFF.toByte(),
0xD8.toByte(),
// APP1, 34 bytes, "Exif\0\0"
0xFF.toByte(),
0xE1.toByte(),
0x00,
0x22,
0x45,
0x78,
0x69,
0x66,
0x00,
0x00,
// TIFF header: big-endian, first IFD at offset 8
0x4D,
0x4D,
0x00,
0x2A,
0x00,
0x00,
0x00,
0x08,
// IFD with one entry: Orientation, SHORT, count 1, value 6
0x00,
0x01,
0x01,
0x12,
0x00,
0x03,
0x00,
0x00,
0x00,
0x01,
0x00,
0x06,
0x00,
0x00,
// No next IFD
0x00,
0x00,
0x00,
0x00,
// EOI
0xFF.toByte(),
0xD9.toByte(),
)
}
}
Loading