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

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

Issue 302333002: Initial KTX file decoder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: More code comments Created 6 years, 6 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
« no previous file with comments | « src/images/SkStreamHelpers.h ('k') | tests/ImageDecodingTest.cpp » ('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 2013 Google Inc. 2 * Copyright 2013 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 "SkData.h"
8 #include "SkStream.h" 9 #include "SkStream.h"
9 #include "SkStreamHelpers.h" 10 #include "SkStreamHelpers.h"
10 #include "SkTypes.h" 11 #include "SkTypes.h"
11 12
12 size_t CopyStreamToStorage(SkAutoMalloc* storage, SkStream* stream) { 13 size_t CopyStreamToStorage(SkAutoMalloc* storage, SkStream* stream) {
13 SkASSERT(storage != NULL); 14 SkASSERT(storage != NULL);
14 SkASSERT(stream != NULL); 15 SkASSERT(stream != NULL);
15 16
16 if (stream->hasLength()) { 17 if (stream->hasLength()) {
17 const size_t length = stream->getLength(); 18 const size_t length = stream->getLength();
(...skipping 13 matching lines...) Expand all
31 size_t bytesRead = stream->read(buffer, bufferSize); 32 size_t bytesRead = stream->read(buffer, bufferSize);
32 tempStream.write(buffer, bytesRead); 33 tempStream.write(buffer, bytesRead);
33 SkDEBUGCODE(debugLength += bytesRead); 34 SkDEBUGCODE(debugLength += bytesRead);
34 SkASSERT(tempStream.bytesWritten() == debugLength); 35 SkASSERT(tempStream.bytesWritten() == debugLength);
35 } while (!stream->isAtEnd()); 36 } while (!stream->isAtEnd());
36 const size_t length = tempStream.bytesWritten(); 37 const size_t length = tempStream.bytesWritten();
37 void* dst = storage->reset(length); 38 void* dst = storage->reset(length);
38 tempStream.copyTo(dst); 39 tempStream.copyTo(dst);
39 return length; 40 return length;
40 } 41 }
42
43 SkData *CopyStreamToData(SkStream* stream) {
44 SkASSERT(stream != NULL);
45
46 if (stream->hasLength()) {
47 const size_t length = stream->getLength();
48 void* dst = sk_malloc_throw(length);
49 if (stream->read(dst, length) != length) {
50 return 0;
51 }
52 return SkData::NewFromMalloc(dst, length);
53 }
54
55 SkDynamicMemoryWStream tempStream;
56 // Arbitrary buffer size.
57 const size_t bufferSize = 256 * 1024; // 256KB
58 char buffer[bufferSize];
59 SkDEBUGCODE(size_t debugLength = 0;)
60 do {
61 size_t bytesRead = stream->read(buffer, bufferSize);
62 tempStream.write(buffer, bytesRead);
63 SkDEBUGCODE(debugLength += bytesRead);
64 SkASSERT(tempStream.bytesWritten() == debugLength);
65 } while (!stream->isAtEnd());
66 return tempStream.copyToData();
67 }
OLDNEW
« no previous file with comments | « src/images/SkStreamHelpers.h ('k') | tests/ImageDecodingTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698