xref: /aosp_15_r20/external/skia/include/private/SkXmp.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 SkXmp_DEFINED
9*c8dee2aaSAndroid Build Coastguard Worker #define SkXmp_DEFINED
10*c8dee2aaSAndroid Build Coastguard Worker 
11*c8dee2aaSAndroid Build Coastguard Worker #include "include/core/SkRefCnt.h"
12*c8dee2aaSAndroid Build Coastguard Worker #include "include/private/base/SkAPI.h"
13*c8dee2aaSAndroid Build Coastguard Worker 
14*c8dee2aaSAndroid Build Coastguard Worker class SkData;
15*c8dee2aaSAndroid Build Coastguard Worker struct SkGainmapInfo;
16*c8dee2aaSAndroid Build Coastguard Worker 
17*c8dee2aaSAndroid Build Coastguard Worker #include <cstddef>
18*c8dee2aaSAndroid Build Coastguard Worker #include <memory>
19*c8dee2aaSAndroid Build Coastguard Worker 
20*c8dee2aaSAndroid Build Coastguard Worker /*
21*c8dee2aaSAndroid Build Coastguard Worker  * An interface to extract information from XMP metadata.
22*c8dee2aaSAndroid Build Coastguard Worker  */
23*c8dee2aaSAndroid Build Coastguard Worker class SK_API SkXmp {
24*c8dee2aaSAndroid Build Coastguard Worker public:
25*c8dee2aaSAndroid Build Coastguard Worker     SkXmp() = default;
26*c8dee2aaSAndroid Build Coastguard Worker     virtual ~SkXmp() = default;
27*c8dee2aaSAndroid Build Coastguard Worker     // Make noncopyable
28*c8dee2aaSAndroid Build Coastguard Worker     SkXmp(const SkXmp&) = delete;
29*c8dee2aaSAndroid Build Coastguard Worker     SkXmp& operator= (const SkXmp&) = delete;
30*c8dee2aaSAndroid Build Coastguard Worker 
31*c8dee2aaSAndroid Build Coastguard Worker     // Create from XMP data.
32*c8dee2aaSAndroid Build Coastguard Worker     static std::unique_ptr<SkXmp> Make(sk_sp<SkData> xmpData);
33*c8dee2aaSAndroid Build Coastguard Worker     // Create from standard XMP + extended XMP data, see XMP Specification Part 3: Storage in files,
34*c8dee2aaSAndroid Build Coastguard Worker     // Section 1.1.3.1: Extended XMP in JPEG
35*c8dee2aaSAndroid Build Coastguard Worker     static std::unique_ptr<SkXmp> Make(sk_sp<SkData> xmpStandard, sk_sp<SkData> xmpExtended);
36*c8dee2aaSAndroid Build Coastguard Worker 
37*c8dee2aaSAndroid Build Coastguard Worker     // Extract HDRGM gainmap parameters.
38*c8dee2aaSAndroid Build Coastguard Worker     // TODO(b/338342146): Remove this once all callers are removed.
getGainmapInfoHDRGM(SkGainmapInfo * info)39*c8dee2aaSAndroid Build Coastguard Worker     bool getGainmapInfoHDRGM(SkGainmapInfo* info) const { return getGainmapInfoAdobe(info); }
40*c8dee2aaSAndroid Build Coastguard Worker 
41*c8dee2aaSAndroid Build Coastguard Worker     // Extract gainmap parameters from http://ns.adobe.com/hdr-gain-map/1.0/.
42*c8dee2aaSAndroid Build Coastguard Worker     virtual bool getGainmapInfoAdobe(SkGainmapInfo* info) const = 0;
43*c8dee2aaSAndroid Build Coastguard Worker 
44*c8dee2aaSAndroid Build Coastguard Worker     // If the image specifies http://ns.apple.com/pixeldatainfo/1.0/ AuxiliaryImageType of
45*c8dee2aaSAndroid Build Coastguard Worker     // urn:com:apple:photo:2020:aux:hdrgainmap, and includes a http://ns.apple.com/HDRGainMap/1.0/
46*c8dee2aaSAndroid Build Coastguard Worker     // HDRGainMapVersion, then populate |info| with gainmap parameters that will approximate the
47*c8dee2aaSAndroid Build Coastguard Worker     // math specified at [0] and return true.
48*c8dee2aaSAndroid Build Coastguard Worker     // [0] https://developer.apple.com/documentation/appkit/images_and_pdf/
49*c8dee2aaSAndroid Build Coastguard Worker     //     applying_apple_hdr_effect_to_your_photos
50*c8dee2aaSAndroid Build Coastguard Worker     virtual bool getGainmapInfoApple(float exifHdrHeadroom, SkGainmapInfo* info) const = 0;
51*c8dee2aaSAndroid Build Coastguard Worker 
52*c8dee2aaSAndroid Build Coastguard Worker     // If this includes GContainer metadata and the GContainer contains an item with semantic
53*c8dee2aaSAndroid Build Coastguard Worker     // GainMap and Mime of image/jpeg, then return true, and populate |offset| and |size| with
54*c8dee2aaSAndroid Build Coastguard Worker     // that item's offset (from the end of the primary JPEG image's EndOfImage), and the size of
55*c8dee2aaSAndroid Build Coastguard Worker     // the gainmap.
56*c8dee2aaSAndroid Build Coastguard Worker     virtual bool getContainerGainmapLocation(size_t* offset, size_t* size) const = 0;
57*c8dee2aaSAndroid Build Coastguard Worker 
58*c8dee2aaSAndroid Build Coastguard Worker     // Return the GUID of an Extended XMP if present, or null otherwise.
59*c8dee2aaSAndroid Build Coastguard Worker     virtual const char* getExtendedXmpGuid() const = 0;
60*c8dee2aaSAndroid Build Coastguard Worker };
61*c8dee2aaSAndroid Build Coastguard Worker 
62*c8dee2aaSAndroid Build Coastguard Worker #endif
63