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

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: 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 }
829 m_buffer->setHasAlpha(true);
Peter Kasting 2017/03/16 04:37:14 Removing this is not correct. It will mean any BM
cblume 2017/03/16 09:36:47 You are right that the call to zeroFillPixelData()
830 } 826 }
831 827
832 setRGBA(getComponent(pixel, 0), getComponent(pixel, 1), 828 setRGBA(getComponent(pixel, 0), getComponent(pixel, 1),
833 getComponent(pixel, 2), alpha); 829 getComponent(pixel, 2), alpha);
834 } 830 }
835 } 831 }
836 832
837 // Success, keep going. 833 // Success, keep going.
838 m_decodedOffset += paddedNumBytes; 834 m_decodedOffset += paddedNumBytes;
839 if (inRLE) 835 if (inRLE)
840 return Success; 836 return Success;
841 moveBufferToNextRow(); 837 moveBufferToNextRow();
842 } 838 }
843 839
844 // Finished decoding whole image. 840 // Finished decoding whole image.
845 return Success; 841 return Success;
846 } 842 }
847 843
848 void BMPImageReader::moveBufferToNextRow() { 844 void BMPImageReader::moveBufferToNextRow() {
849 m_coord.move(-m_coord.x(), m_isTopDown ? 1 : -1); 845 m_coord.move(-m_coord.x(), m_isTopDown ? 1 : -1);
850 } 846 }
851 847
852 } // namespace blink 848 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698