| 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 "SkCodec_libpng.h" | 10 #include "SkCodec_libpng.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 // 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 |
| 70 // rewinding. | 70 // rewinding. |
| 71 // 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. |
| 72 bytesRead = stream->read(buffer, bytesToRead); | 72 bytesRead = stream->read(buffer, bytesToRead); |
| 73 if (!stream->rewind()) { | 73 if (!stream->rewind()) { |
| 74 SkCodecPrintf("Encoded image data could not peek or rewind to determ
ine format!\n"); | 74 SkCodecPrintf("Encoded image data could not peek or rewind to determ
ine format!\n"); |
| 75 return nullptr; | 75 return nullptr; |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 | 78 |
| 79 SkAutoTDelete<SkCodec> codec(nullptr); | |
| 80 // PNG is special, since we want to be able to supply an SkPngChunkReader. | 79 // PNG is special, since we want to be able to supply an SkPngChunkReader. |
| 81 // But this code follows the same pattern as the loop. | 80 // But this code follows the same pattern as the loop. |
| 82 if (SkPngCodec::IsPng(buffer, bytesRead)) { | 81 if (SkPngCodec::IsPng(buffer, bytesRead)) { |
| 83 codec.reset(SkPngCodec::NewFromStream(streamDeleter.detach(), chunkReade
r)); | 82 return SkPngCodec::NewFromStream(streamDeleter.detach(), chunkReader); |
| 84 } else { | 83 } else { |
| 85 for (DecoderProc proc : gDecoderProcs) { | 84 for (DecoderProc proc : gDecoderProcs) { |
| 86 if (proc.IsFormat(buffer, bytesRead)) { | 85 if (proc.IsFormat(buffer, bytesRead)) { |
| 87 codec.reset(proc.NewFromStream(streamDeleter.detach())); | 86 return proc.NewFromStream(streamDeleter.detach()); |
| 88 break; | |
| 89 } | 87 } |
| 90 } | 88 } |
| 91 } | 89 } |
| 92 | 90 |
| 93 // Set the max size at 128 megapixels (512 MB for kN32). | 91 return nullptr; |
| 94 // This is about 4x smaller than a test image that takes a few minutes for | |
| 95 // dm to decode and draw. | |
| 96 const int32_t maxSize = 1 << 27; | |
| 97 if (codec && codec->getInfo().width() * codec->getInfo().height() > maxSize)
{ | |
| 98 SkCodecPrintf("Error: Image size too large, cannot decode.\n"); | |
| 99 return nullptr; | |
| 100 } else { | |
| 101 return codec.detach(); | |
| 102 } | |
| 103 } | 92 } |
| 104 | 93 |
| 105 SkCodec* SkCodec::NewFromData(SkData* data, SkPngChunkReader* reader) { | 94 SkCodec* SkCodec::NewFromData(SkData* data, SkPngChunkReader* reader) { |
| 106 if (!data) { | 95 if (!data) { |
| 107 return nullptr; | 96 return nullptr; |
| 108 } | 97 } |
| 109 return NewFromStream(new SkMemoryStream(data), reader); | 98 return NewFromStream(new SkMemoryStream(data), reader); |
| 110 } | 99 } |
| 111 | 100 |
| 112 SkCodec::SkCodec(const SkImageInfo& info, SkStream* stream) | 101 SkCodec::SkCodec(const SkImageInfo& info, SkStream* stream) |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 SkASSERT(1 == linesRequested || this->getInfo().height() == linesReq
uested); | 366 SkASSERT(1 == linesRequested || this->getInfo().height() == linesReq
uested); |
| 378 const SkImageInfo fillInfo = info.makeWH(info.width(), 1); | 367 const SkImageInfo fillInfo = info.makeWH(info.width(), 1); |
| 379 for (int srcY = linesDecoded; srcY < linesRequested; srcY++) { | 368 for (int srcY = linesDecoded; srcY < linesRequested; srcY++) { |
| 380 fillDst = SkTAddOffset<void>(dst, this->outputScanline(srcY) * r
owBytes); | 369 fillDst = SkTAddOffset<void>(dst, this->outputScanline(srcY) * r
owBytes); |
| 381 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, samp
ler); | 370 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, samp
ler); |
| 382 } | 371 } |
| 383 break; | 372 break; |
| 384 } | 373 } |
| 385 } | 374 } |
| 386 } | 375 } |
| OLD | NEW |