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 #include "SkStream.h" | 19 #include "SkStream.h" |
20 #include "SkWebpCodec.h" | 20 #include "SkWebpCodec.h" |
21 #include "SkRawCodec.h" | |
21 | 22 |
22 struct DecoderProc { | 23 struct DecoderProc { |
23 bool (*IsFormat)(const void*, size_t); | 24 bool (*IsFormat)(const void*, size_t); |
24 SkCodec* (*NewFromStream)(SkStream*); | 25 SkCodec* (*NewFromStream)(SkStream*); |
25 }; | 26 }; |
26 | 27 |
27 static const DecoderProc gDecoderProcs[] = { | 28 static const DecoderProc gDecoderProcs[] = { |
28 #if !defined(GOOGLE3) | 29 #if !defined(GOOGLE3) |
29 { SkJpegCodec::IsJpeg, SkJpegCodec::NewFromStream }, | 30 { SkJpegCodec::IsJpeg, SkJpegCodec::NewFromStream }, |
30 #endif | 31 #endif |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 // But this code follows the same pattern as the loop. | 79 // But this code follows the same pattern as the loop. |
79 if (SkPngCodec::IsPng(buffer, bytesRead)) { | 80 if (SkPngCodec::IsPng(buffer, bytesRead)) { |
80 codec.reset(SkPngCodec::NewFromStream(streamDeleter.detach(), chunkReade r)); | 81 codec.reset(SkPngCodec::NewFromStream(streamDeleter.detach(), chunkReade r)); |
81 } else { | 82 } else { |
82 for (DecoderProc proc : gDecoderProcs) { | 83 for (DecoderProc proc : gDecoderProcs) { |
83 if (proc.IsFormat(buffer, bytesRead)) { | 84 if (proc.IsFormat(buffer, bytesRead)) { |
84 codec.reset(proc.NewFromStream(streamDeleter.detach())); | 85 codec.reset(proc.NewFromStream(streamDeleter.detach())); |
85 break; | 86 break; |
86 } | 87 } |
87 } | 88 } |
89 | |
90 // Try to treat the input as RAW. | |
91 codec.reset(SkRawCodec::NewFromStream(streamDeleter.detach())); | |
scroggo
2016/01/06 22:30:20
I think you need to first check that codec is NULL
yujieqin
2016/01/07 09:22:25
Oh, you are right!
| |
88 } | 92 } |
89 | 93 |
90 // Set the max size at 128 megapixels (512 MB for kN32). | 94 // 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 | 95 // This is about 4x smaller than a test image that takes a few minutes for |
92 // dm to decode and draw. | 96 // dm to decode and draw. |
93 const int32_t maxSize = 1 << 27; | 97 const int32_t maxSize = 1 << 27; |
94 if (codec && codec->getInfo().width() * codec->getInfo().height() > maxSize) { | 98 if (codec && codec->getInfo().width() * codec->getInfo().height() > maxSize) { |
95 SkCodecPrintf("Error: Image size too large, cannot decode.\n"); | 99 SkCodecPrintf("Error: Image size too large, cannot decode.\n"); |
96 return nullptr; | 100 return nullptr; |
97 } else { | 101 } else { |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
374 SkASSERT(1 == linesRequested || this->getInfo().height() == linesReq uested); | 378 SkASSERT(1 == linesRequested || this->getInfo().height() == linesReq uested); |
375 const SkImageInfo fillInfo = info.makeWH(info.width(), 1); | 379 const SkImageInfo fillInfo = info.makeWH(info.width(), 1); |
376 for (int srcY = linesDecoded; srcY < linesRequested; srcY++) { | 380 for (int srcY = linesDecoded; srcY < linesRequested; srcY++) { |
377 fillDst = SkTAddOffset<void>(dst, this->outputScanline(srcY) * r owBytes); | 381 fillDst = SkTAddOffset<void>(dst, this->outputScanline(srcY) * r owBytes); |
378 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, samp ler); | 382 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, samp ler); |
379 } | 383 } |
380 break; | 384 break; |
381 } | 385 } |
382 } | 386 } |
383 } | 387 } |
OLD | NEW |