| 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: |
| 25 |
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 { |
| 35 |
Segment(uint8_t marker, sk_sp<const SkData> data) |
| 36 |
: fMarker(marker), fData(std::move(data)) {} |
| 37 |
|
| 38 |
// The segment's marker. |
| 39 |
uint8_t fMarker = 0; |
| 40 |
|
| 41 |
// The segment's parameters (not including the marker and parameter length). |
| 42 |
sk_sp<const SkData> fData; |
| 43 |
}; |
| 44 |
|
| 45 |
/** |
| 46 |
* Create metadata for the specified segments from a JPEG file's header (defined as all segments |
| 47 |
* before the first StartOfScan). This may return nullptr. |
| 48 |
*/ |
| 49 |
static std::unique_ptr<SkJpegMetadataDecoder> Make(std::vector<Segment> headerSegments); |
| 50 |
|
| 51 |
/** |
| 52 |
* Create metadata for the specified encoded JPEG file. This may return nullptr. |
| 53 |
*/ |
| 54 |
static std::unique_ptr<SkJpegMetadataDecoder> Make(sk_sp<const SkData> data); |
| 55 |
|
| 56 |
/** |
| 57 |
* Return the Exif data attached to the image (if any) and nullptr otherwise. If |copyData| is |
| 58 |
* false, then the returned SkData may directly reference the data provided when this object was |
| 59 |
* created. |
| 60 |
*/ |
| 61 |
virtual sk_sp<const SkData> getExifMetadata(bool copyData) const = 0; |
| 62 |
|
| 63 |
/** |
| 64 |
* Return the ICC profile of the image if any, and nullptr otherwise. If |copyData| is false, |
| 65 |
* then the returned SkData may directly reference the data provided when this object was |
| 66 |
* created. |
| 67 |
*/ |
| 68 |
virtual sk_sp<const SkData> getICCProfileData(bool copyData) const = 0; |
| 69 |
|
| 70 |
/** |
| 71 |
* Return the ISO 21496-1 metadata, if any, and nullptr otherwise. If |copyData| is false, |
| 72 |
* then the returned SkData may directly reference the data provided when this object was |
| 73 |
* created. |
| 74 |
*/ |
| 75 |
virtual sk_sp<const SkData> getISOGainmapMetadata(bool copyData) const = 0; |
| 76 |
|
| 77 |
/** |
| 78 |
* Return true if there is a possibility that this image contains a gainmap image. |
| 79 |
*/ |
| 80 |
virtual bool mightHaveGainmapImage() const = 0; |
| 81 |
|
| 82 |
/** |
| 83 |
* Given a JPEG encoded image |baseImageData|, return in |outGainmapImageData| the JPEG encoded |
| 84 |
* gainmap image and return in |outGainmapInfo| its gainmap rendering parameters. Return true if |
| 85 |
* both output variables were successfully populated, otherwise return false. |
| 86 |
*/ |
| 87 |
virtual std::pair<sk_sp<const SkData>, SkGainmapInfo> findGainmapImage( |
| 88 |
sk_sp<const SkData>) const = 0; |
| 89 |
|
| 90 |
// deprecated |
| 91 |
virtual bool findGainmapImage(sk_sp<const SkData> baseImageData, |
| 92 |
sk_sp<SkData>& outGainmapImagedata, |
| 93 |
SkGainmapInfo& outGainmapInfo) = 0; |
| 94 |
|
| 95 |
/** |
| 96 |
* Return the first JUMBF superbox, if any, and nullptr otherwise. If |copyData| is false, |
| 97 |
* then the returned SkData may directly reference the data provided when this object was |
| 98 |
* created. |
| 99 |
*/ |
| 100 |
virtual sk_sp<const SkData> getJUMBFMetadata(bool copyData) const = 0; |
| 101 |
}; |
| 102 |
|
| 103 |
#endif |