Skip to content

Commit 439709a

Browse files
dnfieldSkia Commit-Bot
authored and
Skia Commit-Bot
committed
Expose multi-frame methods for SkCodecImageGenerator
This will allow Flutter to avoid some usages of SkCodec and have consistent EXIF handling for multi-frame formats that support EXIF. Change-Id: I80daee9b00777d88d0a960cc0f0d76da6680e257 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302270 Reviewed-by: Leon Scroggins <[email protected]> Commit-Queue: Dan Field <[email protected]>
1 parent 3b5a4fa commit 439709a

File tree

2 files changed

+76
-10
lines changed

2 files changed

+76
-10
lines changed

src/codec/SkCodecImageGenerator.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,11 @@ sk_sp<SkData> SkCodecImageGenerator::onRefEncodedData() {
4646
return fData;
4747
}
4848

49-
bool SkCodecImageGenerator::onGetPixels(const SkImageInfo& requestInfo, void* requestPixels,
50-
size_t requestRowBytes, const Options&) {
51-
SkPixmap dst(requestInfo, requestPixels, requestRowBytes);
49+
bool SkCodecImageGenerator::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, const SkCodec::Options* options) {
50+
SkPixmap dst(info, pixels, rowBytes);
5251

53-
auto decode = [this](const SkPixmap& pm) {
54-
SkCodec::Result result = fCodec->getPixels(pm);
52+
auto decode = [this, options](const SkPixmap& pm) {
53+
SkCodec::Result result = fCodec->getPixels(pm, options);
5554
switch (result) {
5655
case SkCodec::kSuccess:
5756
case SkCodec::kIncompleteInput:
@@ -65,6 +64,11 @@ bool SkCodecImageGenerator::onGetPixels(const SkImageInfo& requestInfo, void* re
6564
return SkPixmapPriv::Orient(dst, fCodec->getOrigin(), decode);
6665
}
6766

67+
bool SkCodecImageGenerator::onGetPixels(const SkImageInfo& requestInfo, void* requestPixels,
68+
size_t requestRowBytes, const Options& options) {
69+
return this->getPixels(requestInfo, requestPixels, requestRowBytes, nullptr);
70+
}
71+
6872
bool SkCodecImageGenerator::onQueryYUVA8(SkYUVASizeInfo* sizeInfo,
6973
SkYUVAIndex yuvaIndices[SkYUVAIndex::kIndexCount],
7074
SkYUVColorSpace* colorSpace) const {

src/codec/SkCodecImageGenerator.h

+67-5
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,78 @@ class SkCodecImageGenerator : public SkImageGenerator {
3232
*/
3333
SkISize getScaledDimensions(float desiredScale) const;
3434

35+
/**
36+
* Decode into the given pixels, a block of memory of size at
37+
* least (info.fHeight - 1) * rowBytes + (info.fWidth *
38+
* bytesPerPixel)
39+
*
40+
* Repeated calls to this function should give the same results,
41+
* allowing the PixelRef to be immutable.
42+
*
43+
* @param info A description of the format
44+
* expected by the caller. This can simply be identical
45+
* to the info returned by getInfo().
46+
*
47+
* This contract also allows the caller to specify
48+
* different output-configs, which the implementation can
49+
* decide to support or not.
50+
*
51+
* A size that does not match getInfo() implies a request
52+
* to scale. If the generator cannot perform this scale,
53+
* it will return false.
54+
*
55+
* @return true on success.
56+
*/
57+
bool getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, const SkCodec::Options* options = nullptr);
58+
59+
/**
60+
* Return the number of frames in the image.
61+
*
62+
* May require reading through the stream.
63+
*/
64+
int getFrameCount() { return fCodec->getFrameCount(); }
65+
66+
/**
67+
* Return info about a single frame.
68+
*
69+
* Only supported by multi-frame images. Does not read through the stream,
70+
* so it should be called after getFrameCount() to parse any frames that
71+
* have not already been parsed.
72+
*/
73+
bool getFrameInfo(int index, SkCodec::FrameInfo* info) const {
74+
return fCodec->getFrameInfo(index, info);
75+
}
76+
77+
/**
78+
* Return the number of times to repeat, if this image is animated. This number does not
79+
* include the first play through of each frame. For example, a repetition count of 4 means
80+
* that each frame is played 5 times and then the animation stops.
81+
*
82+
* It can return kRepetitionCountInfinite, a negative number, meaning that the animation
83+
* should loop forever.
84+
*
85+
* May require reading the stream to find the repetition count.
86+
*
87+
* As such, future decoding calls may require a rewind.
88+
*
89+
* For still (non-animated) image codecs, this will return 0.
90+
*/
91+
int getRepetitionCount() { return fCodec->getRepetitionCount(); }
92+
3593
protected:
3694
sk_sp<SkData> onRefEncodedData() override;
3795

38-
bool onGetPixels(
39-
const SkImageInfo& info, void* pixels, size_t rowBytes, const Options& opts) override;
96+
bool onGetPixels(const SkImageInfo& info,
97+
void* pixels,
98+
size_t rowBytes,
99+
const Options& opts) override;
40100

41-
bool onQueryYUVA8(
42-
SkYUVASizeInfo*, SkYUVAIndex[SkYUVAIndex::kIndexCount], SkYUVColorSpace*) const override;
101+
bool onQueryYUVA8(SkYUVASizeInfo*,
102+
SkYUVAIndex[SkYUVAIndex::kIndexCount],
103+
SkYUVColorSpace*) const override;
43104

44-
bool onGetYUVA8Planes(const SkYUVASizeInfo&, const SkYUVAIndex[SkYUVAIndex::kIndexCount],
105+
bool onGetYUVA8Planes(const SkYUVASizeInfo&,
106+
const SkYUVAIndex[SkYUVAIndex::kIndexCount],
45107
void* planes[]) override;
46108

47109
private:

0 commit comments

Comments
 (0)