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

Side by Side Diff: include/core/SkColorPriv.h

Issue 1691403002: Change SkUnitScalarClampToByte to more accurate implementation. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Revert to Patch 2. Created 4 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
« 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 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 #ifndef SkColorPriv_DEFINED 8 #ifndef SkColorPriv_DEFINED
9 #define SkColorPriv_DEFINED 9 #define SkColorPriv_DEFINED
10 10
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 SkASSERT((int16_t)src == src); 217 SkASSERT((int16_t)src == src);
218 SkASSERT((int16_t)dst == dst); 218 SkASSERT((int16_t)dst == dst);
219 SkASSERT((uint8_t)alpha == alpha); 219 SkASSERT((uint8_t)alpha == alpha);
220 220
221 int prod = (src - dst) * alpha + 128; 221 int prod = (src - dst) * alpha + 128;
222 prod = (prod + (prod >> 8)) >> 8; 222 prod = (prod + (prod >> 8)) >> 8;
223 return dst + prod; 223 return dst + prod;
224 } 224 }
225 225
226 static inline U8CPU SkUnitScalarClampToByte(SkScalar x) { 226 static inline U8CPU SkUnitScalarClampToByte(SkScalar x) {
227 if (x < 0) { 227 return static_cast<U8CPU>(SkScalarPin(x, 0, 1) * 255 + 0.5);
228 return 0;
229 }
230 if (x >= SK_Scalar1) {
231 return 255;
232 }
233 return SkScalarToFixed(x) >> 8;
234 } 228 }
235 229
236 #define SK_R16_BITS 5 230 #define SK_R16_BITS 5
237 #define SK_G16_BITS 6 231 #define SK_G16_BITS 6
238 #define SK_B16_BITS 5 232 #define SK_B16_BITS 5
239 233
240 #define SK_R16_SHIFT (SK_B16_BITS + SK_G16_BITS) 234 #define SK_R16_SHIFT (SK_B16_BITS + SK_G16_BITS)
241 #define SK_G16_SHIFT (SK_B16_BITS) 235 #define SK_G16_SHIFT (SK_B16_BITS)
242 #define SK_B16_SHIFT 0 236 #define SK_B16_SHIFT 0
243 237
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 int srcG = SkColorGetG(src); 1052 int srcG = SkColorGetG(src);
1059 int srcB = SkColorGetB(src); 1053 int srcB = SkColorGetB(src);
1060 1054
1061 for (int i = 0; i < width; i++) { 1055 for (int i = 0; i < width; i++) {
1062 dst[i] = SkBlendLCD16Opaque(srcR, srcG, srcB, dst[i], mask[i], 1056 dst[i] = SkBlendLCD16Opaque(srcR, srcG, srcB, dst[i], mask[i],
1063 opaqueDst); 1057 opaqueDst);
1064 } 1058 }
1065 } 1059 }
1066 1060
1067 #endif 1061 #endif
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