Home | History | Annotate | Download | only in include
      1 /*
      2  * Copyright (C) 2018 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 #ifndef ANDROID_HARDWARE_INTERFACES_CAMERA_COMMON_1_0_EXIF_H
     18 #define ANDROID_HARDWARE_INTERFACES_CAMERA_COMMON_1_0_EXIF_H
     19 
     20 #include "CameraMetadata.h"
     21 
     22 namespace android {
     23 namespace hardware {
     24 namespace camera {
     25 namespace common {
     26 namespace V1_0 {
     27 namespace helper {
     28 
     29 
     30 // This is based on the original ChromeOS ARC implementation of a V4L2 HAL
     31 
     32 // ExifUtils can generate APP1 segment with tags which caller set. ExifUtils can
     33 // also add a thumbnail in the APP1 segment if thumbnail size is specified.
     34 // ExifUtils can be reused with different images by calling initialize().
     35 //
     36 // Example of using this class :
     37 //  std::unique_ptr<ExifUtils> utils(ExifUtils::Create());
     38 //  utils->initialize();
     39 //  ...
     40 //  // Call ExifUtils functions to set Exif tags.
     41 //  ...
     42 //  utils->GenerateApp1(thumbnail_buffer, thumbnail_size);
     43 //  unsigned int app1Length = utils->GetApp1Length();
     44 //  uint8_t* app1Buffer = new uint8_t[app1Length];
     45 //  memcpy(app1Buffer, utils->GetApp1Buffer(), app1Length);
     46 class ExifUtils {
     47 
     48  public:
     49     virtual ~ExifUtils();
     50 
     51     static ExifUtils* create();
     52 
     53     // Initialize() can be called multiple times. The setting of Exif tags will be
     54     // cleared.
     55     virtual bool initialize() = 0;
     56 
     57     // Set all known fields from a metadata structure
     58     virtual bool setFromMetadata(const CameraMetadata& metadata,
     59                                  const size_t imageWidth,
     60                                  const size_t imageHeight) = 0;
     61 
     62     // Sets the len aperture.
     63     // Returns false if memory allocation fails.
     64     virtual bool setAperture(uint32_t numerator, uint32_t denominator) = 0;
     65 
     66     // Sets the value of brightness.
     67     // Returns false if memory allocation fails.
     68     virtual bool setBrightness(int32_t numerator, int32_t denominator) = 0;
     69 
     70     // Sets the color space.
     71     // Returns false if memory allocation fails.
     72     virtual bool setColorSpace(uint16_t color_space) = 0;
     73 
     74     // Sets the information to compressed data.
     75     // Returns false if memory allocation fails.
     76     virtual bool setComponentsConfiguration(const std::string& components_configuration) = 0;
     77 
     78     // Sets the compression scheme used for the image data.
     79     // Returns false if memory allocation fails.
     80     virtual bool setCompression(uint16_t compression) = 0;
     81 
     82     // Sets image contrast.
     83     // Returns false if memory allocation fails.
     84     virtual bool setContrast(uint16_t contrast) = 0;
     85 
     86     // Sets the date and time of image last modified. It takes local time. The
     87     // name of the tag is DateTime in IFD0.
     88     // Returns false if memory allocation fails.
     89     virtual bool setDateTime(const struct tm& t) = 0;
     90 
     91     // Sets the image description.
     92     // Returns false if memory allocation fails.
     93     virtual bool setDescription(const std::string& description) = 0;
     94 
     95     // Sets the digital zoom ratio. If the numerator is 0, it means digital zoom
     96     // was not used.
     97     // Returns false if memory allocation fails.
     98     virtual bool setDigitalZoomRatio(uint32_t numerator, uint32_t denominator) = 0;
     99 
    100     // Sets the exposure bias.
    101     // Returns false if memory allocation fails.
    102     virtual bool setExposureBias(int32_t numerator, int32_t denominator) = 0;
    103 
    104     // Sets the exposure mode set when the image was shot.
    105     // Returns false if memory allocation fails.
    106     virtual bool setExposureMode(uint16_t exposure_mode) = 0;
    107 
    108     // Sets the program used by the camera to set exposure when the picture is
    109     // taken.
    110     // Returns false if memory allocation fails.
    111     virtual bool setExposureProgram(uint16_t exposure_program) = 0;
    112 
    113     // Sets the exposure time, given in seconds.
    114     // Returns false if memory allocation fails.
    115     virtual bool setExposureTime(uint32_t numerator, uint32_t denominator) = 0;
    116 
    117     // Sets the status of flash.
    118     // Returns false if memory allocation fails.
    119     virtual bool setFlash(uint16_t flash) = 0;
    120 
    121     // Sets the F number.
    122     // Returns false if memory allocation fails.
    123     virtual bool setFNumber(uint32_t numerator, uint32_t denominator) = 0;
    124 
    125     // Sets the focal length of lens used to take the image in millimeters.
    126     // Returns false if memory allocation fails.
    127     virtual bool setFocalLength(uint32_t numerator, uint32_t denominator) = 0;
    128 
    129     // Sets the degree of overall image gain adjustment.
    130     // Returns false if memory allocation fails.
    131     virtual bool setGainControl(uint16_t gain_control) = 0;
    132 
    133     // Sets the altitude in meters.
    134     // Returns false if memory allocation fails.
    135     virtual bool setGpsAltitude(double altitude) = 0;
    136 
    137     // Sets the latitude with degrees minutes seconds format.
    138     // Returns false if memory allocation fails.
    139     virtual bool setGpsLatitude(double latitude) = 0;
    140 
    141     // Sets the longitude with degrees minutes seconds format.
    142     // Returns false if memory allocation fails.
    143     virtual bool setGpsLongitude(double longitude) = 0;
    144 
    145     // Sets GPS processing method.
    146     // Returns false if memory allocation fails.
    147     virtual bool setGpsProcessingMethod(const std::string& method) = 0;
    148 
    149     // Sets GPS date stamp and time stamp (atomic clock). It takes UTC time.
    150     // Returns false if memory allocation fails.
    151     virtual bool setGpsTimestamp(const struct tm& t) = 0;
    152 
    153     // Sets the height (number of rows) of main image.
    154     // Returns false if memory allocation fails.
    155     virtual bool setImageHeight(uint32_t length) = 0;
    156 
    157     // Sets the width (number of columns) of main image.
    158     // Returns false if memory allocation fails.
    159     virtual bool setImageWidth(uint32_t width) = 0;
    160 
    161     // Sets the ISO speed.
    162     // Returns false if memory allocation fails.
    163     virtual bool setIsoSpeedRating(uint16_t iso_speed_ratings) = 0;
    164 
    165     // Sets the kind of light source.
    166     // Returns false if memory allocation fails.
    167     virtual bool setLightSource(uint16_t light_source) = 0;
    168 
    169     // Sets the smallest F number of the lens.
    170     // Returns false if memory allocation fails.
    171     virtual bool setMaxAperture(uint32_t numerator, uint32_t denominator) = 0;
    172 
    173     // Sets the metering mode.
    174     // Returns false if memory allocation fails.
    175     virtual bool setMeteringMode(uint16_t metering_mode) = 0;
    176 
    177     // Sets image orientation.
    178     // Returns false if memory allocation fails.
    179     virtual bool setOrientation(uint16_t orientation) = 0;
    180 
    181     // Sets the unit for measuring XResolution and YResolution.
    182     // Returns false if memory allocation fails.
    183     virtual bool setResolutionUnit(uint16_t resolution_unit) = 0;
    184 
    185     // Sets image saturation.
    186     // Returns false if memory allocation fails.
    187     virtual bool setSaturation(uint16_t saturation) = 0;
    188 
    189     // Sets the type of scene that was shot.
    190     // Returns false if memory allocation fails.
    191     virtual bool setSceneCaptureType(uint16_t type) = 0;
    192 
    193     // Sets image sharpness.
    194     // Returns false if memory allocation fails.
    195     virtual bool setSharpness(uint16_t sharpness) = 0;
    196 
    197     // Sets the shutter speed.
    198     // Returns false if memory allocation fails.
    199     virtual bool setShutterSpeed(int32_t numerator, int32_t denominator) = 0;
    200 
    201     // Sets the distance to the subject, given in meters.
    202     // Returns false if memory allocation fails.
    203     virtual bool setSubjectDistance(uint32_t numerator, uint32_t denominator) = 0;
    204 
    205     // Sets the fractions of seconds for the <DateTime> tag.
    206     // Returns false if memory allocation fails.
    207     virtual bool setSubsecTime(const std::string& subsec_time) = 0;
    208 
    209     // Sets the white balance mode set when the image was shot.
    210     // Returns false if memory allocation fails.
    211     virtual bool setWhiteBalance(uint16_t white_balance) = 0;
    212 
    213     // Sets the number of pixels per resolution unit in the image width.
    214     // Returns false if memory allocation fails.
    215     virtual bool setXResolution(uint32_t numerator, uint32_t denominator) = 0;
    216 
    217     // Sets the position of chrominance components in relation to the luminance
    218     // component.
    219     // Returns false if memory allocation fails.
    220     virtual bool setYCbCrPositioning(uint16_t ycbcr_positioning) = 0;
    221 
    222     // Sets the number of pixels per resolution unit in the image length.
    223     // Returns false if memory allocation fails.
    224     virtual bool setYResolution(uint32_t numerator, uint32_t denominator) = 0;
    225 
    226     // Sets the manufacturer of camera.
    227     // Returns false if memory allocation fails.
    228     virtual bool setMake(const std::string& make) = 0;
    229 
    230     // Sets the model number of camera.
    231     // Returns false if memory allocation fails.
    232     virtual bool setModel(const std::string& model) = 0;
    233 
    234     // Generates APP1 segment.
    235     // Returns false if generating APP1 segment fails.
    236     virtual bool generateApp1(const void* thumbnail_buffer, uint32_t size) = 0;
    237 
    238     // Gets buffer of APP1 segment. This method must be called only after calling
    239     // GenerateAPP1().
    240     virtual const uint8_t* getApp1Buffer() = 0;
    241 
    242     // Gets length of APP1 segment. This method must be called only after calling
    243     // GenerateAPP1().
    244     virtual unsigned int getApp1Length() = 0;
    245 };
    246 
    247 
    248 } // namespace helper
    249 } // namespace V1_0
    250 } // namespace common
    251 } // namespace camera
    252 } // namespace hardware
    253 } // namespace android
    254 
    255 
    256 #endif  // ANDROID_HARDWARE_INTERFACES_CAMERA_COMMON_1_0_EXIF_H
    257