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