• 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   };
41 
42   std::uint16_t width = 0;
43   std::uint16_t height = 0;
44   std::uint32_t length = 0;
45   std::uint32_t offset = 0;
46   Format format = kJpegCompressed;
47 
48   bool operator>(const Image& rhs) const {
49     return width > rhs.width && height > rhs.height;
50   }
51 };
52 
53 // Contains relevant image information as well as the 'preview_offset' and the
54 // 'preview_length' which are used to obtain the JPEG compressed preview image.
55 // 'full_width' and 'full_height' are correctly cropped but not rotated.
56 struct PreviewImageData {
57   enum ColorSpace {
58     kSrgb,
59     kAdobeRgb,
60   };
61   struct Rational {
62     std::uint32_t numerator = 0;
63     std::uint32_t denominator = 1;
64   };
65   struct Gps {
66     // Indicates if the gps data is valid to use.
67     bool is_valid = false;
68 
69     char latitude_ref;  // Either 'N' or 'S'
70     Rational latitude[3];
71     char longitude_ref;  // Either 'E' or 'W'
72     Rational longitude[3];
73     bool altitude_ref = false;  // true is above, false below sea level
74     Rational altitude;
75 
76     Rational time_stamp[3];  // Giving hour, minute and second.
77     std::string date_stamp;  // Giving as "YYYY:MM:DD" format.
78   };
79 
80   // Optional data to find the preview and thumbnail image to handle them
81   // correctly. A thumbnail is typically 160x120 pixel small and usually
82   // has black borders at the top and bottom. If length is 0 the image could not
83   // be extracted.
84   Image preview;
85   Image thumbnail;
86 
87   std::uint32_t exif_orientation = 1;  // horizontal as default
88   ColorSpace color_space = kSrgb;
89 
90   // Optional Exif metadata that describes the image.
91   std::uint32_t full_width = 0;
92   std::uint32_t full_height = 0;
93   std::string maker;
94   std::string model;
95   std::string date_time;
96   std::uint32_t iso = 0;
97   Rational exposure_time;
98   Rational fnumber;
99   Rational focal_length;
100   Gps gps;
101 
102   // Hint for the mosaic pattern dimension of the RAW image data. (0, 0) implies
103   // that no mosaic info found. It is valid for DNG, NEF and NRW files.
104   std::vector<std::uint32_t> cfa_pattern_dim = std::vector<std::uint32_t>(2, 0);
105 };
106 
107 // Defines the StreamInterface that needs to be implemented by the client.
108 class StreamInterface {
109  public:
~StreamInterface()110   virtual ~StreamInterface() {}
111 
112   // Reads 'length' amount of bytes from 'offset' to 'data'. The 'data' buffer
113   // provided by the caller, guaranteed to be at least "length" bytes long.
114   // On 'kOk' the 'data' pointer contains 'length' valid bytes beginning at
115   // 'offset' bytes from the start of the stream.
116   // Returns 'kFail' if 'offset' + 'length' exceeds the stream and does not
117   // change the contents of 'data'.
118   virtual Error GetData(const size_t offset, const size_t length,
119                         std::uint8_t* data) = 0;
120 };
121 
122 }  // namespace piex
123 
124 #endif  // PIEX_PIEX_TYPES_H_
125