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

Side by Side Diff: tests/ImageFilterTest.cpp

Issue 112803004: Make SkImageFilter crop rects relative to the primitive origin, instead of relative to their parent (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Updated to ToT Created 6 years, 11 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 | « src/gpu/SkGpuDevice.cpp ('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 2013 Google Inc. 2 * Copyright 2013 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 "Test.h" 8 #include "Test.h"
9 #include "TestClassDef.h" 9 #include "TestClassDef.h"
10 #include "SkBicubicImageFilter.h" 10 #include "SkBicubicImageFilter.h"
11 #include "SkBitmap.h" 11 #include "SkBitmap.h"
12 #include "SkBitmapDevice.h" 12 #include "SkBitmapDevice.h"
13 #include "SkBitmapSource.h" 13 #include "SkBitmapSource.h"
14 #include "SkCanvas.h" 14 #include "SkCanvas.h"
15 #include "SkColorMatrixFilter.h" 15 #include "SkColorMatrixFilter.h"
16 #include "SkColorFilterImageFilter.h" 16 #include "SkColorFilterImageFilter.h"
17 #include "SkDeviceImageFilterProxy.h" 17 #include "SkDeviceImageFilterProxy.h"
18 #include "SkBlurImageFilter.h"
19 #include "SkDisplacementMapEffect.h"
20 #include "SkDropShadowImageFilter.h"
18 #include "SkLightingImageFilter.h" 21 #include "SkLightingImageFilter.h"
22 #include "SkMergeImageFilter.h"
23 #include "SkMorphologyImageFilter.h"
24 #include "SkMatrixConvolutionImageFilter.h"
25 #include "SkOffsetImageFilter.h"
26 #include "SkTileImageFilter.h"
27 #include "SkXfermodeImageFilter.h"
19 #include "SkRect.h" 28 #include "SkRect.h"
20 29
21 static const int kBitmapSize = 4; 30 static const int kBitmapSize = 4;
22 31
23 static void make_small_bitmap(SkBitmap& bitmap) { 32 static void make_small_bitmap(SkBitmap& bitmap) {
24 bitmap.setConfig(SkBitmap::kARGB_8888_Config, kBitmapSize, kBitmapSize); 33 bitmap.setConfig(SkBitmap::kARGB_8888_Config, kBitmapSize, kBitmapSize);
25 bitmap.allocPixels(); 34 bitmap.allocPixels();
26 SkBitmapDevice device(bitmap); 35 SkBitmapDevice device(bitmap);
27 SkCanvas canvas(&device); 36 SkCanvas canvas(&device);
28 canvas.clear(0x00000000); 37 canvas.clear(0x00000000);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 SkAutoTUnref<SkBicubicImageFilter> bicubic( 150 SkAutoTUnref<SkBicubicImageFilter> bicubic(
142 SkBicubicImageFilter::CreateMitchell(scale, bmSrc)); 151 SkBicubicImageFilter::CreateMitchell(scale, bmSrc));
143 SkBitmapDevice device(bitmap); 152 SkBitmapDevice device(bitmap);
144 SkDeviceImageFilterProxy proxy(&device); 153 SkDeviceImageFilterProxy proxy(&device);
145 SkIPoint loc = SkIPoint::Make(0, 0); 154 SkIPoint loc = SkIPoint::Make(0, 0);
146 // An empty input should early return and return false 155 // An empty input should early return and return false
147 REPORTER_ASSERT(reporter, 156 REPORTER_ASSERT(reporter,
148 !bicubic->filterImage(&proxy, bitmap, SkMatrix::I(), &result, &loc)); 157 !bicubic->filterImage(&proxy, bitmap, SkMatrix::I(), &result, &loc));
149 } 158 }
150 } 159 }
160
161 {
162 // Check that all filters offset to their absolute crop rect,
163 // unaffected by the input crop rect.
164 // Tests pass by not asserting.
165 SkBitmap bitmap, temp;
166 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
167 temp.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
168 bitmap.allocPixels();
169 temp.allocPixels();
170 bitmap.eraseARGB(0, 0, 0, 0);
171 SkBitmapDevice device(temp);
172 SkDeviceImageFilterProxy proxy(&device);
173
174 SkImageFilter::CropRect inputCropRect(SkRect::MakeXYWH(8, 13, 80, 80));
175 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 30, 60, 60));
176 SkAutoTUnref<SkImageFilter> input(make_grayscale(NULL, &inputCropRect));
177
178 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorR ED, SkXfermode::kSrcIn_Mode));
179 SkPoint3 location(0, 0, SK_Scalar1);
180 SkPoint3 target(SK_Scalar1, SK_Scalar1, SK_Scalar1);
181 SkScalar kernel[9] = {
182 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
183 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1),
184 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
185 };
186 SkISize kernelSize = SkISize::Make(3, 3);
187 SkScalar gain = SK_Scalar1, bias = 0;
188
189 SkImageFilter* filters[] = {
190 SkColorFilterImageFilter::Create(cf.get(), input.get(), &cropRect),
191 new SkDisplacementMapEffect(SkDisplacementMapEffect::kR_ChannelSelec torType,
192 SkDisplacementMapEffect::kB_ChannelSelec torType,
193 40.0f, input.get(), input.get(), &cropRe ct),
194 new SkBlurImageFilter(SK_Scalar1, SK_Scalar1, input.get(), &cropRect ),
195 new SkDropShadowImageFilter(SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_S calar1, SK_ColorGREEN, input.get(), &cropRect),
196 SkLightingImageFilter::CreatePointLitDiffuse(location, SK_ColorGREEN , 0, 0, input.get(), &cropRect),
197 SkLightingImageFilter::CreatePointLitSpecular(location, SK_ColorGREE N, 0, 0, 0, input.get(), &cropRect),
198 new SkMatrixConvolutionImageFilter(kernelSize, kernel, gain, bias, S kIPoint::Make(1, 1), SkMatrixConvolutionImageFilter::kRepeat_TileMode, false, in put.get(), &cropRect),
199 new SkMergeImageFilter(input.get(), input.get(), SkXfermode::kSrcOve r_Mode, &cropRect),
200 new SkOffsetImageFilter(SK_Scalar1, SK_Scalar1, input.get(), &cropRe ct),
201 new SkOffsetImageFilter(SK_Scalar1, SK_Scalar1, input.get(), &cropRe ct),
202 new SkDilateImageFilter(3, 2, input.get(), &cropRect),
203 new SkErodeImageFilter(2, 3, input.get(), &cropRect),
204 new SkTileImageFilter(inputCropRect.rect(), cropRect.rect(), input.g et()),
205 new SkXfermodeImageFilter(SkXfermode::Create(SkXfermode::kSrcOver_Mo de), input.get(), input.get(), &cropRect),
206 };
207
208 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
209 SkImageFilter* filter = filters[i];
210 SkBitmap result;
211 SkIPoint offset;
212 REPORTER_ASSERT(reporter, filter->filterImage(&proxy, bitmap, SkMatr ix::I(), &result, &offset));
213 REPORTER_ASSERT(reporter, offset.fX == 20 && offset.fY == 30);
214 }
215
216 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) {
217 SkSafeUnref(filters[i]);
218 }
219 }
151 } 220 }
OLDNEW
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698