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 "SkCodecPriv.h" | 10 #include "SkCodecPriv.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 // startScanlineDecode will need to be called before decoding scanlines. | 147 // startScanlineDecode will need to be called before decoding scanlines. |
148 fCurrScanline = -1; | 148 fCurrScanline = -1; |
149 | 149 |
150 if (!fStream->rewind()) { | 150 if (!fStream->rewind()) { |
151 return false; | 151 return false; |
152 } | 152 } |
153 | 153 |
154 return this->onRewind(); | 154 return this->onRewind(); |
155 } | 155 } |
156 | 156 |
157 #define CHECK_COLOR_TABLE \ | |
158 if (kIndex_8_SkColorType == info.colorType()) { \ | |
msarett
2016/05/20 18:21:38
nit: line up slash?
scroggo_chromium
2016/05/20 18:58:37
D'oh! edited this after putting the slash there. D
| |
159 if (nullptr == ctable || nullptr == ctableCount) { \ | |
160 return SkCodec::kInvalidParameters; \ | |
161 } \ | |
162 } else { \ | |
163 if (ctableCount) { \ | |
164 *ctableCount = 0; \ | |
165 } \ | |
166 ctableCount = nullptr; \ | |
167 ctable = nullptr; \ | |
168 } | |
169 | |
170 | |
157 SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, | 171 SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, |
158 const Options* options, SkPMColor ctable[], i nt* ctableCount) { | 172 const Options* options, SkPMColor ctable[], i nt* ctableCount) { |
159 if (kUnknown_SkColorType == info.colorType()) { | 173 if (kUnknown_SkColorType == info.colorType()) { |
160 return kInvalidConversion; | 174 return kInvalidConversion; |
161 } | 175 } |
162 if (nullptr == pixels) { | 176 if (nullptr == pixels) { |
163 return kInvalidParameters; | 177 return kInvalidParameters; |
164 } | 178 } |
165 if (rowBytes < info.minRowBytes()) { | 179 if (rowBytes < info.minRowBytes()) { |
166 return kInvalidParameters; | 180 return kInvalidParameters; |
167 } | 181 } |
168 | 182 |
169 if (kIndex_8_SkColorType == info.colorType()) { | 183 CHECK_COLOR_TABLE; |
170 if (nullptr == ctable || nullptr == ctableCount) { | |
171 return kInvalidParameters; | |
172 } | |
173 } else { | |
174 if (ctableCount) { | |
175 *ctableCount = 0; | |
176 } | |
177 ctableCount = nullptr; | |
178 ctable = nullptr; | |
179 } | |
180 | 184 |
181 if (!this->rewindIfNeeded()) { | 185 if (!this->rewindIfNeeded()) { |
182 return kCouldNotRewind; | 186 return kCouldNotRewind; |
183 } | 187 } |
184 | 188 |
185 // Default options. | 189 // Default options. |
186 Options optsStorage; | 190 Options optsStorage; |
187 if (nullptr == options) { | 191 if (nullptr == options) { |
188 options = &optsStorage; | 192 options = &optsStorage; |
189 } else if (options->fSubset) { | 193 } else if (options->fSubset) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 rowsDecoded); | 225 rowsDecoded); |
222 } | 226 } |
223 | 227 |
224 return result; | 228 return result; |
225 } | 229 } |
226 | 230 |
227 SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes) { | 231 SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes) { |
228 return this->getPixels(info, pixels, rowBytes, nullptr, nullptr, nullptr); | 232 return this->getPixels(info, pixels, rowBytes, nullptr, nullptr, nullptr); |
229 } | 233 } |
230 | 234 |
231 SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& dstInfo, | 235 SkCodec::Result SkCodec::startIncrementalDecode(const SkImageInfo& info, |
236 const SkCodec::Options* options, SkPMColor* ctable, int* ctableCount) { | |
237 fStartedIncrementalDecode = false; | |
238 | |
239 // Ensure that valid color ptrs are passed in for kIndex8 color type | |
240 CHECK_COLOR_TABLE; | |
241 | |
242 // FIXME: If the rows come after the rows of a previous incremental decode, | |
243 // we might be able to skip the rewind, but only the implementation knows | |
244 // that. (e.g. PNG will always need to rewind, since we called longjmp, but | |
245 // a bottom-up BMP could skip rewinding if the new rows are above the old | |
246 // rows.) | |
247 if (!this->rewindIfNeeded()) { | |
248 return kCouldNotRewind; | |
249 } | |
250 | |
251 // Set options. | |
252 Options optsStorage; | |
253 if (nullptr == options) { | |
254 options = &optsStorage; | |
255 } else if (options->fSubset) { | |
256 SkIRect size = SkIRect::MakeSize(info.dimensions()); | |
257 if (!size.contains(*options->fSubset)) { | |
258 return kInvalidParameters; | |
259 } | |
260 | |
261 const int top = options->fSubset->top(); | |
262 const int bottom = options->fSubset->bottom(); | |
263 if (top < 0 || top >= info.height() || top >= bottom || bottom > info.he ight()) { | |
264 return kInvalidParameters; | |
265 } | |
266 } | |
267 | |
268 if (!this->dimensionsSupported(info.dimensions())) { | |
269 return kInvalidScale; | |
270 } | |
271 | |
272 fDstInfo = info; | |
273 fOptions = *options; | |
274 | |
275 const Result result = this->onStartIncrementalDecode(info, fOptions, ctable, | |
276 ctableCount); | |
277 if (kSuccess == result) { | |
278 fStartedIncrementalDecode = true; | |
279 } | |
280 return result; | |
281 } | |
282 | |
283 | |
284 SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& info, | |
232 const SkCodec::Options* options, SkPMColor ctable[], int* ctableCount) { | 285 const SkCodec::Options* options, SkPMColor ctable[], int* ctableCount) { |
233 // Reset fCurrScanline in case of failure. | 286 // Reset fCurrScanline in case of failure. |
234 fCurrScanline = -1; | 287 fCurrScanline = -1; |
235 // Ensure that valid color ptrs are passed in for kIndex8 color type | 288 // Ensure that valid color ptrs are passed in for kIndex8 color type |
236 if (kIndex_8_SkColorType == dstInfo.colorType()) { | 289 CHECK_COLOR_TABLE; |
237 if (nullptr == ctable || nullptr == ctableCount) { | |
238 return SkCodec::kInvalidParameters; | |
239 } | |
240 } else { | |
241 if (ctableCount) { | |
242 *ctableCount = 0; | |
243 } | |
244 ctableCount = nullptr; | |
245 ctable = nullptr; | |
246 } | |
247 | 290 |
248 if (!this->rewindIfNeeded()) { | 291 if (!this->rewindIfNeeded()) { |
249 return kCouldNotRewind; | 292 return kCouldNotRewind; |
250 } | 293 } |
251 | 294 |
252 // Set options. | 295 // Set options. |
253 Options optsStorage; | 296 Options optsStorage; |
254 if (nullptr == options) { | 297 if (nullptr == options) { |
255 options = &optsStorage; | 298 options = &optsStorage; |
256 } else if (options->fSubset) { | 299 } else if (options->fSubset) { |
257 SkIRect size = SkIRect::MakeSize(dstInfo.dimensions()); | 300 SkIRect size = SkIRect::MakeSize(info.dimensions()); |
258 if (!size.contains(*options->fSubset)) { | 301 if (!size.contains(*options->fSubset)) { |
259 return kInvalidInput; | 302 return kInvalidInput; |
260 } | 303 } |
261 | 304 |
262 // We only support subsetting in the x-dimension for scanline decoder. | 305 // We only support subsetting in the x-dimension for scanline decoder. |
263 // Subsetting in the y-dimension can be accomplished using skipScanlines (). | 306 // Subsetting in the y-dimension can be accomplished using skipScanlines (). |
264 if (options->fSubset->top() != 0 || options->fSubset->height() != dstInf o.height()) { | 307 if (options->fSubset->top() != 0 || options->fSubset->height() != info.h eight()) { |
265 return kInvalidInput; | 308 return kInvalidInput; |
266 } | 309 } |
267 } | 310 } |
268 | 311 |
269 // FIXME: Support subsets somehow? | 312 // FIXME: Support subsets somehow? |
270 if (!this->dimensionsSupported(dstInfo.dimensions())) { | 313 if (!this->dimensionsSupported(info.dimensions())) { |
271 return kInvalidScale; | 314 return kInvalidScale; |
272 } | 315 } |
273 | 316 |
274 const Result result = this->onStartScanlineDecode(dstInfo, *options, ctable, ctableCount); | 317 const Result result = this->onStartScanlineDecode(info, *options, ctable, ct ableCount); |
275 if (result != SkCodec::kSuccess) { | 318 if (result != SkCodec::kSuccess) { |
276 return result; | 319 return result; |
277 } | 320 } |
278 | 321 |
279 fCurrScanline = 0; | 322 fCurrScanline = 0; |
280 fDstInfo = dstInfo; | 323 fDstInfo = info; |
281 fOptions = *options; | 324 fOptions = *options; |
282 return kSuccess; | 325 return kSuccess; |
283 } | 326 } |
284 | 327 |
285 SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& dstInfo) { | 328 #undef CHECK_COLOR_TABLE |
286 return this->startScanlineDecode(dstInfo, nullptr, nullptr, nullptr); | 329 |
330 SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& info) { | |
331 return this->startScanlineDecode(info, nullptr, nullptr, nullptr); | |
287 } | 332 } |
288 | 333 |
289 int SkCodec::getScanlines(void* dst, int countLines, size_t rowBytes) { | 334 int SkCodec::getScanlines(void* dst, int countLines, size_t rowBytes) { |
290 if (fCurrScanline < 0) { | 335 if (fCurrScanline < 0) { |
291 return 0; | 336 return 0; |
292 } | 337 } |
293 | 338 |
294 SkASSERT(!fDstInfo.isEmpty()); | 339 SkASSERT(!fDstInfo.isEmpty()); |
295 if (countLines <= 0 || fCurrScanline + countLines > fDstInfo.height()) { | 340 if (countLines <= 0 || fCurrScanline + countLines > fDstInfo.height()) { |
296 return 0; | 341 return 0; |
(...skipping 27 matching lines...) Expand all Loading... | |
324 } | 369 } |
325 | 370 |
326 int SkCodec::outputScanline(int inputScanline) const { | 371 int SkCodec::outputScanline(int inputScanline) const { |
327 SkASSERT(0 <= inputScanline && inputScanline < this->getInfo().height()); | 372 SkASSERT(0 <= inputScanline && inputScanline < this->getInfo().height()); |
328 return this->onOutputScanline(inputScanline); | 373 return this->onOutputScanline(inputScanline); |
329 } | 374 } |
330 | 375 |
331 int SkCodec::onOutputScanline(int inputScanline) const { | 376 int SkCodec::onOutputScanline(int inputScanline) const { |
332 switch (this->getScanlineOrder()) { | 377 switch (this->getScanlineOrder()) { |
333 case kTopDown_SkScanlineOrder: | 378 case kTopDown_SkScanlineOrder: |
334 case kNone_SkScanlineOrder: | |
335 return inputScanline; | 379 return inputScanline; |
336 case kBottomUp_SkScanlineOrder: | 380 case kBottomUp_SkScanlineOrder: |
337 return this->getInfo().height() - inputScanline - 1; | 381 return this->getInfo().height() - inputScanline - 1; |
338 default: | 382 default: |
339 // This case indicates an interlaced gif and is implemented by SkGif Codec. | 383 // This case indicates an interlaced gif and is implemented by SkGif Codec. |
340 SkASSERT(false); | 384 SkASSERT(false); |
341 return 0; | 385 return 0; |
342 } | 386 } |
343 } | 387 } |
344 | 388 |
(...skipping 13 matching lines...) Expand all Loading... | |
358 const uint32_t fillValue = this->getFillValue(info.colorType()); | 402 const uint32_t fillValue = this->getFillValue(info.colorType()); |
359 const int linesRemaining = linesRequested - linesDecoded; | 403 const int linesRemaining = linesRequested - linesDecoded; |
360 SkSampler* sampler = this->getSampler(false); | 404 SkSampler* sampler = this->getSampler(false); |
361 | 405 |
362 int fillWidth = info.width(); | 406 int fillWidth = info.width(); |
363 if (fOptions.fSubset) { | 407 if (fOptions.fSubset) { |
364 fillWidth = fOptions.fSubset->width(); | 408 fillWidth = fOptions.fSubset->width(); |
365 } | 409 } |
366 | 410 |
367 switch (this->getScanlineOrder()) { | 411 switch (this->getScanlineOrder()) { |
368 case kTopDown_SkScanlineOrder: | 412 case kTopDown_SkScanlineOrder: { |
369 case kNone_SkScanlineOrder: { | |
370 const SkImageInfo fillInfo = info.makeWH(fillWidth, linesRemaining); | 413 const SkImageInfo fillInfo = info.makeWH(fillWidth, linesRemaining); |
371 fillDst = SkTAddOffset<void>(dst, linesDecoded * rowBytes); | 414 fillDst = SkTAddOffset<void>(dst, linesDecoded * rowBytes); |
372 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, sampler) ; | 415 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, sampler) ; |
373 break; | 416 break; |
374 } | 417 } |
375 case kBottomUp_SkScanlineOrder: { | 418 case kBottomUp_SkScanlineOrder: { |
376 fillDst = dst; | 419 fillDst = dst; |
377 const SkImageInfo fillInfo = info.makeWH(fillWidth, linesRemaining); | 420 const SkImageInfo fillInfo = info.makeWH(fillWidth, linesRemaining); |
378 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, sampler) ; | 421 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, sampler) ; |
379 break; | 422 break; |
380 } | 423 } |
381 case kOutOfOrder_SkScanlineOrder: { | 424 case kOutOfOrder_SkScanlineOrder: { |
382 SkASSERT(1 == linesRequested || this->getInfo().height() == linesReq uested); | 425 SkASSERT(1 == linesRequested || this->getInfo().height() == linesReq uested); |
383 const SkImageInfo fillInfo = info.makeWH(fillWidth, 1); | 426 const SkImageInfo fillInfo = info.makeWH(fillWidth, 1); |
384 for (int srcY = linesDecoded; srcY < linesRequested; srcY++) { | 427 for (int srcY = linesDecoded; srcY < linesRequested; srcY++) { |
385 fillDst = SkTAddOffset<void>(dst, this->outputScanline(srcY) * r owBytes); | 428 fillDst = SkTAddOffset<void>(dst, this->outputScanline(srcY) * r owBytes); |
386 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, samp ler); | 429 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, samp ler); |
387 } | 430 } |
388 break; | 431 break; |
389 } | 432 } |
390 } | 433 } |
391 } | 434 } |
OLD | NEW |