| 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 "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| 10 #include "SkColorTable.h" | 11 #include "SkColorTable.h" |
| 11 #include "SkBitmap.h" | 12 #include "SkBitmap.h" |
| 12 #include "SkMath.h" | 13 #include "SkMath.h" |
| 13 #include "SkSize.h" | 14 #include "SkSize.h" |
| 14 #include "SkStream.h" | 15 #include "SkStream.h" |
| 15 #include "SkSwizzler.h" | 16 #include "SkSwizzler.h" |
| 16 | 17 |
| 17 /////////////////////////////////////////////////////////////////////////////// | 18 /////////////////////////////////////////////////////////////////////////////// |
| 18 // Helper macros | 19 // Helper macros |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 , fInfo_ptr(info_ptr) {} | 340 , fInfo_ptr(info_ptr) {} |
| 340 | 341 |
| 341 SkPngCodec::~SkPngCodec() { | 342 SkPngCodec::~SkPngCodec() { |
| 342 png_destroy_read_struct(&fPng_ptr, &fInfo_ptr, png_infopp_NULL); | 343 png_destroy_read_struct(&fPng_ptr, &fInfo_ptr, png_infopp_NULL); |
| 343 } | 344 } |
| 344 | 345 |
| 345 /////////////////////////////////////////////////////////////////////////////// | 346 /////////////////////////////////////////////////////////////////////////////// |
| 346 // Getting the pixels | 347 // Getting the pixels |
| 347 /////////////////////////////////////////////////////////////////////////////// | 348 /////////////////////////////////////////////////////////////////////////////// |
| 348 | 349 |
| 349 static bool premul_and_unpremul(SkAlphaType A, SkAlphaType B) { | |
| 350 return kPremul_SkAlphaType == A && kUnpremul_SkAlphaType == B; | |
| 351 } | |
| 352 | |
| 353 static bool conversion_possible(const SkImageInfo& A, const SkImageInfo& B) { | 350 static bool conversion_possible(const SkImageInfo& A, const SkImageInfo& B) { |
| 354 // TODO: Support other conversions | 351 // TODO: Support other conversions |
| 355 if (A.colorType() != B.colorType()) { | 352 if (A.colorType() != B.colorType()) { |
| 356 return false; | 353 return false; |
| 357 } | 354 } |
| 358 if (A.profileType() != B.profileType()) { | 355 if (A.profileType() != B.profileType()) { |
| 359 return false; | 356 return false; |
| 360 } | 357 } |
| 361 if (A.alphaType() == B.alphaType()) { | 358 if (A.alphaType() == B.alphaType()) { |
| 362 return true; | 359 return true; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 for (int y = 0; y < height; y++) { | 456 for (int y = 0; y < height; y++) { |
| 460 uint8_t* bmRow = row; | 457 uint8_t* bmRow = row; |
| 461 png_read_rows(fPng_ptr, &bmRow, png_bytepp_NULL, 1); | 458 png_read_rows(fPng_ptr, &bmRow, png_bytepp_NULL, 1); |
| 462 row += rowBytes; | 459 row += rowBytes; |
| 463 } | 460 } |
| 464 } | 461 } |
| 465 | 462 |
| 466 // Now swizzle it. | 463 // Now swizzle it. |
| 467 uint8_t* row = base; | 464 uint8_t* row = base; |
| 468 for (int y = 0; y < height; y++) { | 465 for (int y = 0; y < height; y++) { |
| 469 reallyHasAlpha |= swizzler->next(row); | 466 reallyHasAlpha |= !SkSwizzler::IsOpaque(swizzler->next(row)); |
| 470 row += rowBytes; | 467 row += rowBytes; |
| 471 } | 468 } |
| 472 } else { | 469 } else { |
| 473 storage.reset(requestedInfo.width() * SkSwizzler::BytesPerPixel(sc)); | 470 storage.reset(requestedInfo.width() * SkSwizzler::BytesPerPixel(sc)); |
| 474 uint8_t* srcRow = static_cast<uint8_t*>(storage.get()); | 471 uint8_t* srcRow = static_cast<uint8_t*>(storage.get()); |
| 475 for (int y = 0; y < requestedInfo.height(); y++) { | 472 for (int y = 0; y < requestedInfo.height(); y++) { |
| 476 png_read_rows(fPng_ptr, &srcRow, png_bytepp_NULL, 1); | 473 png_read_rows(fPng_ptr, &srcRow, png_bytepp_NULL, 1); |
| 477 reallyHasAlpha |= swizzler->next(srcRow); | 474 reallyHasAlpha |= !SkSwizzler::IsOpaque(swizzler->next(srcRow)); |
| 478 } | 475 } |
| 479 } | 476 } |
| 480 | 477 |
| 481 /* read rest of file, and get additional chunks in info_ptr - REQUIRED */ | 478 /* read rest of file, and get additional chunks in info_ptr - REQUIRED */ |
| 482 png_read_end(fPng_ptr, fInfo_ptr); | 479 png_read_end(fPng_ptr, fInfo_ptr); |
| 483 | 480 |
| 484 // FIXME: do we need substituteTranspColor? | 481 // FIXME: do we need substituteTranspColor? |
| 485 | 482 |
| 486 if (reallyHasAlpha && requestedInfo.alphaType() != kOpaque_SkAlphaType) { | 483 if (reallyHasAlpha && requestedInfo.alphaType() != kOpaque_SkAlphaType) { |
| 487 // 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? |
| 488 SkImageInfo* modInfo = const_cast<SkImageInfo*>(&requestedInfo); | 485 SkImageInfo* modInfo = const_cast<SkImageInfo*>(&requestedInfo); |
| 489 *modInfo = requestedInfo.makeAlphaType(kOpaque_SkAlphaType); | 486 *modInfo = requestedInfo.makeAlphaType(kOpaque_SkAlphaType); |
| 490 } | 487 } |
| 491 return kSuccess; | 488 return kSuccess; |
| 492 } | 489 } |
| OLD | NEW |