Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
SkJpegMetadataDecoderImpl Class Reference

#include <SkJpegMetadataDecoderImpl.h>

Inheritance diagram for SkJpegMetadataDecoderImpl:
SkJpegMetadataDecoder

Public Member Functions

 SkJpegMetadataDecoderImpl (SkJpegMarkerList markerList)
 
 SkJpegMetadataDecoderImpl (sk_sp< SkData > data)
 
bool findGainmapImage (SkJpegSourceMgr *sourceMgr, sk_sp< SkData > &outGainmapImageData, SkGainmapInfo &outGainmapInfo) const
 
sk_sp< SkDatagetExifMetadata (bool copyData) const override
 
sk_sp< SkDatagetICCProfileData (bool copyData) const override
 
sk_sp< SkDatagetISOGainmapMetadata (bool copyData) const override
 
bool mightHaveGainmapImage () const override
 
bool findGainmapImage (sk_sp< SkData > baseImageData, sk_sp< SkData > &outGainmapImageData, SkGainmapInfo &outGainmapInfo) override
 
- Public Member Functions inherited from SkJpegMetadataDecoder
 SkJpegMetadataDecoder ()
 
virtual ~SkJpegMetadataDecoder ()
 
 SkJpegMetadataDecoder (const SkJpegMetadataDecoder &)=delete
 
SkJpegMetadataDecoderoperator= (const SkJpegMetadataDecoder &)=delete
 
virtual sk_sp< SkDatagetExifMetadata (bool copyData) const =0
 
virtual sk_sp< SkDatagetICCProfileData (bool copyData) const =0
 
virtual sk_sp< SkDatagetISOGainmapMetadata (bool copyData) const =0
 
virtual bool mightHaveGainmapImage () const =0
 
virtual bool findGainmapImage (sk_sp< SkData > baseImageData, sk_sp< SkData > &outGainmapImagedata, SkGainmapInfo &outGainmapInfo)=0
 

Additional Inherited Members

- Static Public Member Functions inherited from SkJpegMetadataDecoder
static std::unique_ptr< SkJpegMetadataDecoderMake (std::vector< Segment > headerSegments)
 

Detailed Description

Definition at line 27 of file SkJpegMetadataDecoderImpl.h.

Constructor & Destructor Documentation

◆ SkJpegMetadataDecoderImpl() [1/2]

SkJpegMetadataDecoderImpl::SkJpegMetadataDecoderImpl ( SkJpegMarkerList  markerList)

Definition at line 413 of file SkJpegMetadataDecoderImpl.cpp.

414 : fMarkerList(std::move(markerList)) {}

◆ SkJpegMetadataDecoderImpl() [2/2]

SkJpegMetadataDecoderImpl::SkJpegMetadataDecoderImpl ( sk_sp< SkData data)

Definition at line 416 of file SkJpegMetadataDecoderImpl.cpp.

416 {
417#ifdef SK_CODEC_DECODES_JPEG_GAINMAPS
419 scan.onBytes(data->data(), data->size());
420 if (scan.hadError() || !scan.isDone()) {
421 SkCodecPrintf("Failed to scan header of MP image.\n");
422 return;
423 }
424 for (const auto& segment : scan.getSegments()) {
425 // Save the APP1 and APP2 parameters (which includes Exif, XMP, ICC, and MPF).
426 if (segment.marker != kJpegMarkerAPP0 + 1 && segment.marker != kJpegMarkerAPP0 + 2) {
427 continue;
428 }
429 auto parameters = SkJpegSegmentScanner::GetParameters(data.get(), segment);
430 if (!parameters) {
431 continue;
432 }
433 fMarkerList.emplace_back(segment.marker, std::move(parameters));
434 }
435#endif
436}
#define SkCodecPrintf(...)
Definition: SkCodecPriv.h:23
static constexpr uint8_t kJpegMarkerStartOfScan
static constexpr uint8_t kJpegMarkerAPP0
static sk_sp< SkData > GetParameters(const SkData *scannedData, const SkJpegSegment &segment)
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

Member Function Documentation

◆ findGainmapImage() [1/2]

bool SkJpegMetadataDecoderImpl::findGainmapImage ( sk_sp< SkData baseImageData,
sk_sp< SkData > &  outGainmapImagedata,
SkGainmapInfo outGainmapInfo 
)
overridevirtual

Given a JPEG encoded image |baseImageData|, return in |outGainmapImageData| the JPEG encoded gainmap image and return in |outGainmapInfo| its gainmap rendering parameters. Return true if both output variables were successfully populated, otherwise return false.

Implements SkJpegMetadataDecoder.

Definition at line 477 of file SkJpegMetadataDecoderImpl.cpp.

479 {
480#ifdef SK_CODEC_DECODES_JPEG_GAINMAPS
481 auto baseImageStream = SkMemoryStream::Make(baseImageData);
482 auto sourceMgr = SkJpegSourceMgr::Make(baseImageStream.get());
483 return findGainmapImage(sourceMgr.get(), outGainmapImageData, outGainmapInfo);
484#else
485 return false;
486#endif
487}
bool findGainmapImage(SkJpegSourceMgr *sourceMgr, sk_sp< SkData > &outGainmapImageData, SkGainmapInfo &outGainmapInfo) const
static std::unique_ptr< SkJpegSourceMgr > Make(SkStream *stream, size_t bufferSize=1024)
static std::unique_ptr< SkMemoryStream > Make(sk_sp< SkData > data)
Definition: SkStream.cpp:314

◆ findGainmapImage() [2/2]

bool SkJpegMetadataDecoderImpl::findGainmapImage ( SkJpegSourceMgr sourceMgr,
sk_sp< SkData > &  outGainmapImageData,
SkGainmapInfo outGainmapInfo 
) const

Definition at line 170 of file SkJpegMetadataDecoderImpl.cpp.

172 {
173#ifdef SK_CODEC_DECODES_JPEG_GAINMAPS
174 SkExif::Metadata baseExif;
175 SkExif::Parse(baseExif, getExifMetadata(/*copyData=*/false).get());
176 auto xmp = getXmpMetadata();
177
178 // Determine if a support ISO 21496-1 gain map version is present in the base image.
179 bool isoGainmapPresent =
181
182 // Determine if Adobe HDR gain map is indicated in the base image.
183 bool adobeGainmapPresent = xmp && xmp->getGainmapInfoAdobe(nullptr);
184
185 // Attempt to locate the gainmap from the container XMP.
186 size_t containerGainmapOffset = 0;
187 size_t containerGainmapSize = 0;
188 if (xmp && xmp->getContainerGainmapLocation(&containerGainmapOffset, &containerGainmapSize)) {
189 const auto& segments = sourceMgr->getAllSegments();
190 if (!segments.empty()) {
191 const auto& lastSegment = segments.back();
192 if (lastSegment.marker == kJpegMarkerEndOfImage) {
193 containerGainmapOffset += lastSegment.offset + kJpegMarkerCodeSize;
194 }
195 }
196 }
197
198 // Attempt to find MultiPicture parameters.
199 SkJpegSegment mpParamsSegment;
200 auto mpParams = find_mp_params(fMarkerList, sourceMgr, &mpParamsSegment);
201
202 // First, search through the Multi-Picture images.
203 if (mpParams) {
204 for (size_t mpImageIndex = 1; mpImageIndex < mpParams->images.size(); ++mpImageIndex) {
206 mpParams->images[mpImageIndex].dataOffset, mpParamsSegment.offset);
207 size_t mpImageSize = mpParams->images[mpImageIndex].size;
208
209 if (extract_gainmap(sourceMgr,
210 mpImageOffset,
211 mpImageSize,
212 isoGainmapPresent,
213 adobeGainmapPresent,
214 baseExif.fHdrHeadroom,
215 outInfo,
216 outData)) {
217 // If the GContainer also suggested an offset and size, assert that we found the
218 // image that the GContainer suggested.
219 if (containerGainmapOffset) {
220 SkASSERT(containerGainmapOffset == mpImageOffset);
221 SkASSERT(containerGainmapSize == mpImageSize);
222 }
223 return true;
224 }
225 }
226 }
227
228 // Next, try the location suggested by the container XMP.
229 if (containerGainmapOffset) {
230 if (extract_gainmap(sourceMgr,
231 containerGainmapOffset,
232 containerGainmapSize,
233 /*baseImageHasIsoVersion=*/false,
234 adobeGainmapPresent,
235 /*baseImageAppleHdrHeadroom=*/std::nullopt,
236 outInfo,
237 outData)) {
238 return true;
239 }
240 SkCodecPrintf("Failed to extract container-specified gainmap.\n");
241 }
242#endif
243 return false;
244}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static constexpr uint8_t kJpegMarkerEndOfImage
static constexpr size_t kJpegMarkerCodeSize
sk_sp< SkData > getISOGainmapMetadata(bool copyData) const override
sk_sp< SkData > getExifMetadata(bool copyData) const override
void SK_API Parse(Metadata &metadata, const SkData *data)
Definition: SkExif.cpp:182
const myers::Point & get(const myers::Segment &)
std::optional< float > fHdrHeadroom
Definition: SkExif.h:35
static bool ParseVersion(const SkData *data)
static size_t GetImageAbsoluteOffset(uint32_t dataOffset, size_t mpSegmentOffset)

◆ getExifMetadata()

sk_sp< SkData > SkJpegMetadataDecoderImpl::getExifMetadata ( bool  copyData) const
overridevirtual

Return the Exif data attached to the image (if any) and nullptr otherwise. If |copyData| is false, then the returned SkData may directly reference the data provided when this object was created.

Implements SkJpegMetadataDecoder.

Definition at line 438 of file SkJpegMetadataDecoderImpl.cpp.

438 {
439 return read_metadata(fMarkerList,
441 kExifSig,
442 sizeof(kExifSig),
443 /*signaturePadding=*/1,
444 /*bytesInIndex=*/0,
445 copyData);
446}
static constexpr uint32_t kExifMarker
constexpr uint8_t kExifSig[]
static sk_sp< SkData > read_metadata(const SkJpegMarkerList &markerList, const uint32_t targetMarker, const uint8_t *signature, size_t signatureSize, size_t signaturePadding, size_t bytesInIndex, bool alwaysCopyData)

◆ getICCProfileData()

sk_sp< SkData > SkJpegMetadataDecoderImpl::getICCProfileData ( bool  copyData) const
overridevirtual

Return the ICC profile of the image if any, and nullptr otherwise. If |copyData| is false, then the returned SkData may directly reference the data provided when this object was created.

Implements SkJpegMetadataDecoder.

Definition at line 448 of file SkJpegMetadataDecoderImpl.cpp.

448 {
449 return read_metadata(fMarkerList,
451 kICCSig,
452 sizeof(kICCSig),
453 /*signaturePadding=*/0,
455 copyData);
456}
static constexpr uint8_t kICCSig[]
static constexpr uint32_t kICCMarker
static constexpr uint32_t kICCMarkerIndexSize

◆ getISOGainmapMetadata()

sk_sp< SkData > SkJpegMetadataDecoderImpl::getISOGainmapMetadata ( bool  copyData) const
overridevirtual

Return the ISO 21496-1 metadata, if any, and nullptr otherwise. If |copyData| is false, then the returned SkData may directly reference the data provided when this object was created.

Implements SkJpegMetadataDecoder.

Definition at line 458 of file SkJpegMetadataDecoderImpl.cpp.

458 {
459 return read_metadata(fMarkerList,
462 sizeof(kISOGainmapSig),
463 /*signaturePadding=*/0,
464 /*bytesInIndex=*/0,
465 copyData);
466}
static constexpr uint32_t kISOGainmapMarker
static constexpr uint8_t kISOGainmapSig[]

◆ mightHaveGainmapImage()

bool SkJpegMetadataDecoderImpl::mightHaveGainmapImage ( ) const
overridevirtual

Return true if there is a possibility that this image contains a gainmap image.

Implements SkJpegMetadataDecoder.

Definition at line 468 of file SkJpegMetadataDecoderImpl.cpp.

468 {
469#ifdef SK_CODEC_DECODES_JPEG_GAINMAPS
470 // All supported gainmap formats require MPF. Reject images that do not have MPF.
471 return find_mp_params(fMarkerList, nullptr, nullptr) != nullptr;
472#else
473 return false;
474#endif
475}

The documentation for this class was generated from the following files: