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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 // Initialize the framebuffer if needed. | 117 // Initialize the framebuffer if needed. |
118 DCHECK(m_buffer); // Parent should set this before asking us to decode! | 118 DCHECK(m_buffer); // Parent should set this before asking us to decode! |
119 if (m_buffer->getStatus() == ImageFrame::FrameEmpty) { | 119 if (m_buffer->getStatus() == ImageFrame::FrameEmpty) { |
120 if (!m_buffer->allocatePixelData(m_parent->size().width(), | 120 if (!m_buffer->allocatePixelData(m_parent->size().width(), |
121 m_parent->size().height(), | 121 m_parent->size().height(), |
122 m_parent->colorSpaceForSkImages())) { | 122 m_parent->colorSpaceForSkImages())) { |
123 return m_parent->setFailed(); // Unable to allocate. | 123 return m_parent->setFailed(); // Unable to allocate. |
124 } | 124 } |
125 m_buffer->zeroFillPixelData(); | 125 m_buffer->zeroFillPixelData(); |
126 m_buffer->setStatus(ImageFrame::FramePartial); | 126 m_buffer->setStatus(ImageFrame::FramePartial); |
127 // setSize() calls eraseARGB(), which resets the alpha flag, so we force | |
128 // it back to false here. We'll set it true below in all cases where | |
129 // these 0s could actually show through. | |
130 m_buffer->setHasAlpha(false); | |
131 | 127 |
132 // For BMPs, the frame always fills the entire image. | 128 // For BMPs, the frame always fills the entire image. |
133 m_buffer->setOriginalFrameRect(IntRect(IntPoint(), m_parent->size())); | 129 m_buffer->setOriginalFrameRect(IntRect(IntPoint(), m_parent->size())); |
134 | 130 |
135 if (!m_isTopDown) | 131 if (!m_isTopDown) |
136 m_coord.setY(m_parent->size().height() - 1); | 132 m_coord.setY(m_parent->size().height() - 1); |
137 } | 133 } |
138 | 134 |
139 // Decode the data. | 135 // Decode the data. |
140 if (!m_decodingAndMask && !pastEndOfImage(0) && | 136 if (!m_decodingAndMask && !pastEndOfImage(0) && |
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 // images where all alpha values are 255; opaque images are | 813 // images where all alpha values are 255; opaque images are |
818 // faster to draw. | 814 // faster to draw. |
819 int alpha = getAlpha(pixel); | 815 int alpha = getAlpha(pixel); |
820 if (!m_seenNonZeroAlphaPixel && !alpha) { | 816 if (!m_seenNonZeroAlphaPixel && !alpha) { |
821 m_seenZeroAlphaPixel = true; | 817 m_seenZeroAlphaPixel = true; |
822 alpha = 255; | 818 alpha = 255; |
823 } else { | 819 } else { |
824 m_seenNonZeroAlphaPixel = true; | 820 m_seenNonZeroAlphaPixel = true; |
825 if (m_seenZeroAlphaPixel) { | 821 if (m_seenZeroAlphaPixel) { |
826 m_buffer->zeroFillPixelData(); | 822 m_buffer->zeroFillPixelData(); |
| 823 m_buffer->setHasAlpha(true); |
827 m_seenZeroAlphaPixel = false; | 824 m_seenZeroAlphaPixel = false; |
828 } else if (alpha != 255) | 825 } else if (alpha != 255) |
829 m_buffer->setHasAlpha(true); | 826 m_buffer->setHasAlpha(true); |
830 } | 827 } |
831 | 828 |
832 setRGBA(getComponent(pixel, 0), getComponent(pixel, 1), | 829 setRGBA(getComponent(pixel, 0), getComponent(pixel, 1), |
833 getComponent(pixel, 2), alpha); | 830 getComponent(pixel, 2), alpha); |
834 } | 831 } |
835 } | 832 } |
836 | 833 |
837 // Success, keep going. | 834 // Success, keep going. |
838 m_decodedOffset += paddedNumBytes; | 835 m_decodedOffset += paddedNumBytes; |
839 if (inRLE) | 836 if (inRLE) |
840 return Success; | 837 return Success; |
841 moveBufferToNextRow(); | 838 moveBufferToNextRow(); |
842 } | 839 } |
843 | 840 |
844 // Finished decoding whole image. | 841 // Finished decoding whole image. |
845 return Success; | 842 return Success; |
846 } | 843 } |
847 | 844 |
848 void BMPImageReader::moveBufferToNextRow() { | 845 void BMPImageReader::moveBufferToNextRow() { |
849 m_coord.move(-m_coord.x(), m_isTopDown ? 1 : -1); | 846 m_coord.move(-m_coord.x(), m_isTopDown ? 1 : -1); |
850 } | 847 } |
851 | 848 |
852 } // namespace blink | 849 } // namespace blink |
OLD | NEW |