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

Side by Side Diff: gm/lighting.cpp

Issue 20426002: Implement crop rect for lighting image filters. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Bugfix: set the bitmap's width and height to the bounds's width and height, Created 7 years, 4 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 | « no previous file | include/core/SkImageFilter.h » ('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 2012 Google Inc. 2 * Copyright 2012 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 "gm.h" 8 #include "gm.h"
9 #include "SkLightingImageFilter.h" 9 #include "SkLightingImageFilter.h"
10 10
11 #define WIDTH 330 11 #define WIDTH 330
12 #define HEIGHT 220 12 #define HEIGHT 440
13 13
14 namespace skiagm { 14 namespace skiagm {
15 15
16 class ImageLightingGM : public GM { 16 class ImageLightingGM : public GM {
17 public: 17 public:
18 ImageLightingGM() : fInitialized(false) { 18 ImageLightingGM() : fInitialized(false) {
19 this->setBGColor(0xFF000000); 19 this->setBGColor(0xFF000000);
20 } 20 }
21 21
22 protected: 22 protected:
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 SkPoint3 spotLocation(SkIntToScalar(-10), SkIntToScalar(-10), SkIntToSca lar(20)); 76 SkPoint3 spotLocation(SkIntToScalar(-10), SkIntToScalar(-10), SkIntToSca lar(20));
77 SkPoint3 spotTarget(SkIntToScalar(40), SkIntToScalar(40), 0); 77 SkPoint3 spotTarget(SkIntToScalar(40), SkIntToScalar(40), 0);
78 SkScalar spotExponent = SK_Scalar1; 78 SkScalar spotExponent = SK_Scalar1;
79 SkScalar cutoffAngle = SkIntToScalar(15); 79 SkScalar cutoffAngle = SkIntToScalar(15);
80 SkScalar kd = SkIntToScalar(2); 80 SkScalar kd = SkIntToScalar(2);
81 SkScalar ks = SkIntToScalar(1); 81 SkScalar ks = SkIntToScalar(1);
82 SkScalar shininess = SkIntToScalar(8); 82 SkScalar shininess = SkIntToScalar(8);
83 SkScalar surfaceScale = SkIntToScalar(1); 83 SkScalar surfaceScale = SkIntToScalar(1);
84 SkColor white(0xFFFFFFFF); 84 SkColor white(0xFFFFFFFF);
85 SkPaint paint; 85 SkPaint paint;
86 paint.setImageFilter(SkLightingImageFilter::CreatePointLitDiffuse(pointL ocation, white, surfaceScale, kd))->unref(); 86
87 drawClippedBitmap(canvas, paint, 0, 0); 87 SkIRect cropRect = SkIRect::MakeXYWH(20, 10, 60, 65);
88 paint.setImageFilter(SkLightingImageFilter::CreateDistantLitDiffuse(dist antDirection, white, surfaceScale, kd))->unref(); 88
89 drawClippedBitmap(canvas, paint, 110, 0); 89 int y = 0;
90 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitDiffuse(spotLoc ation, spotTarget, spotExponent, cutoffAngle, white, surfaceScale, kd))->unref() ; 90 for (int i = 0; i < 2; i++) {
91 drawClippedBitmap(canvas, paint, 220, 0); 91 const SkIRect* cr = (i == 0) ? NULL : &cropRect;
92 paint.setImageFilter(SkLightingImageFilter::CreatePointLitSpecular(point Location, white, surfaceScale, ks, shininess))->unref(); 92 paint.setImageFilter(SkLightingImageFilter::CreatePointLitDiffuse(po intLocation, white, surfaceScale, kd, NULL, cr))->unref();
93 drawClippedBitmap(canvas, paint, 0, 110); 93 drawClippedBitmap(canvas, paint, 0, y);
94 paint.setImageFilter(SkLightingImageFilter::CreateDistantLitSpecular(dis tantDirection, white, surfaceScale, ks, shininess))->unref(); 94 paint.setImageFilter(SkLightingImageFilter::CreateDistantLitDiffuse( distantDirection, white, surfaceScale, kd, NULL, cr))->unref();
95 drawClippedBitmap(canvas, paint, 110, 110); 95 drawClippedBitmap(canvas, paint, 110, y);
96 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(spotLo cation, spotTarget, spotExponent, cutoffAngle, white, surfaceScale, ks, shinines s))->unref(); 96 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitDiffuse(spo tLocation, spotTarget, spotExponent, cutoffAngle, white, surfaceScale, kd, NULL, cr))->unref();
97 drawClippedBitmap(canvas, paint, 220, 110); 97 drawClippedBitmap(canvas, paint, 220, y);
98
99 y += 110;
100 paint.setImageFilter(SkLightingImageFilter::CreatePointLitSpecular(p ointLocation, white, surfaceScale, ks, shininess, NULL, cr))->unref();
101 drawClippedBitmap(canvas, paint, 0, y);
102 paint.setImageFilter(SkLightingImageFilter::CreateDistantLitSpecular (distantDirection, white, surfaceScale, ks, shininess, NULL, cr))->unref();
103 drawClippedBitmap(canvas, paint, 110, y);
104 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(sp otLocation, spotTarget, spotExponent, cutoffAngle, white, surfaceScale, ks, shin iness, NULL, cr))->unref();
105 drawClippedBitmap(canvas, paint, 220, y);
106 y += 110;
107 }
98 } 108 }
99 109
100 private: 110 private:
101 typedef GM INHERITED; 111 typedef GM INHERITED;
102 SkBitmap fBitmap; 112 SkBitmap fBitmap;
103 bool fInitialized; 113 bool fInitialized;
104 }; 114 };
105 115
106 ////////////////////////////////////////////////////////////////////////////// 116 //////////////////////////////////////////////////////////////////////////////
107 117
108 static GM* MyFactory(void*) { return new ImageLightingGM; } 118 static GM* MyFactory(void*) { return new ImageLightingGM; }
109 static GMRegistry reg(MyFactory); 119 static GMRegistry reg(MyFactory);
110 120
111 } 121 }
OLDNEW
« no previous file with comments | « no previous file | include/core/SkImageFilter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698