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