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 | 127 // setSize() calls eraseARGB(), which resets the alpha flag, so we force |
Noel Gordon
2017/03/20 21:09:03
Comment seems out-of-date.
cblume
2017/03/20 22:40:28
Oh, you're right.
In fact, the comment indicates t
Peter Kasting
2017/03/20 22:42:04
Just be careful that at that point the code has an
cblume
2017/03/20 23:14:00
You are right.
I think it would be better for the
| |
128 // 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 |
129 // these 0s could actually show through. | 129 // these 0s could actually show through. |
130 m_buffer->setHasAlpha(false); | 130 m_buffer->setHasAlpha(false); |
131 | 131 |
132 // For BMPs, the frame always fills the entire image. | 132 // For BMPs, the frame always fills the entire image. |
133 m_buffer->setOriginalFrameRect(IntRect(IntPoint(), m_parent->size())); | 133 m_buffer->setOriginalFrameRect(IntRect(IntPoint(), m_parent->size())); |
134 | 134 |
135 if (!m_isTopDown) | 135 if (!m_isTopDown) |
136 m_coord.setY(m_parent->size().height() - 1); | 136 m_coord.setY(m_parent->size().height() - 1); |
137 } | 137 } |
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
817 // images where all alpha values are 255; opaque images are | 817 // images where all alpha values are 255; opaque images are |
818 // faster to draw. | 818 // faster to draw. |
819 int alpha = getAlpha(pixel); | 819 int alpha = getAlpha(pixel); |
820 if (!m_seenNonZeroAlphaPixel && !alpha) { | 820 if (!m_seenNonZeroAlphaPixel && !alpha) { |
821 m_seenZeroAlphaPixel = true; | 821 m_seenZeroAlphaPixel = true; |
822 alpha = 255; | 822 alpha = 255; |
823 } else { | 823 } else { |
824 m_seenNonZeroAlphaPixel = true; | 824 m_seenNonZeroAlphaPixel = true; |
825 if (m_seenZeroAlphaPixel) { | 825 if (m_seenZeroAlphaPixel) { |
826 m_buffer->zeroFillPixelData(); | 826 m_buffer->zeroFillPixelData(); |
827 m_buffer->setHasAlpha(true); | |
827 m_seenZeroAlphaPixel = false; | 828 m_seenZeroAlphaPixel = false; |
828 } else if (alpha != 255) | 829 } else if (alpha != 255) |
829 m_buffer->setHasAlpha(true); | 830 m_buffer->setHasAlpha(true); |
830 } | 831 } |
831 | 832 |
832 setRGBA(getComponent(pixel, 0), getComponent(pixel, 1), | 833 setRGBA(getComponent(pixel, 0), getComponent(pixel, 1), |
833 getComponent(pixel, 2), alpha); | 834 getComponent(pixel, 2), alpha); |
834 } | 835 } |
835 } | 836 } |
836 | 837 |
837 // Success, keep going. | 838 // Success, keep going. |
838 m_decodedOffset += paddedNumBytes; | 839 m_decodedOffset += paddedNumBytes; |
839 if (inRLE) | 840 if (inRLE) |
840 return Success; | 841 return Success; |
841 moveBufferToNextRow(); | 842 moveBufferToNextRow(); |
842 } | 843 } |
843 | 844 |
844 // Finished decoding whole image. | 845 // Finished decoding whole image. |
845 return Success; | 846 return Success; |
846 } | 847 } |
847 | 848 |
848 void BMPImageReader::moveBufferToNextRow() { | 849 void BMPImageReader::moveBufferToNextRow() { |
849 m_coord.move(-m_coord.x(), m_isTopDown ? 1 : -1); | 850 m_coord.move(-m_coord.x(), m_isTopDown ? 1 : -1); |
850 } | 851 } |
851 | 852 |
852 } // namespace blink | 853 } // namespace blink |
OLD | NEW |