Chromium Code Reviews| 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 "SkCodec.h" | 8 #include "SkCodec.h" |
| 9 #include "SkData.h" | 9 #include "SkData.h" |
| 10 #include "SkCodec_libbmp.h" | 10 #include "SkCodec_libbmp.h" |
| 11 #include "SkCodec_libgif.h" | |
| 11 #include "SkCodec_libico.h" | 12 #include "SkCodec_libico.h" |
| 12 #include "SkCodec_libpng.h" | 13 #include "SkCodec_libpng.h" |
| 13 #include "SkStream.h" | 14 #include "SkStream.h" |
| 14 | 15 |
| 15 struct DecoderProc { | 16 struct DecoderProc { |
| 16 bool (*IsFormat)(SkStream*); | 17 bool (*IsFormat)(SkStream*); |
| 17 SkCodec* (*NewFromStream)(SkStream*); | 18 SkCodec* (*NewFromStream)(SkStream*); |
| 18 }; | 19 }; |
| 19 | 20 |
| 20 static const DecoderProc gDecoderProcs[] = { | 21 static const DecoderProc gDecoderProcs[] = { |
| 21 { SkPngCodec::IsPng, SkPngCodec::NewFromStream }, | 22 { SkPngCodec::IsPng, SkPngCodec::NewFromStream }, |
| 22 { SkIcoCodec::IsIco, SkIcoCodec::NewFromStream }, | 23 { SkGifCodec::IsGif, SkGifCodec::NewFromStream }, |
| 23 { SkBmpCodec::IsBmp, SkBmpCodec::NewFromStream } | 24 { SkBmpCodec::IsBmp, SkBmpCodec::NewFromStream }, |
| 25 { SkIcoCodec::IsIco, SkIcoCodec::NewFromStream } | |
| 24 }; | 26 }; |
| 25 | 27 |
| 26 SkCodec* SkCodec::NewFromStream(SkStream* stream) { | 28 SkCodec* SkCodec::NewFromStream(SkStream* stream) { |
| 27 if (!stream) { | 29 if (!stream) { |
| 28 return NULL; | 30 return NULL; |
| 29 } | 31 } |
| 32 | |
| 33 SkCodec* codec; | |
| 30 for (uint32_t i = 0; i < SK_ARRAY_COUNT(gDecoderProcs); i++) { | 34 for (uint32_t i = 0; i < SK_ARRAY_COUNT(gDecoderProcs); i++) { |
| 31 DecoderProc proc = gDecoderProcs[i]; | 35 DecoderProc proc = gDecoderProcs[i]; |
| 32 const bool correctFormat = proc.IsFormat(stream); | 36 const bool correctFormat = proc.IsFormat(stream); |
| 33 if (!stream->rewind()) { | 37 if (!stream->rewind()) { |
| 34 return NULL; | 38 return NULL; |
| 35 } | 39 } |
| 36 if (correctFormat) { | 40 if (correctFormat) { |
| 37 return proc.NewFromStream(stream); | 41 codec = proc.NewFromStream(stream); |
| 42 break; | |
| 38 } | 43 } |
| 39 } | 44 } |
| 40 return NULL; | 45 |
| 46 // TODO: Is this the correct maxSize? This is 512 MB for kN32. | |
|
scroggo
2015/03/26 20:03:53
Maybe explain why it was chosen?
msarett
2015/03/26 22:26:36
Done.
| |
| 47 const int32_t maxSize = 1 << 27; | |
| 48 if (codec->getInfo().width() * codec->getInfo().height() > maxSize) { | |
|
scroggo
2015/03/26 20:03:53
We need to check codec for NULL.
msarett
2015/03/26 22:26:36
Done.
| |
| 49 SkDebugf("Error: Image size too large, cannot decode.\n"); | |
|
scroggo
2015/03/26 20:03:53
Use SkCodecPrintf.
msarett
2015/03/26 22:26:36
Done.
| |
| 50 return NULL; | |
| 51 } else { | |
| 52 return codec; | |
| 53 } | |
| 41 } | 54 } |
| 42 | 55 |
| 43 SkCodec* SkCodec::NewFromData(SkData* data) { | 56 SkCodec* SkCodec::NewFromData(SkData* data) { |
| 44 if (!data) { | 57 if (!data) { |
| 45 return NULL; | 58 return NULL; |
| 46 } | 59 } |
| 47 return NewFromStream(SkNEW_ARGS(SkMemoryStream, (data))); | 60 return NewFromStream(SkNEW_ARGS(SkMemoryStream, (data))); |
| 48 } | 61 } |
| 49 | 62 |
| 50 SkCodec::SkCodec(const SkImageInfo& info, SkStream* stream) | 63 SkCodec::SkCodec(const SkImageInfo& info, SkStream* stream) |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 65 } | 78 } |
| 66 | 79 |
| 67 SkScanlineDecoder* SkCodec::getScanlineDecoder(const SkImageInfo& dstInfo) { | 80 SkScanlineDecoder* SkCodec::getScanlineDecoder(const SkImageInfo& dstInfo) { |
| 68 fScanlineDecoder.reset(NULL); | 81 fScanlineDecoder.reset(NULL); |
| 69 if (!rewindIfNeeded()) { | 82 if (!rewindIfNeeded()) { |
| 70 return NULL; | 83 return NULL; |
| 71 } | 84 } |
| 72 fScanlineDecoder.reset(this->onGetScanlineDecoder(dstInfo)); | 85 fScanlineDecoder.reset(this->onGetScanlineDecoder(dstInfo)); |
| 73 return fScanlineDecoder.get(); | 86 return fScanlineDecoder.get(); |
| 74 } | 87 } |
| OLD | NEW |