blob: 20621368558e153955385a2959b4f83031aeaf54 [file] [log] [blame]
Jaesung Chung29345532016-01-14 02:28:47 +09001// 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>
Eik Brauer8aac9372016-02-02 17:07:01 +010022#include <vector>
Jaesung Chung29345532016-01-14 02:28:47 +090023
24namespace piex {
25
26// Defines the error codes used by piex.
27enum Error {
28 kOk,
29 kFail,
30 kUnsupported,
31};
32
Eik Brauer883a1e52016-02-23 12:19:25 +010033// 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.
36struct Image {
37 enum Format {
38 kJpegCompressed,
Yujie Qin2f5d8ea2016-04-06 12:55:08 +020039 kUncompressedRgb,
Nick Chusid5c5b6712021-06-03 15:33:24 -040040 kHevcCompressed,
Eik Brauer883a1e52016-02-23 12:19:25 +010041 };
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
Yujie Qin3eaa8312016-01-15 16:22:20 +010054// 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.
Jaesung Chung29345532016-01-14 02:28:47 +090056// 'full_width' and 'full_height' are correctly cropped but not rotated.
57struct 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.
Eik Brauer883a1e52016-02-23 12:19:25 +010085 Image preview;
86 Image thumbnail;
87
Jaesung Chung29345532016-01-14 02:28:47 +090088 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;
Eik Brauerb415ce22016-02-01 12:26:23 +0100102
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.
Eik Brauer8aac9372016-02-02 17:07:01 +0100105 std::vector<std::uint32_t> cfa_pattern_dim = std::vector<std::uint32_t>(2, 0);
Jaesung Chung29345532016-01-14 02:28:47 +0900106};
107
108// Defines the StreamInterface that needs to be implemented by the client.
109class StreamInterface {
110 public:
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_