• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 ////////////////////////////////////////////////////////////////////////////////
16 
17 #ifndef PIEX_PIEX_TYPES_H_
18 #define PIEX_PIEX_TYPES_H_
19 
20 #include <cstdint>
21 #include <string>
22 #include <vector>
23 
24 namespace piex {
25 
26 // Defines the error codes used by piex.
27 enum Error {
28   kOk,
29   kFail,
30   kUnsupported,
31 };
32 
33 // Defines the properties of an image. width and height are required for
34 // uncompressed images, but are optional for compressed images. An image is
35 // invalid when its length is 0.
36 struct Image {
37   enum Format {
38     kJpegCompressed,
39     kUncompressedRgb,
40     kHevcCompressed,
41   };
42 
43   std::uint16_t width = 0;
44   std::uint16_t height = 0;
45   std::uint32_t length = 0;
46   std::uint32_t offset = 0;
47   Format format = kJpegCompressed;
48 
49   bool operator>(const Image& rhs) const {
50     return width > rhs.width && height > rhs.height;
51   }
52 };
53 
54 // Contains relevant image information as well as the 'preview_offset' and the
55 // 'preview_length' which are used to obtain the JPEG compressed preview image.
56 // 'full_width' and 'full_height' are correctly cropped but not rotated.
57 struct PreviewImageData {
58   enum ColorSpace {
59     kSrgb,
60     kAdobeRgb,
61   };
62   struct Rational {
63     std::uint32_t numerator = 0;
64     std::uint32_t denominator = 1;
65   };
66   struct Gps {
67     // Indicates if the gps data is valid to use.
68     bool is_valid = false;
69 
70     char latitude_ref;  // Either 'N' or 'S'
71     Rational latitude[3];
72     char longitude_ref;  // Either 'E' or 'W'
73     Rational longitude[3];
74     bool altitude_ref = false;  // true is above, false below sea level
75     Rational altitude;
76 
77     Rational time_stamp[3];  // Giving hour, minute and second.
78     std::string date_stamp;  // Giving as "YYYY:MM:DD" format.
79   };
80 
81   // Optional data to find the preview and thumbnail image to handle them
82   // correctly. A thumbnail is typically 160x120 pixel small and usually
83   // has black borders at the top and bottom. If length is 0 the image could not
84   // be extracted.
85   Image preview;
86   Image thumbnail;
87 
88   std::uint32_t exif_orientation = 1;  // horizontal as default
89   ColorSpace color_space = kSrgb;
90 
91   // Optional Exif metadata that describes the image.
92   std::uint32_t full_width = 0;
93   std::uint32_t full_height = 0;
94   std::string maker;
95   std::string model;
96   std::string date_time;
97   std::uint32_t iso = 0;
98   Rational exposure_time;
99   Rational fnumber;
100   Rational focal_length;
101   Gps gps;
102 
103   // Hint for the mosaic pattern dimension of the RAW image data. (0, 0) implies
104   // that no mosaic info found. It is valid for DNG, NEF and NRW files.
105   std::vector<std::uint32_t> cfa_pattern_dim = std::vector<std::uint32_t>(2, 0);
106 };
107 
108 // Defines the StreamInterface that needs to be implemented by the client.
109 class StreamInterface {
110  public:
~StreamInterface()111   virtual ~StreamInterface() {}
112 
113   // Reads 'length' amount of bytes from 'offset' to 'data'. The 'data' buffer
114   // provided by the caller, guaranteed to be at least "length" bytes long.
115   // On 'kOk' the 'data' pointer contains 'length' valid bytes beginning at
116   // 'offset' bytes from the start of the stream.
117   // Returns 'kFail' if 'offset' + 'length' exceeds the stream and does not
118   // change the contents of 'data'.
119   virtual Error GetData(const size_t offset, const size_t length,
120                         std::uint8_t* data) = 0;
121 };
122 
123 }  // namespace piex
124 
125 #endif  // PIEX_PIEX_TYPES_H_
126