Skip to content

Commit cd641d6

Browse files
committed
port modified Exif class from CameraX to 1.5.0-alpha04
1 parent 66f8ff7 commit cd641d6

File tree

1 file changed

+20
-28
lines changed
  • app/src/main/java/androidxc/camera/core/impl/utils

1 file changed

+20
-28
lines changed

Diff for: app/src/main/java/androidxc/camera/core/impl/utils/Exif.java

+20-28
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616

1717
package androidxc.camera.core.impl.utils;
1818

19-
import android.annotation.SuppressLint;
2019
import android.location.Location;
2120

2221
import androidx.annotation.NonNull;
2322
import androidx.annotation.Nullable;
24-
import androidx.annotation.RequiresApi;
23+
import androidx.annotation.VisibleForTesting;
2524
import androidx.camera.core.ImageProxy;
2625
import androidx.camera.core.Logger;
2726
import androidxc.exifinterface.media.ExifInterface;
@@ -38,18 +37,20 @@
3837
import java.util.Date;
3938
import java.util.List;
4039
import java.util.Locale;
40+
import java.util.Objects;
4141

4242
/**
4343
* Utility class for modifying metadata on JPEG files.
4444
*
4545
* <p>Call {@link #save()} to persist changes to disc.
4646
*/
47-
@SuppressLint("RestrictedApi")
48-
@RequiresApi(21) // TODO(b/200306659): Remove and replace with annotation on package-info.java
4947
public final class Exif {
5048

5149
/** Timestamp value indicating a timestamp value that is either not set or not valid */
5250
public static final long INVALID_TIMESTAMP = -1;
51+
// Forked from ExifInterface.TAG_THUMBNAIL_ORIENTATION. The value is library-internal so we
52+
// can't depend on it directly.
53+
public static final String TAG_THUMBNAIL_ORIENTATION = "ThumbnailOrientation";
5354

5455
private static final String TAG = Exif.class.getSimpleName();
5556

@@ -94,7 +95,7 @@ public SimpleDateFormat initialValue() {
9495
ExifInterface.TAG_JPEG_INTERCHANGE_FORMAT_LENGTH,
9596
ExifInterface.TAG_THUMBNAIL_IMAGE_LENGTH,
9697
ExifInterface.TAG_THUMBNAIL_IMAGE_WIDTH,
97-
ExifInterface.TAG_THUMBNAIL_ORIENTATION);
98+
TAG_THUMBNAIL_ORIENTATION);
9899

99100
private final ExifInterface mExifInterface;
100101

@@ -187,7 +188,8 @@ public void copyToCroppedImage(@NonNull Exif croppedExif) {
187188
exifTags.removeAll(DO_NOT_COPY_EXIF_TAGS);
188189
for (String tag : exifTags) {
189190
String originalValue = mExifInterface.getAttribute(tag);
190-
if (originalValue != null) {
191+
String croppedExifValue = croppedExif.mExifInterface.getAttribute(tag);
192+
if (originalValue != null && !Objects.equals(originalValue, croppedExifValue)) {
191193
croppedExif.mExifInterface.setAttribute(tag, originalValue);
192194
}
193195
}
@@ -603,6 +605,17 @@ public void flipHorizontally() {
603605
mExifInterface.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(orientation));
604606
}
605607

608+
@VisibleForTesting
609+
@Nullable
610+
public String getMetadata() {
611+
return mExifInterface.getAttribute(ExifInterface.TAG_XMP);
612+
}
613+
614+
@NonNull
615+
public ExifInterface getExifInterface() {
616+
return mExifInterface;
617+
}
618+
606619
/** Attaches the current timestamp to the file. */
607620
public void attachTimestamp() {
608621
long now = System.currentTimeMillis();
@@ -690,11 +703,6 @@ private static final class Speed {
690703
static Converter fromKilometersPerHour(double kph) {
691704
return new Converter(kph * 0.621371);
692705
}
693-
694-
static Converter fromMetersPerSecond(double mps) {
695-
return new Converter(mps * 2.23694);
696-
}
697-
698706
static Converter fromMilesPerHour(double mph) {
699707
return new Converter(mph);
700708
}
@@ -710,18 +718,6 @@ static final class Converter {
710718
mMph = mph;
711719
}
712720

713-
double toKilometersPerHour() {
714-
return mMph / 0.621371;
715-
}
716-
717-
double toMilesPerHour() {
718-
return mMph;
719-
}
720-
721-
double toKnots() {
722-
return mMph / 1.15078;
723-
}
724-
725721
double toMetersPerSecond() {
726722
return mMph / 2.23694;
727723
}
@@ -873,7 +869,7 @@ public static List<String> getAllExifTags() {
873869
ExifInterface.TAG_INTEROPERABILITY_INDEX,
874870
ExifInterface.TAG_THUMBNAIL_IMAGE_LENGTH,
875871
ExifInterface.TAG_THUMBNAIL_IMAGE_WIDTH,
876-
ExifInterface.TAG_THUMBNAIL_ORIENTATION,
872+
TAG_THUMBNAIL_ORIENTATION,
877873
ExifInterface.TAG_DNG_VERSION,
878874
ExifInterface.TAG_DEFAULT_CROP_SIZE,
879875
ExifInterface.TAG_ORF_THUMBNAIL_IMAGE,
@@ -890,9 +886,5 @@ public static List<String> getAllExifTags() {
890886
ExifInterface.TAG_NEW_SUBFILE_TYPE,
891887
ExifInterface.TAG_SUBFILE_TYPE);
892888
}
893-
894-
public ExifInterface getExifInterface() {
895-
return mExifInterface;
896-
}
897889
}
898890

0 commit comments

Comments
 (0)