Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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]); |
|
Noel Gordon
2013/06/26 05:15:26
address++ not working for you? Why address + x or
| |
| 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 if (!buffer.hasAlpha()) |
| 516 buffer.setHasAlpha(hasNonTrivialAlpha); | |
| 504 } | 517 } |
| 505 | 518 |
| 506 void PNGImageDecoder::pngComplete() | 519 void PNGImageDecoder::pngComplete() |
| 507 { | 520 { |
| 508 if (!m_frameBufferCache.isEmpty()) | 521 if (!m_frameBufferCache.isEmpty()) |
| 509 m_frameBufferCache.first().setStatus(ImageFrame::FrameComplete); | 522 m_frameBufferCache.first().setStatus(ImageFrame::FrameComplete); |
| 510 } | 523 } |
| 511 | 524 |
| 512 void PNGImageDecoder::decode(bool onlySize) | 525 void PNGImageDecoder::decode(bool onlySize) |
| 513 { | 526 { |
| 514 if (failed()) | 527 if (failed()) |
| 515 return; | 528 return; |
| 516 | 529 |
| 517 if (!m_reader) | 530 if (!m_reader) |
| 518 m_reader = adoptPtr(new PNGImageReader(this)); | 531 m_reader = adoptPtr(new PNGImageReader(this)); |
| 519 | 532 |
| 520 // If we couldn't decode the image but we've received all the data, decoding | 533 // If we couldn't decode the image but we've received all the data, decoding |
| 521 // has failed. | 534 // has failed. |
| 522 if (!m_reader->decode(*m_data, onlySize) && isAllDataReceived()) | 535 if (!m_reader->decode(*m_data, onlySize) && isAllDataReceived()) |
| 523 setFailed(); | 536 setFailed(); |
| 524 // If we're done decoding the image, we don't need the PNGImageReader | 537 // If we're done decoding the image, we don't need the PNGImageReader |
| 525 // anymore. (If we failed, |m_reader| has already been cleared.) | 538 // anymore. (If we failed, |m_reader| has already been cleared.) |
| 526 else if (isComplete()) | 539 else if (isComplete()) |
| 527 m_reader.clear(); | 540 m_reader.clear(); |
| 528 } | 541 } |
| 529 | 542 |
| 530 } // namespace WebCore | 543 } // namespace WebCore |
| OLD | NEW |