| 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 "SkCodec.h" | 8 #include "SkCodec.h" |
| 9 #include "SkData.h" | 9 #include "SkData.h" |
| 10 #include "SkCodec_libbmp.h" | 10 #include "SkCodec_libbmp.h" |
| 11 #include "SkCodec_libgif.h" | 11 #include "SkCodec_libgif.h" |
| 12 #include "SkCodec_libico.h" | 12 #include "SkCodec_libico.h" |
| 13 #include "SkCodec_libpng.h" | 13 #include "SkCodec_libpng.h" |
| 14 #include "SkCodec_wbmp.h" | 14 #include "SkCodec_wbmp.h" |
| 15 #include "SkCodecPriv.h" | 15 #include "SkCodecPriv.h" |
| 16 #ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK | 16 #ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 17 #include "SkJpegCodec.h" | 17 #include "SkJpegCodec.h" |
| 18 #endif | 18 #endif |
| 19 #include "SkScanlineDecoder.h" | |
| 20 #include "SkStream.h" | 19 #include "SkStream.h" |
| 21 #include "SkWebpCodec.h" | 20 #include "SkWebpCodec.h" |
| 22 | 21 |
| 23 struct DecoderProc { | 22 struct DecoderProc { |
| 24 bool (*IsFormat)(SkStream*); | 23 bool (*IsFormat)(SkStream*); |
| 25 SkCodec* (*NewFromStream)(SkStream*); | 24 SkCodec* (*NewFromStream)(SkStream*); |
| 26 }; | 25 }; |
| 27 | 26 |
| 28 static const DecoderProc gDecoderProcs[] = { | 27 static const DecoderProc gDecoderProcs[] = { |
| 29 { SkPngCodec::IsPng, SkPngCodec::NewFromStream }, | 28 { SkPngCodec::IsPng, SkPngCodec::NewFromStream }, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 if (!data) { | 72 if (!data) { |
| 74 return NULL; | 73 return NULL; |
| 75 } | 74 } |
| 76 return NewFromStream(SkNEW_ARGS(SkMemoryStream, (data))); | 75 return NewFromStream(SkNEW_ARGS(SkMemoryStream, (data))); |
| 77 } | 76 } |
| 78 | 77 |
| 79 SkCodec::SkCodec(const SkImageInfo& info, SkStream* stream) | 78 SkCodec::SkCodec(const SkImageInfo& info, SkStream* stream) |
| 80 : fInfo(info) | 79 : fInfo(info) |
| 81 , fStream(stream) | 80 , fStream(stream) |
| 82 , fNeedsRewind(false) | 81 , fNeedsRewind(false) |
| 83 , fScanlineDecoder(NULL) | |
| 84 {} | 82 {} |
| 85 | 83 |
| 86 SkCodec::~SkCodec() { | 84 SkCodec::~SkCodec() {} |
| 87 SkDELETE(fScanlineDecoder); | |
| 88 } | |
| 89 | 85 |
| 90 SkCodec::RewindState SkCodec::rewindIfNeeded() { | 86 SkCodec::RewindState SkCodec::rewindIfNeeded() { |
| 91 // Store the value of fNeedsRewind so we can update it. Next read will | 87 // Store the value of fNeedsRewind so we can update it. Next read will |
| 92 // require a rewind. | 88 // require a rewind. |
| 93 const bool needsRewind = fNeedsRewind; | 89 const bool needsRewind = fNeedsRewind; |
| 94 fNeedsRewind = true; | 90 fNeedsRewind = true; |
| 95 if (!needsRewind) { | 91 if (!needsRewind) { |
| 96 return kNoRewindNecessary_RewindState; | 92 return kNoRewindNecessary_RewindState; |
| 97 } | 93 } |
| 98 return fStream->rewind() ? kRewound_RewindState | 94 return fStream->rewind() ? kRewound_RewindState |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 142 |
| 147 SkScanlineDecoder* SkCodec::getScanlineDecoder(const SkImageInfo& dstInfo, const
Options* options, | 143 SkScanlineDecoder* SkCodec::getScanlineDecoder(const SkImageInfo& dstInfo, const
Options* options, |
| 148 SkPMColor ctable[], int* ctableCount) { | 144 SkPMColor ctable[], int* ctableCount) { |
| 149 | 145 |
| 150 // Set options. | 146 // Set options. |
| 151 Options optsStorage; | 147 Options optsStorage; |
| 152 if (NULL == options) { | 148 if (NULL == options) { |
| 153 options = &optsStorage; | 149 options = &optsStorage; |
| 154 } | 150 } |
| 155 | 151 |
| 156 SkDELETE(fScanlineDecoder); | 152 return this->onGetScanlineDecoder(dstInfo, *options, ctable, ctableCount); |
| 157 fScanlineDecoder = this->onGetScanlineDecoder(dstInfo, *options, ctable, cta
bleCount); | |
| 158 return fScanlineDecoder; | |
| 159 } | 153 } |
| 160 | 154 |
| 161 SkScanlineDecoder* SkCodec::getScanlineDecoder(const SkImageInfo& dstInfo) { | 155 SkScanlineDecoder* SkCodec::getScanlineDecoder(const SkImageInfo& dstInfo) { |
| 162 SkASSERT(kIndex_8_SkColorType != dstInfo.colorType()); | 156 SkASSERT(kIndex_8_SkColorType != dstInfo.colorType()); |
| 163 if (kIndex_8_SkColorType == dstInfo.colorType()) { | 157 if (kIndex_8_SkColorType == dstInfo.colorType()) { |
| 164 return NULL; | 158 return NULL; |
| 165 } | 159 } |
| 166 return this->getScanlineDecoder(dstInfo, NULL, NULL, NULL); | 160 return this->getScanlineDecoder(dstInfo, NULL, NULL, NULL); |
| 167 } | 161 } |
| OLD | NEW |