Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.camera; |
| 18 | |
Angus Kong | 2bca210 | 2014-03-11 16:27:30 -0700 | [diff] [blame] | 19 | import com.android.camera.debug.Log; |
ztenghui | a16e7b5 | 2013-08-23 11:47:56 -0700 | [diff] [blame] | 20 | import com.android.camera.exif.ExifInterface; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 21 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 22 | import java.io.IOException; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 23 | |
| 24 | public class Exif { |
Angus Kong | 2bca210 | 2014-03-11 16:27:30 -0700 | [diff] [blame] | 25 | private static final Log.Tag TAG = new Log.Tag("CameraExif"); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 26 | |
Angus Kong | 0d00a89 | 2013-03-26 11:40:40 -0700 | [diff] [blame] | 27 | public static ExifInterface getExif(byte[] jpegData) { |
Ruben Brunk | 29fd4aa | 2013-03-11 19:00:12 -0700 | [diff] [blame] | 28 | ExifInterface exif = new ExifInterface(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 29 | try { |
Angus Kong | 0d00a89 | 2013-03-26 11:40:40 -0700 | [diff] [blame] | 30 | exif.readExif(jpegData); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 31 | } catch (IOException e) { |
Angus Kong | 0d00a89 | 2013-03-26 11:40:40 -0700 | [diff] [blame] | 32 | Log.w(TAG, "Failed to read EXIF data", e); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 33 | } |
Angus Kong | 0d00a89 | 2013-03-26 11:40:40 -0700 | [diff] [blame] | 34 | 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 Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 52 | } |
| 53 | } |