Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: src/codec/SkCodec_libpng.cpp

Issue 947283002: Bmp Image Decoding (Closed) Base URL: https://skia.googlesource.com/skia.git@decode-leon-3
Patch Set: More code sharing Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkColorTable.h" 10 #include "SkColorTable.h"
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 , fInfo_ptr(info_ptr) {} 339 , fInfo_ptr(info_ptr) {}
340 340
341 SkPngCodec::~SkPngCodec() { 341 SkPngCodec::~SkPngCodec() {
342 png_destroy_read_struct(&fPng_ptr, &fInfo_ptr, png_infopp_NULL); 342 png_destroy_read_struct(&fPng_ptr, &fInfo_ptr, png_infopp_NULL);
343 } 343 }
344 344
345 /////////////////////////////////////////////////////////////////////////////// 345 ///////////////////////////////////////////////////////////////////////////////
346 // Getting the pixels 346 // Getting the pixels
347 /////////////////////////////////////////////////////////////////////////////// 347 ///////////////////////////////////////////////////////////////////////////////
348 348
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) { 349 static bool conversion_possible(const SkImageInfo& A, const SkImageInfo& B) {
354 // TODO: Support other conversions 350 // TODO: Support other conversions
355 if (A.colorType() != B.colorType()) { 351 if (A.colorType() != B.colorType()) {
356 return false; 352 return false;
357 } 353 }
358 if (A.profileType() != B.profileType()) { 354 if (A.profileType() != B.profileType()) {
359 return false; 355 return false;
360 } 356 }
361 if (A.alphaType() == B.alphaType()) { 357 if (A.alphaType() == B.alphaType()) {
362 return true; 358 return true;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 for (int y = 0; y < height; y++) { 455 for (int y = 0; y < height; y++) {
460 uint8_t* bmRow = row; 456 uint8_t* bmRow = row;
461 png_read_rows(fPng_ptr, &bmRow, png_bytepp_NULL, 1); 457 png_read_rows(fPng_ptr, &bmRow, png_bytepp_NULL, 1);
462 row += rowBytes; 458 row += rowBytes;
463 } 459 }
464 } 460 }
465 461
466 // Now swizzle it. 462 // Now swizzle it.
467 uint8_t* row = base; 463 uint8_t* row = base;
468 for (int y = 0; y < height; y++) { 464 for (int y = 0; y < height; y++) {
469 reallyHasAlpha |= swizzler->next(row); 465 reallyHasAlpha |= !SkSwizzler::IsOpaque(swizzler->next(row));
470 row += rowBytes; 466 row += rowBytes;
471 } 467 }
472 } else { 468 } else {
473 storage.reset(requestedInfo.width() * SkSwizzler::BytesPerPixel(sc)); 469 storage.reset(requestedInfo.width() * SkSwizzler::BytesPerPixel(sc));
474 uint8_t* srcRow = static_cast<uint8_t*>(storage.get()); 470 uint8_t* srcRow = static_cast<uint8_t*>(storage.get());
475 for (int y = 0; y < requestedInfo.height(); y++) { 471 for (int y = 0; y < requestedInfo.height(); y++) {
476 png_read_rows(fPng_ptr, &srcRow, png_bytepp_NULL, 1); 472 png_read_rows(fPng_ptr, &srcRow, png_bytepp_NULL, 1);
477 reallyHasAlpha |= swizzler->next(srcRow); 473 reallyHasAlpha |= !SkSwizzler::IsOpaque(swizzler->next(srcRow));
478 } 474 }
479 } 475 }
480 476
481 /* read rest of file, and get additional chunks in info_ptr - REQUIRED */ 477 /* read rest of file, and get additional chunks in info_ptr - REQUIRED */
482 png_read_end(fPng_ptr, fInfo_ptr); 478 png_read_end(fPng_ptr, fInfo_ptr);
483 479
484 // FIXME: do we need substituteTranspColor? 480 // FIXME: do we need substituteTranspColor?
485 481
486 if (reallyHasAlpha && requestedInfo.alphaType() != kOpaque_SkAlphaType) { 482 if (reallyHasAlpha && requestedInfo.alphaType() != kOpaque_SkAlphaType) {
487 // FIXME: We want to alert the caller. Is this the right way? 483 // FIXME: We want to alert the caller. Is this the right way?
488 SkImageInfo* modInfo = const_cast<SkImageInfo*>(&requestedInfo); 484 SkImageInfo* modInfo = const_cast<SkImageInfo*>(&requestedInfo);
489 *modInfo = requestedInfo.makeAlphaType(kOpaque_SkAlphaType); 485 *modInfo = requestedInfo.makeAlphaType(kOpaque_SkAlphaType);
490 } 486 }
491 return kSuccess; 487 return kSuccess;
492 } 488 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698