OLD | NEW |
---|---|
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.h" | 9 #include "SkCodec.h" |
10 #include "SkData.h" | 10 #include "SkData.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 size_t bytesRead = stream->peek(buffer, bytesToRead); | 55 size_t bytesRead = stream->peek(buffer, bytesToRead); |
56 | 56 |
57 // It is also possible to have a complete image less than bytesToRead bytes | 57 // It is also possible to have a complete image less than bytesToRead bytes |
58 // (e.g. a 1 x 1 wbmp), meaning peek() would return less than bytesToRead. | 58 // (e.g. a 1 x 1 wbmp), meaning peek() would return less than bytesToRead. |
59 // Assume that if bytesRead < bytesToRead, but > 0, the stream is shorter | 59 // Assume that if bytesRead < bytesToRead, but > 0, the stream is shorter |
60 // than bytesToRead, so pass that directly to the decoder. | 60 // than bytesToRead, so pass that directly to the decoder. |
61 // It also is possible the stream uses too small a buffer for peeking, but | 61 // It also is possible the stream uses too small a buffer for peeking, but |
62 // we trust the caller to use a large enough buffer. | 62 // we trust the caller to use a large enough buffer. |
63 | 63 |
64 if (0 == bytesRead) { | 64 if (0 == bytesRead) { |
65 SkCodecPrintf("Could not peek!\n"); | 65 // TODO: After implementing peek in CreateJavaOutputStreamAdaptor.cpp, t his |
66 // printf could be useful to notice failures. | |
67 // SkCodecPrintf("Encoded image data failed to peek!\n"); | |
68 | |
66 // It is possible the stream does not support peeking, but does support | 69 // It is possible the stream does not support peeking, but does support |
67 // rewinding. | 70 // rewinding. |
68 // Attempt to read() and pass the actual amount read to the decoder. | 71 // Attempt to read() and pass the actual amount read to the decoder. |
69 bytesRead = stream->read(buffer, bytesToRead); | 72 bytesRead = stream->read(buffer, bytesToRead); |
70 if (!stream->rewind()) { | 73 if (!stream->rewind()) { |
71 SkCodecPrintf("Could not rewind!\n"); | 74 SkCodecPrintf("Encoded image data could not peek or rewind to determ ine format!\n"); |
scroggo
2016/01/06 16:57:52
I could imagine making SkCodecPrintf add something
msarett
2016/01/06 17:11:27
Yes I agree.
| |
72 return nullptr; | 75 return nullptr; |
73 } | 76 } |
74 } | 77 } |
75 | 78 |
76 SkAutoTDelete<SkCodec> codec(nullptr); | 79 SkAutoTDelete<SkCodec> codec(nullptr); |
77 // PNG is special, since we want to be able to supply an SkPngChunkReader. | 80 // PNG is special, since we want to be able to supply an SkPngChunkReader. |
78 // But this code follows the same pattern as the loop. | 81 // But this code follows the same pattern as the loop. |
79 if (SkPngCodec::IsPng(buffer, bytesRead)) { | 82 if (SkPngCodec::IsPng(buffer, bytesRead)) { |
80 codec.reset(SkPngCodec::NewFromStream(streamDeleter.detach(), chunkReade r)); | 83 codec.reset(SkPngCodec::NewFromStream(streamDeleter.detach(), chunkReade r)); |
81 } else { | 84 } else { |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
374 SkASSERT(1 == linesRequested || this->getInfo().height() == linesReq uested); | 377 SkASSERT(1 == linesRequested || this->getInfo().height() == linesReq uested); |
375 const SkImageInfo fillInfo = info.makeWH(info.width(), 1); | 378 const SkImageInfo fillInfo = info.makeWH(info.width(), 1); |
376 for (int srcY = linesDecoded; srcY < linesRequested; srcY++) { | 379 for (int srcY = linesDecoded; srcY < linesRequested; srcY++) { |
377 fillDst = SkTAddOffset<void>(dst, this->outputScanline(srcY) * r owBytes); | 380 fillDst = SkTAddOffset<void>(dst, this->outputScanline(srcY) * r owBytes); |
378 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, samp ler); | 381 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, samp ler); |
379 } | 382 } |
380 break; | 383 break; |
381 } | 384 } |
382 } | 385 } |
383 } | 386 } |
OLD | NEW |