| 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 "SkScanlineDecoder.h" | 8 #include "SkScanlineDecoder.h" |
| 9 #include "SkCodec_libpng.h" | 9 #include "SkCodec_libpng.h" |
| 10 #include "SkCodec_wbmp.h" |
| 10 #include "SkCodecPriv.h" | 11 #include "SkCodecPriv.h" |
| 11 #ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK | 12 #ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 12 #include "SkJpegCodec.h" | 13 #include "SkJpegCodec.h" |
| 13 #endif | 14 #endif |
| 14 | 15 |
| 15 struct DecoderProc { | 16 struct DecoderProc { |
| 16 bool (*IsFormat)(SkStream*); | 17 bool (*IsFormat)(SkStream*); |
| 17 SkScanlineDecoder* (*NewFromStream)(SkStream*); | 18 SkScanlineDecoder* (*NewFromStream)(SkStream*); |
| 18 }; | 19 }; |
| 19 | 20 |
| 20 static const DecoderProc gDecoderProcs[] = { | 21 static const DecoderProc gDecoderProcs[] = { |
| 21 { SkPngCodec::IsPng, SkPngCodec::NewSDFromStream }, | 22 { SkPngCodec::IsPng, SkPngCodec::NewSDFromStream }, |
| 22 #ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK | 23 #ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 23 { SkJpegCodec::IsJpeg, SkJpegCodec::NewSDFromStream }, | 24 { SkJpegCodec::IsJpeg, SkJpegCodec::NewSDFromStream }, |
| 24 #endif | 25 #endif |
| 26 { SkWbmpCodec::IsWbmp, SkWbmpCodec::NewSDFromStream }, |
| 25 }; | 27 }; |
| 26 | 28 |
| 27 SkScanlineDecoder* SkScanlineDecoder::NewFromStream(SkStream* stream) { | 29 SkScanlineDecoder* SkScanlineDecoder::NewFromStream(SkStream* stream) { |
| 28 if (!stream) { | 30 if (!stream) { |
| 29 return NULL; | 31 return NULL; |
| 30 } | 32 } |
| 31 | 33 |
| 32 SkAutoTDelete<SkStream> streamDeleter(stream); | 34 SkAutoTDelete<SkStream> streamDeleter(stream); |
| 33 | 35 |
| 34 SkAutoTDelete<SkScanlineDecoder> codec(NULL); | 36 SkAutoTDelete<SkScanlineDecoder> codec(NULL); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 59 SkScanlineDecoder* SkScanlineDecoder::NewFromData(SkData* data) { | 61 SkScanlineDecoder* SkScanlineDecoder::NewFromData(SkData* data) { |
| 60 if (!data) { | 62 if (!data) { |
| 61 return NULL; | 63 return NULL; |
| 62 } | 64 } |
| 63 return NewFromStream(SkNEW_ARGS(SkMemoryStream, (data))); | 65 return NewFromStream(SkNEW_ARGS(SkMemoryStream, (data))); |
| 64 } | 66 } |
| 65 | 67 |
| 66 | 68 |
| 67 SkCodec::Result SkScanlineDecoder::start(const SkImageInfo& dstInfo, | 69 SkCodec::Result SkScanlineDecoder::start(const SkImageInfo& dstInfo, |
| 68 const SkCodec::Options* options, SkPMColor ctable[], int* ctableCount) { | 70 const SkCodec::Options* options, SkPMColor ctable[], int* ctableCount) { |
| 71 // Ensure that valid color ptrs are passed in for kIndex8 color type |
| 72 if (kIndex_8_SkColorType == dstInfo.colorType()) { |
| 73 if (NULL == ctable || NULL == ctableCount) { |
| 74 return SkCodec::kInvalidParameters; |
| 75 } |
| 76 } else { |
| 77 if (ctableCount) { |
| 78 *ctableCount = 0; |
| 79 } |
| 80 ctableCount = NULL; |
| 81 ctable = NULL; |
| 82 } |
| 83 |
| 69 // Set options. | 84 // Set options. |
| 70 SkCodec::Options optsStorage; | 85 SkCodec::Options optsStorage; |
| 71 if (NULL == options) { | 86 if (NULL == options) { |
| 72 options = &optsStorage; | 87 options = &optsStorage; |
| 73 } | 88 } |
| 74 | 89 |
| 75 const SkCodec::Result result = this->onStart(dstInfo, *options, ctable, ctab
leCount); | 90 const SkCodec::Result result = this->onStart(dstInfo, *options, ctable, ctab
leCount); |
| 76 if (result != SkCodec::kSuccess) { | 91 if (result != SkCodec::kSuccess) { |
| 77 return result; | 92 return result; |
| 78 } | 93 } |
| 79 | 94 |
| 80 fCurrScanline = 0; | 95 fCurrScanline = 0; |
| 81 fDstInfo = dstInfo; | 96 fDstInfo = dstInfo; |
| 82 return SkCodec::kSuccess; | 97 return SkCodec::kSuccess; |
| 83 } | 98 } |
| 84 | 99 |
| 85 SkCodec::Result SkScanlineDecoder::start(const SkImageInfo& dstInfo) { | 100 SkCodec::Result SkScanlineDecoder::start(const SkImageInfo& dstInfo) { |
| 86 SkASSERT(kIndex_8_SkColorType != dstInfo.colorType()); | |
| 87 if (kIndex_8_SkColorType == dstInfo.colorType()) { | |
| 88 return SkCodec::kInvalidConversion; | |
| 89 } | |
| 90 return this->start(dstInfo, NULL, NULL, NULL); | 101 return this->start(dstInfo, NULL, NULL, NULL); |
| 91 } | 102 } |
| 92 | 103 |
| OLD | NEW |