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" | 10 #include "SkBitmapSource.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 static SkImageFilter* make_scale(float amount, SkImageFilter* input = NULL) { | 126 static SkImageFilter* make_scale(float amount, SkImageFilter* input = NULL) { |
127 SkScalar s = amount; | 127 SkScalar s = amount; |
128 SkScalar matrix[20] = { s, 0, 0, 0, 0, | 128 SkScalar matrix[20] = { s, 0, 0, 0, 0, |
129 0, s, 0, 0, 0, | 129 0, s, 0, 0, 0, |
130 0, 0, s, 0, 0, | 130 0, 0, s, 0, 0, |
131 0, 0, 0, s, 0 }; | 131 0, 0, 0, s, 0 }; |
132 SkAutoTUnref<SkColorFilter> filter(SkColorMatrixFilter::Create(matrix)); | 132 SkAutoTUnref<SkColorFilter> filter(SkColorMatrixFilter::Create(matrix)); |
133 return SkColorFilterImageFilter::Create(filter, input); | 133 return SkColorFilterImageFilter::Create(filter, input); |
134 } | 134 } |
135 | 135 |
136 static SkImageFilter* make_grayscale(SkImageFilter* input = NULL, const SkImageF ilter::CropRect* cropRect = NULL) { | 136 static SkImageFilter* make_grayscale(SkImageFilter* input, const SkImageFilter:: CropRect* cropRect) { |
137 SkScalar matrix[20]; | 137 SkScalar matrix[20]; |
138 memset(matrix, 0, 20 * sizeof(SkScalar)); | 138 memset(matrix, 0, 20 * sizeof(SkScalar)); |
139 matrix[0] = matrix[5] = matrix[10] = 0.2126f; | 139 matrix[0] = matrix[5] = matrix[10] = 0.2126f; |
140 matrix[1] = matrix[6] = matrix[11] = 0.7152f; | 140 matrix[1] = matrix[6] = matrix[11] = 0.7152f; |
141 matrix[2] = matrix[7] = matrix[12] = 0.0722f; | 141 matrix[2] = matrix[7] = matrix[12] = 0.0722f; |
142 matrix[18] = 1.0f; | 142 matrix[18] = 1.0f; |
143 SkAutoTUnref<SkColorFilter> filter(SkColorMatrixFilter::Create(matrix)); | 143 SkAutoTUnref<SkColorFilter> filter(SkColorMatrixFilter::Create(matrix)); |
144 return SkColorFilterImageFilter::Create(filter, input, cropRect); | 144 return SkColorFilterImageFilter::Create(filter, input, cropRect); |
145 } | 145 } |
146 | 146 |
147 static SkImageFilter* make_blue(SkImageFilter* input, const SkImageFilter::CropR ect* cropRect) { | |
148 SkAutoTUnref<SkColorFilter> filter(SkColorFilter::CreateModeFilter(SK_ColorB LUE, SkXfermode::kSrcIn_Mode)); | |
149 return SkColorFilterImageFilter::Create(filter, input, cropRect); | |
150 } | |
151 | |
147 DEF_TEST(ImageFilter, reporter) { | 152 DEF_TEST(ImageFilter, reporter) { |
148 { | 153 { |
149 // Check that two non-clipping color matrices concatenate into a single filter. | 154 // Check that two non-clipping color matrices concatenate into a single filter. |
150 SkAutoTUnref<SkImageFilter> halfBrightness(make_scale(0.5f)); | 155 SkAutoTUnref<SkImageFilter> halfBrightness(make_scale(0.5f)); |
151 SkAutoTUnref<SkImageFilter> quarterBrightness(make_scale(0.5f, halfBrigh tness)); | 156 SkAutoTUnref<SkImageFilter> quarterBrightness(make_scale(0.5f, halfBrigh tness)); |
152 REPORTER_ASSERT(reporter, NULL == quarterBrightness->getInput(0)); | 157 REPORTER_ASSERT(reporter, NULL == quarterBrightness->getInput(0)); |
153 } | 158 } |
154 | 159 |
155 { | 160 { |
156 // Check that a clipping color matrix followed by a grayscale does not c oncatenate into a single filter. | |
Stephen White
2015/03/04 19:38:37
Why did this test go away?
reed1
2015/03/04 20:00:58
With the change to the factory, we *do* fold the t
| |
157 SkAutoTUnref<SkImageFilter> doubleBrightness(make_scale(2.0f)); | |
158 SkAutoTUnref<SkImageFilter> halfBrightness(make_scale(0.5f, doubleBright ness)); | |
159 REPORTER_ASSERT(reporter, halfBrightness->getInput(0)); | |
160 } | |
161 | |
162 { | |
163 // Check that a color filter image filter without a crop rect can be | 161 // Check that a color filter image filter without a crop rect can be |
164 // expressed as a color filter. | 162 // expressed as a color filter. |
165 SkAutoTUnref<SkImageFilter> gray(make_grayscale()); | 163 SkAutoTUnref<SkImageFilter> gray(make_grayscale(NULL, NULL)); |
166 REPORTER_ASSERT(reporter, true == gray->asColorFilter(NULL)); | 164 REPORTER_ASSERT(reporter, true == gray->asColorFilter(NULL)); |
167 } | 165 } |
168 | 166 |
167 { | |
168 // Check that a colorfilterimage filter without a crop rect but with an input | |
169 // that is another colorfilterimage can be expressed as a colorfilter (c omposed). | |
170 // | |
171 SkAutoTUnref<SkImageFilter> mode(make_blue(NULL, NULL)); | |
172 SkAutoTUnref<SkImageFilter> gray(make_grayscale(mode, NULL)); | |
173 REPORTER_ASSERT(reporter, true == gray->asColorFilter(NULL)); | |
174 } | |
175 | |
169 { | 176 { |
170 // Check that a color filter image filter with a crop rect cannot | 177 // Check that a color filter image filter with a crop rect cannot |
171 // be expressed as a color filter. | 178 // be expressed as a color filter. |
172 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(0, 0, 100, 100)); | 179 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(0, 0, 100, 100)); |
173 SkAutoTUnref<SkImageFilter> grayWithCrop(make_grayscale(NULL, &cropRect) ); | 180 SkAutoTUnref<SkImageFilter> grayWithCrop(make_grayscale(NULL, &cropRect) ); |
174 REPORTER_ASSERT(reporter, false == grayWithCrop->asColorFilter(NULL)); | 181 REPORTER_ASSERT(reporter, false == grayWithCrop->asColorFilter(NULL)); |
175 } | 182 } |
176 | 183 |
177 { | 184 { |
178 // Check that two non-commutative matrices are concatenated in | 185 // Check that two non-commutative matrices are concatenated in |
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1137 DEF_GPUTEST(TestNegativeBlurSigmaGPU, reporter, factory) { | 1144 DEF_GPUTEST(TestNegativeBlurSigmaGPU, reporter, factory) { |
1138 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp e>(0)); | 1145 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp e>(0)); |
1139 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, | 1146 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, |
1140 SkSurface::kNo_Budgeted , | 1147 SkSurface::kNo_Budgeted , |
1141 SkImageInfo::MakeN32Pre mul(1, 1), | 1148 SkImageInfo::MakeN32Pre mul(1, 1), |
1142 0, | 1149 0, |
1143 &gProps)); | 1150 &gProps)); |
1144 test_negative_blur_sigma(device, reporter); | 1151 test_negative_blur_sigma(device, reporter); |
1145 } | 1152 } |
1146 #endif | 1153 #endif |
OLD | NEW |