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

Side by Side Diff: tests/ImageFilterTest.cpp

Issue 555603002: Allow negative values in SkBlurImageFilter sigma. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix re: sugoi's comment Created 6 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 | « src/effects/SkBlurImageFilter.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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkBitmapDevice.h" 9 #include "SkBitmapDevice.h"
10 #include "SkBitmapSource.h" 10 #include "SkBitmapSource.h"
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 SkAutoTUnref<SkShader> shader( 300 SkAutoTUnref<SkShader> shader(
301 SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors, NULL , 2, 301 SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors, NULL , 2,
302 SkShader::kClamp_TileMode) 302 SkShader::kClamp_TileMode)
303 ); 303 );
304 SkPaint paint; 304 SkPaint paint;
305 paint.setShader(shader); 305 paint.setShader(shader);
306 canvas.drawCircle(x, y, radius, paint); 306 canvas.drawCircle(x, y, radius, paint);
307 return bitmap; 307 return bitmap;
308 } 308 }
309 309
310 static void test_negative_blur_sigma(SkBaseDevice* device, skiatest::Reporter* r eporter) {
311 // Check that SkBlurImageFilter will accept a negative sigma, either in
312 // the given arguments or after CTM application.
313 int width = 32, height = 32;
314 SkDeviceImageFilterProxy proxy(device);
315 SkScalar five = SkIntToScalar(5);
316
317 SkAutoTUnref<SkBlurImageFilter> positiveFilter(
318 SkBlurImageFilter::Create(five, five)
319 );
320
321 SkAutoTUnref<SkBlurImageFilter> negativeFilter(
322 SkBlurImageFilter::Create(-five, five)
323 );
324
325 SkBitmap gradient = make_gradient_circle(width, height);
326 SkBitmap positiveResult1, negativeResult1;
327 SkBitmap positiveResult2, negativeResult2;
328 SkIPoint offset;
329 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), NULL);
330 positiveFilter->filterImage(&proxy, gradient, ctx, &positiveResult1, &offset );
331 negativeFilter->filterImage(&proxy, gradient, ctx, &negativeResult1, &offset );
332 SkMatrix negativeScale;
333 negativeScale.setScale(-SK_Scalar1, SK_Scalar1);
334 SkImageFilter::Context negativeCTX(negativeScale, SkIRect::MakeLargest(), NU LL);
335 positiveFilter->filterImage(&proxy, gradient, negativeCTX, &negativeResult2, &offset);
336 negativeFilter->filterImage(&proxy, gradient, negativeCTX, &positiveResult2, &offset);
337 SkAutoLockPixels lockP1(positiveResult1);
338 SkAutoLockPixels lockP2(positiveResult2);
339 SkAutoLockPixels lockN1(negativeResult1);
340 SkAutoLockPixels lockN2(negativeResult2);
341 for (int y = 0; y < height; y++) {
342 int diffs = memcmp(positiveResult1.getAddr32(0, y), negativeResult1.getA ddr32(0, y), positiveResult1.rowBytes());
343 REPORTER_ASSERT(reporter, !diffs);
344 if (diffs) {
345 break;
346 }
347 diffs = memcmp(positiveResult1.getAddr32(0, y), negativeResult2.getAddr3 2(0, y), positiveResult1.rowBytes());
348 REPORTER_ASSERT(reporter, !diffs);
349 if (diffs) {
350 break;
351 }
352 diffs = memcmp(positiveResult1.getAddr32(0, y), positiveResult2.getAddr3 2(0, y), positiveResult1.rowBytes());
353 REPORTER_ASSERT(reporter, !diffs);
354 if (diffs) {
355 break;
356 }
357 }
358 }
359
360 DEF_TEST(TestNegativeBlurSigma, reporter) {
361 SkBitmap temp;
362 temp.allocN32Pixels(100, 100);
363 SkBitmapDevice device(temp);
364 test_negative_blur_sigma(&device, reporter);
365 }
366
310 DEF_TEST(ImageFilterDrawTiled, reporter) { 367 DEF_TEST(ImageFilterDrawTiled, reporter) {
311 // Check that all filters when drawn tiled (with subsequent clip rects) exac tly 368 // Check that all filters when drawn tiled (with subsequent clip rects) exac tly
312 // match the same filters drawn with a single full-canvas bitmap draw. 369 // match the same filters drawn with a single full-canvas bitmap draw.
313 // Tests pass by not asserting. 370 // Tests pass by not asserting.
314 371
315 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode)); 372 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode));
316 SkPoint3 location(0, 0, SK_Scalar1); 373 SkPoint3 location(0, 0, SK_Scalar1);
317 SkPoint3 target(SK_Scalar1, SK_Scalar1, SK_Scalar1); 374 SkPoint3 target(SK_Scalar1, SK_Scalar1, SK_Scalar1);
318 SkScalar kernel[9] = { 375 SkScalar kernel[9] = {
319 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), 376 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 test_huge_blur(device, reporter); 1016 test_huge_blur(device, reporter);
960 } 1017 }
961 1018
962 DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) { 1019 DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) {
963 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp e>(0)); 1020 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp e>(0));
964 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, 1021 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context,
965 SkImageInfo::MakeN32Pre mul(1, 1), 1022 SkImageInfo::MakeN32Pre mul(1, 1),
966 0)); 1023 0));
967 test_xfermode_cropped_input(device, reporter); 1024 test_xfermode_cropped_input(device, reporter);
968 } 1025 }
1026
1027 DEF_GPUTEST(TestNegativeBlurSigmaGPU, reporter, factory) {
1028 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp e>(0));
1029 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context,
1030 SkImageInfo::MakeN32Pre mul(1, 1),
1031 0));
1032 test_negative_blur_sigma(device, reporter);
1033 }
969 #endif 1034 #endif
OLDNEW
« no previous file with comments | « src/effects/SkBlurImageFilter.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698