Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: tests/ImageFilterTest.cpp

Issue 967833003: check for inputs before reporting asColorFilter (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: check if the composecolorfilter succeeded Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 {
149 // Check that two non-clipping color matrices concatenate into a single filter. 155 // Check that two non-clipping color-matrice-filters 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 {
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-matrice-filter followed by a color-matric e-filters
167 // concatenates into a single filter, but not a matrixfilter (due to cla mping).
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).
187 SkAutoTUnref<SkImageFilter> mode(make_blue(NULL, NULL));
188 SkAutoTUnref<SkImageFilter> gray(make_grayscale(mode, NULL));
189 REPORTER_ASSERT(reporter, true == gray->asColorFilter(NULL));
190 }
191
169 { 192 {
170 // Check that a color filter image filter with a crop rect cannot 193 // Check that a color filter image filter with a crop rect cannot
171 // be expressed as a color filter. 194 // be expressed as a color filter.
172 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(0, 0, 100, 100)); 195 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(0, 0, 100, 100));
173 SkAutoTUnref<SkImageFilter> grayWithCrop(make_grayscale(NULL, &cropRect) ); 196 SkAutoTUnref<SkImageFilter> grayWithCrop(make_grayscale(NULL, &cropRect) );
174 REPORTER_ASSERT(reporter, false == grayWithCrop->asColorFilter(NULL)); 197 REPORTER_ASSERT(reporter, false == grayWithCrop->asColorFilter(NULL));
175 } 198 }
176 199
177 { 200 {
178 // Check that two non-commutative matrices are concatenated in 201 // Check that two non-commutative matrices are concatenated in
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 DEF_GPUTEST(TestNegativeBlurSigmaGPU, reporter, factory) { 1160 DEF_GPUTEST(TestNegativeBlurSigmaGPU, reporter, factory) {
1138 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp e>(0)); 1161 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp e>(0));
1139 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, 1162 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context,
1140 SkSurface::kNo_Budgeted , 1163 SkSurface::kNo_Budgeted ,
1141 SkImageInfo::MakeN32Pre mul(1, 1), 1164 SkImageInfo::MakeN32Pre mul(1, 1),
1142 0, 1165 0,
1143 &gProps)); 1166 &gProps));
1144 test_negative_blur_sigma(device, reporter); 1167 test_negative_blur_sigma(device, reporter);
1145 } 1168 }
1146 #endif 1169 #endif
OLDNEW
« src/effects/SkColorFilterImageFilter.cpp ('K') | « src/effects/SkColorFilterImageFilter.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698