diff --git a/src/images/SkImageDecoder_Factory.cpp b/src/images/SkImageDecoder_Factory.cpp index 9dd9913bb5..bd81d1fc1d 100644 --- a/src/images/SkImageDecoder_Factory.cpp +++ b/src/images/SkImageDecoder_Factory.cpp @@ -28,6 +28,8 @@ SkImageDecoder* SkImageDecoder::Factory(SkStream* stream) { const DecodeReg* curr = DecodeReg::Head(); while (curr) { SkImageDecoder* codec = curr->factory()(stream); + // we rewind here, because we promise later when we call "decode", that + // the stream will be at its beginning. stream->rewind(); if (codec) { return codec; @@ -48,6 +50,8 @@ SkMovie* SkMovie::DecodeStream(SkStream* stream) { if (movie) { return movie; } + // we must rewind only if we got NULL, since we gave the stream to the + // movie, who may have already started reading from it stream->rewind(); curr = curr->next(); } diff --git a/src/images/SkMovie_gif.cpp b/src/images/SkMovie_gif.cpp index 68af85a94b..113804462a 100644 --- a/src/images/SkMovie_gif.cpp +++ b/src/images/SkMovie_gif.cpp @@ -220,6 +220,8 @@ SkMovie* Factory(SkStream* stream) { if (memcmp(GIF_STAMP, buf, GIF_STAMP_LEN) == 0 || memcmp(GIF87_STAMP, buf, GIF_STAMP_LEN) == 0 || memcmp(GIF89_STAMP, buf, GIF_STAMP_LEN) == 0) { + // must rewind here, since our construct wants to re-read the data + stream->rewind(); return SkNEW_ARGS(SkGIFMovie, (stream)); } }