Switch SkCodec to int for counts and indices
This matches other Skia APIs. size_t was adopted from blink/
GIFImageReader.
Change-Id: Ic83e59f0942f597c4fb834e623acd9886ad483fe
Reviewed-on: https://skia-review.googlesource.com/13274
Reviewed-by: Mike Reed <reed@google.com>
Reviewed-by: Matt Sarett <msarett@google.com>
Reviewed-by: Chris Blume <cblume@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
diff --git a/src/codec/SkCodec.cpp b/src/codec/SkCodec.cpp
index 6a6fdc7..9e693b1 100644
--- a/src/codec/SkCodec.cpp
+++ b/src/codec/SkCodec.cpp
@@ -491,22 +491,20 @@
}
std::vector<SkCodec::FrameInfo> SkCodec::getFrameInfo() {
- const size_t frameCount = this->getFrameCount();
- switch (frameCount) {
- case 0:
- return std::vector<FrameInfo>{};
- case 1:
- if (!this->onGetFrameInfo(0, nullptr)) {
- // Not animated.
- return std::vector<FrameInfo>{};
- }
- // fall through
- default: {
- std::vector<FrameInfo> result(frameCount);
- for (size_t i = 0; i < frameCount; ++i) {
- SkAssertResult(this->onGetFrameInfo(i, &result[i]));
- }
- return result;
- }
+ const int frameCount = this->getFrameCount();
+ SkASSERT(frameCount >= 0);
+ if (frameCount <= 0) {
+ return std::vector<FrameInfo>{};
}
+
+ if (frameCount == 1 && !this->onGetFrameInfo(0, nullptr)) {
+ // Not animated.
+ return std::vector<FrameInfo>{};
+ }
+
+ std::vector<FrameInfo> result(frameCount);
+ for (int i = 0; i < frameCount; ++i) {
+ SkAssertResult(this->onGetFrameInfo(i, &result[i]));
+ }
+ return result;
}
diff --git a/src/codec/SkGifCodec.cpp b/src/codec/SkGifCodec.cpp
index 2e0ec30..2584ee5 100644
--- a/src/codec/SkGifCodec.cpp
+++ b/src/codec/SkGifCodec.cpp
@@ -132,12 +132,12 @@
reader->setClient(this);
}
-size_t SkGifCodec::onGetFrameCount() {
+int SkGifCodec::onGetFrameCount() {
fReader->parse(SkGifImageReader::SkGIFFrameCountQuery);
return fReader->imagesCount();
}
-bool SkGifCodec::onGetFrameInfo(size_t i, SkCodec::FrameInfo* frameInfo) const {
+bool SkGifCodec::onGetFrameInfo(int i, SkCodec::FrameInfo* frameInfo) const {
if (i >= fReader->imagesCount()) {
return false;
}
@@ -164,7 +164,7 @@
static const SkColorType kXformSrcColorType = kRGBA_8888_SkColorType;
-void SkGifCodec::initializeColorTable(const SkImageInfo& dstInfo, size_t frameIndex) {
+void SkGifCodec::initializeColorTable(const SkImageInfo& dstInfo, int frameIndex) {
SkColorType colorTableColorType = dstInfo.colorType();
if (this->colorXform()) {
colorTableColorType = kXformSrcColorType;
@@ -215,7 +215,7 @@
return gif_error("Subsets not supported.\n", kUnimplemented);
}
- const size_t frameIndex = opts.fFrameIndex;
+ const int frameIndex = opts.fFrameIndex;
if (frameIndex > 0) {
switch (dstInfo.colorType()) {
case kIndex_8_SkColorType:
@@ -276,7 +276,7 @@
return kSuccess;
}
-void SkGifCodec::initializeSwizzler(const SkImageInfo& dstInfo, size_t frameIndex) {
+void SkGifCodec::initializeSwizzler(const SkImageInfo& dstInfo, int frameIndex) {
const SkGIFFrameContext* frame = fReader->frameContext(frameIndex);
// This is only called by prepareToDecode, which ensures frameIndex is in range.
SkASSERT(frame);
@@ -365,7 +365,7 @@
SkCodec::Result SkGifCodec::onIncrementalDecode(int* rowsDecoded) {
// It is possible the client has appended more data. Parse, if needed.
const auto& options = this->options();
- const size_t frameIndex = options.fFrameIndex;
+ const int frameIndex = options.fFrameIndex;
fReader->parse((SkGifImageReader::SkGIFParseQuery) frameIndex);
const bool firstCallToIncrementalDecode = fFirstCallToIncrementalDecode;
@@ -375,7 +375,7 @@
SkCodec::Result SkGifCodec::decodeFrame(bool firstAttempt, const Options& opts, int* rowsDecoded) {
const SkImageInfo& dstInfo = this->dstInfo();
- const size_t frameIndex = opts.fFrameIndex;
+ const int frameIndex = opts.fFrameIndex;
SkASSERT(frameIndex < fReader->imagesCount());
const SkGIFFrameContext* frameContext = fReader->frameContext(frameIndex);
if (firstAttempt) {
@@ -500,8 +500,8 @@
// compatibity on Android, so we are using the color table for the first frame.
SkASSERT(this->options().fFrameIndex == 0);
// Use the transparent index for the first frame.
- const size_t transPixel = fReader->frameContext(0)->transparentPixel();
- if (transPixel < (size_t) fCurrColorTable->count()) {
+ const int transPixel = fReader->frameContext(0)->transparentPixel();
+ if (transPixel >= 0 && transPixel < fCurrColorTable->count()) {
return transPixel;
}
// Fall through to return SK_ColorTRANSPARENT (i.e. 0). This choice is arbitrary,
@@ -532,8 +532,8 @@
}
}
-bool SkGifCodec::haveDecodedRow(size_t frameIndex, const unsigned char* rowBegin,
- size_t rowNumber, unsigned repeatCount, bool writeTransparentPixels)
+bool SkGifCodec::haveDecodedRow(int frameIndex, const unsigned char* rowBegin,
+ int rowNumber, int repeatCount, bool writeTransparentPixels)
{
const SkGIFFrameContext* frameContext = fReader->frameContext(frameIndex);
// The pixel data and coordinates supplied to us are relative to the frame's
@@ -542,13 +542,11 @@
// that width == (size().width() - frameContext->xOffset), so
// we must ensure we don't run off the end of either the source data or the
// row's X-coordinates.
- const size_t width = frameContext->width();
+ const int width = frameContext->width();
const int xBegin = frameContext->xOffset();
const int yBegin = frameContext->yOffset() + rowNumber;
- const int xEnd = std::min(static_cast<int>(frameContext->xOffset() + width),
- this->getInfo().width());
- const int yEnd = std::min(static_cast<int>(frameContext->yOffset() + rowNumber + repeatCount),
- this->getInfo().height());
+ const int xEnd = std::min(xBegin + width, this->getInfo().width());
+ const int yEnd = std::min(yBegin + rowNumber + repeatCount, this->getInfo().height());
// FIXME: No need to make the checks on width/xBegin/xEnd for every row. We could instead do
// this once in prepareToDecode.
if (!width || (xBegin < 0) || (yBegin < 0) || (xEnd <= xBegin) || (yEnd <= yBegin))
@@ -563,7 +561,7 @@
// Check to see whether this row or one that falls in the repeatCount is needed in the
// output.
bool foundNecessaryRow = false;
- for (unsigned i = 0; i < repeatCount; i++) {
+ for (int i = 0; i < repeatCount; i++) {
const int potentialRow = yBegin + i;
if (fSwizzler->rowNeeded(potentialRow)) {
dstRow = potentialRow / sampleY;
@@ -578,7 +576,7 @@
repeatCount = (repeatCount - 1) / sampleY + 1;
// Make sure the repeatCount does not take us beyond the end of the dst
- if (dstRow + (int) repeatCount > scaledHeight) {
+ if (dstRow + repeatCount > scaledHeight) {
repeatCount = scaledHeight - dstRow;
SkASSERT(repeatCount >= 1);
}
@@ -592,7 +590,7 @@
} else {
// Make sure the repeatCount does not take us beyond the end of the dst
SkASSERT(this->dstInfo().height() >= yBegin);
- repeatCount = SkTMin(repeatCount, (unsigned) (this->dstInfo().height() - yBegin));
+ repeatCount = SkTMin(repeatCount, this->dstInfo().height() - yBegin);
}
if (!fFilledBackground) {
@@ -665,7 +663,7 @@
const size_t bytesToCopy = fSwizzler->swizzleWidth() * bytesPerPixel;
void* copiedLine = SkTAddOffset<void>(dstLine, fSwizzler->swizzleOffsetBytes());
void* dst = copiedLine;
- for (unsigned i = 1; i < repeatCount; i++) {
+ for (int i = 1; i < repeatCount; i++) {
dst = SkTAddOffset<void>(dst, fDstRowBytes);
memcpy(dst, copiedLine, bytesToCopy);
}
diff --git a/src/codec/SkGifCodec.h b/src/codec/SkGifCodec.h
index 11714eb..9cb6632 100644
--- a/src/codec/SkGifCodec.h
+++ b/src/codec/SkGifCodec.h
@@ -33,8 +33,8 @@
static SkCodec* NewFromStream(SkStream*);
// Callback for SkGifImageReader when a row is available.
- bool haveDecodedRow(size_t frameIndex, const unsigned char* rowBegin,
- size_t rowNumber, unsigned repeatCount, bool writeTransparentPixels);
+ bool haveDecodedRow(int frameIndex, const unsigned char* rowBegin,
+ int rowNumber, int repeatCount, bool writeTransparentPixels);
protected:
/*
* Performs the full gif decode
@@ -50,8 +50,8 @@
uint64_t onGetFillValue(const SkImageInfo&) const override;
- size_t onGetFrameCount() override;
- bool onGetFrameInfo(size_t, FrameInfo*) const override;
+ int onGetFrameCount() override;
+ bool onGetFrameInfo(int, FrameInfo*) const override;
int onGetRepetitionCount() override;
Result onStartIncrementalDecode(const SkImageInfo& /*dstInfo*/, void*, size_t,
@@ -67,7 +67,7 @@
* @param dstInfo Contains the requested dst color type.
* @param frameIndex Frame whose color table to use.
*/
- void initializeColorTable(const SkImageInfo& dstInfo, size_t frameIndex);
+ void initializeColorTable(const SkImageInfo& dstInfo, int frameIndex);
/*
* Does necessary setup, including setting up the color table and swizzler,
@@ -85,7 +85,7 @@
* @param frameIndex Which frame we are decoding. This determines the frameRect
* to use.
*/
- void initializeSwizzler(const SkImageInfo& dstInfo, size_t frameIndex);
+ void initializeSwizzler(const SkImageInfo& dstInfo, int frameIndex);
SkSampler* getSampler(bool createIfNecessary) override {
SkASSERT(fSwizzler);