Home | History | Annotate | Download | only in camera
      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 
     19 import com.android.camera.debug.Log;
     20 import com.android.camera.exif.ExifInterface;
     21 
     22 import java.io.IOException;
     23 
     24 public class Exif {
     25     private static final Log.Tag TAG = new Log.Tag("CameraExif");
     26 
     27     public static ExifInterface getExif(byte[] jpegData) {
     28         ExifInterface exif = new ExifInterface();
     29         try {
     30             exif.readExif(jpegData);
     31         } catch (IOException e) {
     32             Log.w(TAG, "Failed to read EXIF data", e);
     33         }
     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);
     52     }
     53 }
     54