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

Side by Side Diff: src/effects/SkLightingImageFilter.cpp

Issue 205073002: Use rounding to 8888 in lighting filters, raster path. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fix expectations Created 6 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 | Annotate | Revision Log
« no previous file with comments | « expectations/gm/ignored-tests.txt ('k') | 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 2012 The Android Open Source Project 2 * Copyright 2012 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 "SkLightingImageFilter.h" 8 #include "SkLightingImageFilter.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 class DiffuseLightingType { 58 class DiffuseLightingType {
59 public: 59 public:
60 DiffuseLightingType(SkScalar kd) 60 DiffuseLightingType(SkScalar kd)
61 : fKD(kd) {} 61 : fKD(kd) {}
62 SkPMColor light(const SkPoint3& normal, const SkPoint3& surfaceTolight, cons t SkPoint3& lightColor) const { 62 SkPMColor light(const SkPoint3& normal, const SkPoint3& surfaceTolight, cons t SkPoint3& lightColor) const {
63 SkScalar colorScale = SkScalarMul(fKD, normal.dot(surfaceTolight)); 63 SkScalar colorScale = SkScalarMul(fKD, normal.dot(surfaceTolight));
64 colorScale = SkScalarClampMax(colorScale, SK_Scalar1); 64 colorScale = SkScalarClampMax(colorScale, SK_Scalar1);
65 SkPoint3 color(lightColor * colorScale); 65 SkPoint3 color(lightColor * colorScale);
66 return SkPackARGB32(255, 66 return SkPackARGB32(255,
67 SkClampMax(SkScalarFloorToInt(color.fX), 255), 67 SkClampMax(SkScalarRoundToInt(color.fX), 255),
68 SkClampMax(SkScalarFloorToInt(color.fY), 255), 68 SkClampMax(SkScalarRoundToInt(color.fY), 255),
69 SkClampMax(SkScalarFloorToInt(color.fZ), 255)); 69 SkClampMax(SkScalarRoundToInt(color.fZ), 255));
70 } 70 }
71 private: 71 private:
72 SkScalar fKD; 72 SkScalar fKD;
73 }; 73 };
74 74
75 class SpecularLightingType { 75 class SpecularLightingType {
76 public: 76 public:
77 SpecularLightingType(SkScalar ks, SkScalar shininess) 77 SpecularLightingType(SkScalar ks, SkScalar shininess)
78 : fKS(ks), fShininess(shininess) {} 78 : fKS(ks), fShininess(shininess) {}
79 SkPMColor light(const SkPoint3& normal, const SkPoint3& surfaceTolight, cons t SkPoint3& lightColor) const { 79 SkPMColor light(const SkPoint3& normal, const SkPoint3& surfaceTolight, cons t SkPoint3& lightColor) const {
80 SkPoint3 halfDir(surfaceTolight); 80 SkPoint3 halfDir(surfaceTolight);
81 halfDir.fZ += SK_Scalar1; // eye position is always (0, 0, 1) 81 halfDir.fZ += SK_Scalar1; // eye position is always (0, 0, 1)
82 halfDir.normalize(); 82 halfDir.normalize();
83 SkScalar colorScale = SkScalarMul(fKS, 83 SkScalar colorScale = SkScalarMul(fKS,
84 SkScalarPow(normal.dot(halfDir), fShininess)); 84 SkScalarPow(normal.dot(halfDir), fShininess));
85 colorScale = SkScalarClampMax(colorScale, SK_Scalar1); 85 colorScale = SkScalarClampMax(colorScale, SK_Scalar1);
86 SkPoint3 color(lightColor * colorScale); 86 SkPoint3 color(lightColor * colorScale);
87 return SkPackARGB32(SkClampMax(SkScalarFloorToInt(color.maxComponent()), 255), 87 return SkPackARGB32(SkClampMax(SkScalarRoundToInt(color.maxComponent()), 255),
88 SkClampMax(SkScalarFloorToInt(color.fX), 255), 88 SkClampMax(SkScalarRoundToInt(color.fX), 255),
89 SkClampMax(SkScalarFloorToInt(color.fY), 255), 89 SkClampMax(SkScalarRoundToInt(color.fY), 255),
90 SkClampMax(SkScalarFloorToInt(color.fZ), 255)); 90 SkClampMax(SkScalarRoundToInt(color.fZ), 255));
91 } 91 }
92 private: 92 private:
93 SkScalar fKS; 93 SkScalar fKS;
94 SkScalar fShininess; 94 SkScalar fShininess;
95 }; 95 };
96 96
97 inline SkScalar sobel(int a, int b, int c, int d, int e, int f, SkScalar scale) { 97 inline SkScalar sobel(int a, int b, int c, int d, int e, int f, SkScalar scale) {
98 return SkScalarMul(SkIntToScalar(-a + b - 2 * c + 2 * d -e + f), scale); 98 return SkScalarMul(SkIntToScalar(-a + b - 2 * c + 2 * d -e + f), scale);
99 } 99 }
100 100
(...skipping 1514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1615 1615
1616 builder->fsCodeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); 1616 builder->fsCodeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight);
1617 } 1617 }
1618 1618
1619 #endif 1619 #endif
1620 1620
1621 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) 1621 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter)
1622 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) 1622 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter)
1623 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) 1623 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter)
1624 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 1624 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
OLDNEW
« no previous file with comments | « expectations/gm/ignored-tests.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698