| 1 |
/* |
| 2 |
* Copyright 2024 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 SkJpegMetadataDecoderImpl_DEFINED |
| 9 |
#define SkJpegMetadataDecoderImpl_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkRefCnt.h" |
| 12 |
#include "include/private/SkGainmapInfo.h" |
| 13 |
#include "include/private/SkJpegMetadataDecoder.h" |
| 14 |
|
| 15 |
#include <vector> |
| 16 |
|
| 17 |
#ifdef SK_CODEC_DECODES_JPEG_GAINMAPS |
| 18 |
#include "include/private/SkXmp.h" |
| 19 |
#endif // SK_CODEC_DECODES_JPEG_GAINMAPS |
| 20 |
|
| 21 |
class SkData; |
| 22 |
class SkJpegSourceMgr; |
| 23 |
struct SkGainmapInfo; |
| 24 |
|
| 25 |
using SkJpegMarker = SkJpegMetadataDecoder::Segment; |
| 26 |
using SkJpegMarkerList = std::vector<SkJpegMarker>; |
| 27 |
|
| 28 |
class SkJpegMetadataDecoderImpl : public SkJpegMetadataDecoder { |
| 29 |
public: |
| 30 |
explicit SkJpegMetadataDecoderImpl(SkJpegMarkerList markerList); |
| 31 |
explicit SkJpegMetadataDecoderImpl(sk_sp<const SkData> data); |
| 32 |
|
| 33 |
std::pair<sk_sp<const SkData>, SkGainmapInfo> findGainmapImage( |
| 34 |
SkJpegSourceMgr* sourceMgr) const; |
| 35 |
|
| 36 |
#ifdef SK_CODEC_DECODES_JPEG_GAINMAPS |
| 37 |
std::unique_ptr<SkXmp> getXmpMetadata() const; |
| 38 |
#endif // SK_CODEC_DECODES_JPEG_GAINMAPS |
| 39 |
|
| 40 |
// SkJpegMetadataDecoder implementation: |
| 41 |
sk_sp<const SkData> getExifMetadata(bool copyData) const override; |
| 42 |
sk_sp<const SkData> getICCProfileData(bool copyData) const override; |
| 43 |
sk_sp<const SkData> getISOGainmapMetadata(bool copyData) const override; |
| 44 |
bool mightHaveGainmapImage() const override; |
| 45 |
std::pair<sk_sp<const SkData>, SkGainmapInfo> findGainmapImage( |
| 46 |
sk_sp<const SkData>) const override; |
| 47 |
sk_sp<const SkData> getJUMBFMetadata(bool copyData) const override; |
| 48 |
|
| 49 |
// TODO(kjlubick): delete after updating Chromium |
| 50 |
bool findGainmapImage(sk_sp<const SkData> baseImageData, |
| 51 |
sk_sp<SkData>& outGainmapImagedata, |
| 52 |
SkGainmapInfo& outGainmapInfo) override { |
| 53 |
auto [data, info] = this->findGainmapImage(baseImageData); |
| 54 |
if (data) { |
| 55 |
outGainmapImagedata = sk_sp<SkData>(const_cast<SkData*>(data.release())); |
| 56 |
outGainmapInfo = info; |
| 57 |
return true; |
| 58 |
} |
| 59 |
return false; |
| 60 |
} |
| 61 |
|
| 62 |
private: |
| 63 |
SkJpegMarkerList fMarkerList; |
| 64 |
}; |
| 65 |
|
| 66 |
#endif // SkJpegMetadataDecoderImpl_DEFINED |