blob: fba1d0f0d3a1c9b25485a9bd3e19dac745fcc6b4 [file] [log] [blame]
Michael Kolb8872c232013-01-29 10:33:22 -08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.camera;
18
Angus Kong2bca2102014-03-11 16:27:30 -070019import com.android.camera.debug.Log;
ztenghuia16e7b52013-08-23 11:47:56 -070020import com.android.camera.exif.ExifInterface;
Michael Kolb8872c232013-01-29 10:33:22 -080021
Michael Kolb8872c232013-01-29 10:33:22 -080022import java.io.IOException;
Michael Kolb8872c232013-01-29 10:33:22 -080023
24public class Exif {
Angus Kong2bca2102014-03-11 16:27:30 -070025 private static final Log.Tag TAG = new Log.Tag("CameraExif");
Michael Kolb8872c232013-01-29 10:33:22 -080026
Angus Kong0d00a892013-03-26 11:40:40 -070027 public static ExifInterface getExif(byte[] jpegData) {
Ruben Brunk29fd4aa2013-03-11 19:00:12 -070028 ExifInterface exif = new ExifInterface();
Michael Kolb8872c232013-01-29 10:33:22 -080029 try {
Angus Kong0d00a892013-03-26 11:40:40 -070030 exif.readExif(jpegData);
Michael Kolb8872c232013-01-29 10:33:22 -080031 } catch (IOException e) {
Angus Kong0d00a892013-03-26 11:40:40 -070032 Log.w(TAG, "Failed to read EXIF data", e);
Michael Kolb8872c232013-01-29 10:33:22 -080033 }
Angus Kong0d00a892013-03-26 11:40:40 -070034 return exif;
35 }
36
37 // Returns the degrees in clockwise. Values are 0, 90, 180, or 270.
38 public static int getOrientation(ExifInterface exif) {
39 Integer val = exif.getTagIntValue(ExifInterface.TAG_ORIENTATION);
40 if (val == null) {
41 return 0;
42 } else {
43 return ExifInterface.getRotationForOrientationValue(val.shortValue());
44 }
45 }
46
47 public static int getOrientation(byte[] jpegData) {
48 if (jpegData == null) return 0;
49
50 ExifInterface exif = getExif(jpegData);
51 return getOrientation(exif);
Michael Kolb8872c232013-01-29 10:33:22 -080052 }
53}