Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2008, 2009, Google Inc. All rights reserved. | 2 * Copyright (c) 2008, 2009, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 , m_decodedOffset(decodedAndHeaderOffset) | 72 , m_decodedOffset(decodedAndHeaderOffset) |
| 73 , m_headerOffset(decodedAndHeaderOffset) | 73 , m_headerOffset(decodedAndHeaderOffset) |
| 74 , m_imgDataOffset(imgDataOffset) | 74 , m_imgDataOffset(imgDataOffset) |
| 75 , m_isOS21x(false) | 75 , m_isOS21x(false) |
| 76 , m_isOS22x(false) | 76 , m_isOS22x(false) |
| 77 , m_isTopDown(false) | 77 , m_isTopDown(false) |
| 78 , m_needToProcessBitmasks(false) | 78 , m_needToProcessBitmasks(false) |
| 79 , m_needToProcessColorTable(false) | 79 , m_needToProcessColorTable(false) |
| 80 , m_seenNonZeroAlphaPixel(false) | 80 , m_seenNonZeroAlphaPixel(false) |
| 81 , m_seenZeroAlphaPixel(false) | 81 , m_seenZeroAlphaPixel(false) |
| 82 , m_hasPixelsWithAlpha(false) | |
| 82 , m_isInICO(isInICO) | 83 , m_isInICO(isInICO) |
| 83 , m_decodingAndMask(false) | 84 , m_decodingAndMask(false) |
| 84 { | 85 { |
| 85 // Clue-in decodeBMP() that we need to detect the correct info header size. | 86 // Clue-in decodeBMP() that we need to detect the correct info header size. |
| 86 memset(&m_infoHeader, 0, sizeof(m_infoHeader)); | 87 memset(&m_infoHeader, 0, sizeof(m_infoHeader)); |
| 87 } | 88 } |
| 88 | 89 |
| 89 bool BMPImageReader::decodeBMP(bool onlySize) | 90 bool BMPImageReader::decodeBMP(bool onlySize) |
| 90 { | 91 { |
| 91 // Defensively clear the FastSharedBufferReader's cache, as another caller | 92 // Defensively clear the FastSharedBufferReader's cache, as another caller |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 111 | 112 |
| 112 // Read and process the color table, if needed. | 113 // Read and process the color table, if needed. |
| 113 if (m_needToProcessColorTable && !processColorTable()) | 114 if (m_needToProcessColorTable && !processColorTable()) |
| 114 return false; | 115 return false; |
| 115 | 116 |
| 116 // Initialize the framebuffer if needed. | 117 // Initialize the framebuffer if needed. |
| 117 ASSERT(m_buffer); // Parent should set this before asking us to decode! | 118 ASSERT(m_buffer); // Parent should set this before asking us to decode! |
| 118 if (m_buffer->getStatus() == ImageFrame::FrameEmpty) { | 119 if (m_buffer->getStatus() == ImageFrame::FrameEmpty) { |
| 119 if (!m_buffer->setSize(m_parent->size().width(), m_parent->size().height ())) | 120 if (!m_buffer->setSize(m_parent->size().width(), m_parent->size().height ())) |
| 120 return m_parent->setFailed(); // Unable to allocate. | 121 return m_parent->setFailed(); // Unable to allocate. |
| 121 m_buffer->setStatus(ImageFrame::FramePartial); | 122 m_buffer->setStatus(ImageFrame::FramePartial); |
|
scroggo_chromium
2016/05/16 20:32:08
Previously, this set the alpha to false for a part
| |
| 122 // setSize() calls eraseARGB(), which resets the alpha flag, so we force | |
| 123 // it back to false here. We'll set it true below in all cases where | |
| 124 // these 0s could actually show through. | |
| 125 m_buffer->setHasAlpha(false); | |
| 126 | 123 |
| 127 // For BMPs, the frame always fills the entire image. | 124 // For BMPs, the frame always fills the entire image. |
| 128 m_buffer->setOriginalFrameRect(IntRect(IntPoint(), m_parent->size())); | 125 m_buffer->setOriginalFrameRect(IntRect(IntPoint(), m_parent->size())); |
| 129 | 126 |
| 130 if (!m_isTopDown) | 127 if (!m_isTopDown) |
| 131 m_coord.setY(m_parent->size().height() - 1); | 128 m_coord.setY(m_parent->size().height() - 1); |
| 132 } | 129 } |
| 133 | 130 |
| 134 // Decode the data. | 131 // Decode the data. |
| 135 if (!m_decodingAndMask && !pastEndOfImage(0) && !decodePixelData((m_infoHead er.biCompression != RLE4) && (m_infoHeader.biCompression != RLE8) && (m_infoHead er.biCompression != RLE24))) | 132 if (!m_decodingAndMask && !pastEndOfImage(0) && !decodePixelData((m_infoHead er.biCompression != RLE4) && (m_infoHeader.biCompression != RLE8) && (m_infoHead er.biCompression != RLE24))) |
| 136 return false; | 133 return false; |
| 137 | 134 |
| 138 // If the image has an AND mask and there was no alpha data, process the | 135 // If the image has an AND mask and there was no alpha data, process the |
| 139 // mask. | 136 // mask. |
| 140 if (m_isInICO && !m_decodingAndMask && ((m_infoHeader.biBitCount < 16) || !m _bitMasks[3] || !m_seenNonZeroAlphaPixel)) { | 137 if (m_isInICO && !m_decodingAndMask && ((m_infoHeader.biBitCount < 16) || !m _bitMasks[3] || !m_seenNonZeroAlphaPixel)) { |
| 141 // Reset decoding coordinates to start of image. | 138 // Reset decoding coordinates to start of image. |
| 142 m_coord.setX(0); | 139 m_coord.setX(0); |
| 143 m_coord.setY(m_isTopDown ? 0 : (m_parent->size().height() - 1)); | 140 m_coord.setY(m_isTopDown ? 0 : (m_parent->size().height() - 1)); |
| 144 | 141 |
| 145 // The AND mask is stored as 1-bit data. | 142 // The AND mask is stored as 1-bit data. |
| 146 m_infoHeader.biBitCount = 1; | 143 m_infoHeader.biBitCount = 1; |
| 147 | 144 |
| 148 m_decodingAndMask = true; | 145 m_decodingAndMask = true; |
| 149 } | 146 } |
| 150 if (m_decodingAndMask && !decodePixelData(true)) | 147 if (m_decodingAndMask && !decodePixelData(true)) |
| 151 return false; | 148 return false; |
| 152 | 149 |
| 153 // Done! | 150 // Done! |
| 151 m_buffer->setHasAlpha(m_hasPixelsWithAlpha); | |
| 154 m_buffer->setStatus(ImageFrame::FrameComplete); | 152 m_buffer->setStatus(ImageFrame::FrameComplete); |
| 155 return true; | 153 return true; |
| 156 } | 154 } |
| 157 | 155 |
| 158 bool BMPImageReader::decodePixelData(bool nonRLE) | 156 bool BMPImageReader::decodePixelData(bool nonRLE) |
| 159 { | 157 { |
| 160 const IntPoint coord(m_coord); | 158 const IntPoint coord(m_coord); |
| 161 const ProcessingResult result = nonRLE ? processNonRLEData(false, 0) : proce ssRLEData(); | 159 const ProcessingResult result = nonRLE ? processNonRLEData(false, 0) : proce ssRLEData(); |
| 162 if (m_coord != coord) | 160 if (m_coord != coord) |
| 163 m_buffer->setPixelsChanged(true); | 161 m_buffer->setPixelsChanged(true); |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 603 const uint8_t code = readUint8(1); | 601 const uint8_t code = readUint8(1); |
| 604 if ((count || (code != 1)) && pastEndOfImage(0)) | 602 if ((count || (code != 1)) && pastEndOfImage(0)) |
| 605 return Failure; | 603 return Failure; |
| 606 | 604 |
| 607 // Decode. | 605 // Decode. |
| 608 if (!count) { | 606 if (!count) { |
| 609 switch (code) { | 607 switch (code) { |
| 610 case 0: // Magic token: EOL | 608 case 0: // Magic token: EOL |
| 611 // Skip any remaining pixels in this row. | 609 // Skip any remaining pixels in this row. |
| 612 if (m_coord.x() < m_parent->size().width()) | 610 if (m_coord.x() < m_parent->size().width()) |
| 613 m_buffer->setHasAlpha(true); | 611 m_hasPixelsWithAlpha = true; |
| 614 moveBufferToNextRow(); | 612 moveBufferToNextRow(); |
| 615 | 613 |
| 616 m_decodedOffset += 2; | 614 m_decodedOffset += 2; |
| 617 break; | 615 break; |
| 618 | 616 |
| 619 case 1: // Magic token: EOF | 617 case 1: // Magic token: EOF |
| 620 // Skip any remaining pixels in the image. | 618 // Skip any remaining pixels in the image. |
| 621 if ((m_coord.x() < m_parent->size().width()) || (m_isTopDown ? ( m_coord.y() < (m_parent->size().height() - 1)) : (m_coord.y() > 0))) | 619 if ((m_coord.x() < m_parent->size().width()) || (m_isTopDown ? ( m_coord.y() < (m_parent->size().height() - 1)) : (m_coord.y() > 0))) |
| 622 m_buffer->setHasAlpha(true); | 620 m_hasPixelsWithAlpha = true; |
| 623 // There's no need to move |m_coord| here to trigger the caller | 621 // There's no need to move |m_coord| here to trigger the caller |
| 624 // to call setPixelsChanged(). If the only thing that's changed | 622 // to call setPixelsChanged(). If the only thing that's changed |
| 625 // is the alpha state, that will be properly written into the | 623 // is the alpha state, that will be properly written into the |
| 626 // underlying SkBitmap when we mark the frame complete. | 624 // underlying SkBitmap when we mark the frame complete. |
| 627 return Success; | 625 return Success; |
| 628 | 626 |
| 629 case 2: { // Magic token: Delta | 627 case 2: { // Magic token: Delta |
| 630 // The next two bytes specify dx and dy. Bail if there isn't | 628 // The next two bytes specify dx and dy. Bail if there isn't |
| 631 // enough data. | 629 // enough data. |
| 632 if ((m_data->size() - m_decodedOffset) < 4) | 630 if ((m_data->size() - m_decodedOffset) < 4) |
| 633 return InsufficientData; | 631 return InsufficientData; |
| 634 | 632 |
| 635 // Fail if this takes us past the end of the desired row or | 633 // Fail if this takes us past the end of the desired row or |
| 636 // past the end of the image. | 634 // past the end of the image. |
| 637 const uint8_t dx = readUint8(2); | 635 const uint8_t dx = readUint8(2); |
| 638 const uint8_t dy = readUint8(3); | 636 const uint8_t dy = readUint8(3); |
| 639 if (dx || dy) | 637 if (dx || dy) |
| 640 m_buffer->setHasAlpha(true); | 638 m_hasPixelsWithAlpha = true; |
| 641 if (((m_coord.x() + dx) > m_parent->size().width()) || pastEndOf Image(dy)) | 639 if (((m_coord.x() + dx) > m_parent->size().width()) || pastEndOf Image(dy)) |
| 642 return Failure; | 640 return Failure; |
| 643 | 641 |
| 644 // Skip intervening pixels. | 642 // Skip intervening pixels. |
| 645 m_coord.move(dx, m_isTopDown ? dy : -dy); | 643 m_coord.move(dx, m_isTopDown ? dy : -dy); |
| 646 | 644 |
| 647 m_decodedOffset += 4; | 645 m_decodedOffset += 4; |
| 648 break; | 646 break; |
| 649 } | 647 } |
| 650 | 648 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 742 for (size_t pixel = 0; (pixel < pixelsPerByte) && (m_coord.x() < endX); ++pixel) { | 740 for (size_t pixel = 0; (pixel < pixelsPerByte) && (m_coord.x() < endX); ++pixel) { |
| 743 const size_t colorIndex = (pixelData >> (8 - m_infoHeader.bi BitCount)) & mask; | 741 const size_t colorIndex = (pixelData >> (8 - m_infoHeader.bi BitCount)) & mask; |
| 744 if (m_decodingAndMask) { | 742 if (m_decodingAndMask) { |
| 745 // There's no way to accurately represent an AND + XOR | 743 // There's no way to accurately represent an AND + XOR |
| 746 // operation as an RGBA image, so where the AND values | 744 // operation as an RGBA image, so where the AND values |
| 747 // are 1, we simply set the framebuffer pixels to fully | 745 // are 1, we simply set the framebuffer pixels to fully |
| 748 // transparent, on the assumption that most ICOs on the | 746 // transparent, on the assumption that most ICOs on the |
| 749 // web will not be doing a lot of inverting. | 747 // web will not be doing a lot of inverting. |
| 750 if (colorIndex) { | 748 if (colorIndex) { |
| 751 setRGBA(0, 0, 0, 0); | 749 setRGBA(0, 0, 0, 0); |
| 752 m_buffer->setHasAlpha(true); | 750 m_hasPixelsWithAlpha = true; |
| 753 } else | 751 } else |
| 754 m_coord.move(1, 0); | 752 m_coord.move(1, 0); |
| 755 } else { | 753 } else { |
| 756 // See comments near the end of processRLEData(). | 754 // See comments near the end of processRLEData(). |
| 757 if (colorIndex < m_infoHeader.biClrUsed) | 755 if (colorIndex < m_infoHeader.biClrUsed) |
| 758 setI(colorIndex); | 756 setI(colorIndex); |
| 759 else | 757 else |
| 760 setRGBA(0, 0, 0, 255); | 758 setRGBA(0, 0, 0, 255); |
| 761 } | 759 } |
| 762 pixelData <<= m_infoHeader.biBitCount; | 760 pixelData <<= m_infoHeader.biBitCount; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 778 // faster to draw. | 776 // faster to draw. |
| 779 int alpha = getAlpha(pixel); | 777 int alpha = getAlpha(pixel); |
| 780 if (!m_seenNonZeroAlphaPixel && !alpha) { | 778 if (!m_seenNonZeroAlphaPixel && !alpha) { |
| 781 m_seenZeroAlphaPixel = true; | 779 m_seenZeroAlphaPixel = true; |
| 782 alpha = 255; | 780 alpha = 255; |
| 783 } else { | 781 } else { |
| 784 m_seenNonZeroAlphaPixel = true; | 782 m_seenNonZeroAlphaPixel = true; |
| 785 if (m_seenZeroAlphaPixel) { | 783 if (m_seenZeroAlphaPixel) { |
| 786 m_buffer->zeroFillPixelData(); | 784 m_buffer->zeroFillPixelData(); |
| 787 m_seenZeroAlphaPixel = false; | 785 m_seenZeroAlphaPixel = false; |
| 788 } else if (alpha != 255) | 786 } else if (alpha != 255) { |
| 789 m_buffer->setHasAlpha(true); | 787 m_hasPixelsWithAlpha = true; |
| 788 } | |
| 790 } | 789 } |
| 791 | 790 |
| 792 setRGBA(getComponent(pixel, 0), getComponent(pixel, 1), | 791 setRGBA(getComponent(pixel, 0), getComponent(pixel, 1), |
| 793 getComponent(pixel, 2), alpha); | 792 getComponent(pixel, 2), alpha); |
| 794 } | 793 } |
| 795 } | 794 } |
| 796 | 795 |
| 797 // Success, keep going. | 796 // Success, keep going. |
| 798 m_decodedOffset += paddedNumBytes; | 797 m_decodedOffset += paddedNumBytes; |
| 799 if (inRLE) | 798 if (inRLE) |
| 800 return Success; | 799 return Success; |
| 801 moveBufferToNextRow(); | 800 moveBufferToNextRow(); |
| 802 } | 801 } |
| 803 | 802 |
| 804 // Finished decoding whole image. | 803 // Finished decoding whole image. |
| 805 return Success; | 804 return Success; |
| 806 } | 805 } |
| 807 | 806 |
| 808 void BMPImageReader::moveBufferToNextRow() | 807 void BMPImageReader::moveBufferToNextRow() |
| 809 { | 808 { |
| 810 m_coord.move(-m_coord.x(), m_isTopDown ? 1 : -1); | 809 m_coord.move(-m_coord.x(), m_isTopDown ? 1 : -1); |
| 811 } | 810 } |
| 812 | 811 |
| 813 } // namespace blink | 812 } // namespace blink |
| OLD | NEW |