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_libpng.h" | 8 #include "SkCodec_libpng.h" |
9 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 return kPremul_SkAlphaType == dst.alphaType() && | 361 return kPremul_SkAlphaType == dst.alphaType() && |
362 kUnpremul_SkAlphaType == src.alphaType(); | 362 kUnpremul_SkAlphaType == src.alphaType(); |
363 } | 363 } |
364 | 364 |
365 SkCodec::Result SkPngCodec::onGetPixels(const SkImageInfo& requestedInfo, void*
dst, | 365 SkCodec::Result SkPngCodec::onGetPixels(const SkImageInfo& requestedInfo, void*
dst, |
366 size_t rowBytes, const Options& options, | 366 size_t rowBytes, const Options& options, |
367 SkPMColor ctable[], int* ctableCount) { | 367 SkPMColor ctable[], int* ctableCount) { |
368 if (!this->rewindIfNeeded()) { | 368 if (!this->rewindIfNeeded()) { |
369 return kCouldNotRewind; | 369 return kCouldNotRewind; |
370 } | 370 } |
371 if (requestedInfo.dimensions() != this->getOriginalInfo().dimensions()) { | 371 if (requestedInfo.dimensions() != this->getInfo().dimensions()) { |
372 return kInvalidScale; | 372 return kInvalidScale; |
373 } | 373 } |
374 if (!conversion_possible(requestedInfo, this->getOriginalInfo())) { | 374 if (!conversion_possible(requestedInfo, this->getInfo())) { |
375 return kInvalidConversion; | 375 return kInvalidConversion; |
376 } | 376 } |
377 | 377 |
378 SkBitmap decodedBitmap; | 378 SkBitmap decodedBitmap; |
379 // If installPixels would have failed, getPixels should have failed before | 379 // If installPixels would have failed, getPixels should have failed before |
380 // calling onGetPixels. | 380 // calling onGetPixels. |
381 SkAssertResult(decodedBitmap.installPixels(requestedInfo, dst, rowBytes)); | 381 SkAssertResult(decodedBitmap.installPixels(requestedInfo, dst, rowBytes)); |
382 | 382 |
383 // Initialize all non-trivial objects before setjmp. | 383 // Initialize all non-trivial objects before setjmp. |
384 SkAutoTUnref<SkColorTable> colorTable; | 384 SkAutoTUnref<SkColorTable> colorTable; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 | 417 |
418 if (at != requestedInfo.alphaType()) { | 418 if (at != requestedInfo.alphaType()) { |
419 // It turns out the image is opaque. | 419 // It turns out the image is opaque. |
420 SkASSERT(kOpaque_SkAlphaType == at); | 420 SkASSERT(kOpaque_SkAlphaType == at); |
421 } | 421 } |
422 } else if (kAlpha_8_SkColorType == requestedInfo.colorType()) { | 422 } else if (kAlpha_8_SkColorType == requestedInfo.colorType()) { |
423 // Note: we check the destination, since otherwise we would have | 423 // Note: we check the destination, since otherwise we would have |
424 // told png to upscale. | 424 // told png to upscale. |
425 SkASSERT(PNG_COLOR_TYPE_GRAY == pngColorType); | 425 SkASSERT(PNG_COLOR_TYPE_GRAY == pngColorType); |
426 sc = SkSwizzler::kGray; | 426 sc = SkSwizzler::kGray; |
427 } else if (this->getOriginalInfo().alphaType() == kOpaque_SkAlphaType) { | 427 } else if (this->getInfo().alphaType() == kOpaque_SkAlphaType) { |
428 sc = SkSwizzler::kRGBX; | 428 sc = SkSwizzler::kRGBX; |
429 } else { | 429 } else { |
430 sc = SkSwizzler::kRGBA; | 430 sc = SkSwizzler::kRGBA; |
431 } | 431 } |
432 const SkPMColor* colors = colorTable ? colorTable->readColors() : NULL; | 432 const SkPMColor* colors = colorTable ? colorTable->readColors() : NULL; |
433 swizzler.reset(SkSwizzler::CreateSwizzler(sc, colors, requestedInfo, | 433 swizzler.reset(SkSwizzler::CreateSwizzler(sc, colors, requestedInfo, |
434 dst, rowBytes, | 434 dst, rowBytes, |
435 options.fZeroInitialized)); | 435 options.fZeroInitialized)); |
436 if (!swizzler) { | 436 if (!swizzler) { |
437 // FIXME: CreateSwizzler could fail for another reason. | 437 // FIXME: CreateSwizzler could fail for another reason. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 | 480 |
481 // FIXME: do we need substituteTranspColor? | 481 // FIXME: do we need substituteTranspColor? |
482 | 482 |
483 if (reallyHasAlpha && requestedInfo.alphaType() != kOpaque_SkAlphaType) { | 483 if (reallyHasAlpha && requestedInfo.alphaType() != kOpaque_SkAlphaType) { |
484 // FIXME: We want to alert the caller. Is this the right way? | 484 // FIXME: We want to alert the caller. Is this the right way? |
485 SkImageInfo* modInfo = const_cast<SkImageInfo*>(&requestedInfo); | 485 SkImageInfo* modInfo = const_cast<SkImageInfo*>(&requestedInfo); |
486 *modInfo = requestedInfo.makeAlphaType(kOpaque_SkAlphaType); | 486 *modInfo = requestedInfo.makeAlphaType(kOpaque_SkAlphaType); |
487 } | 487 } |
488 return kSuccess; | 488 return kSuccess; |
489 } | 489 } |
OLD | NEW |