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

#include <SkRawCodec.h>

Inheritance diagram for SkRawCodec:
SkCodec SkNoncopyable

Public Member Functions

 ~SkRawCodec () override
 
- Public Member Functions inherited from SkCodec
virtual ~SkCodec ()
 
SkImageInfo getInfo () const
 
SkISize dimensions () const
 
SkIRect bounds () const
 
const skcms_ICCProfilegetICCProfile () const
 
SkEncodedOrigin getOrigin () const
 
SkISize getScaledDimensions (float desiredScale) const
 
bool getValidSubset (SkIRect *desiredSubset) const
 
SkEncodedImageFormat getEncodedFormat () const
 
virtual std::unique_ptr< SkStreamgetEncodedData () const
 
Result getPixels (const SkImageInfo &info, void *pixels, size_t rowBytes, const Options *)
 
Result getPixels (const SkImageInfo &info, void *pixels, size_t rowBytes)
 
Result getPixels (const SkPixmap &pm, const Options *opts=nullptr)
 
std::tuple< sk_sp< SkImage >, SkCodec::ResultgetImage (const SkImageInfo &info, const Options *opts=nullptr)
 
std::tuple< sk_sp< SkImage >, SkCodec::ResultgetImage ()
 
bool queryYUVAInfo (const SkYUVAPixmapInfo::SupportedDataTypes &supportedDataTypes, SkYUVAPixmapInfo *yuvaPixmapInfo) const
 
Result getYUVAPlanes (const SkYUVAPixmaps &yuvaPixmaps)
 
Result startIncrementalDecode (const SkImageInfo &dstInfo, void *dst, size_t rowBytes, const Options *)
 
Result startIncrementalDecode (const SkImageInfo &dstInfo, void *dst, size_t rowBytes)
 
Result incrementalDecode (int *rowsDecoded=nullptr)
 
Result startScanlineDecode (const SkImageInfo &dstInfo, const Options *options)
 
Result startScanlineDecode (const SkImageInfo &dstInfo)
 
int getScanlines (void *dst, int countLines, size_t rowBytes)
 
bool skipScanlines (int countLines)
 
SkScanlineOrder getScanlineOrder () const
 
int nextScanline () const
 
int outputScanline (int inputScanline) const
 
int getFrameCount ()
 
bool getFrameInfo (int index, FrameInfo *info) const
 
std::vector< FrameInfogetFrameInfo ()
 
int getRepetitionCount ()
 

Static Public Member Functions

static std::unique_ptr< SkCodecMakeFromStream (std::unique_ptr< SkStream >, Result *)
 
- Static Public Member Functions inherited from SkCodec
static constexpr size_t MinBufferedBytesNeeded ()
 
static const char * ResultToString (Result)
 
static std::unique_ptr< SkCodecMakeFromStream (std::unique_ptr< SkStream >, SkSpan< const SkCodecs::Decoder > decoders, Result *=nullptr, SkPngChunkReader *=nullptr, SelectionPolicy selectionPolicy=SelectionPolicy::kPreferStillImage)
 
static std::unique_ptr< SkCodecMakeFromStream (std::unique_ptr< SkStream >, Result *=nullptr, SkPngChunkReader *=nullptr, SelectionPolicy selectionPolicy=SelectionPolicy::kPreferStillImage)
 
static std::unique_ptr< SkCodecMakeFromData (sk_sp< SkData >, SkSpan< const SkCodecs::Decoder > decoders, SkPngChunkReader *=nullptr)
 
static std::unique_ptr< SkCodecMakeFromData (sk_sp< SkData >, SkPngChunkReader *=nullptr)
 
static void Register (bool(*peek)(const void *, size_t), std::unique_ptr< SkCodec >(*make)(std::unique_ptr< SkStream >, SkCodec::Result *))
 

Protected Member Functions

Result onGetPixels (const SkImageInfo &dstInfo, void *dst, size_t dstRowBytes, const Options &, int *) override
 
SkEncodedImageFormat onGetEncodedFormat () const override
 
SkISize onGetScaledDimensions (float desiredScale) const override
 
bool onDimensionsSupported (const SkISize &) override
 
bool usesColorXform () const override
 
- Protected Member Functions inherited from SkCodec
const SkEncodedInfogetEncodedInfo () const
 
 SkCodec (SkEncodedInfo &&, XformFormat srcFormat, std::unique_ptr< SkStream >, SkEncodedOrigin=kTopLeft_SkEncodedOrigin)
 
void setSrcXformFormat (XformFormat pixelFormat)
 
XformFormat getSrcXformFormat () const
 
virtual bool onGetGainmapInfo (SkGainmapInfo *, std::unique_ptr< SkStream > *)
 
virtual SkISize onGetScaledDimensions (float) const
 
virtual bool onDimensionsSupported (const SkISize &)
 
virtual SkEncodedImageFormat onGetEncodedFormat () const =0
 
virtual Result onGetPixels (const SkImageInfo &info, void *pixels, size_t rowBytes, const Options &, int *rowsDecoded)=0
 
virtual bool onQueryYUVAInfo (const SkYUVAPixmapInfo::SupportedDataTypes &, SkYUVAPixmapInfo *) const
 
virtual Result onGetYUVAPlanes (const SkYUVAPixmaps &)
 
virtual bool onGetValidSubset (SkIRect *) const
 
bool rewindIfNeeded ()
 
virtual bool onRewind ()
 
SkStreamstream ()
 
virtual SkScanlineOrder onGetScanlineOrder () const
 
const SkImageInfodstInfo () const
 
const Optionsoptions () const
 
int currScanline () const
 
virtual int onOutputScanline (int inputScanline) const
 
virtual bool conversionSupported (const SkImageInfo &dst, bool srcIsOpaque, bool needsColorXform)
 
virtual bool usesColorXform () const
 
void applyColorXform (void *dst, const void *src, int count) const
 
bool colorXform () const
 
bool xformOnDecode () const
 
virtual int onGetFrameCount ()
 
virtual bool onGetFrameInfo (int, FrameInfo *) const
 
virtual int onGetRepetitionCount ()
 

Additional Inherited Members

- Public Types inherited from SkCodec
enum  Result {
  kSuccess , kIncompleteInput , kErrorInInput , kInvalidConversion ,
  kInvalidScale , kInvalidParameters , kInvalidInput , kCouldNotRewind ,
  kInternalError , kUnimplemented
}
 
enum class  SelectionPolicy { kPreferStillImage , kPreferAnimation }
 
enum  ZeroInitialized { kYes_ZeroInitialized , kNo_ZeroInitialized }
 
enum  SkScanlineOrder { kTopDown_SkScanlineOrder , kBottomUp_SkScanlineOrder }
 
- Static Public Attributes inherited from SkCodec
static constexpr int kNoFrame = -1
 
static constexpr int kRepetitionCountInfinite = -1
 
- Protected Types inherited from SkCodec
using XformFormat = skcms_PixelFormat
 

Detailed Description

Definition at line 28 of file SkRawCodec.h.

Constructor & Destructor Documentation

◆ ~SkRawCodec()

SkRawCodec::~SkRawCodec ( )
override

Definition at line 824 of file SkRawCodec.cpp.

824{}

Member Function Documentation

◆ MakeFromStream()

std::unique_ptr< SkCodec > SkRawCodec::MakeFromStream ( std::unique_ptr< SkStream stream,
Result result 
)
static

Definition at line 649 of file SkRawCodec.cpp.

650 {
652 if (!stream) {
654 return nullptr;
655 }
656 std::unique_ptr<SkRawStream> rawStream;
657 if (is_asset_stream(*stream)) {
658 rawStream = std::make_unique<SkRawAssetStream>(std::move(stream));
659 } else {
660 rawStream = std::make_unique<SkRawBufferedStream>(std::move(stream));
661 }
662
663 // Does not take the ownership of rawStream.
664 SkPiexStream piexStream(rawStream.get());
665 ::piex::PreviewImageData imageData;
666 if (::piex::IsRaw(&piexStream)) {
667 ::piex::Error error = ::piex::GetPreviewImageData(&piexStream, &imageData);
670 return nullptr;
671 }
672
673 std::unique_ptr<SkEncodedInfo::ICCProfile> profile;
674 if (imageData.color_space == ::piex::PreviewImageData::kAdobeRgb) {
675 skcms_ICCProfile skcmsProfile;
676 skcms_Init(&skcmsProfile);
680 }
681
682 // Theoretically PIEX can return JPEG compressed image or uncompressed RGB image. We only
683 // handle the JPEG compressed preview image here.
684 if (error == ::piex::Error::kOk && imageData.preview.length > 0 &&
685 imageData.preview.format == ::piex::Image::kJpegCompressed)
686 {
687 // transferBuffer() is destructive to the rawStream. Abandon the rawStream after this
688 // function call.
689 // FIXME: one may avoid the copy of memoryStream and use the buffered rawStream.
690 auto memoryStream = rawStream->transferBuffer(imageData.preview.offset,
691 imageData.preview.length);
692 if (!memoryStream) {
694 return nullptr;
695 }
696 return SkJpegCodec::MakeFromStream(std::move(memoryStream), result,
697 std::move(profile));
698 }
699 }
700
701 if (!SkDngImage::IsTiffHeaderValid(rawStream.get())) {
703 return nullptr;
704 }
705
706 // Takes the ownership of the rawStream.
707 std::unique_ptr<SkDngImage> dngImage(SkDngImage::NewFromStream(rawStream.release()));
708 if (!dngImage) {
710 return nullptr;
711 }
712
713 *result = kSuccess;
714 return std::unique_ptr<SkCodec>(new SkRawCodec(dngImage.release()));
715}
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkStream * stream()
Definition: SkCodec.h:865
@ kInvalidInput
Definition: SkCodec.h:109
@ kUnimplemented
Definition: SkCodec.h:123
@ kSuccess
Definition: SkCodec.h:80
static bool IsTiffHeaderValid(SkRawStream *stream)
Definition: SkRawCodec.cpp:553
static SkDngImage * NewFromStream(SkRawStream *stream)
Definition: SkRawCodec.cpp:464
static std::unique_ptr< ICCProfile > Make(sk_sp< SkData >)
static std::unique_ptr< SkCodec > MakeFromStream(std::unique_ptr< SkStream >, Result *)
const uint8_t uint32_t uint32_t GError ** error
GAsyncResult * result
static constexpr skcms_Matrix3x3 kAdobeRGB
Definition: SkColorSpace.h:77
static constexpr skcms_TransferFunction k2Dot2
Definition: SkColorSpace.h:48
bool IsRaw(const void *, size_t)
Definition: SkRawDecoder.h:21
static void skcms_SetXYZD50(skcms_ICCProfile *p, const skcms_Matrix3x3 *m)
Definition: skcms_public.h:399
static void skcms_SetTransferFunction(skcms_ICCProfile *p, const skcms_TransferFunction *tf)
Definition: skcms_public.h:390
static void skcms_Init(skcms_ICCProfile *p)
Definition: skcms_public.h:384

◆ onDimensionsSupported()

bool SkRawCodec::onDimensionsSupported ( const SkISize )
overrideprotectedvirtual

Subclasses should override if they support dimensions other than the srcInfo's.

Reimplemented from SkCodec.

Definition at line 814 of file SkRawCodec.cpp.

814 {
815 const SkISize fullDim = this->dimensions();
816 const float fullShortEdge = static_cast<float>(std::min(fullDim.fWidth, fullDim.fHeight));
817 const float shortEdge = static_cast<float>(std::min(dim.fWidth, dim.fHeight));
818
819 SkISize sizeFloor = this->onGetScaledDimensions(1.f / std::floor(fullShortEdge / shortEdge));
820 SkISize sizeCeil = this->onGetScaledDimensions(1.f / std::ceil(fullShortEdge / shortEdge));
821 return sizeFloor == dim || sizeCeil == dim;
822}
SkISize dimensions() const
Definition: SkCodec.h:230
SkISize onGetScaledDimensions(float desiredScale) const override
Definition: SkRawCodec.cpp:786
static float min(float r, float g, float b)
Definition: hsl.cpp:48
SIN Vec< N, float > floor(const Vec< N, float > &x)
Definition: SkVx.h:703
SIN Vec< N, float > ceil(const Vec< N, float > &x)
Definition: SkVx.h:702
Definition: SkSize.h:16
int32_t fHeight
Definition: SkSize.h:18
int32_t fWidth
Definition: SkSize.h:17

◆ onGetEncodedFormat()

SkEncodedImageFormat SkRawCodec::onGetEncodedFormat ( ) const
inlineoverrideprotectedvirtual

Implements SkCodec.

Definition at line 44 of file SkRawCodec.h.

◆ onGetPixels()

SkCodec::Result SkRawCodec::onGetPixels ( const SkImageInfo info,
void *  pixels,
size_t  rowBytes,
const Options ,
int rowsDecoded 
)
overrideprotectedvirtual
Parameters
rowsDecodedWhen the encoded image stream is incomplete, this function will return kIncompleteInput and rowsDecoded will be set to the number of scanlines that were successfully decoded. This will allow getPixels() to fill the uninitialized memory.

Implements SkCodec.

Definition at line 717 of file SkRawCodec.cpp.

719 {
720 const int width = dstInfo.width();
721 const int height = dstInfo.height();
722 std::unique_ptr<dng_image> image(fDngImage->render(width, height));
723 if (!image) {
724 return kInvalidInput;
725 }
726
727 // Because the DNG SDK can not guarantee to render to requested size, we allow a small
728 // difference. Only the overlapping region will be converted.
729 const float maxDiffRatio = 1.03f;
730 const dng_point& imageSize = image->Size();
731 if (imageSize.h / (float) width > maxDiffRatio || imageSize.h < width ||
732 imageSize.v / (float) height > maxDiffRatio || imageSize.v < height) {
734 }
735
736 void* dstRow = dst;
737 AutoTMalloc<uint8_t> srcRow(width * 3);
738
739 dng_pixel_buffer buffer;
740 buffer.fData = &srcRow[0];
741 buffer.fPlane = 0;
742 buffer.fPlanes = 3;
743 buffer.fColStep = buffer.fPlanes;
744 buffer.fPlaneStep = 1;
745 buffer.fPixelType = ttByte;
746 buffer.fPixelSize = sizeof(uint8_t);
747 buffer.fRowStep = width * 3;
748
749 constexpr auto srcFormat = skcms_PixelFormat_RGB_888;
750 skcms_PixelFormat dstFormat;
751 if (!sk_select_xform_format(dstInfo.colorType(), false, &dstFormat)) {
752 return kInvalidConversion;
753 }
754
755 const skcms_ICCProfile* const srcProfile = this->getEncodedInfo().profile();
756 skcms_ICCProfile dstProfileStorage;
757 const skcms_ICCProfile* dstProfile = nullptr;
758 if (auto cs = dstInfo.colorSpace()) {
759 cs->toProfile(&dstProfileStorage);
760 dstProfile = &dstProfileStorage;
761 }
762
763 for (int i = 0; i < height; ++i) {
764 buffer.fArea = dng_rect(i, 0, i + 1, width);
765
766 try {
767 image->Get(buffer, dng_image::edge_zero);
768 } catch (...) {
769 *rowsDecoded = i;
770 return kIncompleteInput;
771 }
772
773 if (!skcms_Transform(&srcRow[0], srcFormat, skcms_AlphaFormat_Unpremul, srcProfile,
774 dstRow, dstFormat, skcms_AlphaFormat_Unpremul, dstProfile,
775 dstInfo.width())) {
776 SkDebugf("failed to transform\n");
777 *rowsDecoded = i;
778 return kInternalError;
779 }
780
781 dstRow = SkTAddOffset<void>(dstRow, dstRowBytes);
782 }
783 return kSuccess;
784}
bool sk_select_xform_format(SkColorType colorType, bool forColorTable, skcms_PixelFormat *outFormat)
Definition: SkCodec.cpp:767
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
const SkImageInfo & dstInfo() const
Definition: SkCodec.h:878
const SkEncodedInfo & getEncodedInfo() const
Definition: SkCodec.h:788
@ kInvalidConversion
Definition: SkCodec.h:96
@ kInvalidScale
Definition: SkCodec.h:100
@ kIncompleteInput
Definition: SkCodec.h:84
@ kInternalError
Definition: SkCodec.h:118
sk_sp< const SkImage > image
Definition: SkRecords.h:269
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
dst
Definition: cp.py:12
int32_t height
int32_t width
bool skcms_Transform(const void *src, skcms_PixelFormat srcFmt, skcms_AlphaFormat srcAlpha, const skcms_ICCProfile *srcProfile, void *dst, skcms_PixelFormat dstFmt, skcms_AlphaFormat dstAlpha, const skcms_ICCProfile *dstProfile, size_t nz)
Definition: skcms.cc:2495
skcms_PixelFormat
Definition: skcms_public.h:273
@ skcms_PixelFormat_RGB_888
Definition: skcms_public.h:285
@ skcms_AlphaFormat_Unpremul
Definition: skcms_public.h:339
const skcms_ICCProfile * profile() const
SkColorSpace * colorSpace() const
int width() const
Definition: SkImageInfo.h:365
SkColorType colorType() const
Definition: SkImageInfo.h:373
int height() const
Definition: SkImageInfo.h:371

◆ onGetScaledDimensions()

SkISize SkRawCodec::onGetScaledDimensions ( float  desiredScale) const
overrideprotectedvirtual

Reimplemented from SkCodec.

Definition at line 786 of file SkRawCodec.cpp.

786 {
787 SkASSERT(desiredScale <= 1.f);
788
789 const SkISize dim = this->dimensions();
790 SkASSERT(dim.fWidth != 0 && dim.fHeight != 0);
791
792 if (!fDngImage->isScalable()) {
793 return dim;
794 }
795
796 // Limits the minimum size to be 80 on the short edge.
797 const float shortEdge = static_cast<float>(std::min(dim.fWidth, dim.fHeight));
798 if (desiredScale < 80.f / shortEdge) {
799 desiredScale = 80.f / shortEdge;
800 }
801
802 // For Xtrans images, the integer-factor scaling does not support the half-size scaling case
803 // (stronger downscalings are fine). In this case, returns the factor "3" scaling instead.
804 if (fDngImage->isXtransImage() && desiredScale > 1.f / 3.f && desiredScale < 1.f) {
805 desiredScale = 1.f / 3.f;
806 }
807
808 // Round to integer-factors.
809 const float finalScale = std::floor(1.f/ desiredScale);
810 return SkISize::Make(static_cast<int32_t>(std::floor(dim.fWidth / finalScale)),
811 static_cast<int32_t>(std::floor(dim.fHeight / finalScale)));
812}
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ usesColorXform()

bool SkRawCodec::usesColorXform ( ) const
inlineoverrideprotectedvirtual

Reimplemented from SkCodec.

Definition at line 54 of file SkRawCodec.h.

54{ return false; }

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