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" | |
9 #include "SkCodec.h" | 8 #include "SkCodec.h" |
10 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
11 #include "SkData.h" | 10 #include "SkData.h" |
| 11 #include "SkStream.h" |
| 12 |
| 13 #ifdef SK_CODEC_DECODES_BMP |
| 14 #include "SkBmpCodec.h" |
| 15 #endif |
| 16 #ifdef SK_CODEC_DECODES_GIF |
12 #include "SkGifCodec.h" | 17 #include "SkGifCodec.h" |
| 18 #endif |
| 19 #ifdef SK_CODEC_DECODES_ICO |
13 #include "SkIcoCodec.h" | 20 #include "SkIcoCodec.h" |
| 21 #endif |
| 22 #ifdef SK_CODEC_DECODES_JPEG |
14 #include "SkJpegCodec.h" | 23 #include "SkJpegCodec.h" |
| 24 #endif |
| 25 #ifdef SK_CODEC_DECODES_PNG |
15 #include "SkPngCodec.h" | 26 #include "SkPngCodec.h" |
| 27 #endif |
16 #ifdef SK_CODEC_DECODES_RAW | 28 #ifdef SK_CODEC_DECODES_RAW |
17 #include "SkRawCodec.h" | 29 #include "SkRawCodec.h" |
18 #endif | 30 #endif |
19 #include "SkStream.h" | 31 #ifdef SK_CODEC_DECODES_WBMP |
20 #include "SkWbmpCodec.h" | 32 #include "SkWbmpCodec.h" |
| 33 #endif |
| 34 #ifdef SK_CODEC_DECODES_WEBP |
21 #include "SkWebpCodec.h" | 35 #include "SkWebpCodec.h" |
| 36 #endif |
22 | 37 |
23 struct DecoderProc { | 38 struct DecoderProc { |
24 bool (*IsFormat)(const void*, size_t); | 39 bool (*IsFormat)(const void*, size_t); |
25 SkCodec* (*NewFromStream)(SkStream*); | 40 SkCodec* (*NewFromStream)(SkStream*); |
26 }; | 41 }; |
27 | 42 |
28 static const DecoderProc gDecoderProcs[] = { | 43 static const DecoderProc gDecoderProcs[] = { |
| 44 #ifdef SK_CODEC_DECODES_JPEG |
29 { SkJpegCodec::IsJpeg, SkJpegCodec::NewFromStream }, | 45 { SkJpegCodec::IsJpeg, SkJpegCodec::NewFromStream }, |
| 46 #endif |
| 47 #ifdef SK_CODEC_DECODES_WEBP |
30 { SkWebpCodec::IsWebp, SkWebpCodec::NewFromStream }, | 48 { SkWebpCodec::IsWebp, SkWebpCodec::NewFromStream }, |
| 49 #endif |
| 50 #ifdef SK_CODEC_DECODES_GIF |
31 { SkGifCodec::IsGif, SkGifCodec::NewFromStream }, | 51 { SkGifCodec::IsGif, SkGifCodec::NewFromStream }, |
| 52 #endif |
| 53 #ifdef SK_CODEC_DECODES_ICO |
32 { SkIcoCodec::IsIco, SkIcoCodec::NewFromStream }, | 54 { SkIcoCodec::IsIco, SkIcoCodec::NewFromStream }, |
| 55 #endif |
| 56 #ifdef SK_CODEC_DECODES_BMP |
33 { SkBmpCodec::IsBmp, SkBmpCodec::NewFromStream }, | 57 { SkBmpCodec::IsBmp, SkBmpCodec::NewFromStream }, |
| 58 #endif |
| 59 #ifdef SK_CODEC_DECODES_WBMP |
34 { SkWbmpCodec::IsWbmp, SkWbmpCodec::NewFromStream } | 60 { SkWbmpCodec::IsWbmp, SkWbmpCodec::NewFromStream } |
| 61 #endif |
35 }; | 62 }; |
36 | 63 |
37 size_t SkCodec::MinBufferedBytesNeeded() { | 64 size_t SkCodec::MinBufferedBytesNeeded() { |
38 return WEBP_VP8_HEADER_SIZE; | 65 return WEBP_VP8_HEADER_SIZE; |
39 } | 66 } |
40 | 67 |
41 SkCodec* SkCodec::NewFromStream(SkStream* stream, | 68 SkCodec* SkCodec::NewFromStream(SkStream* stream, |
42 SkPngChunkReader* chunkReader) { | 69 SkPngChunkReader* chunkReader) { |
43 if (!stream) { | 70 if (!stream) { |
44 return nullptr; | 71 return nullptr; |
(...skipping 25 matching lines...) Expand all Loading... |
70 // Attempt to read() and pass the actual amount read to the decoder. | 97 // Attempt to read() and pass the actual amount read to the decoder. |
71 bytesRead = stream->read(buffer, bytesToRead); | 98 bytesRead = stream->read(buffer, bytesToRead); |
72 if (!stream->rewind()) { | 99 if (!stream->rewind()) { |
73 SkCodecPrintf("Encoded image data could not peek or rewind to determ
ine format!\n"); | 100 SkCodecPrintf("Encoded image data could not peek or rewind to determ
ine format!\n"); |
74 return nullptr; | 101 return nullptr; |
75 } | 102 } |
76 } | 103 } |
77 | 104 |
78 // PNG is special, since we want to be able to supply an SkPngChunkReader. | 105 // PNG is special, since we want to be able to supply an SkPngChunkReader. |
79 // But this code follows the same pattern as the loop. | 106 // But this code follows the same pattern as the loop. |
| 107 #ifdef SK_CODEC_DECODES_PNG |
80 if (SkPngCodec::IsPng(buffer, bytesRead)) { | 108 if (SkPngCodec::IsPng(buffer, bytesRead)) { |
81 return SkPngCodec::NewFromStream(streamDeleter.detach(), chunkReader); | 109 return SkPngCodec::NewFromStream(streamDeleter.detach(), chunkReader); |
82 } else { | 110 } else |
| 111 #endif |
| 112 { |
83 for (DecoderProc proc : gDecoderProcs) { | 113 for (DecoderProc proc : gDecoderProcs) { |
84 if (proc.IsFormat(buffer, bytesRead)) { | 114 if (proc.IsFormat(buffer, bytesRead)) { |
85 return proc.NewFromStream(streamDeleter.detach()); | 115 return proc.NewFromStream(streamDeleter.detach()); |
86 } | 116 } |
87 } | 117 } |
88 | 118 |
89 #ifdef SK_CODEC_DECODES_RAW | 119 #ifdef SK_CODEC_DECODES_RAW |
90 // Try to treat the input as RAW if all the other checks failed. | 120 // Try to treat the input as RAW if all the other checks failed. |
91 return SkRawCodec::NewFromStream(streamDeleter.detach()); | 121 return SkRawCodec::NewFromStream(streamDeleter.detach()); |
92 #endif | 122 #endif |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 SkASSERT(1 == linesRequested || this->getInfo().height() == linesReq
uested); | 391 SkASSERT(1 == linesRequested || this->getInfo().height() == linesReq
uested); |
362 const SkImageInfo fillInfo = info.makeWH(info.width(), 1); | 392 const SkImageInfo fillInfo = info.makeWH(info.width(), 1); |
363 for (int srcY = linesDecoded; srcY < linesRequested; srcY++) { | 393 for (int srcY = linesDecoded; srcY < linesRequested; srcY++) { |
364 fillDst = SkTAddOffset<void>(dst, this->outputScanline(srcY) * r
owBytes); | 394 fillDst = SkTAddOffset<void>(dst, this->outputScanline(srcY) * r
owBytes); |
365 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, samp
ler); | 395 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, samp
ler); |
366 } | 396 } |
367 break; | 397 break; |
368 } | 398 } |
369 } | 399 } |
370 } | 400 } |
OLD | NEW |