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

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: Remove redundant conditional Created 3 years, 6 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 // Decode the data. 139 // Decode the data.
140 if (!decoding_and_mask_ && !PastEndOfImage(0) && 140 if (!decoding_and_mask_ && !PastEndOfImage(0) &&
141 !DecodePixelData((info_header_.bi_compression != RLE4) && 141 !DecodePixelData((info_header_.bi_compression != RLE4) &&
142 (info_header_.bi_compression != RLE8) && 142 (info_header_.bi_compression != RLE8) &&
143 (info_header_.bi_compression != RLE24))) 143 (info_header_.bi_compression != RLE24)))
144 return false; 144 return false;
145 145
146 // If the image has an AND mask and there was no alpha data, process the 146 // If the image has an AND mask and there was no alpha data, process the
147 // mask. 147 // mask.
148 if (is_in_ico_ && !decoding_and_mask_ && 148 if (is_in_ico_ && !decoding_and_mask_ &&
149 ((info_header_.bi_bit_count < 16) || !bit_masks_[3] || 149 ((info_header_.bi_bit_count < 16) || !IsAlphaSupported() ||
150 !seen_non_zero_alpha_pixel_)) { 150 !seen_non_zero_alpha_pixel_)) {
151 // Reset decoding coordinates to start of image. 151 // Reset decoding coordinates to start of image.
152 coord_.SetX(0); 152 coord_.SetX(0);
153 coord_.SetY(is_top_down_ ? 0 : (parent_->Size().Height() - 1)); 153 coord_.SetY(is_top_down_ ? 0 : (parent_->Size().Height() - 1));
154 154
155 // The AND mask is stored as 1-bit data. 155 // The AND mask is stored as 1-bit data.
156 info_header_.bi_bit_count = 1; 156 info_header_.bi_bit_count = 1;
157 157
158 decoding_and_mask_ = true; 158 decoding_and_mask_ = true;
159 } 159 }
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 // RGB data. Decode pixels one at a time, left to right. 810 // RGB data. Decode pixels one at a time, left to right.
811 while (coord_.X() < end_x) { 811 while (coord_.X() < end_x) {
812 const uint32_t pixel = ReadCurrentPixel(bytes_per_pixel); 812 const uint32_t pixel = ReadCurrentPixel(bytes_per_pixel);
813 813
814 // Some BMPs specify an alpha channel but don't actually use it 814 // Some BMPs specify an alpha channel but don't actually use it
815 // (it contains all 0s). To avoid displaying these images as 815 // (it contains all 0s). To avoid displaying these images as
816 // fully-transparent, decode as if images are fully opaque 816 // fully-transparent, decode as if images are fully opaque
817 // until we actually see a non-zero alpha value; at that point, 817 // until we actually see a non-zero alpha value; at that point,
818 // reset any previously-decoded pixels to fully transparent and 818 // reset any previously-decoded pixels to fully transparent and
819 // continue decoding based on the real alpha channel values. 819 // continue decoding based on the real alpha channel values.
820 // As an optimization, avoid calling SetHasAlpha(true) for 820 int alpha = 255;
821 // images where all alpha values are 255; opaque images are 821 if (IsAlphaSupported()) {
822 // faster to draw. 822 alpha = GetAlpha(pixel);
823 int alpha = GetAlpha(pixel); 823 if (!seen_non_zero_alpha_pixel_ && !alpha) {
824 if (!seen_non_zero_alpha_pixel_ && !alpha) { 824 seen_zero_alpha_pixel_ = true;
825 seen_zero_alpha_pixel_ = true; 825 alpha = 255;
826 alpha = 255; 826 } else {
827 } else { 827 seen_non_zero_alpha_pixel_ = true;
828 seen_non_zero_alpha_pixel_ = true; 828 if (seen_zero_alpha_pixel_) {
829 if (seen_zero_alpha_pixel_) { 829 buffer_->ZeroFillPixelData();
830 buffer_->ZeroFillPixelData(); 830 seen_zero_alpha_pixel_ = false;
831 seen_zero_alpha_pixel_ = false; 831 } else {
scroggo_chromium 2017/05/31 14:27:50 Why did you remove "if (alpha != 255)" here? I thi
cblume 2017/05/31 19:40:37 You are right that we should ideally call buffer_-
scroggo_chromium 2017/05/31 21:12:15 I don't understand the distinction - we have to lo
832 } else if (alpha != 255) 832 buffer_->SetHasAlpha(true);
833 buffer_->SetHasAlpha(true); 833 }
834 }
834 } 835 }
835 836
836 SetRGBA(GetComponent(pixel, 0), GetComponent(pixel, 1), 837 SetRGBA(GetComponent(pixel, 0), GetComponent(pixel, 1),
837 GetComponent(pixel, 2), alpha); 838 GetComponent(pixel, 2), alpha);
838 } 839 }
839 } 840 }
840 841
841 // Success, keep going. 842 // Success, keep going.
842 decoded_offset_ += padded_num_bytes; 843 decoded_offset_ += padded_num_bytes;
843 if (in_rle) 844 if (in_rle)
844 return kSuccess; 845 return kSuccess;
845 MoveBufferToNextRow(); 846 MoveBufferToNextRow();
846 } 847 }
847 848
848 // Finished decoding whole image. 849 // Finished decoding whole image.
849 return kSuccess; 850 return kSuccess;
850 } 851 }
851 852
852 void BMPImageReader::MoveBufferToNextRow() { 853 void BMPImageReader::MoveBufferToNextRow() {
853 coord_.Move(-coord_.X(), is_top_down_ ? 1 : -1); 854 coord_.Move(-coord_.X(), is_top_down_ ? 1 : -1);
854 } 855 }
855 856
856 } // namespace blink 857 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698