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