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

Side by Side Diff: src/images/SkImageDecoder.cpp

Issue 23330002: Avoid getLength in ico decoder. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 4 months 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 8
9 #include "SkImageDecoder.h" 9 #include "SkImageDecoder.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 if (kUnknown_Format == *format) { 460 if (kUnknown_Format == *format) {
461 if (stream->rewind()) { 461 if (stream->rewind()) {
462 *format = GetStreamFormat(stream); 462 *format = GetStreamFormat(stream);
463 } 463 }
464 } 464 }
465 } 465 }
466 delete codec; 466 delete codec;
467 } 467 }
468 return success; 468 return success;
469 } 469 }
470
471 /**
472 * Copy the provided stream to memory allocated by storage.
473 * Used by SkImageDecoder_libbmp and SkImageDecoder_libico.
474 * @param storage Allocator to hold the memory. Will be reset to be large
475 * enough to hold the entire stream. Upon successful return,
476 * storage->get() will point to data holding the streams entire
477 * contents.
478 * @param stream SkStream to be copied into storage.
479 * @return size_t Total number of bytes in the SkStream, which is also the
480 * number of bytes pointed to by storage->get(). Returns 0 on failure.
481 */
482 size_t copy_stream_to_storage(SkAutoMalloc* storage, SkStream* stream) {
483 SkASSERT(storage != NULL);
484 SkASSERT(stream != NULL);
485
486 if (stream->hasLength()) {
487 const size_t length = stream->getLength();
488 void* dst = storage->reset(length);
489 if (stream->read(dst, length) != length) {
490 return 0;
491 }
492 return length;
493 }
494
495 SkDynamicMemoryWStream tempStream;
496 // Arbitrary buffer size.
497 const size_t bufferSize = 256 * 1024; // 256KB
498 char buffer[bufferSize];
499 SkDEBUGCODE(size_t debugLength = 0;)
500 do {
501 size_t bytesRead = stream->read(buffer, bufferSize);
502 tempStream.write(buffer, bytesRead);
503 SkDEBUGCODE(debugLength += bytesRead);
504 SkASSERT(tempStream.bytesWritten() == debugLength);
505 } while (!stream->isAtEnd());
506 const size_t length = tempStream.bytesWritten();
507 void* dst = storage->reset(length);
508 tempStream.copyTo(dst);
509 return length;
510 }
OLDNEW
« no previous file with comments | « no previous file | src/images/SkImageDecoder_libbmp.cpp » ('j') | src/images/SkImageDecoder_libbmp.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698