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

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

Issue 1040453002: Add SkPngChunkReader. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update SkImageDecoder_empty Created 5 years 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 | « include/core/SkPngChunkReader.h ('k') | src/codec/SkCodec_libpng.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 "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 21
22 struct DecoderProc { 22 struct DecoderProc {
23 bool (*IsFormat)(SkStream*); 23 bool (*IsFormat)(SkStream*);
24 SkCodec* (*NewFromStream)(SkStream*); 24 SkCodec* (*NewFromStream)(SkStream*);
25 }; 25 };
26 26
27 static const DecoderProc gDecoderProcs[] = { 27 static const DecoderProc gDecoderProcs[] = {
28 { SkPngCodec::IsPng, SkPngCodec::NewFromStream },
29 #if !defined(GOOGLE3) 28 #if !defined(GOOGLE3)
30 { SkJpegCodec::IsJpeg, SkJpegCodec::NewFromStream }, 29 { SkJpegCodec::IsJpeg, SkJpegCodec::NewFromStream },
31 #endif 30 #endif
32 { SkWebpCodec::IsWebp, SkWebpCodec::NewFromStream }, 31 { SkWebpCodec::IsWebp, SkWebpCodec::NewFromStream },
33 { SkGifCodec::IsGif, SkGifCodec::NewFromStream }, 32 { SkGifCodec::IsGif, SkGifCodec::NewFromStream },
34 { SkIcoCodec::IsIco, SkIcoCodec::NewFromStream }, 33 { SkIcoCodec::IsIco, SkIcoCodec::NewFromStream },
35 { SkBmpCodec::IsBmp, SkBmpCodec::NewFromStream }, 34 { SkBmpCodec::IsBmp, SkBmpCodec::NewFromStream },
36 { SkWbmpCodec::IsWbmp, SkWbmpCodec::NewFromStream } 35 { SkWbmpCodec::IsWbmp, SkWbmpCodec::NewFromStream }
37 }; 36 };
38 37
39 SkCodec* SkCodec::NewFromStream(SkStream* stream) { 38 SkCodec* SkCodec::NewFromStream(SkStream* stream,
39 SkPngChunkReader* chunkReader) {
40 if (!stream) { 40 if (!stream) {
41 return nullptr; 41 return nullptr;
42 } 42 }
43 43
44 SkAutoTDelete<SkStream> streamDeleter(stream); 44 SkAutoTDelete<SkStream> streamDeleter(stream);
45 45
46 SkAutoTDelete<SkCodec> codec(nullptr); 46 SkAutoTDelete<SkCodec> codec(nullptr);
47 for (uint32_t i = 0; i < SK_ARRAY_COUNT(gDecoderProcs); i++) { 47 // PNG is special, since we want to be able to supply an SkPngChunkReader.
48 DecoderProc proc = gDecoderProcs[i]; 48 // But this code follows the same pattern as the loop.
49 const bool correctFormat = proc.IsFormat(stream); 49 const bool isPng = SkPngCodec::IsPng(stream);
50 if (!stream->rewind()) { 50 if (!stream->rewind()) {
51 return nullptr; 51 return NULL;
52 } 52 }
53 if (correctFormat) { 53 if (isPng) {
54 codec.reset(proc.NewFromStream(streamDeleter.detach())); 54 codec.reset(SkPngCodec::NewFromStream(streamDeleter.detach(), chunkReade r));
55 break; 55 } else {
56 for (DecoderProc proc : gDecoderProcs) {
57 const bool correctFormat = proc.IsFormat(stream);
58 if (!stream->rewind()) {
59 return nullptr;
60 }
61 if (correctFormat) {
62 codec.reset(proc.NewFromStream(streamDeleter.detach()));
63 break;
64 }
56 } 65 }
57 } 66 }
58 67
59 // Set the max size at 128 megapixels (512 MB for kN32). 68 // Set the max size at 128 megapixels (512 MB for kN32).
60 // This is about 4x smaller than a test image that takes a few minutes for 69 // This is about 4x smaller than a test image that takes a few minutes for
61 // dm to decode and draw. 70 // dm to decode and draw.
62 const int32_t maxSize = 1 << 27; 71 const int32_t maxSize = 1 << 27;
63 if (codec && codec->getInfo().width() * codec->getInfo().height() > maxSize) { 72 if (codec && codec->getInfo().width() * codec->getInfo().height() > maxSize) {
64 SkCodecPrintf("Error: Image size too large, cannot decode.\n"); 73 SkCodecPrintf("Error: Image size too large, cannot decode.\n");
65 return nullptr; 74 return nullptr;
66 } else { 75 } else {
67 return codec.detach(); 76 return codec.detach();
68 } 77 }
69 } 78 }
70 79
71 SkCodec* SkCodec::NewFromData(SkData* data) { 80 SkCodec* SkCodec::NewFromData(SkData* data, SkPngChunkReader* reader) {
72 if (!data) { 81 if (!data) {
73 return nullptr; 82 return nullptr;
74 } 83 }
75 return NewFromStream(new SkMemoryStream(data)); 84 return NewFromStream(new SkMemoryStream(data), reader);
76 } 85 }
77 86
78 SkCodec::SkCodec(const SkImageInfo& info, SkStream* stream) 87 SkCodec::SkCodec(const SkImageInfo& info, SkStream* stream)
79 : fSrcInfo(info) 88 : fSrcInfo(info)
80 , fStream(stream) 89 , fStream(stream)
81 , fNeedsRewind(false) 90 , fNeedsRewind(false)
82 , fDstInfo() 91 , fDstInfo()
83 , fOptions() 92 , fOptions()
84 , fCurrScanline(-1) 93 , fCurrScanline(-1)
85 {} 94 {}
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 SkASSERT(1 == linesRequested || this->getInfo().height() == linesReq uested); 352 SkASSERT(1 == linesRequested || this->getInfo().height() == linesReq uested);
344 const SkImageInfo fillInfo = info.makeWH(info.width(), 1); 353 const SkImageInfo fillInfo = info.makeWH(info.width(), 1);
345 for (int srcY = linesDecoded; srcY < linesRequested; srcY++) { 354 for (int srcY = linesDecoded; srcY < linesRequested; srcY++) {
346 fillDst = SkTAddOffset<void>(dst, this->outputScanline(srcY) * r owBytes); 355 fillDst = SkTAddOffset<void>(dst, this->outputScanline(srcY) * r owBytes);
347 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, samp ler); 356 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, samp ler);
348 } 357 }
349 break; 358 break;
350 } 359 }
351 } 360 }
352 } 361 }
OLDNEW
« no previous file with comments | « include/core/SkPngChunkReader.h ('k') | src/codec/SkCodec_libpng.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698