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

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

Issue 17448010: Speed up png decoding by eliminating branches from the core loop that fills ImageFrame with pixels (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 6 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 (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 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 482
483 #if USE(QCMSLIB) 483 #if USE(QCMSLIB)
484 if (qcms_transform* transform = m_reader->colorTransform()) { 484 if (qcms_transform* transform = m_reader->colorTransform()) {
485 qcms_transform_data(transform, row, m_reader->rowBuffer(), size().width( )); 485 qcms_transform_data(transform, row, m_reader->rowBuffer(), size().width( ));
486 row = m_reader->rowBuffer(); 486 row = m_reader->rowBuffer();
487 } 487 }
488 #endif 488 #endif
489 489
490 // Write the decoded row pixels to the frame buffer. 490 // Write the decoded row pixels to the frame buffer.
491 ImageFrame::PixelData* address = buffer.getAddr(0, y); 491 ImageFrame::PixelData* address = buffer.getAddr(0, y);
492 bool nonTrivialAlpha = false; 492 unsigned alphaMask = 255;
493 int width = size().width(); 493 int width = size().width();
494 494
495 // Do not merge the loops below. They are hand rolled for each case for maxi mal performance.
495 png_bytep pixel = row; 496 png_bytep pixel = row;
496 for (int x = 0; x < width; ++x, pixel += colorChannels) { 497 if (hasAlpha) {
497 unsigned alpha = hasAlpha ? pixel[3] : 255; 498 if (buffer.premultiplyAlpha()) {
498 buffer.setRGBA(address++, pixel[0], pixel[1], pixel[2], alpha); 499 for (int x = 0; x < width; ++x, pixel += 4) {
499 nonTrivialAlpha |= alpha < 255; 500 buffer.setRGBAPremultiply(address + x, pixel[0], pixel[1], pixel [2], pixel[3]);
501 alphaMask &= pixel[3];
502 }
503 } else {
504 for (int x = 0; x < width; ++x, pixel += 4) {
505 buffer.setRGBARaw(address + x, pixel[0], pixel[1], pixel[2], pix el[3]);
506 alphaMask &= pixel[3];
507 }
508 }
509 } else {
510 for (int x = 0; x < width; ++x, pixel += 3)
511 buffer.setRGB(address + x, pixel[0], pixel[1], pixel[2]);
500 } 512 }
501 513
502 if (nonTrivialAlpha && !buffer.hasAlpha()) 514 bool hasNonTrivialAlpha = alphaMask != 255;
503 buffer.setHasAlpha(nonTrivialAlpha); 515 buffer.setHasAlpha(hasNonTrivialAlpha);
kbalazs_ 2013/06/25 13:20:18 Oops, this war wrong, we cannot make !hasAlpha() j
504 } 516 }
505 517
506 void PNGImageDecoder::pngComplete() 518 void PNGImageDecoder::pngComplete()
507 { 519 {
508 if (!m_frameBufferCache.isEmpty()) 520 if (!m_frameBufferCache.isEmpty())
509 m_frameBufferCache.first().setStatus(ImageFrame::FrameComplete); 521 m_frameBufferCache.first().setStatus(ImageFrame::FrameComplete);
510 } 522 }
511 523
512 void PNGImageDecoder::decode(bool onlySize) 524 void PNGImageDecoder::decode(bool onlySize)
513 { 525 {
514 if (failed()) 526 if (failed())
515 return; 527 return;
516 528
517 if (!m_reader) 529 if (!m_reader)
518 m_reader = adoptPtr(new PNGImageReader(this)); 530 m_reader = adoptPtr(new PNGImageReader(this));
519 531
520 // If we couldn't decode the image but we've received all the data, decoding 532 // If we couldn't decode the image but we've received all the data, decoding
521 // has failed. 533 // has failed.
522 if (!m_reader->decode(*m_data, onlySize) && isAllDataReceived()) 534 if (!m_reader->decode(*m_data, onlySize) && isAllDataReceived())
523 setFailed(); 535 setFailed();
524 // If we're done decoding the image, we don't need the PNGImageReader 536 // If we're done decoding the image, we don't need the PNGImageReader
525 // anymore. (If we failed, |m_reader| has already been cleared.) 537 // anymore. (If we failed, |m_reader| has already been cleared.)
526 else if (isComplete()) 538 else if (isComplete())
527 m_reader.clear(); 539 m_reader.clear();
528 } 540 }
529 541
530 } // namespace WebCore 542 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698