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