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 "SkBicubicImageFilter.h" | 8 #include "SkBicubicImageFilter.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
11 #include "SkBitmapSource.h" | 11 #include "SkBitmapSource.h" |
12 #include "SkBlurImageFilter.h" | 12 #include "SkBlurImageFilter.h" |
13 #include "SkCanvas.h" | 13 #include "SkCanvas.h" |
14 #include "SkColorFilterImageFilter.h" | 14 #include "SkColorFilterImageFilter.h" |
15 #include "SkColorMatrixFilter.h" | 15 #include "SkColorMatrixFilter.h" |
16 #include "SkDeviceImageFilterProxy.h" | 16 #include "SkDeviceImageFilterProxy.h" |
17 #include "SkDisplacementMapEffect.h" | 17 #include "SkDisplacementMapEffect.h" |
18 #include "SkDropShadowImageFilter.h" | 18 #include "SkDropShadowImageFilter.h" |
19 #include "SkLightingImageFilter.h" | 19 #include "SkLightingImageFilter.h" |
20 #include "SkMatrixConvolutionImageFilter.h" | 20 #include "SkMatrixConvolutionImageFilter.h" |
21 #include "SkMergeImageFilter.h" | 21 #include "SkMergeImageFilter.h" |
22 #include "SkMorphologyImageFilter.h" | 22 #include "SkMorphologyImageFilter.h" |
23 #include "SkOffsetImageFilter.h" | 23 #include "SkOffsetImageFilter.h" |
24 #include "SkRect.h" | 24 #include "SkRect.h" |
25 #include "SkTileImageFilter.h" | 25 #include "SkTileImageFilter.h" |
26 #include "SkXfermodeImageFilter.h" | 26 #include "SkXfermodeImageFilter.h" |
27 #include "Test.h" | 27 #include "Test.h" |
28 | 28 |
| 29 #if SK_SUPPORT_GPU |
| 30 #include "GrContextFactory.h" |
| 31 #include "SkGpuDevice.h" |
| 32 #endif |
| 33 |
29 static const int kBitmapSize = 4; | 34 static const int kBitmapSize = 4; |
30 | 35 |
31 static void make_small_bitmap(SkBitmap& bitmap) { | 36 static void make_small_bitmap(SkBitmap& bitmap) { |
32 bitmap.setConfig(SkBitmap::kARGB_8888_Config, kBitmapSize, kBitmapSize); | 37 bitmap.setConfig(SkBitmap::kARGB_8888_Config, kBitmapSize, kBitmapSize); |
33 bitmap.allocPixels(); | 38 bitmap.allocPixels(); |
34 SkBitmapDevice device(bitmap); | 39 SkBitmapDevice device(bitmap); |
35 SkCanvas canvas(&device); | 40 SkCanvas canvas(&device); |
36 canvas.clear(0x00000000); | 41 canvas.clear(0x00000000); |
37 SkPaint darkPaint; | 42 SkPaint darkPaint; |
38 darkPaint.setColor(0xFF804020); | 43 darkPaint.setColor(0xFF804020); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 SkAutoTUnref<SkBicubicImageFilter> bicubic( | 154 SkAutoTUnref<SkBicubicImageFilter> bicubic( |
150 SkBicubicImageFilter::CreateMitchell(scale, bmSrc)); | 155 SkBicubicImageFilter::CreateMitchell(scale, bmSrc)); |
151 SkBitmapDevice device(bitmap); | 156 SkBitmapDevice device(bitmap); |
152 SkDeviceImageFilterProxy proxy(&device); | 157 SkDeviceImageFilterProxy proxy(&device); |
153 SkIPoint loc = SkIPoint::Make(0, 0); | 158 SkIPoint loc = SkIPoint::Make(0, 0); |
154 // An empty input should early return and return false | 159 // An empty input should early return and return false |
155 REPORTER_ASSERT(reporter, | 160 REPORTER_ASSERT(reporter, |
156 !bicubic->filterImage(&proxy, bitmap, SkMatrix::I(),
&result, &loc)); | 161 !bicubic->filterImage(&proxy, bitmap, SkMatrix::I(),
&result, &loc)); |
157 } | 162 } |
158 } | 163 } |
| 164 } |
159 | 165 |
160 { | 166 static void test_crop_rects(SkBaseDevice* device, skiatest::Reporter* reporter)
{ |
161 // Check that all filters offset to their absolute crop rect, | 167 // Check that all filters offset to their absolute crop rect, |
162 // unaffected by the input crop rect. | 168 // unaffected by the input crop rect. |
163 // Tests pass by not asserting. | 169 // Tests pass by not asserting. |
164 SkBitmap bitmap, temp; | 170 SkBitmap bitmap; |
165 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 171 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); |
166 temp.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 172 bitmap.allocPixels(); |
167 bitmap.allocPixels(); | 173 bitmap.eraseARGB(0, 0, 0, 0); |
168 temp.allocPixels(); | 174 SkDeviceImageFilterProxy proxy(device); |
169 bitmap.eraseARGB(0, 0, 0, 0); | |
170 SkBitmapDevice device(temp); | |
171 SkDeviceImageFilterProxy proxy(&device); | |
172 | 175 |
173 SkImageFilter::CropRect inputCropRect(SkRect::MakeXYWH(8, 13, 80, 80)); | 176 SkImageFilter::CropRect inputCropRect(SkRect::MakeXYWH(8, 13, 80, 80)); |
174 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 30, 60, 60)); | 177 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 30, 60, 60)); |
175 SkAutoTUnref<SkImageFilter> input(make_grayscale(NULL, &inputCropRect)); | 178 SkAutoTUnref<SkImageFilter> input(make_grayscale(NULL, &inputCropRect)); |
176 | 179 |
177 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorR
ED, SkXfermode::kSrcIn_Mode)); | 180 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED,
SkXfermode::kSrcIn_Mode)); |
178 SkPoint3 location(0, 0, SK_Scalar1); | 181 SkPoint3 location(0, 0, SK_Scalar1); |
179 SkPoint3 target(SK_Scalar1, SK_Scalar1, SK_Scalar1); | 182 SkPoint3 target(SK_Scalar1, SK_Scalar1, SK_Scalar1); |
180 SkScalar kernel[9] = { | 183 SkScalar kernel[9] = { |
181 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), | 184 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), |
182 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1), | 185 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1), |
183 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), | 186 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), |
184 }; | 187 }; |
185 SkISize kernelSize = SkISize::Make(3, 3); | 188 SkISize kernelSize = SkISize::Make(3, 3); |
186 SkScalar gain = SK_Scalar1, bias = 0; | 189 SkScalar gain = SK_Scalar1, bias = 0; |
187 | 190 |
188 SkImageFilter* filters[] = { | 191 SkImageFilter* filters[] = { |
189 SkColorFilterImageFilter::Create(cf.get(), input.get(), &cropRect), | 192 SkColorFilterImageFilter::Create(cf.get(), input.get(), &cropRect), |
190 new SkDisplacementMapEffect(SkDisplacementMapEffect::kR_ChannelSelec
torType, | 193 new SkDisplacementMapEffect(SkDisplacementMapEffect::kR_ChannelSelectorT
ype, |
191 SkDisplacementMapEffect::kB_ChannelSelec
torType, | 194 SkDisplacementMapEffect::kB_ChannelSelectorT
ype, |
192 40.0f, input.get(), input.get(), &cropRe
ct), | 195 40.0f, input.get(), input.get(), &cropRect), |
193 new SkBlurImageFilter(SK_Scalar1, SK_Scalar1, input.get(), &cropRect
), | 196 new SkBlurImageFilter(SK_Scalar1, SK_Scalar1, input.get(), &cropRect), |
194 new SkDropShadowImageFilter(SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_S
calar1, SK_ColorGREEN, input.get(), &cropRect), | 197 new SkDropShadowImageFilter(SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scala
r1, SK_ColorGREEN, input.get(), &cropRect), |
195 SkLightingImageFilter::CreatePointLitDiffuse(location, SK_ColorGREEN
, 0, 0, input.get(), &cropRect), | 198 SkLightingImageFilter::CreatePointLitDiffuse(location, SK_ColorGREEN, 0,
0, input.get(), &cropRect), |
196 SkLightingImageFilter::CreatePointLitSpecular(location, SK_ColorGREE
N, 0, 0, 0, input.get(), &cropRect), | 199 SkLightingImageFilter::CreatePointLitSpecular(location, SK_ColorGREEN, 0
, 0, 0, input.get(), &cropRect), |
197 new SkMatrixConvolutionImageFilter(kernelSize, kernel, gain, bias, S
kIPoint::Make(1, 1), SkMatrixConvolutionImageFilter::kRepeat_TileMode, false, in
put.get(), &cropRect), | 200 new SkMatrixConvolutionImageFilter(kernelSize, kernel, gain, bias, SkIPo
int::Make(1, 1), SkMatrixConvolutionImageFilter::kRepeat_TileMode, false, input.
get(), &cropRect), |
198 new SkMergeImageFilter(input.get(), input.get(), SkXfermode::kSrcOve
r_Mode, &cropRect), | 201 new SkMergeImageFilter(input.get(), input.get(), SkXfermode::kSrcOver_Mo
de, &cropRect), |
199 new SkOffsetImageFilter(SK_Scalar1, SK_Scalar1, input.get(), &cropRe
ct), | 202 new SkOffsetImageFilter(SK_Scalar1, SK_Scalar1, input.get(), &cropRect), |
200 new SkOffsetImageFilter(SK_Scalar1, SK_Scalar1, input.get(), &cropRe
ct), | 203 new SkOffsetImageFilter(SK_Scalar1, SK_Scalar1, input.get(), &cropRect), |
201 new SkDilateImageFilter(3, 2, input.get(), &cropRect), | 204 new SkDilateImageFilter(3, 2, input.get(), &cropRect), |
202 new SkErodeImageFilter(2, 3, input.get(), &cropRect), | 205 new SkErodeImageFilter(2, 3, input.get(), &cropRect), |
203 new SkTileImageFilter(inputCropRect.rect(), cropRect.rect(), input.g
et()), | 206 new SkTileImageFilter(inputCropRect.rect(), cropRect.rect(), input.get()
), |
204 new SkXfermodeImageFilter(SkXfermode::Create(SkXfermode::kSrcOver_Mo
de), input.get(), input.get(), &cropRect), | 207 new SkXfermodeImageFilter(SkXfermode::Create(SkXfermode::kSrcOver_Mode),
input.get(), input.get(), &cropRect), |
205 }; | 208 }; |
206 | 209 |
207 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | 210 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { |
208 SkImageFilter* filter = filters[i]; | 211 SkImageFilter* filter = filters[i]; |
209 SkBitmap result; | 212 SkBitmap result; |
210 SkIPoint offset; | 213 SkIPoint offset; |
211 REPORTER_ASSERT(reporter, filter->filterImage(&proxy, bitmap, SkMatr
ix::I(), &result, &offset)); | 214 SkString str; |
212 REPORTER_ASSERT(reporter, offset.fX == 20 && offset.fY == 30); | 215 str.printf("filter %ld", i); |
213 } | 216 REPORTER_ASSERT_MESSAGE(reporter, filter->filterImage(&proxy, bitmap, Sk
Matrix::I(), &result, &offset), str.c_str()); |
| 217 REPORTER_ASSERT_MESSAGE(reporter, offset.fX == 20 && offset.fY == 30, st
r.c_str()); |
| 218 } |
214 | 219 |
215 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | 220 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { |
216 SkSafeUnref(filters[i]); | 221 SkSafeUnref(filters[i]); |
217 } | |
218 } | 222 } |
219 } | 223 } |
| 224 |
| 225 DEF_TEST(ImageFilterCropRect, reporter) { |
| 226 SkBitmap temp; |
| 227 temp.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); |
| 228 temp.allocPixels(); |
| 229 SkBitmapDevice device(temp); |
| 230 test_crop_rects(&device, reporter); |
| 231 } |
| 232 |
| 233 DEF_GPUTEST(ImageFilterCropRectGPU, reporter, factory) { |
| 234 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); |
| 235 SkGpuDevice device(context, SkBitmap::kARGB_8888_Config, 100, 100); |
| 236 test_crop_rects(&device, reporter); |
| 237 } |
OLD | NEW |