| OLD | NEW |
| 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" | |
| 11 #include "SkBlurImageFilter.h" | 10 #include "SkBlurImageFilter.h" |
| 12 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
| 13 #include "SkColorFilterImageFilter.h" | 12 #include "SkColorFilterImageFilter.h" |
| 14 #include "SkColorMatrixFilter.h" | 13 #include "SkColorMatrixFilter.h" |
| 15 #include "SkComposeImageFilter.h" | 14 #include "SkComposeImageFilter.h" |
| 16 #include "SkDisplacementMapEffect.h" | 15 #include "SkDisplacementMapEffect.h" |
| 17 #include "SkDropShadowImageFilter.h" | 16 #include "SkDropShadowImageFilter.h" |
| 18 #include "SkFlattenableSerialization.h" | 17 #include "SkFlattenableSerialization.h" |
| 19 #include "SkGradientShader.h" | 18 #include "SkGradientShader.h" |
| 19 #include "SkImage.h" |
| 20 #include "SkImageSource.h" | 20 #include "SkImageSource.h" |
| 21 #include "SkLightingImageFilter.h" | 21 #include "SkLightingImageFilter.h" |
| 22 #include "SkMatrixConvolutionImageFilter.h" | 22 #include "SkMatrixConvolutionImageFilter.h" |
| 23 #include "SkMergeImageFilter.h" | 23 #include "SkMergeImageFilter.h" |
| 24 #include "SkMorphologyImageFilter.h" | 24 #include "SkMorphologyImageFilter.h" |
| 25 #include "SkOffsetImageFilter.h" | 25 #include "SkOffsetImageFilter.h" |
| 26 #include "SkPerlinNoiseShader.h" | 26 #include "SkPerlinNoiseShader.h" |
| 27 #include "SkPicture.h" | 27 #include "SkPicture.h" |
| 28 #include "SkPictureImageFilter.h" | 28 #include "SkPictureImageFilter.h" |
| 29 #include "SkPictureRecorder.h" | 29 #include "SkPictureRecorder.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 return new MatrixTestImageFilter(reporter, matrix); | 85 return new MatrixTestImageFilter(reporter, matrix); |
| 86 } | 86 } |
| 87 | 87 |
| 88 #ifndef SK_IGNORE_TO_STRING | 88 #ifndef SK_IGNORE_TO_STRING |
| 89 void MatrixTestImageFilter::toString(SkString* str) const { | 89 void MatrixTestImageFilter::toString(SkString* str) const { |
| 90 str->appendf("MatrixTestImageFilter: ("); | 90 str->appendf("MatrixTestImageFilter: ("); |
| 91 str->append(")"); | 91 str->append(")"); |
| 92 } | 92 } |
| 93 #endif | 93 #endif |
| 94 | 94 |
| 95 static void make_small_bitmap(SkBitmap& bitmap) { | 95 static SkImage* make_small_image() { |
| 96 bitmap.allocN32Pixels(kBitmapSize, kBitmapSize); | 96 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(kBitmapSize, k
BitmapSize)); |
| 97 SkCanvas canvas(bitmap); | 97 SkCanvas* canvas = surface->getCanvas(); |
| 98 canvas.clear(0x00000000); | 98 canvas->clear(0x00000000); |
| 99 SkPaint darkPaint; | 99 SkPaint darkPaint; |
| 100 darkPaint.setColor(0xFF804020); | 100 darkPaint.setColor(0xFF804020); |
| 101 SkPaint lightPaint; | 101 SkPaint lightPaint; |
| 102 lightPaint.setColor(0xFF244484); | 102 lightPaint.setColor(0xFF244484); |
| 103 const int i = kBitmapSize / 4; | 103 const int i = kBitmapSize / 4; |
| 104 for (int y = 0; y < kBitmapSize; y += i) { | 104 for (int y = 0; y < kBitmapSize; y += i) { |
| 105 for (int x = 0; x < kBitmapSize; x += i) { | 105 for (int x = 0; x < kBitmapSize; x += i) { |
| 106 canvas.save(); | 106 canvas->save(); |
| 107 canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); | 107 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
| 108 canvas.drawRect(SkRect::MakeXYWH(0, 0, | 108 canvas->drawRect(SkRect::MakeXYWH(0, 0, |
| 109 SkIntToScalar(i), | 109 SkIntToScalar(i), |
| 110 SkIntToScalar(i)), darkPaint); | 110 SkIntToScalar(i)), darkPaint); |
| 111 canvas.drawRect(SkRect::MakeXYWH(SkIntToScalar(i), | 111 canvas->drawRect(SkRect::MakeXYWH(SkIntToScalar(i), |
| 112 0, | 112 0, |
| 113 SkIntToScalar(i), | 113 SkIntToScalar(i), |
| 114 SkIntToScalar(i)), lightPaint); | 114 SkIntToScalar(i)), lightPaint); |
| 115 canvas.drawRect(SkRect::MakeXYWH(0, | 115 canvas->drawRect(SkRect::MakeXYWH(0, |
| 116 SkIntToScalar(i), | 116 SkIntToScalar(i), |
| 117 SkIntToScalar(i), | 117 SkIntToScalar(i), |
| 118 SkIntToScalar(i)), lightPaint); | 118 SkIntToScalar(i)), lightPaint); |
| 119 canvas.drawRect(SkRect::MakeXYWH(SkIntToScalar(i), | 119 canvas->drawRect(SkRect::MakeXYWH(SkIntToScalar(i), |
| 120 SkIntToScalar(i), | 120 SkIntToScalar(i), |
| 121 SkIntToScalar(i), | 121 SkIntToScalar(i), |
| 122 SkIntToScalar(i)), darkPaint); | 122 SkIntToScalar(i)), darkPaint); |
| 123 canvas.restore(); | 123 canvas->restore(); |
| 124 } | 124 } |
| 125 } | 125 } |
| 126 |
| 127 return surface->newImageSnapshot(); |
| 126 } | 128 } |
| 127 | 129 |
| 128 static SkImageFilter* make_scale(float amount, SkImageFilter* input = nullptr) { | 130 static SkImageFilter* make_scale(float amount, SkImageFilter* input = nullptr) { |
| 129 SkScalar s = amount; | 131 SkScalar s = amount; |
| 130 SkScalar matrix[20] = { s, 0, 0, 0, 0, | 132 SkScalar matrix[20] = { s, 0, 0, 0, 0, |
| 131 0, s, 0, 0, 0, | 133 0, s, 0, 0, 0, |
| 132 0, 0, s, 0, 0, | 134 0, 0, s, 0, 0, |
| 133 0, 0, 0, s, 0 }; | 135 0, 0, 0, s, 0 }; |
| 134 SkAutoTUnref<SkColorFilter> filter(SkColorMatrixFilter::Create(matrix)); | 136 SkAutoTUnref<SkColorFilter> filter(SkColorMatrixFilter::Create(matrix)); |
| 135 return SkColorFilterImageFilter::Create(filter, input); | 137 return SkColorFilterImageFilter::Create(filter, input); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 canvas.clear(0x0); | 236 canvas.clear(0x0); |
| 235 SkRect rect = SkRect::Make(SkIRect::MakeWH(kBitmapSize, kBitmapSize)); | 237 SkRect rect = SkRect::Make(SkIRect::MakeWH(kBitmapSize, kBitmapSize)); |
| 236 canvas.drawRect(rect, paint); | 238 canvas.drawRect(rect, paint); |
| 237 uint32_t pixel = *result.getAddr32(0, 0); | 239 uint32_t pixel = *result.getAddr32(0, 0); |
| 238 // The result here should be green, since we have effectively shifted bl
ue to green. | 240 // The result here should be green, since we have effectively shifted bl
ue to green. |
| 239 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); | 241 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); |
| 240 } | 242 } |
| 241 | 243 |
| 242 { | 244 { |
| 243 // Tests pass by not asserting | 245 // Tests pass by not asserting |
| 244 SkBitmap bitmap, result; | 246 SkAutoTUnref<SkImage> image(make_small_image()); |
| 245 make_small_bitmap(bitmap); | 247 SkBitmap result; |
| 246 result.allocN32Pixels(kBitmapSize, kBitmapSize); | 248 result.allocN32Pixels(kBitmapSize, kBitmapSize); |
| 247 | 249 |
| 248 { | 250 { |
| 249 // This tests for : | 251 // This tests for : |
| 250 // 1 ) location at (0,0,1) | 252 // 1 ) location at (0,0,1) |
| 251 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); | 253 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); |
| 252 // 2 ) location and target at same value | 254 // 2 ) location and target at same value |
| 253 SkPoint3 target = SkPoint3::Make(location.fX, location.fY, location.
fZ); | 255 SkPoint3 target = SkPoint3::Make(location.fX, location.fY, location.
fZ); |
| 254 // 3 ) large negative specular exponent value | 256 // 3 ) large negative specular exponent value |
| 255 SkScalar specularExponent = -1000; | 257 SkScalar specularExponent = -1000; |
| 256 | 258 |
| 257 SkAutoTUnref<SkImageFilter> bmSrc(SkBitmapSource::Create(bitmap)); | 259 SkAutoTUnref<SkImageFilter> bmSrc(SkImageSource::Create(image)); |
| 258 SkPaint paint; | 260 SkPaint paint; |
| 259 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular( | 261 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular( |
| 260 location, target, specularExponent, 180, | 262 location, target, specularExponent, 180, |
| 261 0xFFFFFFFF, SK_Scalar1, SK_Scalar1, SK_Scalar1, | 263 0xFFFFFFFF, SK_Scalar1, SK_Scalar1, SK_Scalar1, |
| 262 bmSrc))->unref(); | 264 bmSrc))->unref(); |
| 263 SkCanvas canvas(result); | 265 SkCanvas canvas(result); |
| 264 SkRect r = SkRect::MakeWH(SkIntToScalar(kBitmapSize), | 266 SkRect r = SkRect::MakeWH(SkIntToScalar(kBitmapSize), |
| 265 SkIntToScalar(kBitmapSize)); | 267 SkIntToScalar(kBitmapSize)); |
| 266 canvas.drawRect(r, paint); | 268 canvas.drawRect(r, paint); |
| 267 } | 269 } |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); | 419 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); |
| 418 SkScalar kernel[9] = { | 420 SkScalar kernel[9] = { |
| 419 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), | 421 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), |
| 420 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1), | 422 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1), |
| 421 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), | 423 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), |
| 422 }; | 424 }; |
| 423 SkISize kernelSize = SkISize::Make(3, 3); | 425 SkISize kernelSize = SkISize::Make(3, 3); |
| 424 SkScalar gain = SK_Scalar1, bias = 0; | 426 SkScalar gain = SK_Scalar1, bias = 0; |
| 425 SkScalar five = SkIntToScalar(5); | 427 SkScalar five = SkIntToScalar(5); |
| 426 | 428 |
| 427 SkAutoTUnref<SkImageFilter> gradient_source(SkBitmapSource::Create(make_grad
ient_circle(64, 64))); | 429 SkAutoTUnref<SkImage> gradientImage(SkImage::NewFromBitmap(make_gradient_cir
cle(64, 64))); |
| 430 SkAutoTUnref<SkImageFilter> gradientSource(SkImageSource::Create(gradientIma
ge)); |
| 428 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(five, five)); | 431 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(five, five)); |
| 429 SkMatrix matrix; | 432 SkMatrix matrix; |
| 430 | 433 |
| 431 matrix.setTranslate(SK_Scalar1, SK_Scalar1); | 434 matrix.setTranslate(SK_Scalar1, SK_Scalar1); |
| 432 matrix.postRotate(SkIntToScalar(45), SK_Scalar1, SK_Scalar1); | 435 matrix.postRotate(SkIntToScalar(45), SK_Scalar1, SK_Scalar1); |
| 433 | 436 |
| 434 SkRTreeFactory factory; | 437 SkRTreeFactory factory; |
| 435 SkPictureRecorder recorder; | 438 SkPictureRecorder recorder; |
| 436 SkCanvas* recordingCanvas = recorder.beginRecording(64, 64, &factory, 0); | 439 SkCanvas* recordingCanvas = recorder.beginRecording(64, 64, &factory, 0); |
| 437 | 440 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 451 SkAutoTUnref<SkImageFilter> rectShaderFilterRight(SkRectShaderImageFilter::C
reate(greenColorShader.get(), &rightSideCropRect)); | 454 SkAutoTUnref<SkImageFilter> rectShaderFilterRight(SkRectShaderImageFilter::C
reate(greenColorShader.get(), &rightSideCropRect)); |
| 452 | 455 |
| 453 struct { | 456 struct { |
| 454 const char* fName; | 457 const char* fName; |
| 455 SkImageFilter* fFilter; | 458 SkImageFilter* fFilter; |
| 456 } filters[] = { | 459 } filters[] = { |
| 457 { "color filter", SkColorFilterImageFilter::Create(cf.get()) }, | 460 { "color filter", SkColorFilterImageFilter::Create(cf.get()) }, |
| 458 { "displacement map", SkDisplacementMapEffect::Create( | 461 { "displacement map", SkDisplacementMapEffect::Create( |
| 459 SkDisplacementMapEffect::kR_ChannelSelectorType, | 462 SkDisplacementMapEffect::kR_ChannelSelectorType, |
| 460 SkDisplacementMapEffect::kB_ChannelSelectorType, | 463 SkDisplacementMapEffect::kB_ChannelSelectorType, |
| 461 20.0f, gradient_source.get()) }, | 464 20.0f, gradientSource.get()) }, |
| 462 { "blur", SkBlurImageFilter::Create(SK_Scalar1, SK_Scalar1) }, | 465 { "blur", SkBlurImageFilter::Create(SK_Scalar1, SK_Scalar1) }, |
| 463 { "drop shadow", SkDropShadowImageFilter::Create( | 466 { "drop shadow", SkDropShadowImageFilter::Create( |
| 464 SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_ColorGREEN, | 467 SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_ColorGREEN, |
| 465 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode) }, | 468 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode) }, |
| 466 { "diffuse lighting", SkLightingImageFilter::CreatePointLitDiffuse( | 469 { "diffuse lighting", SkLightingImageFilter::CreatePointLitDiffuse( |
| 467 location, SK_ColorGREEN, 0, 0) }, | 470 location, SK_ColorGREEN, 0, 0) }, |
| 468 { "specular lighting", | 471 { "specular lighting", |
| 469 SkLightingImageFilter::CreatePointLitSpecular(location, SK_ColorGR
EEN, 0, 0, 0) }, | 472 SkLightingImageFilter::CreatePointLitSpecular(location, SK_ColorGR
EEN, 0, 0, 0) }, |
| 470 { "matrix convolution", | 473 { "matrix convolution", |
| 471 SkMatrixConvolutionImageFilter::Create( | 474 SkMatrixConvolutionImageFilter::Create( |
| (...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1305 SkSurface::kNo_Budgeted
, | 1308 SkSurface::kNo_Budgeted
, |
| 1306 SkImageInfo::MakeN32Pre
mul(1, 1), | 1309 SkImageInfo::MakeN32Pre
mul(1, 1), |
| 1307 0, | 1310 0, |
| 1308 &props, | 1311 &props, |
| 1309 SkGpuDevice::kUninit_In
itContents)); | 1312 SkGpuDevice::kUninit_In
itContents)); |
| 1310 SkImageFilter::Proxy proxy(device); | 1313 SkImageFilter::Proxy proxy(device); |
| 1311 | 1314 |
| 1312 test_negative_blur_sigma(&proxy, reporter); | 1315 test_negative_blur_sigma(&proxy, reporter); |
| 1313 } | 1316 } |
| 1314 #endif | 1317 #endif |
| OLD | NEW |