xref: /aosp_15_r20/external/skia/include/private/SkJpegMetadataDecoder.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2013 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 SkJpegMetadataDecoder_DEFINED
9 #define SkJpegMetadataDecoder_DEFINED
10 
11 #include "include/core/SkData.h"
12 #include "include/core/SkRefCnt.h"
13 #include "include/core/SkTypes.h"
14 
15 #include <memory>
16 #include <vector>
17 
18 struct SkGainmapInfo;
19 
20 /**
21  * An interface that can be used to extract metadata from an encoded JPEG file.
22  */
23 class SK_API SkJpegMetadataDecoder {
24 public:
SkJpegMetadataDecoder()25     SkJpegMetadataDecoder() {}
~SkJpegMetadataDecoder()26     virtual ~SkJpegMetadataDecoder() {}
27 
28     SkJpegMetadataDecoder(const SkJpegMetadataDecoder&) = delete;
29     SkJpegMetadataDecoder& operator=(const SkJpegMetadataDecoder&) = delete;
30 
31     /**
32      * A segment from a JPEG file. This is usually populated from a jpeg_marker_struct.
33      */
34     struct SK_API Segment {
SegmentSegment35         Segment(uint8_t marker, sk_sp<SkData> data) : fMarker(marker), fData(std::move(data)) {}
36 
37         // The segment's marker.
38         uint8_t fMarker = 0;
39 
40         // The segment's parameters (not including the marker and parameter length).
41         sk_sp<SkData> fData;
42     };
43 
44     /**
45      * Create metadata for the specified segments from a JPEG file's header (defined as all segments
46      * before the first StartOfScan). This may return nullptr.
47      */
48     static std::unique_ptr<SkJpegMetadataDecoder> Make(std::vector<Segment> headerSegments);
49 
50     /**
51      * Create metadata for the specified encoded JPEG file. This may return nullptr.
52      */
53     static std::unique_ptr<SkJpegMetadataDecoder> Make(sk_sp<SkData> data);
54 
55     /**
56      * Return the Exif data attached to the image (if any) and nullptr otherwise. If |copyData| is
57      * false, then the returned SkData may directly reference the data provided when this object was
58      * created.
59      */
60     virtual sk_sp<SkData> getExifMetadata(bool copyData) const = 0;
61 
62     /**
63      * Return the ICC profile of the image if any, and nullptr otherwise. If |copyData| is false,
64      * then the returned SkData may directly reference the data provided when this object was
65      * created.
66      */
67     virtual sk_sp<SkData> getICCProfileData(bool copyData) const = 0;
68 
69     /**
70      * Return the ISO 21496-1 metadata, if any, and nullptr otherwise. If |copyData| is false,
71      * then the returned SkData may directly reference the data provided when this object was
72      * created.
73      */
74     virtual sk_sp<SkData> getISOGainmapMetadata(bool copyData) const = 0;
75 
76     /**
77      * Return true if there is a possibility that this image contains a gainmap image.
78      */
79     virtual bool mightHaveGainmapImage() const = 0;
80 
81     /**
82      * Given a JPEG encoded image |baseImageData|, return in |outGainmapImageData| the JPEG encoded
83      * gainmap image and return in |outGainmapInfo| its gainmap rendering parameters. Return true if
84      * both output variables were successfully populated, otherwise return false.
85      */
86     virtual bool findGainmapImage(sk_sp<SkData> baseImageData,
87                                   sk_sp<SkData>& outGainmapImagedata,
88                                   SkGainmapInfo& outGainmapInfo) = 0;
89 };
90 
91 #endif
92