Chromium Code Reviews| 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 | |
|
mtklein
2016/02/16 23:16:01
You might not need to guard all these headers? II
msarett
2016/02/17 14:34:54
Done. Was able to get rid of some but not all of
| |
| 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() { |
| 65 #ifdef SK_CODEC_DECODES_WEBP | |
| 38 return WEBP_VP8_HEADER_SIZE; | 66 return WEBP_VP8_HEADER_SIZE; |
| 67 #else | |
| 68 return 30; | |
| 69 #endif | |
| 39 } | 70 } |
| 40 | 71 |
| 41 SkCodec* SkCodec::NewFromStream(SkStream* stream, | 72 SkCodec* SkCodec::NewFromStream(SkStream* stream, |
| 42 SkPngChunkReader* chunkReader) { | 73 SkPngChunkReader* chunkReader) { |
| 43 if (!stream) { | 74 if (!stream) { |
| 44 return nullptr; | 75 return nullptr; |
| 45 } | 76 } |
| 46 | 77 |
| 47 SkAutoTDelete<SkStream> streamDeleter(stream); | 78 SkAutoTDelete<SkStream> streamDeleter(stream); |
| 48 | 79 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 70 // Attempt to read() and pass the actual amount read to the decoder. | 101 // Attempt to read() and pass the actual amount read to the decoder. |
| 71 bytesRead = stream->read(buffer, bytesToRead); | 102 bytesRead = stream->read(buffer, bytesToRead); |
| 72 if (!stream->rewind()) { | 103 if (!stream->rewind()) { |
| 73 SkCodecPrintf("Encoded image data could not peek or rewind to determ ine format!\n"); | 104 SkCodecPrintf("Encoded image data could not peek or rewind to determ ine format!\n"); |
| 74 return nullptr; | 105 return nullptr; |
| 75 } | 106 } |
| 76 } | 107 } |
| 77 | 108 |
| 78 // PNG is special, since we want to be able to supply an SkPngChunkReader. | 109 // PNG is special, since we want to be able to supply an SkPngChunkReader. |
| 79 // But this code follows the same pattern as the loop. | 110 // But this code follows the same pattern as the loop. |
| 111 #ifdef SK_CODEC_DECODES_PNG | |
| 80 if (SkPngCodec::IsPng(buffer, bytesRead)) { | 112 if (SkPngCodec::IsPng(buffer, bytesRead)) { |
| 81 return SkPngCodec::NewFromStream(streamDeleter.detach(), chunkReader); | 113 return SkPngCodec::NewFromStream(streamDeleter.detach(), chunkReader); |
| 82 } else { | 114 } else |
| 115 #endif | |
| 116 { | |
| 83 for (DecoderProc proc : gDecoderProcs) { | 117 for (DecoderProc proc : gDecoderProcs) { |
| 84 if (proc.IsFormat(buffer, bytesRead)) { | 118 if (proc.IsFormat(buffer, bytesRead)) { |
| 85 return proc.NewFromStream(streamDeleter.detach()); | 119 return proc.NewFromStream(streamDeleter.detach()); |
| 86 } | 120 } |
| 87 } | 121 } |
| 88 | 122 |
| 89 #ifdef SK_CODEC_DECODES_RAW | 123 #ifdef SK_CODEC_DECODES_RAW |
| 90 // Try to treat the input as RAW if all the other checks failed. | 124 // Try to treat the input as RAW if all the other checks failed. |
| 91 return SkRawCodec::NewFromStream(streamDeleter.detach()); | 125 return SkRawCodec::NewFromStream(streamDeleter.detach()); |
| 92 #endif | 126 #endif |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 SkASSERT(1 == linesRequested || this->getInfo().height() == linesReq uested); | 395 SkASSERT(1 == linesRequested || this->getInfo().height() == linesReq uested); |
| 362 const SkImageInfo fillInfo = info.makeWH(info.width(), 1); | 396 const SkImageInfo fillInfo = info.makeWH(info.width(), 1); |
| 363 for (int srcY = linesDecoded; srcY < linesRequested; srcY++) { | 397 for (int srcY = linesDecoded; srcY < linesRequested; srcY++) { |
| 364 fillDst = SkTAddOffset<void>(dst, this->outputScanline(srcY) * r owBytes); | 398 fillDst = SkTAddOffset<void>(dst, this->outputScanline(srcY) * r owBytes); |
| 365 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, samp ler); | 399 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, samp ler); |
| 366 } | 400 } |
| 367 break; | 401 break; |
| 368 } | 402 } |
| 369 } | 403 } |
| 370 } | 404 } |
| OLD | NEW |