| 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" | 8 #include "SkBmpCodec.h" |
| 9 #include "SkCodec.h" | 9 #include "SkCodec.h" |
| 10 #include "SkData.h" | 10 #include "SkData.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 , fStream(stream) | 80 , fStream(stream) |
| 81 , fNeedsRewind(false) | 81 , fNeedsRewind(false) |
| 82 , fDstInfo() | 82 , fDstInfo() |
| 83 , fOptions() | 83 , fOptions() |
| 84 , fCurrScanline(-1) | 84 , fCurrScanline(-1) |
| 85 {} | 85 {} |
| 86 | 86 |
| 87 SkCodec::~SkCodec() {} | 87 SkCodec::~SkCodec() {} |
| 88 | 88 |
| 89 bool SkCodec::rewindIfNeeded() { | 89 bool SkCodec::rewindIfNeeded() { |
| 90 if (!fStream) { |
| 91 // Some codecs do not have a stream, but they hold others that do. They |
| 92 // must handle rewinding themselves. |
| 93 return true; |
| 94 } |
| 95 |
| 90 // Store the value of fNeedsRewind so we can update it. Next read will | 96 // Store the value of fNeedsRewind so we can update it. Next read will |
| 91 // require a rewind. | 97 // require a rewind. |
| 92 const bool needsRewind = fNeedsRewind; | 98 const bool needsRewind = fNeedsRewind; |
| 93 fNeedsRewind = true; | 99 fNeedsRewind = true; |
| 94 if (!needsRewind) { | 100 if (!needsRewind) { |
| 95 return true; | 101 return true; |
| 96 } | 102 } |
| 97 | 103 |
| 98 // startScanlineDecode will need to be called before decoding scanlines. | 104 // startScanlineDecode will need to be called before decoding scanlines. |
| 99 fCurrScanline = -1; | 105 fCurrScanline = -1; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 137 |
| 132 { | 138 { |
| 133 SkAlphaType canonical; | 139 SkAlphaType canonical; |
| 134 if (!SkColorTypeValidateAlphaType(info.colorType(), info.alphaType(), &c
anonical) | 140 if (!SkColorTypeValidateAlphaType(info.colorType(), info.alphaType(), &c
anonical) |
| 135 || canonical != info.alphaType()) | 141 || canonical != info.alphaType()) |
| 136 { | 142 { |
| 137 return kInvalidConversion; | 143 return kInvalidConversion; |
| 138 } | 144 } |
| 139 } | 145 } |
| 140 | 146 |
| 147 if (!this->rewindIfNeeded()) { |
| 148 return kCouldNotRewind; |
| 149 } |
| 150 |
| 141 // Default options. | 151 // Default options. |
| 142 Options optsStorage; | 152 Options optsStorage; |
| 143 if (nullptr == options) { | 153 if (nullptr == options) { |
| 144 options = &optsStorage; | 154 options = &optsStorage; |
| 145 } | 155 } |
| 146 const Result result = this->onGetPixels(info, pixels, rowBytes, *options, ct
able, ctableCount); | 156 const Result result = this->onGetPixels(info, pixels, rowBytes, *options, ct
able, ctableCount); |
| 147 | 157 |
| 148 if ((kIncompleteInput == result || kSuccess == result) && ctableCount) { | 158 if ((kIncompleteInput == result || kSuccess == result) && ctableCount) { |
| 149 SkASSERT(*ctableCount >= 0 && *ctableCount <= 256); | 159 SkASSERT(*ctableCount >= 0 && *ctableCount <= 256); |
| 150 } | 160 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 165 return SkCodec::kInvalidParameters; | 175 return SkCodec::kInvalidParameters; |
| 166 } | 176 } |
| 167 } else { | 177 } else { |
| 168 if (ctableCount) { | 178 if (ctableCount) { |
| 169 *ctableCount = 0; | 179 *ctableCount = 0; |
| 170 } | 180 } |
| 171 ctableCount = nullptr; | 181 ctableCount = nullptr; |
| 172 ctable = nullptr; | 182 ctable = nullptr; |
| 173 } | 183 } |
| 174 | 184 |
| 185 if (!this->rewindIfNeeded()) { |
| 186 return kCouldNotRewind; |
| 187 } |
| 188 |
| 175 // Set options. | 189 // Set options. |
| 176 Options optsStorage; | 190 Options optsStorage; |
| 177 if (nullptr == options) { | 191 if (nullptr == options) { |
| 178 options = &optsStorage; | 192 options = &optsStorage; |
| 179 } | 193 } |
| 180 | 194 |
| 181 const Result result = this->onStartScanlineDecode(dstInfo, *options, ctable,
ctableCount); | 195 const Result result = this->onStartScanlineDecode(dstInfo, *options, ctable,
ctableCount); |
| 182 if (result != SkCodec::kSuccess) { | 196 if (result != SkCodec::kSuccess) { |
| 183 return result; | 197 return result; |
| 184 } | 198 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 // Arguably, we could just skip the scanlines which are remaining, | 233 // Arguably, we could just skip the scanlines which are remaining, |
| 220 // and return kSuccess. We choose to return invalid so the client | 234 // and return kSuccess. We choose to return invalid so the client |
| 221 // can catch their bug. | 235 // can catch their bug. |
| 222 return SkCodec::kInvalidParameters; | 236 return SkCodec::kInvalidParameters; |
| 223 } | 237 } |
| 224 | 238 |
| 225 const Result result = this->onSkipScanlines(countLines); | 239 const Result result = this->onSkipScanlines(countLines); |
| 226 fCurrScanline += countLines; | 240 fCurrScanline += countLines; |
| 227 return result; | 241 return result; |
| 228 } | 242 } |
| OLD | NEW |