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 #ifdef SK_CODEC_DECODES_RAW | |
93 // Try to treat the input as RAW if all the other checks failed. | |
94 if (streamDeleter) { | |
scroggo
2016/01/20 19:47:16
When you rebase, we have removed the variable "cod
yujieqin
2016/01/20 21:46:45
Sorry, as I am not really using git before, I have
yujieqin
2016/01/21 16:40:01
Thanks for the tips. I got the code rebase and fix
| |
95 SkASSERT(!codec); | |
96 codec.reset(SkRawCodec::NewFromStream(streamDeleter.detach())); | |
97 } | |
98 #endif | |
88 } | 99 } |
89 | 100 |
90 // Set the max size at 128 megapixels (512 MB for kN32). | 101 // 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 | 102 // This is about 4x smaller than a test image that takes a few minutes for |
92 // dm to decode and draw. | 103 // dm to decode and draw. |
93 const int32_t maxSize = 1 << 27; | 104 const int32_t maxSize = 1 << 27; |
94 if (codec && codec->getInfo().width() * codec->getInfo().height() > maxSize) { | 105 if (codec && codec->getInfo().width() * codec->getInfo().height() > maxSize) { |
95 SkCodecPrintf("Error: Image size too large, cannot decode.\n"); | 106 SkCodecPrintf("Error: Image size too large, cannot decode.\n"); |
96 return nullptr; | 107 return nullptr; |
97 } else { | 108 } else { |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
374 SkASSERT(1 == linesRequested || this->getInfo().height() == linesReq uested); | 385 SkASSERT(1 == linesRequested || this->getInfo().height() == linesReq uested); |
375 const SkImageInfo fillInfo = info.makeWH(info.width(), 1); | 386 const SkImageInfo fillInfo = info.makeWH(info.width(), 1); |
376 for (int srcY = linesDecoded; srcY < linesRequested; srcY++) { | 387 for (int srcY = linesDecoded; srcY < linesRequested; srcY++) { |
377 fillDst = SkTAddOffset<void>(dst, this->outputScanline(srcY) * r owBytes); | 388 fillDst = SkTAddOffset<void>(dst, this->outputScanline(srcY) * r owBytes); |
378 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, samp ler); | 389 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, samp ler); |
379 } | 390 } |
380 break; | 391 break; |
381 } | 392 } |
382 } | 393 } |
383 } | 394 } |
OLD | NEW |