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

Side by Side Diff: src/codec/SkMasks.cpp

Issue 1688003002: Fix bug processing bmp bit masks (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkCodecPriv.h" 8 #include "SkCodecPriv.h"
9 #include "SkMasks.h" 9 #include "SkMasks.h"
10 #include "SkTypes.h" 10 #include "SkTypes.h"
(...skipping 29 matching lines...) Expand all
40 173, 175, 177, 179, 181, 183, 185, 187, 189, 191, 193, 195, 197, 199, 201, 40 173, 175, 177, 179, 181, 183, 185, 187, 189, 191, 193, 195, 197, 199, 201,
41 203, 205, 207, 209, 211, 213, 215, 217, 219, 221, 223, 225, 227, 229, 231, 41 203, 205, 207, 209, 211, 213, 215, 217, 219, 221, 223, 225, 227, 229, 231,
42 233, 235, 237, 239, 241, 243, 245, 247, 249, 251, 253, 255 42 233, 235, 237, 239, 241, 243, 245, 247, 249, 251, 253, 255
43 }; 43 };
44 44
45 /* 45 /*
46 * 46 *
47 * Convert an n bit component to an 8-bit component 47 * Convert an n bit component to an 8-bit component
48 * 48 *
49 */ 49 */
50 static uint8_t convert_to_8(uint32_t component, uint32_t n) { 50 static uint8_t convert_to_8(uint8_t component, uint32_t n) {
msarett 2016/02/10 20:59:28 No reason for "component" to ever be larger than 8
51 if (0 == n) { 51 if (0 == n) {
52 return 0; 52 return 0;
53 } else if (8 > n) { 53 } else if (8 > n) {
54 return n_bit_to_8_bit_lookup_table[(1 << n) - 2 + component]; 54 return n_bit_to_8_bit_lookup_table[(1 << n) - 2 + component];
55 } else { 55 } else {
56 SkASSERT(8 == n); 56 SkASSERT(8 == n);
57 return component; 57 return component;
58 } 58 }
59 } 59 }
60 60
(...skipping 19 matching lines...) Expand all
80 uint8_t SkMasks::getAlpha(uint32_t pixel) const { 80 uint8_t SkMasks::getAlpha(uint32_t pixel) const {
81 return get_comp(pixel, fAlpha.mask, fAlpha.shift, fAlpha.size); 81 return get_comp(pixel, fAlpha.mask, fAlpha.shift, fAlpha.size);
82 } 82 }
83 83
84 /* 84 /*
85 * 85 *
86 * Process an input mask to obtain the necessary information 86 * Process an input mask to obtain the necessary information
87 * 87 *
88 */ 88 */
89 const SkMasks::MaskInfo process_mask(uint32_t mask, uint32_t bpp) { 89 const SkMasks::MaskInfo process_mask(uint32_t mask, uint32_t bpp) {
90 // Trim the masks to the allowed number of bits
msarett 2016/02/10 20:59:28 Unrelated to the bug fix. We do this is CreateMas
91 if (bpp < 32) {
92 mask &= (1 << bpp) - 1;
93 }
94
95 // Determine properties of the mask 90 // Determine properties of the mask
96 uint32_t tempMask = mask; 91 uint32_t tempMask = mask;
97 uint32_t shift = 0; 92 uint32_t shift = 0;
98 uint32_t size = 0; 93 uint32_t size = 0;
99 if (tempMask != 0) { 94 if (tempMask != 0) {
100 // Count trailing zeros on masks 95 // Count trailing zeros on masks
101 for (; (tempMask & 1) == 0; tempMask >>= 1) { 96 for (; (tempMask & 1) == 0; tempMask >>= 1) {
102 shift++; 97 shift++;
103 } 98 }
104 // Count the size of the mask 99 // Count the size of the mask
105 for (; tempMask & 1; tempMask >>= 1) { 100 for (; tempMask & 1; tempMask >>= 1) {
106 size++; 101 size++;
107 } 102 }
108 // Check that the mask is continuous 103 // Verify that the mask is continuous
109 if (tempMask != 0) { 104 if (tempMask) {
110 SkCodecPrintf("Warning: Bit masks is not continuous.\n"); 105 SkCodecPrintf("Warning: Bit mask is not continuous.\n");
106 // Finish processing the mask
msarett 2016/02/10 20:59:28 Even if the mask is not continuous, let's count al
107 for (; tempMask; tempMask >>= 1) {
108 size++;
109 }
111 } 110 }
112 // Truncate masks greater than 8 bits 111 // Truncate masks greater than 8 bits
113 if (size > 8) { 112 if (size > 8) {
114 shift += size - 8; 113 shift += size - 8;
115 size = 8; 114 size = 8;
115 mask &= 0xFF << shift;
msarett 2016/02/10 20:59:28 Make sure that the final mask is no larger than 8-
116 } 116 }
117 } 117 }
118 118
119 // Save the calculated values 119 // Save the calculated values
120 const SkMasks::MaskInfo info = { mask, shift, size }; 120 const SkMasks::MaskInfo info = { mask, shift, size };
121 return info; 121 return info;
122 } 122 }
123 123
124 /* 124 /*
125 * 125 *
(...skipping 26 matching lines...) Expand all
152 } 152 }
153 153
154 154
155 SkMasks::SkMasks(const MaskInfo& red, const MaskInfo& green, 155 SkMasks::SkMasks(const MaskInfo& red, const MaskInfo& green,
156 const MaskInfo& blue, const MaskInfo& alpha) 156 const MaskInfo& blue, const MaskInfo& alpha)
157 : fRed(red) 157 : fRed(red)
158 , fGreen(green) 158 , fGreen(green)
159 , fBlue(blue) 159 , fBlue(blue)
160 , fAlpha(alpha) 160 , fAlpha(alpha)
161 {} 161 {}
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698