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

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

Issue 1520403003: Prototype of RAW decoding in Skia. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Initial upload of the Prototype. 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
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 #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
31 { SkWebpCodec::IsWebp, SkWebpCodec::NewFromStream }, 32 { SkWebpCodec::IsWebp, SkWebpCodec::NewFromStream },
32 { SkGifCodec::IsGif, SkGifCodec::NewFromStream }, 33 { SkGifCodec::IsGif, SkGifCodec::NewFromStream },
33 { SkIcoCodec::IsIco, SkIcoCodec::NewFromStream }, 34 { SkIcoCodec::IsIco, SkIcoCodec::NewFromStream },
34 { SkBmpCodec::IsBmp, SkBmpCodec::NewFromStream }, 35 { SkBmpCodec::IsBmp, SkBmpCodec::NewFromStream },
35 { SkWbmpCodec::IsWbmp, SkWbmpCodec::NewFromStream } 36 { SkWbmpCodec::IsWbmp, SkWbmpCodec::NewFromStream }
36 }; 37 };
37 38
38 size_t SkCodec::MinBufferedBytesNeeded() { 39 size_t SkCodec::MinBufferedBytesNeeded() {
39 return WEBP_VP8_HEADER_SIZE; 40 return WEBP_VP8_HEADER_SIZE;
40 } 41 }
41 42
42 SkCodec* SkCodec::NewFromStream(SkStream* stream, 43 SkCodec* SkCodec::NewFromStream(SkStream* stream,
43 SkPngChunkReader* chunkReader) { 44 SkPngChunkReader* chunkReader) {
44 if (!stream) { 45 if (!stream) {
45 return nullptr; 46 return nullptr;
46 } 47 }
47 48
48 SkAutoTDelete<SkStream> streamDeleter(stream); 49 SkAutoTDelete<SkStream> streamDeleter(stream);
49 50
51
scroggo 2015/12/18 15:56:26 nit: extra blank line.
yujieqin 2016/01/06 18:47:19 Done.
50 // 14 is enough to read all of the supported types. 52 // 14 is enough to read all of the supported types.
51 const size_t bytesToRead = 14; 53 const size_t bytesToRead = 14;
52 SkASSERT(bytesToRead <= MinBufferedBytesNeeded()); 54 SkASSERT(bytesToRead <= MinBufferedBytesNeeded());
53 55
54 char buffer[bytesToRead]; 56 char buffer[bytesToRead];
55 size_t bytesRead = stream->peek(buffer, bytesToRead); 57 size_t bytesRead = stream->peek(buffer, bytesToRead);
56 58
57 // It is also possible to have a complete image less than bytesToRead bytes 59 // It is also possible to have a complete image less than bytesToRead bytes
58 // (e.g. a 1 x 1 wbmp), meaning peek() would return less than bytesToRead. 60 // (e.g. a 1 x 1 wbmp), meaning peek() would return less than bytesToRead.
59 // Assume that if bytesRead < bytesToRead, but > 0, the stream is shorter 61 // Assume that if bytesRead < bytesToRead, but > 0, the stream is shorter
(...skipping 18 matching lines...) Expand all
78 // But this code follows the same pattern as the loop. 80 // But this code follows the same pattern as the loop.
79 if (SkPngCodec::IsPng(buffer, bytesRead)) { 81 if (SkPngCodec::IsPng(buffer, bytesRead)) {
80 codec.reset(SkPngCodec::NewFromStream(streamDeleter.detach(), chunkReade r)); 82 codec.reset(SkPngCodec::NewFromStream(streamDeleter.detach(), chunkReade r));
81 } else { 83 } else {
82 for (DecoderProc proc : gDecoderProcs) { 84 for (DecoderProc proc : gDecoderProcs) {
83 if (proc.IsFormat(buffer, bytesRead)) { 85 if (proc.IsFormat(buffer, bytesRead)) {
84 codec.reset(proc.NewFromStream(streamDeleter.detach())); 86 codec.reset(proc.NewFromStream(streamDeleter.detach()));
85 break; 87 break;
86 } 88 }
87 } 89 }
90
91 // Try read more for RAW cases.
msarett 2015/12/18 16:26:12 Is there a reason that we can't add RAW to gDecode
scroggo 2015/12/18 16:47:05 SkRawCodec::IsRaw reads the whole stream, rather t
yujieqin 2016/01/06 18:47:19 As discussed in the buganizer, we don't need IsRaw
92 if (SkRawCodec::IsRaw(stream)) {
93 codec.reset(SkRawCodec::NewFromStream(streamDeleter.detach()));
94 }
88 } 95 }
89 96
90 // Set the max size at 128 megapixels (512 MB for kN32). 97 // 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 98 // This is about 4x smaller than a test image that takes a few minutes for
92 // dm to decode and draw. 99 // dm to decode and draw.
93 const int32_t maxSize = 1 << 27; 100 const int32_t maxSize = 1 << 27;
94 if (codec && codec->getInfo().width() * codec->getInfo().height() > maxSize) { 101 if (codec && codec->getInfo().width() * codec->getInfo().height() > maxSize) {
95 SkCodecPrintf("Error: Image size too large, cannot decode.\n"); 102 SkCodecPrintf("Error: Image size too large, cannot decode.\n");
96 return nullptr; 103 return nullptr;
97 } else { 104 } else {
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 SkASSERT(1 == linesRequested || this->getInfo().height() == linesReq uested); 381 SkASSERT(1 == linesRequested || this->getInfo().height() == linesReq uested);
375 const SkImageInfo fillInfo = info.makeWH(info.width(), 1); 382 const SkImageInfo fillInfo = info.makeWH(info.width(), 1);
376 for (int srcY = linesDecoded; srcY < linesRequested; srcY++) { 383 for (int srcY = linesDecoded; srcY < linesRequested; srcY++) {
377 fillDst = SkTAddOffset<void>(dst, this->outputScanline(srcY) * r owBytes); 384 fillDst = SkTAddOffset<void>(dst, this->outputScanline(srcY) * r owBytes);
378 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, samp ler); 385 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, samp ler);
379 } 386 }
380 break; 387 break;
381 } 388 }
382 } 389 }
383 } 390 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698