Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
SkJpegEncoderImpl Class Reference

#include <SkJpegEncoderImpl.h>

Inheritance diagram for SkJpegEncoderImpl:
SkEncoder SkNoncopyable

Public Member Functions

 ~SkJpegEncoderImpl () override
 
- Public Member Functions inherited from SkEncoder
bool encodeRows (int numRows)
 
virtual ~SkEncoder ()
 

Static Public Member Functions

static std::unique_ptr< SkEncoderMakeRGB (SkWStream *dst, const SkPixmap &src, const SkJpegEncoder::Options &options, const SkJpegMetadataEncoder::SegmentList &metadata)
 
static std::unique_ptr< SkEncoderMakeYUV (SkWStream *dst, const SkYUVAPixmaps &srcYUVA, const SkColorSpace *srcYUVAColorSpace, const SkJpegEncoder::Options &options, const SkJpegMetadataEncoder::SegmentList &metadata)
 

Protected Member Functions

bool onEncodeRows (int numRows) override
 
- Protected Member Functions inherited from SkEncoder
virtual bool onEncodeRows (int numRows)=0
 
 SkEncoder (const SkPixmap &src, size_t storageBytes)
 

Additional Inherited Members

- Protected Attributes inherited from SkEncoder
const SkPixmapfSrc
 
int fCurrRow
 
skia_private::AutoTMalloc< uint8_t > fStorage
 

Detailed Description

Definition at line 57 of file SkJpegEncoderImpl.h.

Constructor & Destructor Documentation

◆ ~SkJpegEncoderImpl()

SkJpegEncoderImpl::~SkJpegEncoderImpl ( )
override

Definition at line 336 of file SkJpegEncoderImpl.cpp.

336{}

Member Function Documentation

◆ MakeRGB()

std::unique_ptr< SkEncoder > SkJpegEncoderImpl::MakeRGB ( SkWStream dst,
const SkPixmap src,
const SkJpegEncoder::Options options,
const SkJpegMetadataEncoder::SegmentList metadata 
)
static

Definition at line 304 of file SkJpegEncoderImpl.cpp.

308 {
309 if (!SkPixmapIsValid(src)) {
310 return nullptr;
311 }
312 std::unique_ptr<SkJpegEncoderMgr> encoderMgr = SkJpegEncoderMgr::Make(dst);
313 skjpeg_error_mgr::AutoPushJmpBuf jmp(encoderMgr->errorMgr());
314 if (setjmp(jmp)) {
315 return nullptr;
316 }
317
318 if (!encoderMgr->initializeRGB(src.info(), options, metadataSegments)) {
319 return nullptr;
320 }
321 return std::unique_ptr<SkJpegEncoderImpl>(new SkJpegEncoderImpl(std::move(encoderMgr), src));
322}
const char * options
static bool SkPixmapIsValid(const SkPixmap &src)
static std::unique_ptr< SkJpegEncoderMgr > Make(SkWStream *stream)
dst
Definition: cp.py:12

◆ MakeYUV()

std::unique_ptr< SkEncoder > SkJpegEncoderImpl::MakeYUV ( SkWStream dst,
const SkYUVAPixmaps srcYUVA,
const SkColorSpace srcYUVAColorSpace,
const SkJpegEncoder::Options options,
const SkJpegMetadataEncoder::SegmentList metadata 
)
static

Definition at line 282 of file SkJpegEncoderImpl.cpp.

287 {
288 if (!srcYUVA.isValid()) {
289 return nullptr;
290 }
291 std::unique_ptr<SkJpegEncoderMgr> encoderMgr = SkJpegEncoderMgr::Make(dst);
292 skjpeg_error_mgr::AutoPushJmpBuf jmp(encoderMgr->errorMgr());
293 if (setjmp(jmp)) {
294 return nullptr;
295 }
296
297 if (!encoderMgr->initializeYUV(srcYUVA.pixmapsInfo(), options, metadataSegments)) {
298 return nullptr;
299 }
300 return std::unique_ptr<SkJpegEncoderImpl>(
301 new SkJpegEncoderImpl(std::move(encoderMgr), srcYUVA));
302}
SkYUVAPixmapInfo pixmapsInfo() const
bool isValid() const

◆ onEncodeRows()

bool SkJpegEncoderImpl::onEncodeRows ( int  numRows)
overrideprotectedvirtual

Implements SkEncoder.

Definition at line 338 of file SkJpegEncoderImpl.cpp.

338 {
339 skjpeg_error_mgr::AutoPushJmpBuf jmp(fEncoderMgr->errorMgr());
340 if (setjmp(jmp)) {
341 return false;
342 }
343
344 if (fSrcYUVA) {
345 // TODO(ccameron): Consider using jpeg_write_raw_data, to avoid having to re-pack the data.
346 for (int i = 0; i < numRows; i++) {
347 yuva_copy_row(*fSrcYUVA, fCurrRow + i, fStorage.get());
348 JSAMPLE* jpegSrcRow = fStorage.get();
349 jpeg_write_scanlines(fEncoderMgr->cinfo(), &jpegSrcRow, 1);
350 }
351 } else {
352 const size_t srcBytes = SkColorTypeBytesPerPixel(fSrc.colorType()) * fSrc.width();
353 const size_t jpegSrcBytes = fEncoderMgr->cinfo()->input_components * fSrc.width();
354 const void* srcRow = fSrc.addr(0, fCurrRow);
355 for (int i = 0; i < numRows; i++) {
356 JSAMPLE* jpegSrcRow = (JSAMPLE*)(const_cast<void*>(srcRow));
357 if (fEncoderMgr->proc()) {
358 sk_msan_assert_initialized(srcRow, SkTAddOffset<const void>(srcRow, srcBytes));
359 fEncoderMgr->proc()((char*)fStorage.get(),
360 (const char*)srcRow,
361 fSrc.width(),
362 fEncoderMgr->cinfo()->input_components);
363 jpegSrcRow = fStorage.get();
365 SkTAddOffset<const void>(jpegSrcRow, jpegSrcBytes));
366 } else {
367 // Same as above, but this repetition allows determining whether a
368 // proc was used when msan asserts.
370 SkTAddOffset<const void>(jpegSrcRow, jpegSrcBytes));
371 }
372
373 jpeg_write_scanlines(fEncoderMgr->cinfo(), &jpegSrcRow, 1);
374 srcRow = SkTAddOffset<const void>(srcRow, fSrc.rowBytes());
375 }
376 }
377
378 fCurrRow += numRows;
379 if (fCurrRow == fSrc.height()) {
380 jpeg_finish_compress(fEncoderMgr->cinfo());
381 }
382
383 return true;
384}
SK_API int SkColorTypeBytesPerPixel(SkColorType ct)
Definition: SkImageInfo.cpp:16
static void yuva_copy_row(const SkYUVAPixmaps &src, int row, uint8_t *dst)
static void sk_msan_assert_initialized(const void *begin, const void *end)
Definition: SkMSAN.h:24
skia_private::AutoTMalloc< uint8_t > fStorage
Definition: SkEncoder.h:60
int fCurrRow
Definition: SkEncoder.h:59
const SkPixmap & fSrc
Definition: SkEncoder.h:58
size_t rowBytes() const
Definition: SkPixmap.h:145
int width() const
Definition: SkPixmap.h:160
SkColorType colorType() const
Definition: SkPixmap.h:173
const void * addr() const
Definition: SkPixmap.h:153
int height() const
Definition: SkPixmap.h:166

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