Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Unified Diff: src/codec/SkCodec_libico.cpp

Issue 1472123002: Make SkCodec support peek() and read() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/codec/SkCodec_libico.h ('k') | src/codec/SkCodec_libpng.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/codec/SkCodec_libico.cpp
diff --git a/src/codec/SkCodec_libico.cpp b/src/codec/SkCodec_libico.cpp
index e1314d712158daaa64daa608ede9ad78fe0358ab..660576a26a0fb098df81745c3b7cc3d30f978118 100644
--- a/src/codec/SkCodec_libico.cpp
+++ b/src/codec/SkCodec_libico.cpp
@@ -55,11 +55,10 @@ static SkImageInfo fix_embedded_alpha(const SkImageInfo& dstInfo, SkAlphaType em
/*
* Checks the start of the stream to see if the image is an Ico or Cur
*/
-bool SkIcoCodec::IsIco(SkStream* stream) {
+bool SkIcoCodec::IsIco(const void* buffer, size_t bytesRead) {
const char icoSig[] = { '\x00', '\x00', '\x01', '\x00' };
const char curSig[] = { '\x00', '\x00', '\x02', '\x00' };
- char buffer[sizeof(icoSig)];
- return stream->read(buffer, sizeof(icoSig)) == sizeof(icoSig) &&
+ return bytesRead >= sizeof(icoSig) &&
(!memcmp(buffer, icoSig, sizeof(icoSig)) ||
!memcmp(buffer, curSig, sizeof(curSig)));
}
@@ -176,10 +175,8 @@ SkCodec* SkIcoCodec::NewFromStream(SkStream* stream) {
bytesRead += size;
// Check if the embedded codec is bmp or png and create the codec
- const bool isPng = SkPngCodec::IsPng(embeddedStream);
- SkAssertResult(embeddedStream->rewind());
SkCodec* codec = nullptr;
- if (isPng) {
+ if (SkPngCodec::IsPng((const char*) data->bytes(), data->size())) {
codec = SkPngCodec::NewFromStream(embeddedStream.detach());
} else {
codec = SkBmpCodec::NewFromIco(embeddedStream.detach());
« no previous file with comments | « src/codec/SkCodec_libico.h ('k') | src/codec/SkCodec_libpng.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698