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 png_progressive_combine_row(m_reader->pngPtr(), row, rowBuffer); | 482 png_progressive_combine_row(m_reader->pngPtr(), row, rowBuffer); |
483 } | 483 } |
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. The repetitive |
| 493 // form of the row write loops is for speed. |
493 ImageFrame::PixelData* address = buffer.getAddr(0, y); | 494 ImageFrame::PixelData* address = buffer.getAddr(0, y); |
494 bool nonTrivialAlpha = false; | 495 unsigned alphaMask = 255; |
495 int width = size().width(); | 496 int width = size().width(); |
496 | 497 |
497 png_bytep pixel = row; | 498 png_bytep pixel = row; |
498 for (int x = 0; x < width; ++x, pixel += colorChannels) { | 499 if (hasAlpha) { |
499 unsigned alpha = hasAlpha ? pixel[3] : 255; | 500 if (buffer.premultiplyAlpha()) { |
500 buffer.setRGBA(address++, pixel[0], pixel[1], pixel[2], alpha); | 501 for (int x = 0; x < width; ++x, pixel += 4) { |
501 nonTrivialAlpha |= alpha < 255; | 502 buffer.setRGBAPremultiply(address++, pixel[0], pixel[1], pixel[2
], pixel[3]); |
| 503 alphaMask &= pixel[3]; |
| 504 } |
| 505 } else { |
| 506 for (int x = 0; x < width; ++x, pixel += 4) { |
| 507 buffer.setRGBARaw(address++, pixel[0], pixel[1], pixel[2], pixel
[3]); |
| 508 alphaMask &= pixel[3]; |
| 509 } |
| 510 } |
| 511 } else { |
| 512 for (int x = 0; x < width; ++x, pixel += 3) { |
| 513 buffer.setRGBARaw(address++, pixel[0], pixel[1], pixel[2], 255); |
| 514 } |
502 } | 515 } |
503 | 516 |
504 if (nonTrivialAlpha && !buffer.hasAlpha()) | 517 if (alphaMask != 255 && !buffer.hasAlpha()) |
505 buffer.setHasAlpha(nonTrivialAlpha); | 518 buffer.setHasAlpha(true); |
506 | 519 |
507 buffer.setPixelsChanged(true); | 520 buffer.setPixelsChanged(true); |
508 } | 521 } |
509 | 522 |
510 void PNGImageDecoder::pngComplete() | 523 void PNGImageDecoder::pngComplete() |
511 { | 524 { |
512 if (!m_frameBufferCache.isEmpty()) | 525 if (!m_frameBufferCache.isEmpty()) |
513 m_frameBufferCache.first().setStatus(ImageFrame::FrameComplete); | 526 m_frameBufferCache.first().setStatus(ImageFrame::FrameComplete); |
514 } | 527 } |
515 | 528 |
516 void PNGImageDecoder::decode(bool onlySize) | 529 void PNGImageDecoder::decode(bool onlySize) |
517 { | 530 { |
518 if (failed()) | 531 if (failed()) |
519 return; | 532 return; |
520 | 533 |
521 if (!m_reader) | 534 if (!m_reader) |
522 m_reader = adoptPtr(new PNGImageReader(this)); | 535 m_reader = adoptPtr(new PNGImageReader(this)); |
523 | 536 |
524 // If we couldn't decode the image but we've received all the data, decoding | 537 // If we couldn't decode the image but we've received all the data, decoding |
525 // has failed. | 538 // has failed. |
526 if (!m_reader->decode(*m_data, onlySize) && isAllDataReceived()) | 539 if (!m_reader->decode(*m_data, onlySize) && isAllDataReceived()) |
527 setFailed(); | 540 setFailed(); |
528 // If we're done decoding the image, we don't need the PNGImageReader | 541 // If we're done decoding the image, we don't need the PNGImageReader |
529 // anymore. (If we failed, |m_reader| has already been cleared.) | 542 // anymore. (If we failed, |m_reader| has already been cleared.) |
530 else if (isComplete()) | 543 else if (isComplete()) |
531 m_reader.clear(); | 544 m_reader.clear(); |
532 } | 545 } |
533 | 546 |
534 } // namespace WebCore | 547 } // namespace WebCore |
OLD | NEW |