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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 if (m_needToProcessBitmasks && !processBitmasks()) | 110 if (m_needToProcessBitmasks && !processBitmasks()) |
111 return false; | 111 return false; |
112 | 112 |
113 // Read and process the color table, if needed. | 113 // Read and process the color table, if needed. |
114 if (m_needToProcessColorTable && !processColorTable()) | 114 if (m_needToProcessColorTable && !processColorTable()) |
115 return false; | 115 return false; |
116 | 116 |
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->setSizeAndColorSpace(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->setStatus(ImageFrame::FramePartial); | 126 m_buffer->setStatus(ImageFrame::FramePartial); |
126 // setSize() calls eraseARGB(), which resets the alpha flag, so we force | 127 // setSize() calls eraseARGB(), which resets the alpha flag, so we force |
127 // it back to false here. We'll set it true below in all cases where | 128 // it back to false here. We'll set it true below in all cases where |
128 // these 0s could actually show through. | 129 // these 0s could actually show through. |
129 m_buffer->setHasAlpha(false); | 130 m_buffer->setHasAlpha(false); |
130 | 131 |
131 // For BMPs, the frame always fills the entire image. | 132 // For BMPs, the frame always fills the entire image. |
132 m_buffer->setOriginalFrameRect(IntRect(IntPoint(), m_parent->size())); | 133 m_buffer->setOriginalFrameRect(IntRect(IntPoint(), m_parent->size())); |
133 | 134 |
134 if (!m_isTopDown) | 135 if (!m_isTopDown) |
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 // images where all alpha values are 255; opaque images are | 817 // images where all alpha values are 255; opaque images are |
817 // faster to draw. | 818 // faster to draw. |
818 int alpha = getAlpha(pixel); | 819 int alpha = getAlpha(pixel); |
819 if (!m_seenNonZeroAlphaPixel && !alpha) { | 820 if (!m_seenNonZeroAlphaPixel && !alpha) { |
820 m_seenZeroAlphaPixel = true; | 821 m_seenZeroAlphaPixel = true; |
821 alpha = 255; | 822 alpha = 255; |
822 } else { | 823 } else { |
823 m_seenNonZeroAlphaPixel = true; | 824 m_seenNonZeroAlphaPixel = true; |
824 if (m_seenZeroAlphaPixel) { | 825 if (m_seenZeroAlphaPixel) { |
825 m_buffer->zeroFillPixelData(); | 826 m_buffer->zeroFillPixelData(); |
| 827 m_buffer->setHasAlpha(false); |
826 m_seenZeroAlphaPixel = false; | 828 m_seenZeroAlphaPixel = false; |
827 } else if (alpha != 255) | 829 } else if (alpha != 255) |
828 m_buffer->setHasAlpha(true); | 830 m_buffer->setHasAlpha(true); |
829 } | 831 } |
830 | 832 |
831 setRGBA(getComponent(pixel, 0), getComponent(pixel, 1), | 833 setRGBA(getComponent(pixel, 0), getComponent(pixel, 1), |
832 getComponent(pixel, 2), alpha); | 834 getComponent(pixel, 2), alpha); |
833 } | 835 } |
834 } | 836 } |
835 | 837 |
836 // Success, keep going. | 838 // Success, keep going. |
837 m_decodedOffset += paddedNumBytes; | 839 m_decodedOffset += paddedNumBytes; |
838 if (inRLE) | 840 if (inRLE) |
839 return Success; | 841 return Success; |
840 moveBufferToNextRow(); | 842 moveBufferToNextRow(); |
841 } | 843 } |
842 | 844 |
843 // Finished decoding whole image. | 845 // Finished decoding whole image. |
844 return Success; | 846 return Success; |
845 } | 847 } |
846 | 848 |
847 void BMPImageReader::moveBufferToNextRow() { | 849 void BMPImageReader::moveBufferToNextRow() { |
848 m_coord.move(-m_coord.x(), m_isTopDown ? 1 : -1); | 850 m_coord.move(-m_coord.x(), m_isTopDown ? 1 : -1); |
849 } | 851 } |
850 | 852 |
851 } // namespace blink | 853 } // namespace blink |
OLD | NEW |