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

Side by Side Diff: Source/platform/image-decoders/png/PNGImageDecoder.cpp

Issue 18099004: Improve PNG decode performance: avoid branching in the row write loop (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: template patch. Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006 Apple Computer, Inc. 2 * Copyright (C) 2006 Apple Computer, Inc.
3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. 3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
4 * 4 *
5 * Portions are Copyright (C) 2001 mozilla.org 5 * Portions are Copyright (C) 2001 mozilla.org
6 * 6 *
7 * Other contributors: 7 * Other contributors:
8 * Stuart Parmenter <stuart@mozilla.com> 8 * Stuart Parmenter <stuart@mozilla.com>
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 484
485 #if USE(QCMSLIB) 485 #if USE(QCMSLIB)
486 if (qcms_transform* transform = m_reader->colorTransform()) { 486 if (qcms_transform* transform = m_reader->colorTransform()) {
487 qcms_transform_data(transform, row, m_reader->rowBuffer(), size().width( )); 487 qcms_transform_data(transform, row, m_reader->rowBuffer(), size().width( ));
488 row = m_reader->rowBuffer(); 488 row = m_reader->rowBuffer();
489 } 489 }
490 #endif 490 #endif
491 491
492 // Write the decoded row pixels to the frame buffer. 492 // Write the decoded row pixels to the frame buffer.
493 ImageFrame::PixelData* address = buffer.getAddr(0, y); 493 ImageFrame::PixelData* address = buffer.getAddr(0, y);
494 bool nonTrivialAlpha = false; 494 unsigned alphaMask = 255;
495 int width = size().width(); 495 int width = size().width();
496 496
497 png_bytep pixel = row; 497 png_bytep pixel = row;
498 for (int x = 0; x < width; ++x, pixel += colorChannels) { 498 if (hasAlpha) {
Peter Kasting 2014/05/12 19:36:11 Nit: Consider adding a comment here about how we w
Noel Gordon 2014/05/13 01:56:32 Added a comment.
499 unsigned alpha = hasAlpha ? pixel[3] : 255; 499 if (buffer.premultiplyAlpha()) {
500 buffer.setRGBA(address++, pixel[0], pixel[1], pixel[2], alpha); 500 for (int x = 0; x < width; ++x, pixel += 4) {
501 nonTrivialAlpha |= alpha < 255; 501 buffer.setRGBA<true>(address++, pixel[0], pixel[1], pixel[2], pi xel[3]);
502 alphaMask &= pixel[3];
503 }
504 } else {
505 for (int x = 0; x < width; ++x, pixel += 4) {
506 buffer.setRGBARaw(address++, pixel[0], pixel[1], pixel[2], pixel [3]);
507 alphaMask &= pixel[3];
508 }
509 }
510 } else {
511 for (int x = 0; x < width; ++x, pixel += 3)
512 buffer.setRGBARaw(address++, pixel[0], pixel[1], pixel[2], 255);
502 } 513 }
503 514
504 if (nonTrivialAlpha && !buffer.hasAlpha()) 515 if (alphaMask != 255 && !buffer.hasAlpha())
505 buffer.setHasAlpha(nonTrivialAlpha); 516 buffer.setHasAlpha(true);
506 517
507 buffer.setPixelsChanged(true); 518 buffer.setPixelsChanged(true);
508 } 519 }
509 520
510 void PNGImageDecoder::pngComplete() 521 void PNGImageDecoder::pngComplete()
511 { 522 {
512 if (!m_frameBufferCache.isEmpty()) 523 if (!m_frameBufferCache.isEmpty())
513 m_frameBufferCache.first().setStatus(ImageFrame::FrameComplete); 524 m_frameBufferCache.first().setStatus(ImageFrame::FrameComplete);
514 } 525 }
515 526
516 void PNGImageDecoder::decode(bool onlySize) 527 void PNGImageDecoder::decode(bool onlySize)
517 { 528 {
518 if (failed()) 529 if (failed())
519 return; 530 return;
520 531
521 if (!m_reader) 532 if (!m_reader)
522 m_reader = adoptPtr(new PNGImageReader(this)); 533 m_reader = adoptPtr(new PNGImageReader(this));
523 534
524 // If we couldn't decode the image but we've received all the data, decoding 535 // If we couldn't decode the image but we've received all the data, decoding
525 // has failed. 536 // has failed.
526 if (!m_reader->decode(*m_data, onlySize) && isAllDataReceived()) 537 if (!m_reader->decode(*m_data, onlySize) && isAllDataReceived())
527 setFailed(); 538 setFailed();
528 // If we're done decoding the image, we don't need the PNGImageReader 539 // If we're done decoding the image, we don't need the PNGImageReader
529 // anymore. (If we failed, |m_reader| has already been cleared.) 540 // anymore. (If we failed, |m_reader| has already been cleared.)
530 else if (isComplete()) 541 else if (isComplete())
531 m_reader.clear(); 542 m_reader.clear();
532 } 543 }
533 544
534 } // namespace WebCore 545 } // namespace WebCore
OLDNEW
« Source/platform/image-decoders/ImageFrame.h ('K') | « Source/platform/image-decoders/ImageFrame.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698