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

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: Moved bmp specific code out of the swizzler 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 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 dst, rowBytes, false)); 438 dst, rowBytes, false));
439 if (!swizzler) { 439 if (!swizzler) {
440 // FIXME: CreateSwizzler could fail for another reason. 440 // FIXME: CreateSwizzler could fail for another reason.
441 return kUnimplemented; 441 return kUnimplemented;
442 } 442 }
443 443
444 // FIXME: Here is where we should likely insert some of the modifications 444 // FIXME: Here is where we should likely insert some of the modifications
445 // made in the factory. 445 // made in the factory.
446 png_read_update_info(fPng_ptr, fInfo_ptr); 446 png_read_update_info(fPng_ptr, fInfo_ptr);
447 447
448 const int bpp = SkSwizzler::BitsPerPixel(sc) / 8;
scroggo 2015/03/06 18:56:14 This makes me nervous that we've messed up if Bits
448 if (numberPasses > 1) { 449 if (numberPasses > 1) {
449 const int width = requestedInfo.width(); 450 const int width = requestedInfo.width();
450 const int height = requestedInfo.height(); 451 const int height = requestedInfo.height();
451 const int bpp = SkSwizzler::BytesPerPixel(sc);
452 const size_t rowBytes = width * bpp; 452 const size_t rowBytes = width * bpp;
453 453
454 storage.reset(width * height * bpp); 454 storage.reset(width * height * bpp);
455 uint8_t* const base = static_cast<uint8_t*>(storage.get()); 455 uint8_t* const base = static_cast<uint8_t*>(storage.get());
456 456
457 for (int i = 0; i < numberPasses; i++) { 457 for (int i = 0; i < numberPasses; i++) {
458 uint8_t* row = base; 458 uint8_t* row = base;
459 for (png_uint_32 y = 0; y < height; y++) { 459 for (png_uint_32 y = 0; y < height; y++) {
460 uint8_t* bmRow = row; 460 uint8_t* bmRow = row;
461 png_read_rows(fPng_ptr, &bmRow, png_bytepp_NULL, 1); 461 png_read_rows(fPng_ptr, &bmRow, png_bytepp_NULL, 1);
462 row += rowBytes; 462 row += rowBytes;
463 } 463 }
464 } 464 }
465 465
466 // Now swizzle it. 466 // Now swizzle it.
467 uint8_t* row = base; 467 uint8_t* row = base;
468 for (int y = 0; y < height; y++) { 468 for (int y = 0; y < height; y++) {
469 reallyHasAlpha |= swizzler->next(row); 469 reallyHasAlpha |= swizzler->next(row);
470 row += rowBytes; 470 row += rowBytes;
471 } 471 }
472 } else { 472 } else {
473 storage.reset(requestedInfo.width() * SkSwizzler::BytesPerPixel(sc)); 473 storage.reset(requestedInfo.width() * bpp);
474 uint8_t* srcRow = static_cast<uint8_t*>(storage.get()); 474 uint8_t* srcRow = static_cast<uint8_t*>(storage.get());
475 for (int y = 0; y < requestedInfo.height(); y++) { 475 for (int y = 0; y < requestedInfo.height(); y++) {
476 png_read_rows(fPng_ptr, &srcRow, png_bytepp_NULL, 1); 476 png_read_rows(fPng_ptr, &srcRow, png_bytepp_NULL, 1);
477 reallyHasAlpha |= swizzler->next(srcRow); 477 reallyHasAlpha |= swizzler->next(srcRow);
478 } 478 }
479 } 479 }
480 480
481 /* 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 */
482 png_read_end(fPng_ptr, fInfo_ptr); 482 png_read_end(fPng_ptr, fInfo_ptr);
483 483
484 // FIXME: do we need substituteTranspColor? 484 // FIXME: do we need substituteTranspColor?
485 485
486 if (reallyHasAlpha && requestedInfo.alphaType() != kOpaque_SkAlphaType) { 486 if (reallyHasAlpha && requestedInfo.alphaType() != kOpaque_SkAlphaType) {
487 // 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?
488 SkImageInfo* modInfo = const_cast<SkImageInfo*>(&requestedInfo); 488 SkImageInfo* modInfo = const_cast<SkImageInfo*>(&requestedInfo);
489 *modInfo = requestedInfo.makeAlphaType(kOpaque_SkAlphaType); 489 *modInfo = requestedInfo.makeAlphaType(kOpaque_SkAlphaType);
490 } 490 }
491 return kSuccess; 491 return kSuccess;
492 } 492 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698