xref: /aosp_15_r20/external/skia/include/private/SkExif.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1*c8dee2aaSAndroid Build Coastguard Worker /*
2*c8dee2aaSAndroid Build Coastguard Worker  * Copyright 2023 Google Inc.
3*c8dee2aaSAndroid Build Coastguard Worker  *
4*c8dee2aaSAndroid Build Coastguard Worker  * Use of this source code is governed by a BSD-style license that can be
5*c8dee2aaSAndroid Build Coastguard Worker  * found in the LICENSE file.
6*c8dee2aaSAndroid Build Coastguard Worker  */
7*c8dee2aaSAndroid Build Coastguard Worker 
8*c8dee2aaSAndroid Build Coastguard Worker #ifndef SkExif_DEFINED
9*c8dee2aaSAndroid Build Coastguard Worker #define SkExif_DEFINED
10*c8dee2aaSAndroid Build Coastguard Worker 
11*c8dee2aaSAndroid Build Coastguard Worker #include "include/codec/SkEncodedOrigin.h"
12*c8dee2aaSAndroid Build Coastguard Worker #include "include/core/SkRefCnt.h"
13*c8dee2aaSAndroid Build Coastguard Worker #include "include/private/base/SkAPI.h"
14*c8dee2aaSAndroid Build Coastguard Worker 
15*c8dee2aaSAndroid Build Coastguard Worker #include <cstdint>
16*c8dee2aaSAndroid Build Coastguard Worker #include <optional>
17*c8dee2aaSAndroid Build Coastguard Worker 
18*c8dee2aaSAndroid Build Coastguard Worker class SkData;
19*c8dee2aaSAndroid Build Coastguard Worker 
20*c8dee2aaSAndroid Build Coastguard Worker namespace SkExif {
21*c8dee2aaSAndroid Build Coastguard Worker 
22*c8dee2aaSAndroid Build Coastguard Worker // Tag values that are parsed by Parse and stored in Metadata.
23*c8dee2aaSAndroid Build Coastguard Worker static constexpr uint16_t kOriginTag = 0x112;
24*c8dee2aaSAndroid Build Coastguard Worker static constexpr uint16_t kResolutionUnitTag = 0x0128;
25*c8dee2aaSAndroid Build Coastguard Worker static constexpr uint16_t kXResolutionTag = 0x011a;
26*c8dee2aaSAndroid Build Coastguard Worker static constexpr uint16_t kYResolutionTag = 0x011b;
27*c8dee2aaSAndroid Build Coastguard Worker static constexpr uint16_t kPixelXDimensionTag = 0xa002;
28*c8dee2aaSAndroid Build Coastguard Worker static constexpr uint16_t kPixelYDimensionTag = 0xa003;
29*c8dee2aaSAndroid Build Coastguard Worker 
30*c8dee2aaSAndroid Build Coastguard Worker struct Metadata {
31*c8dee2aaSAndroid Build Coastguard Worker     // The image orientation.
32*c8dee2aaSAndroid Build Coastguard Worker     std::optional<SkEncodedOrigin> fOrigin;
33*c8dee2aaSAndroid Build Coastguard Worker 
34*c8dee2aaSAndroid Build Coastguard Worker     // The HDR headroom property.
35*c8dee2aaSAndroid Build Coastguard Worker     // https://developer.apple.com/documentation/appkit/images_and_pdf/applying_apple_hdr_effect_to_your_photos
36*c8dee2aaSAndroid Build Coastguard Worker     std::optional<float> fHdrHeadroom;
37*c8dee2aaSAndroid Build Coastguard Worker 
38*c8dee2aaSAndroid Build Coastguard Worker     // Resolution.
39*c8dee2aaSAndroid Build Coastguard Worker     std::optional<uint16_t> fResolutionUnit;
40*c8dee2aaSAndroid Build Coastguard Worker     std::optional<float> fXResolution;
41*c8dee2aaSAndroid Build Coastguard Worker     std::optional<float> fYResolution;
42*c8dee2aaSAndroid Build Coastguard Worker 
43*c8dee2aaSAndroid Build Coastguard Worker     // Size in pixels.
44*c8dee2aaSAndroid Build Coastguard Worker     std::optional<uint32_t> fPixelXDimension;
45*c8dee2aaSAndroid Build Coastguard Worker     std::optional<uint32_t> fPixelYDimension;
46*c8dee2aaSAndroid Build Coastguard Worker };
47*c8dee2aaSAndroid Build Coastguard Worker 
48*c8dee2aaSAndroid Build Coastguard Worker /*
49*c8dee2aaSAndroid Build Coastguard Worker  * Parse the metadata specified in |data| and write them to |metadata|. Stop only at an
50*c8dee2aaSAndroid Build Coastguard Worker  * unrecoverable error (allow truncated input).
51*c8dee2aaSAndroid Build Coastguard Worker  */
52*c8dee2aaSAndroid Build Coastguard Worker void SK_API Parse(Metadata& metadata, const SkData* data);
53*c8dee2aaSAndroid Build Coastguard Worker 
54*c8dee2aaSAndroid Build Coastguard Worker /*
55*c8dee2aaSAndroid Build Coastguard Worker  * Write exif data that includes the values in |metadata| and returns it as SkData
56*c8dee2aaSAndroid Build Coastguard Worker  * untruncated. Return nullptr if a write to the data stream fails or if
57*c8dee2aaSAndroid Build Coastguard Worker  * |metadata.fHdrHeadroom| has value.
58*c8dee2aaSAndroid Build Coastguard Worker  * This function cannot write an IFD entry based on the HdrHeadroom value because
59*c8dee2aaSAndroid Build Coastguard Worker  * the information of maker33 and maker48 are lost in decoding.
60*c8dee2aaSAndroid Build Coastguard Worker  * For metadata that belongs in a subIFD the function will write it to one and
61*c8dee2aaSAndroid Build Coastguard Worker  * store it after the root IFD.
62*c8dee2aaSAndroid Build Coastguard Worker  * Data that does not fit within kSizeEntry, is appended to the end of the data,
63*c8dee2aaSAndroid Build Coastguard Worker  * after the subIFD if it exists.
64*c8dee2aaSAndroid Build Coastguard Worker  */
65*c8dee2aaSAndroid Build Coastguard Worker sk_sp<SkData> WriteExif(Metadata& metadata);
66*c8dee2aaSAndroid Build Coastguard Worker 
67*c8dee2aaSAndroid Build Coastguard Worker }  // namespace SkExif
68*c8dee2aaSAndroid Build Coastguard Worker 
69*c8dee2aaSAndroid Build Coastguard Worker #endif
70