Chromium Code Reviews| 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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() || |
|
scroggo_chromium
2017/05/30 19:45:17
Now that you flipped IsAlphaSupported() back, don'
cblume
2017/05/30 23:45:14
Done.
| |
| 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 Loading... | |
| 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 seen_zero_alpha_pixel_ = true; |
|
scroggo_chromium
2017/05/30 19:45:17
Now this always gets set to true before we read it
cblume
2017/05/30 23:37:34
Done.
| |
| 822 // faster to draw. | 822 if (IsAlphaSupported()) { |
| 823 int alpha = GetAlpha(pixel); | 823 alpha = GetAlpha(pixel); |
| 824 if (!seen_non_zero_alpha_pixel_ && !alpha) { | 824 if (!seen_non_zero_alpha_pixel_ && !alpha) { |
| 825 seen_zero_alpha_pixel_ = true; | 825 alpha = 255; |
| 826 alpha = 255; | 826 } else { |
| 827 } else { | 827 if (seen_zero_alpha_pixel_) { |
|
scroggo_chromium
2017/05/30 19:45:17
This will always be true, since we always set it t
cblume
2017/05/30 23:37:34
Done.
| |
| 828 seen_non_zero_alpha_pixel_ = true; | 828 buffer_->ZeroFillPixelData(); |
| 829 if (seen_zero_alpha_pixel_) { | 829 seen_zero_alpha_pixel_ = false; |
|
scroggo_chromium
2017/05/30 19:45:17
No one ever reads this value, since we set it to t
cblume
2017/05/30 23:37:34
Done.
| |
| 830 buffer_->ZeroFillPixelData(); | 830 } else { |
|
scroggo_chromium
2017/05/30 19:45:17
We will never hit this branch.
cblume
2017/05/30 23:37:34
Done.
| |
| 831 seen_zero_alpha_pixel_ = false; | 831 buffer_->SetHasAlpha(true); |
| 832 } else if (alpha != 255) | 832 } |
| 833 buffer_->SetHasAlpha(true); | 833 } |
| 834 } | 834 } |
| 835 | 835 |
| 836 SetRGBA(GetComponent(pixel, 0), GetComponent(pixel, 1), | 836 SetRGBA(GetComponent(pixel, 0), GetComponent(pixel, 1), |
| 837 GetComponent(pixel, 2), alpha); | 837 GetComponent(pixel, 2), alpha); |
| 838 } | 838 } |
| 839 } | 839 } |
| 840 | 840 |
| 841 // Success, keep going. | 841 // Success, keep going. |
| 842 decoded_offset_ += padded_num_bytes; | 842 decoded_offset_ += padded_num_bytes; |
| 843 if (in_rle) | 843 if (in_rle) |
| 844 return kSuccess; | 844 return kSuccess; |
| 845 MoveBufferToNextRow(); | 845 MoveBufferToNextRow(); |
| 846 } | 846 } |
| 847 | 847 |
| 848 // Finished decoding whole image. | 848 // Finished decoding whole image. |
| 849 return kSuccess; | 849 return kSuccess; |
| 850 } | 850 } |
| 851 | 851 |
| 852 void BMPImageReader::MoveBufferToNextRow() { | 852 void BMPImageReader::MoveBufferToNextRow() { |
| 853 coord_.Move(-coord_.X(), is_top_down_ ? 1 : -1); | 853 coord_.Move(-coord_.X(), is_top_down_ ? 1 : -1); |
| 854 } | 854 } |
| 855 | 855 |
| 856 } // namespace blink | 856 } // namespace blink |
| OLD | NEW |