| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "Test.h" | 9 #include "Test.h" |
| 10 #include "SkBicubicImageFilter.h" | 10 #include "SkBicubicImageFilter.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 canvas.drawRect(SkRect::MakeXYWH(SkIntToScalar(i), | 51 canvas.drawRect(SkRect::MakeXYWH(SkIntToScalar(i), |
| 52 SkIntToScalar(i), | 52 SkIntToScalar(i), |
| 53 SkIntToScalar(i), | 53 SkIntToScalar(i), |
| 54 SkIntToScalar(i)), darkPaint); | 54 SkIntToScalar(i)), darkPaint); |
| 55 canvas.restore(); | 55 canvas.restore(); |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 static SkImageFilter* make_scale(float amount, SkImageFilter* input = NULL)
{ | 60 static SkImageFilter* make_scale(float amount, SkImageFilter* input = NULL)
{ |
| 61 SkScalar s = SkFloatToScalar(amount); | 61 SkScalar s = amount; |
| 62 SkScalar matrix[20] = { s, 0, 0, 0, 0, | 62 SkScalar matrix[20] = { s, 0, 0, 0, 0, |
| 63 0, s, 0, 0, 0, | 63 0, s, 0, 0, 0, |
| 64 0, 0, s, 0, 0, | 64 0, 0, s, 0, 0, |
| 65 0, 0, 0, s, 0 }; | 65 0, 0, 0, s, 0 }; |
| 66 SkAutoTUnref<SkColorFilter> filter(new SkColorMatrixFilter(matrix)); | 66 SkAutoTUnref<SkColorFilter> filter(new SkColorMatrixFilter(matrix)); |
| 67 return SkColorFilterImageFilter::Create(filter, input); | 67 return SkColorFilterImageFilter::Create(filter, input); |
| 68 } | 68 } |
| 69 | 69 |
| 70 static SkImageFilter* make_grayscale(SkImageFilter* input = NULL, const SkIm
ageFilter::CropRect* cropRect = NULL) { | 70 static SkImageFilter* make_grayscale(SkImageFilter* input = NULL, const SkIm
ageFilter::CropRect* cropRect = NULL) { |
| 71 SkScalar matrix[20]; | 71 SkScalar matrix[20]; |
| 72 memset(matrix, 0, 20 * sizeof(SkScalar)); | 72 memset(matrix, 0, 20 * sizeof(SkScalar)); |
| 73 matrix[0] = matrix[5] = matrix[10] = SkFloatToScalar(0.2126f); | 73 matrix[0] = matrix[5] = matrix[10] = 0.2126f; |
| 74 matrix[1] = matrix[6] = matrix[11] = SkFloatToScalar(0.7152f); | 74 matrix[1] = matrix[6] = matrix[11] = 0.7152f; |
| 75 matrix[2] = matrix[7] = matrix[12] = SkFloatToScalar(0.0722f); | 75 matrix[2] = matrix[7] = matrix[12] = 0.0722f; |
| 76 matrix[18] = SkFloatToScalar(1.0f); | 76 matrix[18] = 1.0f; |
| 77 SkAutoTUnref<SkColorFilter> filter(new SkColorMatrixFilter(matrix)); | 77 SkAutoTUnref<SkColorFilter> filter(new SkColorMatrixFilter(matrix)); |
| 78 return SkColorFilterImageFilter::Create(filter, input, cropRect); | 78 return SkColorFilterImageFilter::Create(filter, input, cropRect); |
| 79 } | 79 } |
| 80 | 80 |
| 81 static SkImageFilter* make_mode_blue(SkImageFilter* input = NULL) { | 81 static SkImageFilter* make_mode_blue(SkImageFilter* input = NULL) { |
| 82 SkAutoTUnref<SkColorFilter> filter( | 82 SkAutoTUnref<SkColorFilter> filter( |
| 83 SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mod
e)); | 83 SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mod
e)); |
| 84 return SkColorFilterImageFilter::Create(filter, input); | 84 return SkColorFilterImageFilter::Create(filter, input); |
| 85 } | 85 } |
| 86 | 86 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 result.setConfig(SkBitmap::kARGB_8888_Config, kBitmapSize, kBitmapSi
ze); | 121 result.setConfig(SkBitmap::kARGB_8888_Config, kBitmapSize, kBitmapSi
ze); |
| 122 result.allocPixels(); | 122 result.allocPixels(); |
| 123 | 123 |
| 124 { | 124 { |
| 125 // This tests for : | 125 // This tests for : |
| 126 // 1 ) location at (0,0,1) | 126 // 1 ) location at (0,0,1) |
| 127 SkPoint3 location(0, 0, SK_Scalar1); | 127 SkPoint3 location(0, 0, SK_Scalar1); |
| 128 // 2 ) location and target at same value | 128 // 2 ) location and target at same value |
| 129 SkPoint3 target(location.fX, location.fY, location.fZ); | 129 SkPoint3 target(location.fX, location.fY, location.fZ); |
| 130 // 3 ) large negative specular exponent value | 130 // 3 ) large negative specular exponent value |
| 131 SkScalar specularExponent = SkFloatToScalar(-1000); | 131 SkScalar specularExponent = -1000; |
| 132 | 132 |
| 133 SkAutoTUnref<SkImageFilter> bmSrc(new SkBitmapSource(bitmap)); | 133 SkAutoTUnref<SkImageFilter> bmSrc(new SkBitmapSource(bitmap)); |
| 134 SkPaint paint; | 134 SkPaint paint; |
| 135 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecula
r( | 135 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecula
r( |
| 136 location, target, specularExponent, SkFloatToScalar(180)
, | 136 location, target, specularExponent, 180, |
| 137 0xFFFFFFFF, SK_Scalar1, SK_Scalar1, SK_Scalar1, | 137 0xFFFFFFFF, SK_Scalar1, SK_Scalar1, SK_Scalar1, |
| 138 bmSrc))->unref(); | 138 bmSrc))->unref(); |
| 139 SkCanvas canvas(result); | 139 SkCanvas canvas(result); |
| 140 SkRect r = SkRect::MakeWH(SkIntToScalar(kBitmapSize), | 140 SkRect r = SkRect::MakeWH(SkIntToScalar(kBitmapSize), |
| 141 SkIntToScalar(kBitmapSize)); | 141 SkIntToScalar(kBitmapSize)); |
| 142 canvas.drawRect(r, paint); | 142 canvas.drawRect(r, paint); |
| 143 } | 143 } |
| 144 | 144 |
| 145 { | 145 { |
| 146 // This tests for scale bringing width to 0 | 146 // This tests for scale bringing width to 0 |
| 147 SkSize scale = SkSize::Make(SkFloatToScalar(-0.001f), SK_Scalar1
); | 147 SkSize scale = SkSize::Make(-0.001f, SK_Scalar1); |
| 148 SkAutoTUnref<SkImageFilter> bmSrc(new SkBitmapSource(bitmap)); | 148 SkAutoTUnref<SkImageFilter> bmSrc(new SkBitmapSource(bitmap)); |
| 149 SkAutoTUnref<SkBicubicImageFilter> bicubic( | 149 SkAutoTUnref<SkBicubicImageFilter> bicubic( |
| 150 SkBicubicImageFilter::CreateMitchell(scale, bmSrc)); | 150 SkBicubicImageFilter::CreateMitchell(scale, bmSrc)); |
| 151 SkBitmapDevice device(bitmap); | 151 SkBitmapDevice device(bitmap); |
| 152 SkDeviceImageFilterProxy proxy(&device); | 152 SkDeviceImageFilterProxy proxy(&device); |
| 153 SkIPoint loc = SkIPoint::Make(0, 0); | 153 SkIPoint loc = SkIPoint::Make(0, 0); |
| 154 // An empty input should early return and return false | 154 // An empty input should early return and return false |
| 155 REPORTER_ASSERT(reporter, | 155 REPORTER_ASSERT(reporter, |
| 156 !bicubic->filterImage(&proxy, bitmap, SkMatrix::I(), &result
, &loc)); | 156 !bicubic->filterImage(&proxy, bitmap, SkMatrix::I(), &result
, &loc)); |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 } | 159 } |
| 160 }; | 160 }; |
| 161 | 161 |
| 162 | 162 |
| 163 #include "TestClassDef.h" | 163 #include "TestClassDef.h" |
| 164 DEFINE_TESTCLASS("ImageFilterTest", ImageFilterTestClass, ImageFilterTest::Test) | 164 DEFINE_TESTCLASS("ImageFilterTest", ImageFilterTestClass, ImageFilterTest::Test) |
| OLD | NEW |