Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
SkJpegGainmapEncoder Class Reference

#include <SkJpegGainmapEncoder.h>

Static Public Member Functions

static bool EncodeHDRGM (SkWStream *dst, const SkPixmap &base, const SkJpegEncoder::Options &baseOptions, const SkPixmap &gainmap, const SkJpegEncoder::Options &gainmapOptions, const SkGainmapInfo &gainmapInfo)
 
static bool MakeMPF (SkWStream *dst, const SkData **images, size_t imageCount)
 

Detailed Description

Definition at line 17 of file SkJpegGainmapEncoder.h.

Member Function Documentation

◆ EncodeHDRGM()

bool SkJpegGainmapEncoder::EncodeHDRGM ( SkWStream dst,
const SkPixmap base,
const SkJpegEncoder::Options baseOptions,
const SkPixmap gainmap,
const SkJpegEncoder::Options gainmapOptions,
const SkGainmapInfo gainmapInfo 
)
static

Encode an UltraHDR image to |dst|.

The base image is specified by |base|, and |baseOptions| controls the encoding behavior for the base image.

The gainmap image is specified by |gainmap|, and |gainmapOptions| controls the encoding behavior for the gainmap image.

The rendering behavior of the gainmap image is provided in |gainmapInfo|.

If |baseOptions| or |gainmapOptions| specify XMP metadata, then that metadata will be overwritten.

Returns true on success. Returns false on an invalid or unsupported |src|.

Definition at line 247 of file SkJpegGainmapEncoder.cpp.

252 {
253 // Encode the gainmap image with the HDRGM XMP metadata.
254 sk_sp<SkData> gainmapData;
255 {
256 // We will include the HDRGM XMP metadata in the gainmap image.
257 auto hdrgmXmp = get_hdrgm_xmp_data(gainmapInfo);
258 gainmapData = encode_to_data(gainmap, gainmapOptions, hdrgmXmp.get());
259 if (!gainmapData) {
260 SkCodecPrintf("Failed to encode gainmap image.\n");
261 return false;
262 }
263 }
264
265 // Encode the base image with the Container XMP metadata.
266 sk_sp<SkData> baseData;
267 {
268 auto containerXmp = get_gcontainer_xmp_data(static_cast<int32_t>(gainmapData->size()));
269 baseData = encode_to_data(base, baseOptions, containerXmp.get());
270 if (!baseData) {
271 SkCodecPrintf("Failed to encode base image.\n");
272 return false;
273 }
274 }
275
276 // Combine them into an MPF.
277 const SkData* images[] = {
278 baseData.get(),
279 gainmapData.get(),
280 };
281 return MakeMPF(dst, images, 2);
282}
#define SkCodecPrintf(...)
Definition SkCodecPriv.h:23
static sk_sp< SkData > get_gcontainer_xmp_data(size_t gainmapItemLength)
static sk_sp< SkData > encode_to_data(const SkPixmap &pm, const SkJpegEncoder::Options &options, SkData *xmpMetadata)
sk_sp< SkData > get_hdrgm_xmp_data(const SkGainmapInfo &gainmapInfo)
static bool MakeMPF(SkWStream *dst, const SkData **images, size_t imageCount)
T * get() const
Definition SkRefCnt.h:303
std::array< MockImage, 3 > images

◆ MakeMPF()

bool SkJpegGainmapEncoder::MakeMPF ( SkWStream dst,
const SkData **  images,
size_t  imageCount 
)
static

Write a Multi Picture Format containing the |imageCount| images specified by |images|.

Definition at line 284 of file SkJpegGainmapEncoder.cpp.

284 {
285 if (imageCount < 1) {
286 return true;
287 }
288
289 // Create a scan of the primary image.
290 SkJpegSegmentScanner primaryScan;
291 primaryScan.onBytes(images[0]->data(), images[0]->size());
292 if (!primaryScan.isDone()) {
293 SkCodecPrintf("Failed to scan encoded primary image header.\n");
294 return false;
295 }
296
297 // Copy the primary image up to its StartOfScan, then insert the MPF segment, then copy the rest
298 // of the primary image, and all other images.
299 size_t bytesRead = 0;
300 size_t bytesWritten = 0;
301 for (const auto& segment : primaryScan.getSegments()) {
302 // Write all ECD before this segment.
303 {
304 size_t ecdBytesToWrite = segment.offset - bytesRead;
305 if (!dst->write(images[0]->bytes() + bytesRead, ecdBytesToWrite)) {
306 SkCodecPrintf("Failed to write entropy coded data.\n");
307 return false;
308 }
309 bytesWritten += ecdBytesToWrite;
310 bytesRead = segment.offset;
311 }
312
313 // If this isn't a StartOfScan, write just the segment.
314 if (segment.marker != kJpegMarkerStartOfScan) {
315 const size_t bytesToWrite = kJpegMarkerCodeSize + segment.parameterLength;
316 if (!dst->write(images[0]->bytes() + bytesRead, bytesToWrite)) {
317 SkCodecPrintf("Failed to copy segment.\n");
318 return false;
319 }
320 bytesWritten += bytesToWrite;
321 bytesRead += bytesToWrite;
322 continue;
323 }
324
325 // We're now at the StartOfScan.
326 const size_t bytesRemaining = images[0]->size() - bytesRead;
327
328 // Compute the MPF offsets for the images.
330 {
331 mpParams.images.resize(imageCount);
332 const size_t mpSegmentSize = kJpegMarkerCodeSize + kJpegSegmentParameterLengthSize +
333 mpParams.serialize()->size();
334 mpParams.images[0].size =
335 static_cast<uint32_t>(bytesWritten + mpSegmentSize + bytesRemaining);
336 uint32_t offset =
337 static_cast<uint32_t>(bytesRemaining + mpSegmentSize - kJpegMarkerCodeSize -
339 for (size_t i = 1; i < imageCount; ++i) {
340 mpParams.images[i].dataOffset = offset;
341 mpParams.images[i].size = static_cast<uint32_t>(images[i]->size());
342 offset += mpParams.images[i].size;
343 }
344 }
345
346 // Write the MPF segment.
347 auto mpfSegment = get_mpf_segment(mpParams);
348 if (!dst->write(mpfSegment->data(), mpfSegment->size())) {
349 SkCodecPrintf("Failed to write MPF segment.\n");
350 return false;
351 }
352
353 // Write the rest of the primary file.
354 if (!dst->write(images[0]->bytes() + bytesRead, bytesRemaining)) {
355 SkCodecPrintf("Failed to write remainder of primary image.\n");
356 return false;
357 }
358 bytesRead += bytesRemaining;
359 SkASSERT(bytesRead == images[0]->size());
360 break;
361 }
362
363 // Write the remaining files.
364 for (size_t i = 1; i < imageCount; ++i) {
365 if (!dst->write(images[i]->data(), images[i]->size())) {
366 SkCodecPrintf("Failed to write auxiliary image.\n");
367 }
368 }
369 return true;
370}
#define SkASSERT(cond)
Definition SkAssert.h:116
static constexpr uint8_t kMpfSig[]
static constexpr uint8_t kJpegMarkerStartOfScan
static constexpr size_t kJpegSegmentParameterLengthSize
static constexpr size_t kJpegMarkerCodeSize
static sk_sp< SkData > get_mpf_segment(const SkJpegMultiPictureParameters &mpParams)
size_t size() const
Definition SkData.h:30
void onBytes(const void *data, size_t size)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259
dst
Definition cp.py:12
Point offset
sk_sp< SkData > serialize() const

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