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 "SkCodecPriv.h" | 10 #include "SkCodecPriv.h" |
11 #include "SkData.h" | 11 #include "SkData.h" |
12 #include "SkGifCodec.h" | 12 #include "SkGifCodec.h" |
13 #include "SkIcoCodec.h" | 13 #include "SkIcoCodec.h" |
14 #include "SkJpegCodec.h" | 14 #include "SkJpegCodec.h" |
| 15 #ifdef SK_CODEC_DECODES_PNG |
15 #include "SkPngCodec.h" | 16 #include "SkPngCodec.h" |
16 #ifdef SK_CODEC_DECODES_RAW | 17 #endif |
17 #include "SkRawCodec.h" | 18 #include "SkRawCodec.h" |
18 #endif | |
19 #include "SkStream.h" | 19 #include "SkStream.h" |
20 #include "SkWbmpCodec.h" | 20 #include "SkWbmpCodec.h" |
21 #include "SkWebpCodec.h" | 21 #include "SkWebpCodec.h" |
22 | 22 |
23 struct DecoderProc { | 23 struct DecoderProc { |
24 bool (*IsFormat)(const void*, size_t); | 24 bool (*IsFormat)(const void*, size_t); |
25 SkCodec* (*NewFromStream)(SkStream*); | 25 SkCodec* (*NewFromStream)(SkStream*); |
26 }; | 26 }; |
27 | 27 |
28 static const DecoderProc gDecoderProcs[] = { | 28 static const DecoderProc gDecoderProcs[] = { |
| 29 #ifdef SK_CODEC_DECODES_JPEG |
29 { SkJpegCodec::IsJpeg, SkJpegCodec::NewFromStream }, | 30 { SkJpegCodec::IsJpeg, SkJpegCodec::NewFromStream }, |
| 31 #endif |
| 32 #ifdef SK_CODEC_DECODES_WEBP |
30 { SkWebpCodec::IsWebp, SkWebpCodec::NewFromStream }, | 33 { SkWebpCodec::IsWebp, SkWebpCodec::NewFromStream }, |
| 34 #endif |
| 35 #ifdef SK_CODEC_DECODES_GIF |
31 { SkGifCodec::IsGif, SkGifCodec::NewFromStream }, | 36 { SkGifCodec::IsGif, SkGifCodec::NewFromStream }, |
| 37 #endif |
| 38 #ifdef SK_CODEC_DECODES_PNG |
32 { SkIcoCodec::IsIco, SkIcoCodec::NewFromStream }, | 39 { SkIcoCodec::IsIco, SkIcoCodec::NewFromStream }, |
| 40 #endif |
33 { SkBmpCodec::IsBmp, SkBmpCodec::NewFromStream }, | 41 { SkBmpCodec::IsBmp, SkBmpCodec::NewFromStream }, |
34 { SkWbmpCodec::IsWbmp, SkWbmpCodec::NewFromStream } | 42 { SkWbmpCodec::IsWbmp, SkWbmpCodec::NewFromStream } |
35 }; | 43 }; |
36 | 44 |
37 size_t SkCodec::MinBufferedBytesNeeded() { | 45 size_t SkCodec::MinBufferedBytesNeeded() { |
38 return WEBP_VP8_HEADER_SIZE; | 46 return WEBP_VP8_HEADER_SIZE; |
39 } | 47 } |
40 | 48 |
41 SkCodec* SkCodec::NewFromStream(SkStream* stream, | 49 SkCodec* SkCodec::NewFromStream(SkStream* stream, |
42 SkPngChunkReader* chunkReader) { | 50 SkPngChunkReader* chunkReader) { |
(...skipping 27 matching lines...) Expand all Loading... |
70 // Attempt to read() and pass the actual amount read to the decoder. | 78 // Attempt to read() and pass the actual amount read to the decoder. |
71 bytesRead = stream->read(buffer, bytesToRead); | 79 bytesRead = stream->read(buffer, bytesToRead); |
72 if (!stream->rewind()) { | 80 if (!stream->rewind()) { |
73 SkCodecPrintf("Encoded image data could not peek or rewind to determ
ine format!\n"); | 81 SkCodecPrintf("Encoded image data could not peek or rewind to determ
ine format!\n"); |
74 return nullptr; | 82 return nullptr; |
75 } | 83 } |
76 } | 84 } |
77 | 85 |
78 // PNG is special, since we want to be able to supply an SkPngChunkReader. | 86 // PNG is special, since we want to be able to supply an SkPngChunkReader. |
79 // But this code follows the same pattern as the loop. | 87 // But this code follows the same pattern as the loop. |
| 88 #ifdef SK_CODEC_DECODES_PNG |
80 if (SkPngCodec::IsPng(buffer, bytesRead)) { | 89 if (SkPngCodec::IsPng(buffer, bytesRead)) { |
81 return SkPngCodec::NewFromStream(streamDeleter.detach(), chunkReader); | 90 return SkPngCodec::NewFromStream(streamDeleter.detach(), chunkReader); |
82 } else { | 91 } else |
| 92 #endif |
| 93 { |
83 for (DecoderProc proc : gDecoderProcs) { | 94 for (DecoderProc proc : gDecoderProcs) { |
84 if (proc.IsFormat(buffer, bytesRead)) { | 95 if (proc.IsFormat(buffer, bytesRead)) { |
85 return proc.NewFromStream(streamDeleter.detach()); | 96 return proc.NewFromStream(streamDeleter.detach()); |
86 } | 97 } |
87 } | 98 } |
88 | 99 |
89 #ifdef SK_CODEC_DECODES_RAW | 100 #ifdef SK_CODEC_DECODES_RAW |
90 // Try to treat the input as RAW if all the other checks failed. | 101 // Try to treat the input as RAW if all the other checks failed. |
91 return SkRawCodec::NewFromStream(streamDeleter.detach()); | 102 return SkRawCodec::NewFromStream(streamDeleter.detach()); |
92 #endif | 103 #endif |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 SkASSERT(1 == linesRequested || this->getInfo().height() == linesReq
uested); | 372 SkASSERT(1 == linesRequested || this->getInfo().height() == linesReq
uested); |
362 const SkImageInfo fillInfo = info.makeWH(info.width(), 1); | 373 const SkImageInfo fillInfo = info.makeWH(info.width(), 1); |
363 for (int srcY = linesDecoded; srcY < linesRequested; srcY++) { | 374 for (int srcY = linesDecoded; srcY < linesRequested; srcY++) { |
364 fillDst = SkTAddOffset<void>(dst, this->outputScanline(srcY) * r
owBytes); | 375 fillDst = SkTAddOffset<void>(dst, this->outputScanline(srcY) * r
owBytes); |
365 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, samp
ler); | 376 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, samp
ler); |
366 } | 377 } |
367 break; | 378 break; |
368 } | 379 } |
369 } | 380 } |
370 } | 381 } |
OLD | NEW |