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

Side by Side Diff: src/core/SkPixmap.cpp

Issue 1521673002: In SkPixmap.cpp, change SkAlphaMul to SkMulDiv255. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Make uppercase consistent. Created 5 years 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 | « include/core/SkCanvas.h ('k') | tests/BitmapTest.cpp » ('j') | 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 "SkColorPriv.h" 8 #include "SkColorPriv.h"
9 #include "SkConfig8888.h" 9 #include "SkConfig8888.h"
10 #include "SkMask.h" 10 #include "SkMask.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 } 156 }
157 break; 157 break;
158 } 158 }
159 case kARGB_4444_SkColorType: 159 case kARGB_4444_SkColorType:
160 case kRGB_565_SkColorType: { 160 case kRGB_565_SkColorType: {
161 uint16_t* p = this->writable_addr16(area.fLeft, area.fTop); 161 uint16_t* p = this->writable_addr16(area.fLeft, area.fTop);
162 uint16_t v; 162 uint16_t v;
163 163
164 // make rgb premultiplied 164 // make rgb premultiplied
165 if (255 != a) { 165 if (255 != a) {
166 r = SkAlphaMul(r, a); 166 r = SkMulDiv255Round(r, a);
167 g = SkAlphaMul(g, a); 167 g = SkMulDiv255Round(g, a);
168 b = SkAlphaMul(b, a); 168 b = SkMulDiv255Round(b, a);
169 } 169 }
170 170
171 if (kARGB_4444_SkColorType == this->colorType()) { 171 if (kARGB_4444_SkColorType == this->colorType()) {
172 v = pack_8888_to_4444(a, r, g, b); 172 v = pack_8888_to_4444(a, r, g, b);
173 } else { 173 } else {
174 v = SkPackRGB16(r >> (8 - SK_R16_BITS), 174 v = SkPackRGB16(r >> (8 - SK_R16_BITS),
175 g >> (8 - SK_G16_BITS), 175 g >> (8 - SK_G16_BITS),
176 b >> (8 - SK_B16_BITS)); 176 b >> (8 - SK_B16_BITS));
177 } 177 }
178 while (--height >= 0) { 178 while (--height >= 0) {
179 sk_memset16(p, v, width); 179 sk_memset16(p, v, width);
180 p = (uint16_t*)((char*)p + rowBytes); 180 p = (uint16_t*)((char*)p + rowBytes);
181 } 181 }
182 break; 182 break;
183 } 183 }
184 case kBGRA_8888_SkColorType: 184 case kBGRA_8888_SkColorType:
185 case kRGBA_8888_SkColorType: { 185 case kRGBA_8888_SkColorType: {
186 uint32_t* p = this->writable_addr32(area.fLeft, area.fTop); 186 uint32_t* p = this->writable_addr32(area.fLeft, area.fTop);
187 187
188 if (255 != a && kPremul_SkAlphaType == this->alphaType()) { 188 if (255 != a && kPremul_SkAlphaType == this->alphaType()) {
189 r = SkAlphaMul(r, a); 189 r = SkMulDiv255Round(r, a);
190 g = SkAlphaMul(g, a); 190 g = SkMulDiv255Round(g, a);
191 b = SkAlphaMul(b, a); 191 b = SkMulDiv255Round(b, a);
192 } 192 }
193 uint32_t v = kRGBA_8888_SkColorType == this->colorType() ? 193 uint32_t v = kRGBA_8888_SkColorType == this->colorType()
194 SkPackARGB_as_RGBA(a, r, g, b) : SkPackARGB_as_BGRA(a, r, g, b); 194 ? SkPackARGB_as_RGBA(a, r, g, b)
195 195 : SkPackARGB_as_BGRA(a, r, g, b);
196
196 while (--height >= 0) { 197 while (--height >= 0) {
197 sk_memset32(p, v, width); 198 sk_memset32(p, v, width);
198 p = (uint32_t*)((char*)p + rowBytes); 199 p = (uint32_t*)((char*)p + rowBytes);
199 } 200 }
200 break; 201 break;
201 } 202 }
202 default: 203 default:
203 return false; // no change, so don't call notifyPixelsChanged() 204 return false; // no change, so don't call notifyPixelsChanged()
204 } 205 }
205 return true; 206 return true;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 this->reset(info, pixels, rb); 265 this->reset(info, pixels, rb);
265 fStorage = pixels; 266 fStorage = pixels;
266 return true; 267 return true;
267 } 268 }
268 269
269 void SkAutoPixmapStorage::alloc(const SkImageInfo& info) { 270 void SkAutoPixmapStorage::alloc(const SkImageInfo& info) {
270 if (!this->tryAlloc(info)) { 271 if (!this->tryAlloc(info)) {
271 sk_throw(); 272 sk_throw();
272 } 273 }
273 } 274 }
OLDNEW
« no previous file with comments | « include/core/SkCanvas.h ('k') | tests/BitmapTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698