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 "SkBlurImageFilter.h" | 10 #include "SkBlurImageFilter.h" |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 SkTileImageFilter::Create(inputCropRect.rect(), cropRect.rect(), input.g
et()), | 312 SkTileImageFilter::Create(inputCropRect.rect(), cropRect.rect(), input.g
et()), |
313 SkXfermodeImageFilter::Create(SkXfermode::Create(SkXfermode::kSrcOver_Mo
de), input.get(), input.get(), &cropRect), | 313 SkXfermodeImageFilter::Create(SkXfermode::Create(SkXfermode::kSrcOver_Mo
de), input.get(), input.get(), &cropRect), |
314 }; | 314 }; |
315 | 315 |
316 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | 316 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { |
317 SkImageFilter* filter = filters[i]; | 317 SkImageFilter* filter = filters[i]; |
318 SkBitmap result; | 318 SkBitmap result; |
319 SkIPoint offset; | 319 SkIPoint offset; |
320 SkString str; | 320 SkString str; |
321 str.printf("filter %d", static_cast<int>(i)); | 321 str.printf("filter %d", static_cast<int>(i)); |
322 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), nullpt
r); | 322 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), nullpt
r, SkImageFilter::kApprox_SizeConstraint); |
323 REPORTER_ASSERT_MESSAGE(reporter, filter->filterImage(proxy, bitmap, ctx
, | 323 REPORTER_ASSERT_MESSAGE(reporter, filter->filterImage(proxy, bitmap, ctx
, |
324 &result, &offset), str.c_str()); | 324 &result, &offset), str.c_str()); |
325 REPORTER_ASSERT_MESSAGE(reporter, offset.fX == 20 && offset.fY == 30, st
r.c_str()); | 325 REPORTER_ASSERT_MESSAGE(reporter, offset.fX == 20 && offset.fY == 30, st
r.c_str()); |
326 } | 326 } |
327 | 327 |
328 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | 328 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { |
329 SkSafeUnref(filters[i]); | 329 SkSafeUnref(filters[i]); |
330 } | 330 } |
331 } | 331 } |
332 | 332 |
(...skipping 24 matching lines...) Expand all Loading... |
357 const int width = 32, height = 32; | 357 const int width = 32, height = 32; |
358 const SkScalar five = SkIntToScalar(5); | 358 const SkScalar five = SkIntToScalar(5); |
359 | 359 |
360 SkAutoTUnref<SkImageFilter> positiveFilter(SkBlurImageFilter::Create(five, f
ive)); | 360 SkAutoTUnref<SkImageFilter> positiveFilter(SkBlurImageFilter::Create(five, f
ive)); |
361 SkAutoTUnref<SkImageFilter> negativeFilter(SkBlurImageFilter::Create(-five,
five)); | 361 SkAutoTUnref<SkImageFilter> negativeFilter(SkBlurImageFilter::Create(-five,
five)); |
362 | 362 |
363 SkBitmap gradient = make_gradient_circle(width, height); | 363 SkBitmap gradient = make_gradient_circle(width, height); |
364 SkBitmap positiveResult1, negativeResult1; | 364 SkBitmap positiveResult1, negativeResult1; |
365 SkBitmap positiveResult2, negativeResult2; | 365 SkBitmap positiveResult2, negativeResult2; |
366 SkIPoint offset; | 366 SkIPoint offset; |
367 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), nullptr); | 367 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), nullptr, S
kImageFilter::kApprox_SizeConstraint); |
368 positiveFilter->filterImage(proxy, gradient, ctx, &positiveResult1, &offset)
; | 368 positiveFilter->filterImage(proxy, gradient, ctx, &positiveResult1, &offset)
; |
369 negativeFilter->filterImage(proxy, gradient, ctx, &negativeResult1, &offset)
; | 369 negativeFilter->filterImage(proxy, gradient, ctx, &negativeResult1, &offset)
; |
370 SkMatrix negativeScale; | 370 SkMatrix negativeScale; |
371 negativeScale.setScale(-SK_Scalar1, SK_Scalar1); | 371 negativeScale.setScale(-SK_Scalar1, SK_Scalar1); |
372 SkImageFilter::Context negativeCTX(negativeScale, SkIRect::MakeLargest(), nu
llptr); | 372 SkImageFilter::Context negativeCTX(negativeScale, SkIRect::MakeLargest(), nu
llptr, SkImageFilter::kApprox_SizeConstraint); |
373 positiveFilter->filterImage(proxy, gradient, negativeCTX, &negativeResult2,
&offset); | 373 positiveFilter->filterImage(proxy, gradient, negativeCTX, &negativeResult2,
&offset); |
374 negativeFilter->filterImage(proxy, gradient, negativeCTX, &positiveResult2,
&offset); | 374 negativeFilter->filterImage(proxy, gradient, negativeCTX, &positiveResult2,
&offset); |
375 SkAutoLockPixels lockP1(positiveResult1); | 375 SkAutoLockPixels lockP1(positiveResult1); |
376 SkAutoLockPixels lockP2(positiveResult2); | 376 SkAutoLockPixels lockP2(positiveResult2); |
377 SkAutoLockPixels lockN1(negativeResult1); | 377 SkAutoLockPixels lockN1(negativeResult1); |
378 SkAutoLockPixels lockN2(negativeResult2); | 378 SkAutoLockPixels lockN2(negativeResult2); |
379 for (int y = 0; y < height; y++) { | 379 for (int y = 0; y < height; y++) { |
380 int diffs = memcmp(positiveResult1.getAddr32(0, y), negativeResult1.getA
ddr32(0, y), positiveResult1.rowBytes()); | 380 int diffs = memcmp(positiveResult1.getAddr32(0, y), negativeResult1.getA
ddr32(0, y), positiveResult1.rowBytes()); |
381 REPORTER_ASSERT(reporter, !diffs); | 381 REPORTER_ASSERT(reporter, !diffs); |
382 if (diffs) { | 382 if (diffs) { |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 // Create an SkPicture which simply draws a green 1x1 rectangle. | 875 // Create an SkPicture which simply draws a green 1x1 rectangle. |
876 SkPaint greenPaint; | 876 SkPaint greenPaint; |
877 greenPaint.setColor(SK_ColorGREEN); | 877 greenPaint.setColor(SK_ColorGREEN); |
878 recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), greenPaint); | 878 recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), greenPaint); |
879 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 879 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
880 | 880 |
881 SkAutoTUnref<SkImageFilter> imageFilter(SkPictureImageFilter::Create(picture
.get())); | 881 SkAutoTUnref<SkImageFilter> imageFilter(SkPictureImageFilter::Create(picture
.get())); |
882 | 882 |
883 SkBitmap result; | 883 SkBitmap result; |
884 SkIPoint offset; | 884 SkIPoint offset; |
885 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(1, 1, 1, 1), nul
lptr); | 885 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(1, 1, 1, 1), nul
lptr, SkImageFilter::kApprox_SizeConstraint); |
886 SkBitmap bitmap; | 886 SkBitmap bitmap; |
887 bitmap.allocN32Pixels(2, 2); | 887 bitmap.allocN32Pixels(2, 2); |
888 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); | 888 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); |
889 SkBitmapDevice device(bitmap, props); | 889 SkBitmapDevice device(bitmap, props); |
890 SkImageFilter::DeviceProxy proxy(&device); | 890 SkImageFilter::DeviceProxy proxy(&device); |
891 REPORTER_ASSERT(reporter, !imageFilter->filterImage(&proxy, bitmap, ctx, &re
sult, &offset)); | 891 REPORTER_ASSERT(reporter, !imageFilter->filterImage(&proxy, bitmap, ctx, &re
sult, &offset)); |
892 } | 892 } |
893 | 893 |
894 DEF_TEST(ImageFilterEmptySaveLayer, reporter) { | 894 DEF_TEST(ImageFilterEmptySaveLayer, reporter) { |
895 // Even when there's an empty saveLayer()/restore(), ensure that an image | 895 // Even when there's an empty saveLayer()/restore(), ensure that an image |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1126 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); | 1126 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); |
1127 SkBitmapDevice device(bitmap, props); | 1127 SkBitmapDevice device(bitmap, props); |
1128 SkImageFilter::DeviceProxy proxy(&device); | 1128 SkImageFilter::DeviceProxy proxy(&device); |
1129 | 1129 |
1130 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20)); | 1130 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20)); |
1131 SkAutoTUnref<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(0, 0, n
ullptr, &cropRect)); | 1131 SkAutoTUnref<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(0, 0, n
ullptr, &cropRect)); |
1132 SkAutoTUnref<SkImageFilter> blurFilter(makeBlur()); | 1132 SkAutoTUnref<SkImageFilter> blurFilter(makeBlur()); |
1133 SkAutoTUnref<SkImageFilter> composedFilter(SkComposeImageFilter::Create(blur
Filter, offsetFilter.get())); | 1133 SkAutoTUnref<SkImageFilter> composedFilter(SkComposeImageFilter::Create(blur
Filter, offsetFilter.get())); |
1134 SkBitmap result; | 1134 SkBitmap result; |
1135 SkIPoint offset; | 1135 SkIPoint offset; |
1136 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), nullptr); | 1136 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), nullptr, S
kImageFilter::kApprox_SizeConstraint); |
1137 REPORTER_ASSERT(reporter, composedFilter->filterImage(&proxy, bitmap, ctx, &
result, &offset)); | 1137 REPORTER_ASSERT(reporter, composedFilter->filterImage(&proxy, bitmap, ctx, &
result, &offset)); |
1138 REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0); | 1138 REPORTER_ASSERT(reporter, offset.fX == 1 && offset.fY == 0); |
1139 } | 1139 } |
1140 | 1140 |
1141 DEF_TEST(PartialCropRect, reporter) { | 1141 DEF_TEST(PartialCropRect, reporter) { |
1142 SkBitmap bitmap; | 1142 SkBitmap bitmap; |
1143 bitmap.allocN32Pixels(100, 100); | 1143 bitmap.allocN32Pixels(100, 100); |
1144 bitmap.eraseARGB(0, 0, 0, 0); | 1144 bitmap.eraseARGB(0, 0, 0, 0); |
1145 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); | 1145 const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); |
1146 SkBitmapDevice device(bitmap, props); | 1146 SkBitmapDevice device(bitmap, props); |
1147 SkImageFilter::DeviceProxy proxy(&device); | 1147 SkImageFilter::DeviceProxy proxy(&device); |
1148 | 1148 |
1149 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(100, 0, 20, 30), | 1149 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(100, 0, 20, 30), |
1150 SkImageFilter::CropRect::kHasWidth_CropEdge | SkImageFilter::CropRect::k
HasHeight_CropEdge); | 1150 SkImageFilter::CropRect::kHasWidth_CropEdge | SkImageFilter::CropRect::k
HasHeight_CropEdge); |
1151 SkAutoTUnref<SkImageFilter> filter(make_grayscale(nullptr, &cropRect)); | 1151 SkAutoTUnref<SkImageFilter> filter(make_grayscale(nullptr, &cropRect)); |
1152 SkBitmap result; | 1152 SkBitmap result; |
1153 SkIPoint offset; | 1153 SkIPoint offset; |
1154 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), nullptr); | 1154 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeLargest(), nullptr, S
kImageFilter::kApprox_SizeConstraint); |
1155 REPORTER_ASSERT(reporter, filter->filterImage(&proxy, bitmap, ctx, &result,
&offset)); | 1155 REPORTER_ASSERT(reporter, filter->filterImage(&proxy, bitmap, ctx, &result,
&offset)); |
1156 REPORTER_ASSERT(reporter, offset.fX == 0); | 1156 REPORTER_ASSERT(reporter, offset.fX == 0); |
1157 REPORTER_ASSERT(reporter, offset.fY == 0); | 1157 REPORTER_ASSERT(reporter, offset.fY == 0); |
1158 REPORTER_ASSERT(reporter, result.width() == 20); | 1158 REPORTER_ASSERT(reporter, result.width() == 20); |
1159 REPORTER_ASSERT(reporter, result.height() == 30); | 1159 REPORTER_ASSERT(reporter, result.height() == 30); |
1160 } | 1160 } |
1161 | 1161 |
1162 DEF_TEST(ImageFilterCanComputeFastBounds, reporter) { | 1162 DEF_TEST(ImageFilterCanComputeFastBounds, reporter) { |
1163 | 1163 |
1164 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); | 1164 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1303 SkSurface::kNo_Budgeted
, | 1303 SkSurface::kNo_Budgeted
, |
1304 SkImageInfo::MakeN32Pre
mul(1, 1), | 1304 SkImageInfo::MakeN32Pre
mul(1, 1), |
1305 0, | 1305 0, |
1306 &props, | 1306 &props, |
1307 SkGpuDevice::kUninit_In
itContents)); | 1307 SkGpuDevice::kUninit_In
itContents)); |
1308 SkImageFilter::DeviceProxy proxy(device); | 1308 SkImageFilter::DeviceProxy proxy(device); |
1309 | 1309 |
1310 test_negative_blur_sigma(&proxy, reporter); | 1310 test_negative_blur_sigma(&proxy, reporter); |
1311 } | 1311 } |
1312 #endif | 1312 #endif |
OLD | NEW |