Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
android::skia::BitmapRegionDecoder Class Referencefinal

#include <BitmapRegionDecoder.h>

Public Member Functions

bool decodeRegion (SkBitmap *bitmap, BRDAllocator *allocator, const SkIRect &desiredSubset, int sampleSize, SkColorType colorType, bool requireUnpremul, sk_sp< SkColorSpace > prefColorSpace)
 
SkEncodedImageFormat getEncodedFormat ()
 
SkColorType computeOutputColorType (SkColorType requestedColorType)
 
sk_sp< SkColorSpacecomputeOutputColorSpace (SkColorType outputColorType, sk_sp< SkColorSpace > prefColorSpace=nullptr)
 
int width () const
 
int height () const
 
bool getAndroidGainmap (SkGainmapInfo *outInfo, std::unique_ptr< SkStream > *outGainmapImageStream)
 

Static Public Member Functions

static std::unique_ptr< BitmapRegionDecoderMake (sk_sp< SkData > data)
 

Detailed Description

Definition at line 19 of file BitmapRegionDecoder.h.

Member Function Documentation

◆ computeOutputColorSpace()

sk_sp< SkColorSpace > android::skia::BitmapRegionDecoder::computeOutputColorSpace ( SkColorType  outputColorType,
sk_sp< SkColorSpace prefColorSpace = nullptr 
)
inline

Definition at line 37 of file BitmapRegionDecoder.h.

38 {
39 return fCodec->computeOutputColorSpace(outputColorType, std::move(prefColorSpace));
40 }

◆ computeOutputColorType()

SkColorType android::skia::BitmapRegionDecoder::computeOutputColorType ( SkColorType  requestedColorType)
inline

Definition at line 33 of file BitmapRegionDecoder.h.

33 {
34 return fCodec->computeOutputColorType(requestedColorType);
35 }

◆ decodeRegion()

bool android::skia::BitmapRegionDecoder::decodeRegion ( SkBitmap bitmap,
BRDAllocator allocator,
const SkIRect desiredSubset,
int  sampleSize,
SkColorType  colorType,
bool  requireUnpremul,
sk_sp< SkColorSpace prefColorSpace 
)

Definition at line 49 of file BitmapRegionDecoder.cpp.

51 {
52
53 // Fix the input sampleSize if necessary.
54 if (sampleSize < 1) {
55 sampleSize = 1;
56 }
57
58 // The size of the output bitmap is determined by the size of the
59 // requested subset, not by the size of the intersection of the subset
60 // and the image dimensions.
61 // If inputX is negative, we will need to place decoded pixels into the
62 // output bitmap starting at a left offset. Call this outX.
63 // If outX is non-zero, subsetX must be zero.
64 // If inputY is negative, we will need to place decoded pixels into the
65 // output bitmap starting at a top offset. Call this outY.
66 // If outY is non-zero, subsetY must be zero.
67 int outX;
68 int outY;
69 SkIRect subset = desiredSubset;
70 SubsetType type = adjust_subset_rect(fCodec->getInfo().dimensions(), &subset, &outX, &outY);
72 return false;
73 }
74
75 // Ask the codec for a scaled subset
76 if (!fCodec->getSupportedSubset(&subset)) {
77 SkCodecPrintf("Error: Could not get subset.\n");
78 return false;
79 }
80 SkISize scaledSize = fCodec->getSampledSubsetDimensions(sampleSize, subset);
81
82 // Create the image info for the decode
83 SkAlphaType dstAlphaType = fCodec->computeOutputAlphaType(requireUnpremul);
84 SkImageInfo decodeInfo =
85 SkImageInfo::Make(scaledSize, dstColorType, dstAlphaType, std::move(dstColorSpace));
86
87 // Initialize the destination bitmap
88 int scaledOutX = 0;
89 int scaledOutY = 0;
90 int scaledOutWidth = scaledSize.width();
91 int scaledOutHeight = scaledSize.height();
93 scaledOutX = outX / sampleSize;
94 scaledOutY = outY / sampleSize;
95 // We need to be safe here because getSupportedSubset() may have modified the subset.
96 const int extraX = std::max(0, desiredSubset.width() - outX - subset.width());
97 const int extraY = std::max(0, desiredSubset.height() - outY - subset.height());
98 const int scaledExtraX = extraX / sampleSize;
99 const int scaledExtraY = extraY / sampleSize;
100 scaledOutWidth += scaledOutX + scaledExtraX;
101 scaledOutHeight += scaledOutY + scaledExtraY;
102 }
103 SkImageInfo outInfo = decodeInfo.makeWH(scaledOutWidth, scaledOutHeight);
104 if (kGray_8_SkColorType == dstColorType) {
105 // The legacy implementations of BitmapFactory and BitmapRegionDecoder
106 // used kAlpha8 for grayscale images (before kGray8 existed). While
107 // the codec recognizes kGray8, we need to decode into a kAlpha8
108 // bitmap in order to avoid a behavior change.
110 }
111 bitmap->setInfo(outInfo);
112 if (!bitmap->tryAllocPixels(allocator)) {
113 SkCodecPrintf("Error: Could not allocate pixels.\n");
114 return false;
115 }
116
117 // Zero the bitmap if the region is not completely within the image.
118 // TODO (msarett): Can we make this faster by implementing it to only
119 // zero parts of the image that we won't overwrite with
120 // pixels?
121 SkCodec::ZeroInitialized zeroInit = allocator ? allocator->zeroInit() :
124 SkCodec::kNo_ZeroInitialized == zeroInit) {
125 void* pixels = bitmap->getPixels();
126 size_t bytes = outInfo.computeByteSize(bitmap->rowBytes());
127 memset(pixels, 0, bytes);
128 }
129
130 // Decode into the destination bitmap
132 options.fSampleSize = sampleSize;
133 options.fSubset = &subset;
134 options.fZeroInitialized = zeroInit;
135 void* dst = bitmap->getAddr(scaledOutX, scaledOutY);
136
137 SkCodec::Result result = fCodec->getAndroidPixels(decodeInfo, dst, bitmap->rowBytes(),
138 &options);
139 switch (result) {
143 return true;
144 default:
145 SkCodecPrintf("Error: Could not get pixels with message \"%s\".\n",
147 return false;
148 }
149}
@ kOutside_SubsetType
@ kPartiallyInside_SubsetType
SubsetType adjust_subset_rect(const SkISize &imageDims, SkIRect *subset, int *outX, int *outY)
const char * options
SkAlphaType
Definition: SkAlphaType.h:26
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
#define SkCodecPrintf(...)
Definition: SkCodecPriv.h:23
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
Definition: SkColorType.h:21
@ kGray_8_SkColorType
pixel with grayscale level in 8-bit byte
Definition: SkColorType.h:35
GLenum type
ZeroInitialized
Definition: SkCodec.h:303
@ kNo_ZeroInitialized
Definition: SkCodec.h:315
static const char * ResultToString(Result)
Definition: SkCodec.cpp:880
Result
Definition: SkCodec.h:76
@ kIncompleteInput
Definition: SkCodec.h:84
@ kSuccess
Definition: SkCodec.h:80
@ kErrorInInput
Definition: SkCodec.h:91
GAsyncResult * result
static float max(float r, float g, float b)
Definition: hsl.cpp:49
Definition: bitmap.py:1
dst
Definition: cp.py:12
Definition: SkRect.h:32
constexpr int32_t height() const
Definition: SkRect.h:165
constexpr int32_t width() const
Definition: SkRect.h:158
Definition: SkSize.h:16
constexpr int32_t width() const
Definition: SkSize.h:36
constexpr int32_t height() const
Definition: SkSize.h:37
SkImageInfo makeWH(int newWidth, int newHeight) const
Definition: SkImageInfo.h:444
SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const
Definition: SkImageInfo.h:466
size_t computeByteSize(size_t rowBytes) const
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
SkImageInfo makeColorType(SkColorType newColorType) const
Definition: SkImageInfo.h:475

◆ getAndroidGainmap()

bool android::skia::BitmapRegionDecoder::getAndroidGainmap ( SkGainmapInfo outInfo,
std::unique_ptr< SkStream > *  outGainmapImageStream 
)
inline

Definition at line 45 of file BitmapRegionDecoder.h.

46 {
47 return fCodec->getAndroidGainmap(outInfo, outGainmapImageStream);
48 }

◆ getEncodedFormat()

SkEncodedImageFormat android::skia::BitmapRegionDecoder::getEncodedFormat ( )
inline

Definition at line 31 of file BitmapRegionDecoder.h.

31{ return fCodec->getEncodedFormat(); }

◆ height()

int android::skia::BitmapRegionDecoder::height ( ) const

Definition at line 45 of file BitmapRegionDecoder.cpp.

45 {
46 return fCodec->getInfo().height();
47}

◆ Make()

std::unique_ptr< BitmapRegionDecoder > android::skia::BitmapRegionDecoder::Make ( sk_sp< SkData data)
static

Definition at line 17 of file BitmapRegionDecoder.cpp.

17 {
18 auto codec = SkAndroidCodec::MakeFromData(std::move(data));
19 if (nullptr == codec) {
20 SkCodecPrintf("Error: Failed to create codec.\n");
21 return nullptr;
22 }
23
24 switch (codec->getEncodedFormat()) {
29 break;
30 default:
31 return nullptr;
32 }
33
34 return std::unique_ptr<BitmapRegionDecoder>(new BitmapRegionDecoder(std::move(codec)));
35}
static std::unique_ptr< SkAndroidCodec > MakeFromData(sk_sp< SkData >, SkPngChunkReader *=nullptr)
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ width()

int android::skia::BitmapRegionDecoder::width ( ) const

Definition at line 41 of file BitmapRegionDecoder.cpp.

41 {
42 return fCodec->getInfo().width();
43}

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