Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: src/codec/SkCodec.cpp

Issue 1022673011: Creating a new wrapper for gif decoder (Closed) Base URL: https://skia.googlesource.com/skia.git@ico-real
Patch Set: Second set of fixes to gif codec Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gyp/codec.gyp ('k') | src/codec/SkCodec_libgif.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
14 #include "SkCodecPriv.h"
13 #include "SkStream.h" 15 #include "SkStream.h"
14 16
15 struct DecoderProc { 17 struct DecoderProc {
16 bool (*IsFormat)(SkStream*); 18 bool (*IsFormat)(SkStream*);
17 SkCodec* (*NewFromStream)(SkStream*); 19 SkCodec* (*NewFromStream)(SkStream*);
18 }; 20 };
19 21
20 static const DecoderProc gDecoderProcs[] = { 22 static const DecoderProc gDecoderProcs[] = {
21 { SkPngCodec::IsPng, SkPngCodec::NewFromStream }, 23 { SkPngCodec::IsPng, SkPngCodec::NewFromStream },
22 { SkIcoCodec::IsIco, SkIcoCodec::NewFromStream }, 24 { SkGifCodec::IsGif, SkGifCodec::NewFromStream },
23 { SkBmpCodec::IsBmp, SkBmpCodec::NewFromStream } 25 { SkBmpCodec::IsBmp, SkBmpCodec::NewFromStream },
26 { SkIcoCodec::IsIco, SkIcoCodec::NewFromStream }
24 }; 27 };
25 28
26 SkCodec* SkCodec::NewFromStream(SkStream* stream) { 29 SkCodec* SkCodec::NewFromStream(SkStream* stream) {
27 if (!stream) { 30 if (!stream) {
28 return NULL; 31 return NULL;
29 } 32 }
33
34 SkCodec* codec;
30 for (uint32_t i = 0; i < SK_ARRAY_COUNT(gDecoderProcs); i++) { 35 for (uint32_t i = 0; i < SK_ARRAY_COUNT(gDecoderProcs); i++) {
31 DecoderProc proc = gDecoderProcs[i]; 36 DecoderProc proc = gDecoderProcs[i];
32 const bool correctFormat = proc.IsFormat(stream); 37 const bool correctFormat = proc.IsFormat(stream);
33 if (!stream->rewind()) { 38 if (!stream->rewind()) {
34 return NULL; 39 return NULL;
35 } 40 }
36 if (correctFormat) { 41 if (correctFormat) {
37 return proc.NewFromStream(stream); 42 codec = proc.NewFromStream(stream);
43 break;
38 } 44 }
39 } 45 }
40 return NULL; 46
47 // Set the max size at 128 MP (512 MB for kN32).
scroggo 2015/03/27 13:09:36 mega pixel?
msarett 2015/03/27 14:23:20 Haha yeah. I actually googled "megapixel" to find
48 // This is about 4x smaller than a test image that takes a few minutes to
49 // draw.
scroggo 2015/03/27 13:09:36 decode?
msarett 2015/03/27 14:23:19 This is the test with the very, very large frame s
50 const int32_t maxSize = 1 << 27;
51 if (codec != NULL &&
52 codec->getInfo().width() * codec->getInfo().height() > maxSize) {
53 SkCodecPrintf("Error: Image size too large, cannot decode.\n");
54 return NULL;
55 } else {
56 return codec;
57 }
41 } 58 }
42 59
43 SkCodec* SkCodec::NewFromData(SkData* data) { 60 SkCodec* SkCodec::NewFromData(SkData* data) {
44 if (!data) { 61 if (!data) {
45 return NULL; 62 return NULL;
46 } 63 }
47 return NewFromStream(SkNEW_ARGS(SkMemoryStream, (data))); 64 return NewFromStream(SkNEW_ARGS(SkMemoryStream, (data)));
48 } 65 }
49 66
50 SkCodec::SkCodec(const SkImageInfo& info, SkStream* stream) 67 SkCodec::SkCodec(const SkImageInfo& info, SkStream* stream)
(...skipping 14 matching lines...) Expand all
65 } 82 }
66 83
67 SkScanlineDecoder* SkCodec::getScanlineDecoder(const SkImageInfo& dstInfo) { 84 SkScanlineDecoder* SkCodec::getScanlineDecoder(const SkImageInfo& dstInfo) {
68 fScanlineDecoder.reset(NULL); 85 fScanlineDecoder.reset(NULL);
69 if (!rewindIfNeeded()) { 86 if (!rewindIfNeeded()) {
70 return NULL; 87 return NULL;
71 } 88 }
72 fScanlineDecoder.reset(this->onGetScanlineDecoder(dstInfo)); 89 fScanlineDecoder.reset(this->onGetScanlineDecoder(dstInfo));
73 return fScanlineDecoder.get(); 90 return fScanlineDecoder.get();
74 } 91 }
OLDNEW
« no previous file with comments | « gyp/codec.gyp ('k') | src/codec/SkCodec_libgif.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698