aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/gif
diff options
context:
space:
mode:
authorGravatar Leon Scroggins III <scroggo@google.com>2017-04-17 12:46:33 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-04-17 17:38:35 +0000
commit249b8e3a2b6450be2e2315f8f9496eec03cfd1c1 (patch)
tree4c857c72d3716f13658e52dde2afe93b5d07cb70 /third_party/gif
parentcd11c809f206af0da3ce1779dee3c91193baa7b0 (diff)
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>
Diffstat (limited to 'third_party/gif')
-rw-r--r--third_party/gif/SkGifImageReader.cpp49
-rw-r--r--third_party/gif/SkGifImageReader.h45
2 files changed, 51 insertions, 43 deletions
diff --git a/third_party/gif/SkGifImageReader.cpp b/third_party/gif/SkGifImageReader.cpp
index 86768e301c..8c5cfa1ea8 100644
--- a/third_party/gif/SkGifImageReader.cpp
+++ b/third_party/gif/SkGifImageReader.cpp
@@ -202,7 +202,7 @@ bool SkGIFLZWContext::outputRow(const unsigned char* rowBegin)
// Otherwise, decoding failed; returns false in this case, which will always cause the SkGifImageReader to set the "decode failed" flag.
bool SkGIFLZWContext::doLZW(const unsigned char* block, size_t bytesInBlock)
{
- const size_t width = m_frameContext->width();
+ const int width = m_frameContext->width();
if (rowIter == rowBuffer.end())
return true;
@@ -306,14 +306,14 @@ bool SkGIFLZWContext::doLZW(const unsigned char* block, size_t bytesInBlock)
}
sk_sp<SkColorTable> SkGIFColorMap::buildTable(SkStreamBuffer* streamBuffer, SkColorType colorType,
- size_t transparentPixel) const
+ int transparentPixel) const
{
if (!m_isDefined)
return nullptr;
const PackColorProc proc = choose_pack_color_proc(false, colorType);
if (m_table && proc == m_packColorProc && m_transPixel == transparentPixel) {
- SkASSERT(transparentPixel > (unsigned) m_table->count()
+ SkASSERT(transparentPixel == kNotFound || transparentPixel > m_table->count()
|| m_table->operator[](transparentPixel) == SK_ColorTRANSPARENT);
// This SkColorTable has already been built with the same transparent color and
// packing proc. Reuse it.
@@ -331,7 +331,7 @@ sk_sp<SkColorTable> SkGIFColorMap::buildTable(SkStreamBuffer* streamBuffer, SkCo
SkASSERT(m_colors <= SK_MAX_COLORS);
const uint8_t* srcColormap = rawData->bytes();
SkPMColor colorStorage[SK_MAX_COLORS];
- for (size_t i = 0; i < m_colors; i++) {
+ for (int i = 0; i < m_colors; i++) {
if (i == transparentPixel) {
colorStorage[i] = SK_ColorTRANSPARENT;
} else {
@@ -339,21 +339,21 @@ sk_sp<SkColorTable> SkGIFColorMap::buildTable(SkStreamBuffer* streamBuffer, SkCo
}
srcColormap += SK_BYTES_PER_COLORMAP_ENTRY;
}
- for (size_t i = m_colors; i < SK_MAX_COLORS; i++) {
+ for (int i = m_colors; i < SK_MAX_COLORS; i++) {
colorStorage[i] = SK_ColorTRANSPARENT;
}
m_table = sk_sp<SkColorTable>(new SkColorTable(colorStorage, SK_MAX_COLORS));
return m_table;
}
-sk_sp<SkColorTable> SkGifImageReader::getColorTable(SkColorType colorType, size_t index) {
- if (index >= m_frames.size()) {
+sk_sp<SkColorTable> SkGifImageReader::getColorTable(SkColorType colorType, int index) {
+ if (index < 0 || static_cast<size_t>(index) >= m_frames.size()) {
return nullptr;
}
const SkGIFFrameContext* frameContext = m_frames[index].get();
const SkGIFColorMap& localColorMap = frameContext->localColorMap();
- const size_t transPix = frameContext->transparentPixel();
+ const int transPix = frameContext->transparentPixel();
if (localColorMap.isDefined()) {
return localColorMap.buildTable(&m_streamBuffer, colorType, transPix);
}
@@ -385,7 +385,8 @@ bool SkGIFFrameContext::decode(SkStreamBuffer* streamBuffer, SkGifCodec* client,
}
// Some bad GIFs have extra blocks beyond the last row, which we don't want to decode.
- while (m_currentLzwBlock < m_lzwBlocks.size() && m_lzwContext->hasRemainingRows()) {
+ while (static_cast<size_t>(m_currentLzwBlock) < m_lzwBlocks.size()
+ && m_lzwContext->hasRemainingRows()) {
const auto& block = m_lzwBlocks[m_currentLzwBlock];
const size_t len = block.blockSize;
@@ -411,7 +412,7 @@ bool SkGIFFrameContext::decode(SkStreamBuffer* streamBuffer, SkGifCodec* client,
// Decode a frame.
// This method uses SkGIFFrameContext:decode() to decode the frame; decoding error is reported to client as a critical failure.
// Return true if decoding has progressed. Return false if an error has occurred.
-bool SkGifImageReader::decode(size_t frameIndex, bool* frameComplete)
+bool SkGifImageReader::decode(int frameIndex, bool* frameComplete)
{
SkGIFFrameContext* currentFrame = m_frames[frameIndex].get();
@@ -493,7 +494,7 @@ bool SkGifImageReader::parse(SkGifImageReader::SkGIFParseQuery query)
m_screenWidth = GETINT16(currentComponent);
m_screenHeight = GETINT16(currentComponent + 2);
- const size_t globalColorMapColors = 2 << (currentComponent[4] & 0x07);
+ const int globalColorMapColors = 2 << (currentComponent[4] & 0x07);
if ((currentComponent[4] & 0x80) && globalColorMapColors > 0) { /* global map */
m_globalColorMap.setNumColors(globalColorMapColors);
@@ -753,7 +754,7 @@ bool SkGifImageReader::parse(SkGifImageReader::SkGIFParseQuery query)
const bool isLocalColormapDefined = SkToBool(currentComponent[8] & 0x80);
// The three low-order bits of currentComponent[8] specify the bits per pixel.
- const size_t numColors = 2 << (currentComponent[8] & 0x7);
+ const int numColors = 2 << (currentComponent[8] & 0x7);
if (currentFrameIsFirstFrame()) {
if (hasTransparentPixel(0, isLocalColormapDefined, numColors)) {
m_firstFrameHasAlpha = true;
@@ -851,9 +852,10 @@ bool SkGifImageReader::parse(SkGifImageReader::SkGIFParseQuery query)
return true;
}
-bool SkGifImageReader::hasTransparentPixel(size_t i, bool isLocalColormapDefined,
- size_t localColors) {
- if (m_frames.size() <= i) {
+bool SkGifImageReader::hasTransparentPixel(int i, bool isLocalColormapDefined,
+ int localColors) {
+ SkASSERT(i >= 0);
+ if (m_frames.size() <= static_cast<size_t>(i)) {
// This should only happen when parsing the first frame.
SkASSERT(0 == i);
@@ -863,12 +865,17 @@ bool SkGifImageReader::hasTransparentPixel(size_t i, bool isLocalColormapDefined
return !isLocalColormapDefined && m_globalColorMap.numColors() == 0;
}
- const size_t transparentPixel = m_frames[i]->transparentPixel();
+ const int transparentPixel = m_frames[i]->transparentPixel();
+ if (transparentPixel < 0) {
+ SkASSERT(SkGIFColorMap::kNotFound == transparentPixel);
+ return false;
+ }
+
if (isLocalColormapDefined) {
return transparentPixel < localColors;
}
- const size_t globalColors = m_globalColorMap.numColors();
+ const int globalColors = m_globalColorMap.numColors();
if (!globalColors) {
// No color table for this frame, so the frame is empty.
// This is technically different from having a transparent
@@ -886,7 +893,7 @@ void SkGifImageReader::addFrameIfNecessary()
{
if (m_frames.empty() || m_frames.back()->isComplete()) {
const size_t i = m_frames.size();
- std::unique_ptr<SkGIFFrameContext> frame(new SkGIFFrameContext(i));
+ std::unique_ptr<SkGIFFrameContext> frame(new SkGIFFrameContext(static_cast<int>(i)));
m_frames.push_back(std::move(frame));
}
}
@@ -909,7 +916,7 @@ static bool restore_bg(const SkGIFFrameContext& frame) {
}
void SkGifImageReader::setAlphaAndRequiredFrame(SkGIFFrameContext* frame) {
- const size_t i = frame->frameId();
+ const int i = frame->frameId();
if (0 == i) {
frame->setHasAlpha(m_firstFrameHasAlpha);
frame->setRequiredFrame(SkCodec::kNone);
@@ -933,7 +940,7 @@ void SkGifImageReader::setAlphaAndRequiredFrame(SkGIFFrameContext* frame) {
const SkGIFFrameContext* prevFrame = m_frames[i - 1].get();
while (prevFrame->getDisposalMethod() == SkCodecAnimation::RestorePrevious_DisposalMethod) {
- const size_t prevId = prevFrame->frameId();
+ const int prevId = prevFrame->frameId();
if (0 == prevId) {
frame->setHasAlpha(true);
frame->setRequiredFrame(SkCodec::kNone);
@@ -965,7 +972,7 @@ void SkGifImageReader::setAlphaAndRequiredFrame(SkGIFFrameContext* frame) {
}
while (frameRect.contains(prevFrameRect)) {
- const size_t prevRequiredFrame = prevFrame->getRequiredFrame();
+ const int prevRequiredFrame = prevFrame->getRequiredFrame();
if (prevRequiredFrame == SkCodec::kNone) {
frame->setRequiredFrame(SkCodec::kNone);
frame->setHasAlpha(true);
diff --git a/third_party/gif/SkGifImageReader.h b/third_party/gif/SkGifImageReader.h
index 9d69e48823..4667f7963f 100644
--- a/third_party/gif/SkGifImageReader.h
+++ b/third_party/gif/SkGifImageReader.h
@@ -148,7 +148,7 @@ struct SkGIFLZWBlock {
class SkGIFColorMap final {
public:
- static constexpr size_t kNotFound = static_cast<size_t>(-1);
+ static constexpr int kNotFound = -1;
SkGIFColorMap()
: m_isDefined(false)
@@ -159,7 +159,7 @@ public:
{
}
- void setNumColors(size_t colors) {
+ void setNumColors(int colors) {
SkASSERT(!m_colors);
SkASSERT(!m_position);
@@ -173,20 +173,20 @@ public:
m_isDefined = true;
}
- size_t numColors() const { return m_colors; }
+ int numColors() const { return m_colors; }
bool isDefined() const { return m_isDefined; }
// Build RGBA table using the data stream.
sk_sp<SkColorTable> buildTable(SkStreamBuffer*, SkColorType dstColorType,
- size_t transparentPixel) const;
+ int transparentPixel) const;
private:
bool m_isDefined;
size_t m_position;
- size_t m_colors;
+ int m_colors;
// Cached values. If these match on a new request, we can reuse m_table.
- mutable size_t m_transPixel;
+ mutable int m_transPixel;
mutable PackColorProc m_packColorProc;
mutable sk_sp<SkColorTable> m_table;
};
@@ -239,18 +239,18 @@ public:
unsigned yOffset() const { return m_yOffset; }
unsigned width() const { return m_width; }
unsigned height() const { return m_height; }
- size_t transparentPixel() const { return m_transparentPixel; }
- void setTransparentPixel(size_t pixel) { m_transparentPixel = pixel; }
+ int transparentPixel() const { return m_transparentPixel; }
+ void setTransparentPixel(int pixel) { m_transparentPixel = pixel; }
bool hasAlpha() const { return m_hasAlpha; }
void setHasAlpha(bool alpha) { m_hasAlpha = alpha; }
SkCodecAnimation::DisposalMethod getDisposalMethod() const { return m_disposalMethod; }
void setDisposalMethod(SkCodecAnimation::DisposalMethod disposalMethod) { m_disposalMethod = disposalMethod; }
- size_t getRequiredFrame() const {
+ int getRequiredFrame() const {
SkASSERT(this->reachedStartOfData());
return m_requiredFrame;
}
- void setRequiredFrame(size_t req) { m_requiredFrame = req; }
+ void setRequiredFrame(int req) { m_requiredFrame = req; }
unsigned delayTime() const { return m_delayTime; }
void setDelayTime(unsigned delay) { m_delayTime = delay; }
@@ -277,21 +277,21 @@ public:
bool reachedStartOfData() const { return m_requiredFrame != kUninitialized; }
private:
- static constexpr size_t kUninitialized = static_cast<size_t>(-2);
+ static constexpr int kUninitialized = -2;
int m_frameId;
unsigned m_xOffset;
unsigned m_yOffset; // With respect to "screen" origin.
unsigned m_width;
unsigned m_height;
- size_t m_transparentPixel; // Index of transparent pixel. Value is kNotFound if there is no transparent pixel.
+ int m_transparentPixel; // Index of transparent pixel. Value is kNotFound if there is no transparent pixel.
// Cached value, taking into account:
// - m_transparentPixel
// - frameRect
// - previous required frame
bool m_hasAlpha;
SkCodecAnimation::DisposalMethod m_disposalMethod; // Restore to background, leave in place, etc.
- size_t m_requiredFrame;
+ int m_requiredFrame;
int m_dataSize;
bool m_progressiveDisplay; // If true, do Haeberli interlace hack.
@@ -305,7 +305,7 @@ private:
SkGIFColorMap m_localColorMap;
- size_t m_currentLzwBlock;
+ int m_currentLzwBlock;
bool m_isComplete;
bool m_isHeaderDefined;
bool m_isDataSizeDefined;
@@ -359,15 +359,15 @@ public:
// Decode the frame indicated by frameIndex.
// frameComplete will be set to true if the frame is completely decoded.
// The method returns false if there is an error.
- bool decode(size_t frameIndex, bool* frameComplete);
+ bool decode(int frameIndex, bool* frameComplete);
- size_t imagesCount() const
+ int imagesCount() const
{
// Report the first frame immediately, so the parser can stop when it
// sees the size on a SizeQuery.
const size_t frames = m_frames.size();
if (frames <= 1) {
- return frames;
+ return static_cast<int>(frames);
}
// This avoids counting an empty frame when the file is truncated (or
@@ -375,7 +375,7 @@ public:
// possibly SkGIFImageHeader) but before reading the color table. This
// ensures that we do not count a frame before we know its required
// frame.
- return m_frames.back()->reachedStartOfData() ? frames : frames - 1;
+ return static_cast<int>(m_frames.back()->reachedStartOfData() ? frames : frames - 1);
}
int loopCount() const {
if (cLoopCountNotSeen == m_loopCount) {
@@ -389,9 +389,10 @@ public:
return m_globalColorMap;
}
- const SkGIFFrameContext* frameContext(size_t index) const
+ const SkGIFFrameContext* frameContext(int index) const
{
- return index < m_frames.size() ? m_frames[index].get() : 0;
+ return index >= 0 && index < static_cast<int>(m_frames.size())
+ ? m_frames[index].get() : 0;
}
void clearDecodeState() {
@@ -401,7 +402,7 @@ public:
}
// Return the color table for frame index (which may be the global color table).
- sk_sp<SkColorTable> getColorTable(SkColorType dstColorType, size_t index);
+ sk_sp<SkColorTable> getColorTable(SkColorType dstColorType, int index);
bool firstFrameHasAlpha() const { return m_firstFrameHasAlpha; }
@@ -418,7 +419,7 @@ private:
void setAlphaAndRequiredFrame(SkGIFFrameContext*);
// This method is sometimes called before creating a SkGIFFrameContext, so it cannot rely
// on SkGIFFrameContext::localColorMap().
- bool hasTransparentPixel(size_t frameIndex, bool hasLocalColorMap, size_t localMapColors);
+ bool hasTransparentPixel(int frameIndex, bool hasLocalColorMap, int localMapColors);
bool currentFrameIsFirstFrame() const
{
return m_frames.empty() || (m_frames.size() == 1u && !m_frames[0]->isComplete());