Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: third_party/WebKit/Source/platform/image-decoders/bmp/BMPImageReader.cpp

Issue 2756463003: Remove opaque alpha channel special case (Closed)
Patch Set: Fixing first-pixel alpha case Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 795 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 // RGB data. Decode pixels one at a time, left to right. 806 // RGB data. Decode pixels one at a time, left to right.
807 while (m_coord.x() < endX) { 807 while (m_coord.x() < endX) {
808 const uint32_t pixel = readCurrentPixel(bytesPerPixel); 808 const uint32_t pixel = readCurrentPixel(bytesPerPixel);
809 809
810 // Some BMPs specify an alpha channel but don't actually use it 810 // Some BMPs specify an alpha channel but don't actually use it
811 // (it contains all 0s). To avoid displaying these images as 811 // (it contains all 0s). To avoid displaying these images as
812 // fully-transparent, decode as if images are fully opaque 812 // fully-transparent, decode as if images are fully opaque
813 // until we actually see a non-zero alpha value; at that point, 813 // until we actually see a non-zero alpha value; at that point,
814 // reset any previously-decoded pixels to fully transparent and 814 // reset any previously-decoded pixels to fully transparent and
815 // continue decoding based on the real alpha channel values. 815 // continue decoding based on the real alpha channel values.
816 // As an optimization, avoid setting "hasAlpha" to true for
817 // images where all alpha values are 255; opaque images are
818 // faster to draw.
819 int alpha = getAlpha(pixel); 816 int alpha = getAlpha(pixel);
820 if (!m_seenNonZeroAlphaPixel && !alpha) { 817 if (!m_seenNonZeroAlphaPixel && !alpha) {
821 m_seenZeroAlphaPixel = true; 818 m_seenZeroAlphaPixel = true;
822 alpha = 255; 819 alpha = 255;
823 } else { 820 } else {
824 m_seenNonZeroAlphaPixel = true; 821 m_seenNonZeroAlphaPixel = true;
825 if (m_seenZeroAlphaPixel) { 822 if (m_seenZeroAlphaPixel) {
826 m_buffer->zeroFillPixelData(); 823 m_buffer->zeroFillPixelData();
827 m_seenZeroAlphaPixel = false; 824 m_seenZeroAlphaPixel = false;
828 } else if (alpha != 255) 825 } else
Peter Kasting 2017/03/16 19:43:27 I'm still confused. If you really want to do this
cblume 2017/03/16 20:39:45 I think those are different. An image may or may n
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698