| 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" |
| 19 #include "SkStream.h" | 20 #include "SkStream.h" |
| 20 #include "SkWebpCodec.h" | 21 #include "SkWebpCodec.h" |
| 21 | 22 |
| 22 struct DecoderProc { | 23 struct DecoderProc { |
| 23 bool (*IsFormat)(SkStream*); | 24 bool (*IsFormat)(SkStream*); |
| 24 SkCodec* (*NewFromStream)(SkStream*); | 25 SkCodec* (*NewFromStream)(SkStream*); |
| 25 }; | 26 }; |
| 26 | 27 |
| 27 static const DecoderProc gDecoderProcs[] = { | 28 static const DecoderProc gDecoderProcs[] = { |
| 28 { SkPngCodec::IsPng, SkPngCodec::NewFromStream }, | 29 { SkPngCodec::IsPng, SkPngCodec::NewFromStream }, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 } | 70 } |
| 70 | 71 |
| 71 SkCodec* SkCodec::NewFromData(SkData* data) { | 72 SkCodec* SkCodec::NewFromData(SkData* data) { |
| 72 if (!data) { | 73 if (!data) { |
| 73 return NULL; | 74 return NULL; |
| 74 } | 75 } |
| 75 return NewFromStream(SkNEW_ARGS(SkMemoryStream, (data))); | 76 return NewFromStream(SkNEW_ARGS(SkMemoryStream, (data))); |
| 76 } | 77 } |
| 77 | 78 |
| 78 SkCodec::SkCodec(const SkImageInfo& info, SkStream* stream) | 79 SkCodec::SkCodec(const SkImageInfo& info, SkStream* stream) |
| 79 : INHERITED(info) | 80 : fInfo(info) |
| 80 , fStream(stream) | 81 , fStream(stream) |
| 81 , fNeedsRewind(false) | 82 , fNeedsRewind(false) |
| 83 , fScanlineDecoder(NULL) |
| 82 {} | 84 {} |
| 83 | 85 |
| 86 SkCodec::~SkCodec() { |
| 87 SkDELETE(fScanlineDecoder); |
| 88 } |
| 89 |
| 84 SkCodec::RewindState SkCodec::rewindIfNeeded() { | 90 SkCodec::RewindState SkCodec::rewindIfNeeded() { |
| 85 // Store the value of fNeedsRewind so we can update it. Next read will | 91 // Store the value of fNeedsRewind so we can update it. Next read will |
| 86 // require a rewind. | 92 // require a rewind. |
| 87 const bool needsRewind = fNeedsRewind; | 93 const bool needsRewind = fNeedsRewind; |
| 88 fNeedsRewind = true; | 94 fNeedsRewind = true; |
| 89 if (!needsRewind) { | 95 if (!needsRewind) { |
| 90 return kNoRewindNecessary_RewindState; | 96 return kNoRewindNecessary_RewindState; |
| 91 } | 97 } |
| 92 return fStream->rewind() ? kRewound_RewindState | 98 return fStream->rewind() ? kRewound_RewindState |
| 93 : kCouldNotRewind_RewindState; | 99 : kCouldNotRewind_RewindState; |
| 94 } | 100 } |
| 95 | 101 |
| 102 SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t
rowBytes, |
| 103 const Options* options, SkPMColor ctable[], i
nt* ctableCount) { |
| 104 if (kUnknown_SkColorType == info.colorType()) { |
| 105 return kInvalidConversion; |
| 106 } |
| 107 if (NULL == pixels) { |
| 108 return kInvalidParameters; |
| 109 } |
| 110 if (rowBytes < info.minRowBytes()) { |
| 111 return kInvalidParameters; |
| 112 } |
| 113 |
| 114 if (kIndex_8_SkColorType == info.colorType()) { |
| 115 if (NULL == ctable || NULL == ctableCount) { |
| 116 return kInvalidParameters; |
| 117 } |
| 118 } else { |
| 119 if (ctableCount) { |
| 120 *ctableCount = 0; |
| 121 } |
| 122 ctableCount = NULL; |
| 123 ctable = NULL; |
| 124 } |
| 125 |
| 126 // Default options. |
| 127 Options optsStorage; |
| 128 if (NULL == options) { |
| 129 options = &optsStorage; |
| 130 } |
| 131 const Result result = this->onGetPixels(info, pixels, rowBytes, *options, ct
able, ctableCount); |
| 132 |
| 133 if ((kIncompleteInput == result || kSuccess == result) && ctableCount) { |
| 134 SkASSERT(*ctableCount >= 0 && *ctableCount <= 256); |
| 135 } |
| 136 return result; |
| 137 } |
| 138 |
| 139 SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t
rowBytes) { |
| 140 SkASSERT(kIndex_8_SkColorType != info.colorType()); |
| 141 if (kIndex_8_SkColorType == info.colorType()) { |
| 142 return kInvalidConversion; |
| 143 } |
| 144 return this->getPixels(info, pixels, rowBytes, NULL, NULL, NULL); |
| 145 } |
| 146 |
| 96 SkScanlineDecoder* SkCodec::getScanlineDecoder(const SkImageInfo& dstInfo, const
Options* options, | 147 SkScanlineDecoder* SkCodec::getScanlineDecoder(const SkImageInfo& dstInfo, const
Options* options, |
| 97 SkPMColor ctable[], int* ctableCount) { | 148 SkPMColor ctable[], int* ctableCount) { |
| 98 | 149 |
| 99 // Set options. | 150 // Set options. |
| 100 Options optsStorage; | 151 Options optsStorage; |
| 101 if (NULL == options) { | 152 if (NULL == options) { |
| 102 options = &optsStorage; | 153 options = &optsStorage; |
| 103 } | 154 } |
| 104 | 155 |
| 105 fScanlineDecoder.reset(this->onGetScanlineDecoder(dstInfo, *options, ctable,
ctableCount)); | 156 SkDELETE(fScanlineDecoder); |
| 106 return fScanlineDecoder.get(); | 157 fScanlineDecoder = this->onGetScanlineDecoder(dstInfo, *options, ctable, cta
bleCount); |
| 158 return fScanlineDecoder; |
| 107 } | 159 } |
| 108 | 160 |
| 109 SkScanlineDecoder* SkCodec::getScanlineDecoder(const SkImageInfo& dstInfo) { | 161 SkScanlineDecoder* SkCodec::getScanlineDecoder(const SkImageInfo& dstInfo) { |
| 110 SkASSERT(kIndex_8_SkColorType != dstInfo.colorType()); | 162 SkASSERT(kIndex_8_SkColorType != dstInfo.colorType()); |
| 111 if (kIndex_8_SkColorType == dstInfo.colorType()) { | 163 if (kIndex_8_SkColorType == dstInfo.colorType()) { |
| 112 return NULL; | 164 return NULL; |
| 113 } | 165 } |
| 114 return this->getScanlineDecoder(dstInfo, NULL, NULL, NULL); | 166 return this->getScanlineDecoder(dstInfo, NULL, NULL, NULL); |
| 115 } | 167 } |
| OLD | NEW |