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" |
11 #include "SkCodec_libgif.h" | 11 #include "SkCodec_libgif.h" |
12 #include "SkCodec_libico.h" | 12 #include "SkCodec_libico.h" |
13 #include "SkCodec_libpng.h" | 13 #include "SkCodec_libpng.h" |
14 #include "SkCodec_wbmp.h" | 14 #include "SkCodec_wbmp.h" |
15 #include "SkCodecPriv.h" | 15 #include "SkCodecPriv.h" |
16 #if !defined(GOOGLE3) | 16 #if !defined(GOOGLE3) |
17 #include "SkJpegCodec.h" | 17 #include "SkJpegCodec.h" |
18 #endif | 18 #endif |
19 #ifdef SK_CODEC_DECODES_RAW | |
20 #include "SkRawCodec.h" | |
21 #endif | |
19 #include "SkStream.h" | 22 #include "SkStream.h" |
20 #include "SkWebpCodec.h" | 23 #include "SkWebpCodec.h" |
21 | 24 |
22 struct DecoderProc { | 25 struct DecoderProc { |
23 bool (*IsFormat)(const void*, size_t); | 26 bool (*IsFormat)(const void*, size_t); |
24 SkCodec* (*NewFromStream)(SkStream*); | 27 SkCodec* (*NewFromStream)(SkStream*); |
25 }; | 28 }; |
26 | 29 |
27 static const DecoderProc gDecoderProcs[] = { | 30 static const DecoderProc gDecoderProcs[] = { |
28 #if !defined(GOOGLE3) | 31 #if !defined(GOOGLE3) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 { |
82 for (DecoderProc proc : gDecoderProcs) { | 85 for (DecoderProc proc : gDecoderProcs) { |
83 if (proc.IsFormat(buffer, bytesRead)) { | 86 if (proc.IsFormat(buffer, bytesRead)) { |
84 codec.reset(proc.NewFromStream(streamDeleter.detach())); | 87 codec.reset(proc.NewFromStream(streamDeleter.detach())); |
85 break; | 88 break; |
86 } | 89 } |
87 } | 90 } |
91 | |
92 // Try to treat the input as RAW if all the other checks failed. | |
93 if (!codec && streamDeleter) { | |
msarett
2016/01/07 16:39:11
We check streamDeleter here because one of the oth
scroggo
2016/01/07 20:57:42
I think this is redundant.
If codec is NULL, stre
yujieqin
2016/01/08 14:00:12
msarett@, yes, we run into once this issue that ot
scroggo
2016/01/08 17:12:25
My mistake. It is possible that the first few byte
| |
94 #ifdef SK_CODEC_DECODES_RAW | |
msarett
2016/01/07 16:39:11
nit: Can we surround the entire if statement with
yujieqin
2016/01/08 14:00:12
Done.
| |
95 codec.reset(SkRawCodec::NewFromStream(streamDeleter.detach())); | |
96 #endif | |
97 } | |
88 } | 98 } |
89 | 99 |
90 // Set the max size at 128 megapixels (512 MB for kN32). | 100 // Set the max size at 128 megapixels (512 MB for kN32). |
91 // This is about 4x smaller than a test image that takes a few minutes for | 101 // This is about 4x smaller than a test image that takes a few minutes for |
92 // dm to decode and draw. | 102 // dm to decode and draw. |
93 const int32_t maxSize = 1 << 27; | 103 const int32_t maxSize = 1 << 27; |
94 if (codec && codec->getInfo().width() * codec->getInfo().height() > maxSize) { | 104 if (codec && codec->getInfo().width() * codec->getInfo().height() > maxSize) { |
95 SkCodecPrintf("Error: Image size too large, cannot decode.\n"); | 105 SkCodecPrintf("Error: Image size too large, cannot decode.\n"); |
96 return nullptr; | 106 return nullptr; |
97 } else { | 107 } else { |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
374 SkASSERT(1 == linesRequested || this->getInfo().height() == linesReq uested); | 384 SkASSERT(1 == linesRequested || this->getInfo().height() == linesReq uested); |
375 const SkImageInfo fillInfo = info.makeWH(info.width(), 1); | 385 const SkImageInfo fillInfo = info.makeWH(info.width(), 1); |
376 for (int srcY = linesDecoded; srcY < linesRequested; srcY++) { | 386 for (int srcY = linesDecoded; srcY < linesRequested; srcY++) { |
377 fillDst = SkTAddOffset<void>(dst, this->outputScanline(srcY) * r owBytes); | 387 fillDst = SkTAddOffset<void>(dst, this->outputScanline(srcY) * r owBytes); |
378 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, samp ler); | 388 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, samp ler); |
379 } | 389 } |
380 break; | 390 break; |
381 } | 391 } |
382 } | 392 } |
383 } | 393 } |
OLD | NEW |