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

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

Issue 1311583005: Add special case circle blur for Ganesh (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix no-GPU build Created 5 years, 3 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 | « include/core/SkScalar.h ('k') | src/core/SkMaskFilter.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 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 #include "SkColor.h" 8 #include "SkColor.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkFixed.h" 10 #include "SkFixed.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 if (h < 0) { 63 if (h < 0) {
64 h += SkIntToScalar(360); 64 h += SkIntToScalar(360);
65 } 65 }
66 SkASSERT(h >= 0 && h < SkIntToScalar(360)); 66 SkASSERT(h >= 0 && h < SkIntToScalar(360));
67 67
68 hsv[0] = h; 68 hsv[0] = h;
69 hsv[1] = s; 69 hsv[1] = s;
70 hsv[2] = v; 70 hsv[2] = v;
71 } 71 }
72 72
73 static inline U8CPU UnitScalarToByte(SkScalar x) {
74 if (x < 0) {
75 return 0;
76 }
77 if (x >= SK_Scalar1) {
78 return 255;
79 }
80 return SkScalarToFixed(x) >> 8;
81 }
82
83 SkColor SkHSVToColor(U8CPU a, const SkScalar hsv[3]) { 73 SkColor SkHSVToColor(U8CPU a, const SkScalar hsv[3]) {
84 SkASSERT(hsv); 74 SkASSERT(hsv);
85 75
86 U8CPU s = UnitScalarToByte(hsv[1]); 76 U8CPU s = SkUnitScalarClampToByte(hsv[1]);
87 U8CPU v = UnitScalarToByte(hsv[2]); 77 U8CPU v = SkUnitScalarClampToByte(hsv[2]);
88 78
89 if (0 == s) { // shade of gray 79 if (0 == s) { // shade of gray
90 return SkColorSetARGB(a, v, v, v); 80 return SkColorSetARGB(a, v, v, v);
91 } 81 }
92 SkFixed hx = (hsv[0] < 0 || hsv[0] >= SkIntToScalar(360)) ? 0 : SkScalarToFi xed(hsv[0]/60); 82 SkFixed hx = (hsv[0] < 0 || hsv[0] >= SkIntToScalar(360)) ? 0 : SkScalarToFi xed(hsv[0]/60);
93 SkFixed f = hx & 0xFFFF; 83 SkFixed f = hx & 0xFFFF;
94 84
95 unsigned v_scale = SkAlpha255To256(v); 85 unsigned v_scale = SkAlpha255To256(v);
96 unsigned p = SkAlphaMul(255 - s, v_scale); 86 unsigned p = SkAlphaMul(255 - s, v_scale);
97 unsigned q = SkAlphaMul(255 - (s * f >> 16), v_scale); 87 unsigned q = SkAlphaMul(255 - (s * f >> 16), v_scale);
98 unsigned t = SkAlphaMul(255 - (s * (SK_Fixed1 - f) >> 16), v_scale); 88 unsigned t = SkAlphaMul(255 - (s * (SK_Fixed1 - f) >> 16), v_scale);
99 89
100 unsigned r, g, b; 90 unsigned r, g, b;
101 91
102 SkASSERT((unsigned)(hx >> 16) < 6); 92 SkASSERT((unsigned)(hx >> 16) < 6);
103 switch (hx >> 16) { 93 switch (hx >> 16) {
104 case 0: r = v; g = t; b = p; break; 94 case 0: r = v; g = t; b = p; break;
105 case 1: r = q; g = v; b = p; break; 95 case 1: r = q; g = v; b = p; break;
106 case 2: r = p; g = v; b = t; break; 96 case 2: r = p; g = v; b = t; break;
107 case 3: r = p; g = q; b = v; break; 97 case 3: r = p; g = q; b = v; break;
108 case 4: r = t; g = p; b = v; break; 98 case 4: r = t; g = p; b = v; break;
109 default: r = v; g = p; b = q; break; 99 default: r = v; g = p; b = q; break;
110 } 100 }
111 return SkColorSetARGB(a, r, g, b); 101 return SkColorSetARGB(a, r, g, b);
112 } 102 }
OLDNEW
« no previous file with comments | « include/core/SkScalar.h ('k') | src/core/SkMaskFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698