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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/codec/SkCodec_libico.h ('k') | src/codec/SkCodec_libpng.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkBmpCodec.h" 8 #include "SkBmpCodec.h"
9 #include "SkCodec_libico.h" 9 #include "SkCodec_libico.h"
10 #include "SkCodec_libpng.h" 10 #include "SkCodec_libpng.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 default: 48 default:
49 SkASSERT(false); 49 SkASSERT(false);
50 break; 50 break;
51 } 51 }
52 return dstInfo.makeAlphaType(embeddedAlpha); 52 return dstInfo.makeAlphaType(embeddedAlpha);
53 } 53 }
54 54
55 /* 55 /*
56 * Checks the start of the stream to see if the image is an Ico or Cur 56 * Checks the start of the stream to see if the image is an Ico or Cur
57 */ 57 */
58 bool SkIcoCodec::IsIco(SkStream* stream) { 58 bool SkIcoCodec::IsIco(const void* buffer, size_t bytesRead) {
59 const char icoSig[] = { '\x00', '\x00', '\x01', '\x00' }; 59 const char icoSig[] = { '\x00', '\x00', '\x01', '\x00' };
60 const char curSig[] = { '\x00', '\x00', '\x02', '\x00' }; 60 const char curSig[] = { '\x00', '\x00', '\x02', '\x00' };
61 char buffer[sizeof(icoSig)]; 61 return bytesRead >= sizeof(icoSig) &&
62 return stream->read(buffer, sizeof(icoSig)) == sizeof(icoSig) &&
63 (!memcmp(buffer, icoSig, sizeof(icoSig)) || 62 (!memcmp(buffer, icoSig, sizeof(icoSig)) ||
64 !memcmp(buffer, curSig, sizeof(curSig))); 63 !memcmp(buffer, curSig, sizeof(curSig)));
65 } 64 }
66 65
67 /* 66 /*
68 * Assumes IsIco was called and returned true 67 * Assumes IsIco was called and returned true
69 * Creates an Ico decoder 68 * Creates an Ico decoder
70 * Reads enough of the stream to determine the image format 69 * Reads enough of the stream to determine the image format
71 */ 70 */
72 SkCodec* SkIcoCodec::NewFromStream(SkStream* stream) { 71 SkCodec* SkIcoCodec::NewFromStream(SkStream* stream) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 SkAutoTUnref<SkData> data( 168 SkAutoTUnref<SkData> data(
170 SkData::NewFromStream(inputStream.get(), size)); 169 SkData::NewFromStream(inputStream.get(), size));
171 if (nullptr == data.get()) { 170 if (nullptr == data.get()) {
172 SkCodecPrintf("Warning: could not create embedded stream.\n"); 171 SkCodecPrintf("Warning: could not create embedded stream.\n");
173 break; 172 break;
174 } 173 }
175 SkAutoTDelete<SkMemoryStream> embeddedStream(new SkMemoryStream(data.get ())); 174 SkAutoTDelete<SkMemoryStream> embeddedStream(new SkMemoryStream(data.get ()));
176 bytesRead += size; 175 bytesRead += size;
177 176
178 // Check if the embedded codec is bmp or png and create the codec 177 // Check if the embedded codec is bmp or png and create the codec
179 const bool isPng = SkPngCodec::IsPng(embeddedStream);
180 SkAssertResult(embeddedStream->rewind());
181 SkCodec* codec = nullptr; 178 SkCodec* codec = nullptr;
182 if (isPng) { 179 if (SkPngCodec::IsPng((const char*) data->bytes(), data->size())) {
183 codec = SkPngCodec::NewFromStream(embeddedStream.detach()); 180 codec = SkPngCodec::NewFromStream(embeddedStream.detach());
184 } else { 181 } else {
185 codec = SkBmpCodec::NewFromIco(embeddedStream.detach()); 182 codec = SkBmpCodec::NewFromIco(embeddedStream.detach());
186 } 183 }
187 184
188 // Save a valid codec 185 // Save a valid codec
189 if (nullptr != codec) { 186 if (nullptr != codec) {
190 codecs->push_back().reset(codec); 187 codecs->push_back().reset(codec);
191 } 188 }
192 } 189 }
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 SkCodec::SkScanlineOrder SkIcoCodec::onGetScanlineOrder() const { 369 SkCodec::SkScanlineOrder SkIcoCodec::onGetScanlineOrder() const {
373 // FIXME: This function will possibly return the wrong value if it is called 370 // FIXME: This function will possibly return the wrong value if it is called
374 // before startScanlineDecode(). 371 // before startScanlineDecode().
375 return fCurrScanlineCodec ? fCurrScanlineCodec->getScanlineOrder() : 372 return fCurrScanlineCodec ? fCurrScanlineCodec->getScanlineOrder() :
376 INHERITED::onGetScanlineOrder(); 373 INHERITED::onGetScanlineOrder();
377 } 374 }
378 375
379 SkSampler* SkIcoCodec::getSampler(bool createIfNecessary) { 376 SkSampler* SkIcoCodec::getSampler(bool createIfNecessary) {
380 return fCurrScanlineCodec ? fCurrScanlineCodec->getSampler(createIfNecessary ) : nullptr; 377 return fCurrScanlineCodec ? fCurrScanlineCodec->getSampler(createIfNecessary ) : nullptr;
381 } 378 }
OLDNEW
« 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