18872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolb/* 28872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolb * Copyright (C) 2010 The Android Open Source Project 38872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolb * 48872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolb * Licensed under the Apache License, Version 2.0 (the "License"); 58872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolb * you may not use this file except in compliance with the License. 68872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolb * You may obtain a copy of the License at 78872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolb * 88872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolb * http://www.apache.org/licenses/LICENSE-2.0 98872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolb * 108872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolb * Unless required by applicable law or agreed to in writing, software 118872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolb * distributed under the License is distributed on an "AS IS" BASIS, 128872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolb * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 138872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolb * See the License for the specific language governing permissions and 148872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolb * limitations under the License. 158872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolb */ 168872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolb 178872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolbpackage com.android.camera; 188872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolb 192bca210e5fc8a77685775ffb403096167b017dceAngus Kongimport com.android.camera.debug.Log; 20a16e7b50f3148f581439509279f242092e254309ztenghuiimport com.android.camera.exif.ExifInterface; 218872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolb 228872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolbimport java.io.IOException; 238872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolb 248872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolbpublic class Exif { 252bca210e5fc8a77685775ffb403096167b017dceAngus Kong private static final Log.Tag TAG = new Log.Tag("CameraExif"); 268872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolb 270d00a8907096b9970ac64f52abbd2bfc1ed751b6Angus Kong public static ExifInterface getExif(byte[] jpegData) { 2829fd4aa661f7e626a1d11558f09e8f7c011efcc2Ruben Brunk ExifInterface exif = new ExifInterface(); 298872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolb try { 300d00a8907096b9970ac64f52abbd2bfc1ed751b6Angus Kong exif.readExif(jpegData); 318872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolb } catch (IOException e) { 320d00a8907096b9970ac64f52abbd2bfc1ed751b6Angus Kong Log.w(TAG, "Failed to read EXIF data", e); 330d00a8907096b9970ac64f52abbd2bfc1ed751b6Angus Kong } 340d00a8907096b9970ac64f52abbd2bfc1ed751b6Angus Kong return exif; 350d00a8907096b9970ac64f52abbd2bfc1ed751b6Angus Kong } 360d00a8907096b9970ac64f52abbd2bfc1ed751b6Angus Kong 370d00a8907096b9970ac64f52abbd2bfc1ed751b6Angus Kong // Returns the degrees in clockwise. Values are 0, 90, 180, or 270. 380d00a8907096b9970ac64f52abbd2bfc1ed751b6Angus Kong public static int getOrientation(ExifInterface exif) { 390d00a8907096b9970ac64f52abbd2bfc1ed751b6Angus Kong Integer val = exif.getTagIntValue(ExifInterface.TAG_ORIENTATION); 400d00a8907096b9970ac64f52abbd2bfc1ed751b6Angus Kong if (val == null) { 418872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolb return 0; 420d00a8907096b9970ac64f52abbd2bfc1ed751b6Angus Kong } else { 430d00a8907096b9970ac64f52abbd2bfc1ed751b6Angus Kong return ExifInterface.getRotationForOrientationValue(val.shortValue()); 448872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolb } 458872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolb } 460d00a8907096b9970ac64f52abbd2bfc1ed751b6Angus Kong 470d00a8907096b9970ac64f52abbd2bfc1ed751b6Angus Kong public static int getOrientation(byte[] jpegData) { 480d00a8907096b9970ac64f52abbd2bfc1ed751b6Angus Kong if (jpegData == null) return 0; 490d00a8907096b9970ac64f52abbd2bfc1ed751b6Angus Kong 500d00a8907096b9970ac64f52abbd2bfc1ed751b6Angus Kong ExifInterface exif = getExif(jpegData); 510d00a8907096b9970ac64f52abbd2bfc1ed751b6Angus Kong return getOrientation(exif); 520d00a8907096b9970ac64f52abbd2bfc1ed751b6Angus Kong } 538872c23e739de38d74f04a8c852ebb5199c905f6Michael Kolb} 54