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, | |
149 SkXfermod e::kSrcIn_Mode)); | |
150 return SkColorFilterImageFilter::Create(filter, input, cropRect); | |
151 } | |
152 | |
147 DEF_TEST(ImageFilter, reporter) { | 153 DEF_TEST(ImageFilter, reporter) { |
148 { | 154 { |
robertphillips
2015/03/04 20:39:48
single _color matrix_ filter ?
reed1
2015/03/04 20:45:25
Done.
| |
149 // Check that two non-clipping color matrices concatenate into a single filter. | 155 // Check that two non-clipping color matrices concatenate into a single filter. |
150 SkAutoTUnref<SkImageFilter> halfBrightness(make_scale(0.5f)); | 156 SkAutoTUnref<SkImageFilter> halfBrightness(make_scale(0.5f)); |
151 SkAutoTUnref<SkImageFilter> quarterBrightness(make_scale(0.5f, halfBrigh tness)); | 157 SkAutoTUnref<SkImageFilter> quarterBrightness(make_scale(0.5f, halfBrigh tness)); |
152 REPORTER_ASSERT(reporter, NULL == quarterBrightness->getInput(0)); | 158 REPORTER_ASSERT(reporter, NULL == quarterBrightness->getInput(0)); |
159 SkColorFilter* cf; | |
160 REPORTER_ASSERT(reporter, quarterBrightness->asColorFilter(&cf)); | |
161 REPORTER_ASSERT(reporter, cf->asColorMatrix(NULL)); | |
162 cf->unref(); | |
153 } | 163 } |
154 | 164 |
155 { | 165 { |
robertphillips
2015/03/04 20:39:48
grayscale -> color matrix ?
becuase typo
reed1
2015/03/04 20:45:25
Done.
| |
156 // Check that a clipping color matrix followed by a grayscale does not c oncatenate into a single filter. | 166 // Check that a clipping color matrix followed by a grayscale does conca tenate |
167 // into a single filter, but not a matrix filter (becuase of the need fo r clamping). | |
157 SkAutoTUnref<SkImageFilter> doubleBrightness(make_scale(2.0f)); | 168 SkAutoTUnref<SkImageFilter> doubleBrightness(make_scale(2.0f)); |
158 SkAutoTUnref<SkImageFilter> halfBrightness(make_scale(0.5f, doubleBright ness)); | 169 SkAutoTUnref<SkImageFilter> halfBrightness(make_scale(0.5f, doubleBright ness)); |
159 REPORTER_ASSERT(reporter, halfBrightness->getInput(0)); | 170 REPORTER_ASSERT(reporter, NULL == halfBrightness->getInput(0)); |
171 SkColorFilter* cf; | |
172 REPORTER_ASSERT(reporter, halfBrightness->asColorFilter(&cf)); | |
173 REPORTER_ASSERT(reporter, !cf->asColorMatrix(NULL)); | |
174 cf->unref(); | |
160 } | 175 } |
161 | 176 |
162 { | 177 { |
163 // Check that a color filter image filter without a crop rect can be | 178 // Check that a color filter image filter without a crop rect can be |
164 // expressed as a color filter. | 179 // expressed as a color filter. |
165 SkAutoTUnref<SkImageFilter> gray(make_grayscale()); | 180 SkAutoTUnref<SkImageFilter> gray(make_grayscale(NULL, NULL)); |
166 REPORTER_ASSERT(reporter, true == gray->asColorFilter(NULL)); | 181 REPORTER_ASSERT(reporter, true == gray->asColorFilter(NULL)); |
167 } | 182 } |
168 | 183 |
184 { | |
185 // Check that a colorfilterimage filter without a crop rect but with an input | |
186 // that is another colorfilterimage can be expressed as a colorfilter (c omposed). | |
robertphillips
2015/03/04 20:39:48
extra "//" ?
reed1
2015/03/04 20:45:25
Done.
| |
187 // | |
188 SkAutoTUnref<SkImageFilter> mode(make_blue(NULL, NULL)); | |
189 SkAutoTUnref<SkImageFilter> gray(make_grayscale(mode, NULL)); | |
190 REPORTER_ASSERT(reporter, true == gray->asColorFilter(NULL)); | |
191 } | |
192 | |
169 { | 193 { |
170 // Check that a color filter image filter with a crop rect cannot | 194 // Check that a color filter image filter with a crop rect cannot |
171 // be expressed as a color filter. | 195 // be expressed as a color filter. |
172 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(0, 0, 100, 100)); | 196 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(0, 0, 100, 100)); |
173 SkAutoTUnref<SkImageFilter> grayWithCrop(make_grayscale(NULL, &cropRect) ); | 197 SkAutoTUnref<SkImageFilter> grayWithCrop(make_grayscale(NULL, &cropRect) ); |
174 REPORTER_ASSERT(reporter, false == grayWithCrop->asColorFilter(NULL)); | 198 REPORTER_ASSERT(reporter, false == grayWithCrop->asColorFilter(NULL)); |
175 } | 199 } |
176 | 200 |
177 { | 201 { |
178 // Check that two non-commutative matrices are concatenated in | 202 // 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) { | 1161 DEF_GPUTEST(TestNegativeBlurSigmaGPU, reporter, factory) { |
1138 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp e>(0)); | 1162 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp e>(0)); |
1139 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, | 1163 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, |
1140 SkSurface::kNo_Budgeted , | 1164 SkSurface::kNo_Budgeted , |
1141 SkImageInfo::MakeN32Pre mul(1, 1), | 1165 SkImageInfo::MakeN32Pre mul(1, 1), |
1142 0, | 1166 0, |
1143 &gProps)); | 1167 &gProps)); |
1144 test_negative_blur_sigma(device, reporter); | 1168 test_negative_blur_sigma(device, reporter); |
1145 } | 1169 } |
1146 #endif | 1170 #endif |
OLD | NEW |