• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SkJpegXmp_codec_DEFINED
9 #define SkJpegXmp_codec_DEFINED
10 
11 #include "include/core/SkRefCnt.h"
12 #include "src/xml/SkDOM.h"
13 
14 class SkData;
15 struct SkGainmapInfo;
16 
17 #include <memory>
18 #include <vector>
19 
20 /*
21  * A structure to manage JPEG XMP metadata.
22  */
23 class SkJpegXmp {
24 public:
25     // Find and parse all XMP metadata, given a list of all APP1 segment parameters.
26     static std::unique_ptr<SkJpegXmp> Make(const std::vector<sk_sp<SkData>>& decoderApp1Params);
27 
28     // Extract HDRGM gainmap parameters.
29     bool getGainmapInfoHDRGM(SkGainmapInfo* info) const;
30 
31     // Extract HDRGainMap gainmap parameters.
32     bool getGainmapInfoHDRGainMap(SkGainmapInfo* info) const;
33 
34     // If this includes GContainer metadata and the GContainer contains an item with semantic
35     // GainMap and Mime of image/jpeg, then return true, and populate |offset| and |size| with
36     // that item's offset (from the end of the primary JPEG image's EndOfImage), and the size of
37     // the gainmap.
38     bool getContainerGainmapLocation(size_t* offset, size_t* size) const;
39 
40 private:
41     SkJpegXmp();
42 
43     // Find an XMP node that assigns namespaces to the specified URIs. The XMP that this will search
44     // for is as follows. URIi is the input parameters in |uris|, and NAMESPACEi is the output
45     // written to |outNamespaces|. The output NAMESPACEi strings will always start with the prefix
46     // "xmlns:".
47     //
48     //   <x:xmpmeta ...>
49     //     <rdf:RDF ...>
50     //       <rdf:Description NAMESPACE0="URI0" NAMESPACE1="URI1" .../>
51     //     </rdf:RDF>
52     //   </x:xmpmeta>
53     //
54     // This function will sequentially search the standard XMP, followed by the extended XMP (which
55     // is not correct behavior -- it should merge the two XMP trees and search the merged tree).
56     bool findUriNamespaces(size_t count,
57                            const char* uris[],
58                            const char* outNamespaces[],
59                            const SkDOM** outDom,
60                            const SkDOM::Node** outNode) const;
61 
62     // The DOM for the standard XMP.
63     SkDOM fStandardDOM;
64 
65     // The DOM for the extended XMP. This may be invalid if there is no extended XMP, or the
66     // extended XMP failed to parse.
67     SkDOM fExtendedDOM;
68 };
69 
70 #endif
71