1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/output/filter_operations.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "ui/gfx/point.h"
12 TEST(FilterOperationsTest
, GetOutsetsBlur
) {
14 ops
.Append(FilterOperation::CreateBlurFilter(20));
15 int top
, right
, bottom
, left
;
16 top
= right
= bottom
= left
= 0;
17 ops
.GetOutsets(&top
, &right
, &bottom
, &left
);
20 EXPECT_EQ(57, bottom
);
24 TEST(FilterOperationsTest
, GetOutsetsDropShadow
) {
26 ops
.Append(FilterOperation::CreateDropShadowFilter(gfx::Point(3, 8), 20, 0));
27 int top
, right
, bottom
, left
;
28 top
= right
= bottom
= left
= 0;
29 ops
.GetOutsets(&top
, &right
, &bottom
, &left
);
32 EXPECT_EQ(65, bottom
);
36 #define SAVE_RESTORE_AMOUNT(filter_name, filter_type, a) \
38 FilterOperation op = FilterOperation::Create##filter_name##Filter(a); \
39 EXPECT_EQ(FilterOperation::filter_type, op.type()); \
40 EXPECT_EQ(a, op.amount()); \
42 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \
43 op2.set_type(FilterOperation::filter_type); \
45 EXPECT_NE(a, op2.amount()); \
49 EXPECT_EQ(FilterOperation::filter_type, op2.type()); \
50 EXPECT_EQ(a, op2.amount()); \
53 #define SAVE_RESTORE_OFFSET_AMOUNT_COLOR(filter_name, filter_type, a, b, c) \
55 FilterOperation op = \
56 FilterOperation::Create##filter_name##Filter(a, b, c); \
57 EXPECT_EQ(FilterOperation::filter_type, op.type()); \
58 EXPECT_EQ(a, op.drop_shadow_offset()); \
59 EXPECT_EQ(b, op.amount()); \
60 EXPECT_EQ(c, op.drop_shadow_color()); \
62 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \
63 op2.set_type(FilterOperation::filter_type); \
65 EXPECT_NE(a, op2.drop_shadow_offset()); \
66 EXPECT_NE(b, op2.amount()); \
67 EXPECT_NE(c, op2.drop_shadow_color()); \
69 op2.set_drop_shadow_offset(a); \
71 op2.set_drop_shadow_color(c); \
73 EXPECT_EQ(FilterOperation::filter_type, op2.type()); \
74 EXPECT_EQ(a, op2.drop_shadow_offset()); \
75 EXPECT_EQ(b, op2.amount()); \
76 EXPECT_EQ(c, op2.drop_shadow_color()); \
79 #define SAVE_RESTORE_MATRIX(filter_name, filter_type, a) \
81 FilterOperation op = FilterOperation::Create##filter_name##Filter(a); \
82 EXPECT_EQ(FilterOperation::filter_type, op.type()); \
83 for (size_t i = 0; i < 20; ++i) \
84 EXPECT_EQ(a[i], op.matrix()[i]); \
86 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \
87 op2.set_type(FilterOperation::filter_type); \
89 for (size_t i = 0; i < 20; ++i) \
90 EXPECT_NE(a[i], op2.matrix()[i]); \
94 EXPECT_EQ(FilterOperation::filter_type, op2.type()); \
95 for (size_t i = 0; i < 20; ++i) \
96 EXPECT_EQ(a[i], op.matrix()[i]); \
99 #define SAVE_RESTORE_AMOUNT_INSET(filter_name, filter_type, a, b) \
101 FilterOperation op = FilterOperation::Create##filter_name##Filter(a, b); \
102 EXPECT_EQ(FilterOperation::filter_type, op.type()); \
103 EXPECT_EQ(a, op.amount()); \
104 EXPECT_EQ(b, op.zoom_inset()); \
106 FilterOperation op2 = FilterOperation::CreateEmptyFilter(); \
107 op2.set_type(FilterOperation::filter_type); \
109 EXPECT_NE(a, op2.amount()); \
110 EXPECT_NE(b, op2.zoom_inset()); \
113 op2.set_zoom_inset(b); \
115 EXPECT_EQ(FilterOperation::filter_type, op2.type()); \
116 EXPECT_EQ(a, op2.amount()); \
117 EXPECT_EQ(b, op2.zoom_inset()); \
120 TEST(FilterOperationsTest
, SaveAndRestore
) {
121 SAVE_RESTORE_AMOUNT(Grayscale
, GRAYSCALE
, 0.6f
);
122 SAVE_RESTORE_AMOUNT(Sepia
, SEPIA
, 0.6f
);
123 SAVE_RESTORE_AMOUNT(Saturate
, SATURATE
, 0.6f
);
124 SAVE_RESTORE_AMOUNT(HueRotate
, HUE_ROTATE
, 0.6f
);
125 SAVE_RESTORE_AMOUNT(Invert
, INVERT
, 0.6f
);
126 SAVE_RESTORE_AMOUNT(Brightness
, BRIGHTNESS
, 0.6f
);
127 SAVE_RESTORE_AMOUNT(Contrast
, CONTRAST
, 0.6f
);
128 SAVE_RESTORE_AMOUNT(Opacity
, OPACITY
, 0.6f
);
129 SAVE_RESTORE_AMOUNT(Blur
, BLUR
, 0.6f
);
130 SAVE_RESTORE_AMOUNT(SaturatingBrightness
, SATURATING_BRIGHTNESS
, 0.6f
);
131 SAVE_RESTORE_OFFSET_AMOUNT_COLOR(
132 DropShadow
, DROP_SHADOW
, gfx::Point(3, 4), 0.4f
, 0xffffff00);
134 SkScalar matrix
[20] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
136 SAVE_RESTORE_MATRIX(ColorMatrix
, COLOR_MATRIX
, matrix
);
138 SAVE_RESTORE_AMOUNT_INSET(Zoom
, ZOOM
, 0.5f
, 32);
141 TEST(FilterOperationsTest
, BlendGrayscaleFilters
) {
142 FilterOperation from
= FilterOperation::CreateGrayscaleFilter(0.25f
);
143 FilterOperation to
= FilterOperation::CreateGrayscaleFilter(0.75f
);
145 FilterOperation blended
= FilterOperation::Blend(&from
, &to
, -0.75);
146 FilterOperation expected
= FilterOperation::CreateGrayscaleFilter(0.f
);
147 EXPECT_EQ(expected
, blended
);
149 blended
= FilterOperation::Blend(&from
, &to
, 0.75);
150 expected
= FilterOperation::CreateGrayscaleFilter(0.625f
);
151 EXPECT_EQ(expected
, blended
);
153 blended
= FilterOperation::Blend(&from
, &to
, 1.8);
154 expected
= FilterOperation::CreateGrayscaleFilter(1.f
);
155 EXPECT_EQ(expected
, blended
);
158 TEST(FilterOperationsTest
, BlendGrayscaleWithNull
) {
159 FilterOperation filter
= FilterOperation::CreateGrayscaleFilter(1.f
);
161 FilterOperation blended
= FilterOperation::Blend(&filter
, NULL
, 0.25);
162 FilterOperation expected
= FilterOperation::CreateGrayscaleFilter(0.75f
);
163 EXPECT_EQ(expected
, blended
);
165 blended
= FilterOperation::Blend(NULL
, &filter
, 0.25);
166 expected
= FilterOperation::CreateGrayscaleFilter(0.25f
);
167 EXPECT_EQ(expected
, blended
);
170 TEST(FilterOperationsTest
, BlendSepiaFilters
) {
171 FilterOperation from
= FilterOperation::CreateSepiaFilter(0.25f
);
172 FilterOperation to
= FilterOperation::CreateSepiaFilter(0.75f
);
174 FilterOperation blended
= FilterOperation::Blend(&from
, &to
, -0.75);
175 FilterOperation expected
= FilterOperation::CreateSepiaFilter(0.f
);
176 EXPECT_EQ(expected
, blended
);
178 blended
= FilterOperation::Blend(&from
, &to
, 0.75);
179 expected
= FilterOperation::CreateSepiaFilter(0.625f
);
180 EXPECT_EQ(expected
, blended
);
182 blended
= FilterOperation::Blend(&from
, &to
, 1.8);
183 expected
= FilterOperation::CreateSepiaFilter(1.f
);
184 EXPECT_EQ(expected
, blended
);
187 TEST(FilterOperationsTest
, BlendSepiaWithNull
) {
188 FilterOperation filter
= FilterOperation::CreateSepiaFilter(1.f
);
190 FilterOperation blended
= FilterOperation::Blend(&filter
, NULL
, 0.25);
191 FilterOperation expected
= FilterOperation::CreateSepiaFilter(0.75f
);
192 EXPECT_EQ(expected
, blended
);
194 blended
= FilterOperation::Blend(NULL
, &filter
, 0.25);
195 expected
= FilterOperation::CreateSepiaFilter(0.25f
);
196 EXPECT_EQ(expected
, blended
);
199 TEST(FilterOperationsTest
, BlendSaturateFilters
) {
200 FilterOperation from
= FilterOperation::CreateSaturateFilter(0.25f
);
201 FilterOperation to
= FilterOperation::CreateSaturateFilter(0.75f
);
203 FilterOperation blended
= FilterOperation::Blend(&from
, &to
, -0.75);
204 FilterOperation expected
= FilterOperation::CreateSaturateFilter(0.f
);
205 EXPECT_EQ(expected
, blended
);
207 blended
= FilterOperation::Blend(&from
, &to
, 0.75);
208 expected
= FilterOperation::CreateSaturateFilter(0.625f
);
209 EXPECT_EQ(expected
, blended
);
211 blended
= FilterOperation::Blend(&from
, &to
, 2.0);
212 expected
= FilterOperation::CreateSaturateFilter(1.25f
);
213 EXPECT_EQ(expected
, blended
);
216 TEST(FilterOperationsTest
, BlendSaturateWithNull
) {
217 FilterOperation filter
= FilterOperation::CreateSaturateFilter(0.f
);
219 FilterOperation blended
= FilterOperation::Blend(&filter
, NULL
, 0.25);
220 FilterOperation expected
= FilterOperation::CreateSaturateFilter(0.25f
);
221 EXPECT_EQ(expected
, blended
);
223 blended
= FilterOperation::Blend(NULL
, &filter
, 0.25);
224 expected
= FilterOperation::CreateSaturateFilter(0.75f
);
225 EXPECT_EQ(expected
, blended
);
228 TEST(FilterOperationsTest
, BlendHueRotateFilters
) {
229 FilterOperation from
= FilterOperation::CreateHueRotateFilter(3.f
);
230 FilterOperation to
= FilterOperation::CreateHueRotateFilter(7.f
);
232 FilterOperation blended
= FilterOperation::Blend(&from
, &to
, -0.75);
233 FilterOperation expected
= FilterOperation::CreateHueRotateFilter(0.f
);
234 EXPECT_EQ(expected
, blended
);
236 blended
= FilterOperation::Blend(&from
, &to
, 0.75);
237 expected
= FilterOperation::CreateHueRotateFilter(6.f
);
238 EXPECT_EQ(expected
, blended
);
240 blended
= FilterOperation::Blend(&from
, &to
, 1.5);
241 expected
= FilterOperation::CreateHueRotateFilter(9.f
);
242 EXPECT_EQ(expected
, blended
);
245 TEST(FilterOperationsTest
, BlendHueRotateWithNull
) {
246 FilterOperation filter
= FilterOperation::CreateHueRotateFilter(1.f
);
248 FilterOperation blended
= FilterOperation::Blend(&filter
, NULL
, 0.25);
249 FilterOperation expected
= FilterOperation::CreateHueRotateFilter(0.75f
);
250 EXPECT_EQ(expected
, blended
);
252 blended
= FilterOperation::Blend(NULL
, &filter
, 0.25);
253 expected
= FilterOperation::CreateHueRotateFilter(0.25f
);
254 EXPECT_EQ(expected
, blended
);
257 TEST(FilterOperationsTest
, BlendInvertFilters
) {
258 FilterOperation from
= FilterOperation::CreateInvertFilter(0.25f
);
259 FilterOperation to
= FilterOperation::CreateInvertFilter(0.75f
);
261 FilterOperation blended
= FilterOperation::Blend(&from
, &to
, -0.75);
262 FilterOperation expected
= FilterOperation::CreateInvertFilter(0.f
);
263 EXPECT_EQ(expected
, blended
);
265 blended
= FilterOperation::Blend(&from
, &to
, 0.75);
266 expected
= FilterOperation::CreateInvertFilter(0.625f
);
267 EXPECT_EQ(expected
, blended
);
269 blended
= FilterOperation::Blend(&from
, &to
, 1.8);
270 expected
= FilterOperation::CreateInvertFilter(1.f
);
271 EXPECT_EQ(expected
, blended
);
274 TEST(FilterOperationsTest
, BlendInvertWithNull
) {
275 FilterOperation filter
= FilterOperation::CreateInvertFilter(1.f
);
277 FilterOperation blended
= FilterOperation::Blend(&filter
, NULL
, 0.25);
278 FilterOperation expected
= FilterOperation::CreateInvertFilter(0.75f
);
279 EXPECT_EQ(expected
, blended
);
281 blended
= FilterOperation::Blend(NULL
, &filter
, 0.25);
282 expected
= FilterOperation::CreateInvertFilter(0.25f
);
283 EXPECT_EQ(expected
, blended
);
286 TEST(FilterOperationsTest
, BlendBrightnessFilters
) {
287 FilterOperation from
= FilterOperation::CreateBrightnessFilter(3.f
);
288 FilterOperation to
= FilterOperation::CreateBrightnessFilter(7.f
);
290 FilterOperation blended
= FilterOperation::Blend(&from
, &to
, -0.9);
291 FilterOperation expected
= FilterOperation::CreateBrightnessFilter(0.f
);
292 EXPECT_EQ(expected
, blended
);
294 blended
= FilterOperation::Blend(&from
, &to
, 0.75);
295 expected
= FilterOperation::CreateBrightnessFilter(6.f
);
296 EXPECT_EQ(expected
, blended
);
298 blended
= FilterOperation::Blend(&from
, &to
, 1.5);
299 expected
= FilterOperation::CreateBrightnessFilter(9.f
);
300 EXPECT_EQ(expected
, blended
);
303 TEST(FilterOperationsTest
, BlendBrightnessWithNull
) {
304 FilterOperation filter
= FilterOperation::CreateBrightnessFilter(0.f
);
306 FilterOperation blended
= FilterOperation::Blend(&filter
, NULL
, 0.25);
307 FilterOperation expected
= FilterOperation::CreateBrightnessFilter(0.25f
);
308 EXPECT_EQ(expected
, blended
);
310 blended
= FilterOperation::Blend(NULL
, &filter
, 0.25);
311 expected
= FilterOperation::CreateBrightnessFilter(0.75f
);
312 EXPECT_EQ(expected
, blended
);
315 TEST(FilterOperationsTest
, BlendContrastFilters
) {
316 FilterOperation from
= FilterOperation::CreateContrastFilter(3.f
);
317 FilterOperation to
= FilterOperation::CreateContrastFilter(7.f
);
319 FilterOperation blended
= FilterOperation::Blend(&from
, &to
, -0.9);
320 FilterOperation expected
= FilterOperation::CreateContrastFilter(0.f
);
321 EXPECT_EQ(expected
, blended
);
323 blended
= FilterOperation::Blend(&from
, &to
, 0.75);
324 expected
= FilterOperation::CreateContrastFilter(6.f
);
325 EXPECT_EQ(expected
, blended
);
327 blended
= FilterOperation::Blend(&from
, &to
, 1.5);
328 expected
= FilterOperation::CreateContrastFilter(9.f
);
329 EXPECT_EQ(expected
, blended
);
332 TEST(FilterOperationsTest
, BlendContrastWithNull
) {
333 FilterOperation filter
= FilterOperation::CreateContrastFilter(0.f
);
335 FilterOperation blended
= FilterOperation::Blend(&filter
, NULL
, 0.25);
336 FilterOperation expected
= FilterOperation::CreateContrastFilter(0.25f
);
337 EXPECT_EQ(expected
, blended
);
339 blended
= FilterOperation::Blend(NULL
, &filter
, 0.25);
340 expected
= FilterOperation::CreateContrastFilter(0.75f
);
341 EXPECT_EQ(expected
, blended
);
344 TEST(FilterOperationsTest
, BlendOpacityFilters
) {
345 FilterOperation from
= FilterOperation::CreateOpacityFilter(0.25f
);
346 FilterOperation to
= FilterOperation::CreateOpacityFilter(0.75f
);
348 FilterOperation blended
= FilterOperation::Blend(&from
, &to
, -0.75);
349 FilterOperation expected
= FilterOperation::CreateOpacityFilter(0.f
);
350 EXPECT_EQ(expected
, blended
);
352 blended
= FilterOperation::Blend(&from
, &to
, 0.75);
353 expected
= FilterOperation::CreateOpacityFilter(0.625f
);
354 EXPECT_EQ(expected
, blended
);
356 blended
= FilterOperation::Blend(&from
, &to
, 1.8);
357 expected
= FilterOperation::CreateOpacityFilter(1.f
);
358 EXPECT_EQ(expected
, blended
);
361 TEST(FilterOperationsTest
, BlendOpacityWithNull
) {
362 FilterOperation filter
= FilterOperation::CreateOpacityFilter(0.f
);
364 FilterOperation blended
= FilterOperation::Blend(&filter
, NULL
, 0.25);
365 FilterOperation expected
= FilterOperation::CreateOpacityFilter(0.25f
);
366 EXPECT_EQ(expected
, blended
);
368 blended
= FilterOperation::Blend(NULL
, &filter
, 0.25);
369 expected
= FilterOperation::CreateOpacityFilter(0.75f
);
370 EXPECT_EQ(expected
, blended
);
373 TEST(FilterOperationsTest
, BlendBlurFilters
) {
374 FilterOperation from
= FilterOperation::CreateBlurFilter(3.f
);
375 FilterOperation to
= FilterOperation::CreateBlurFilter(7.f
);
377 FilterOperation blended
= FilterOperation::Blend(&from
, &to
, -0.9);
378 FilterOperation expected
= FilterOperation::CreateBlurFilter(0.f
);
379 EXPECT_EQ(expected
, blended
);
381 blended
= FilterOperation::Blend(&from
, &to
, 0.75);
382 expected
= FilterOperation::CreateBlurFilter(6.f
);
383 EXPECT_EQ(expected
, blended
);
385 blended
= FilterOperation::Blend(&from
, &to
, 1.5);
386 expected
= FilterOperation::CreateBlurFilter(9.f
);
387 EXPECT_EQ(expected
, blended
);
390 TEST(FilterOperationsTest
, BlendBlurWithNull
) {
391 FilterOperation filter
= FilterOperation::CreateBlurFilter(1.f
);
393 FilterOperation blended
= FilterOperation::Blend(&filter
, NULL
, 0.25);
394 FilterOperation expected
= FilterOperation::CreateBlurFilter(0.75f
);
395 EXPECT_EQ(expected
, blended
);
397 blended
= FilterOperation::Blend(NULL
, &filter
, 0.25);
398 expected
= FilterOperation::CreateBlurFilter(0.25f
);
399 EXPECT_EQ(expected
, blended
);
402 TEST(FilterOperationsTest
, BlendDropShadowFilters
) {
403 FilterOperation from
= FilterOperation::CreateDropShadowFilter(
404 gfx::Point(0, 0), 2.f
, SkColorSetARGB(15, 34, 68, 136));
405 FilterOperation to
= FilterOperation::CreateDropShadowFilter(
406 gfx::Point(3, 5), 6.f
, SkColorSetARGB(51, 30, 60, 120));
408 FilterOperation blended
= FilterOperation::Blend(&from
, &to
, -0.75);
409 FilterOperation expected
= FilterOperation::CreateDropShadowFilter(
410 gfx::Point(-2, -4), 0.f
, SkColorSetARGB(0, 0, 0, 0));
411 EXPECT_EQ(expected
, blended
);
413 blended
= FilterOperation::Blend(&from
, &to
, 0.75);
414 expected
= FilterOperation::CreateDropShadowFilter(
415 gfx::Point(2, 4), 5.f
, SkColorSetARGB(42, 30, 61, 121));
416 EXPECT_EQ(expected
, blended
);
418 blended
= FilterOperation::Blend(&from
, &to
, 1.5);
419 expected
= FilterOperation::CreateDropShadowFilter(
420 gfx::Point(5, 8), 8.f
, SkColorSetARGB(69, 30, 59, 118));
421 EXPECT_EQ(expected
, blended
);
424 TEST(FilterOperationsTest
, BlendDropShadowWithNull
) {
425 FilterOperation filter
= FilterOperation::CreateDropShadowFilter(
426 gfx::Point(4, 4), 4.f
, SkColorSetARGB(255, 40, 0, 0));
428 FilterOperation blended
= FilterOperation::Blend(&filter
, NULL
, 0.25);
429 FilterOperation expected
= FilterOperation::CreateDropShadowFilter(
430 gfx::Point(3, 3), 3.f
, SkColorSetARGB(191, 40, 0, 0));
431 EXPECT_EQ(expected
, blended
);
433 blended
= FilterOperation::Blend(NULL
, &filter
, 0.25);
434 expected
= FilterOperation::CreateDropShadowFilter(
435 gfx::Point(1, 1), 1.f
, SkColorSetARGB(64, 40, 0, 0));
436 EXPECT_EQ(expected
, blended
);
439 TEST(FilterOperationsTest
, BlendZoomFilters
) {
440 FilterOperation from
= FilterOperation::CreateZoomFilter(2.f
, 3);
441 FilterOperation to
= FilterOperation::CreateZoomFilter(6.f
, 0);
443 FilterOperation blended
= FilterOperation::Blend(&from
, &to
, -0.75);
444 FilterOperation expected
= FilterOperation::CreateZoomFilter(1.f
, 5);
445 EXPECT_EQ(expected
, blended
);
447 blended
= FilterOperation::Blend(&from
, &to
, 0.75);
448 expected
= FilterOperation::CreateZoomFilter(5.f
, 1);
449 EXPECT_EQ(expected
, blended
);
451 blended
= FilterOperation::Blend(&from
, &to
, 1.5);
452 expected
= FilterOperation::CreateZoomFilter(8.f
, 0);
453 EXPECT_EQ(expected
, blended
);
456 TEST(FilterOperationsTest
, BlendZoomWithNull
) {
457 FilterOperation filter
= FilterOperation::CreateZoomFilter(2.f
, 1);
459 FilterOperation blended
= FilterOperation::Blend(&filter
, NULL
, 0.25);
460 FilterOperation expected
= FilterOperation::CreateZoomFilter(1.75f
, 1);
461 EXPECT_EQ(expected
, blended
);
463 blended
= FilterOperation::Blend(NULL
, &filter
, 0.25);
464 expected
= FilterOperation::CreateZoomFilter(1.25f
, 0);
465 EXPECT_EQ(expected
, blended
);
468 TEST(FilterOperationsTest
, BlendSaturatingBrightnessFilters
) {
469 FilterOperation from
= FilterOperation::CreateSaturatingBrightnessFilter(3.f
);
470 FilterOperation to
= FilterOperation::CreateSaturatingBrightnessFilter(7.f
);
472 FilterOperation blended
= FilterOperation::Blend(&from
, &to
, -0.75);
473 FilterOperation expected
=
474 FilterOperation::CreateSaturatingBrightnessFilter(0.f
);
475 EXPECT_EQ(expected
, blended
);
477 blended
= FilterOperation::Blend(&from
, &to
, 0.75);
478 expected
= FilterOperation::CreateSaturatingBrightnessFilter(6.f
);
479 EXPECT_EQ(expected
, blended
);
481 blended
= FilterOperation::Blend(&from
, &to
, 1.5);
482 expected
= FilterOperation::CreateSaturatingBrightnessFilter(9.f
);
483 EXPECT_EQ(expected
, blended
);
486 TEST(FilterOperationsTest
, BlendSaturatingBrightnessWithNull
) {
487 FilterOperation filter
=
488 FilterOperation::CreateSaturatingBrightnessFilter(1.f
);
490 FilterOperation blended
= FilterOperation::Blend(&filter
, NULL
, 0.25);
491 FilterOperation expected
=
492 FilterOperation::CreateSaturatingBrightnessFilter(0.75f
);
493 EXPECT_EQ(expected
, blended
);
495 blended
= FilterOperation::Blend(NULL
, &filter
, 0.25);
496 expected
= FilterOperation::CreateSaturatingBrightnessFilter(0.25f
);
497 EXPECT_EQ(expected
, blended
);
500 // Tests blending non-empty sequences that have the same length and matching
502 TEST(FilterOperationsTest
, BlendMatchingSequences
) {
503 FilterOperations from
;
506 from
.Append(FilterOperation::CreateBlurFilter(0.f
));
507 to
.Append(FilterOperation::CreateBlurFilter(2.f
));
509 from
.Append(FilterOperation::CreateSaturateFilter(4.f
));
510 to
.Append(FilterOperation::CreateSaturateFilter(0.f
));
512 from
.Append(FilterOperation::CreateZoomFilter(2.0f
, 1));
513 to
.Append(FilterOperation::CreateZoomFilter(10.f
, 9));
515 FilterOperations blended
= to
.Blend(from
, -0.75);
516 FilterOperations expected
;
517 expected
.Append(FilterOperation::CreateBlurFilter(0.f
));
518 expected
.Append(FilterOperation::CreateSaturateFilter(7.f
));
519 expected
.Append(FilterOperation::CreateZoomFilter(1.f
, 0));
520 EXPECT_EQ(blended
, expected
);
522 blended
= to
.Blend(from
, 0.75);
524 expected
.Append(FilterOperation::CreateBlurFilter(1.5f
));
525 expected
.Append(FilterOperation::CreateSaturateFilter(1.f
));
526 expected
.Append(FilterOperation::CreateZoomFilter(8.f
, 7));
527 EXPECT_EQ(blended
, expected
);
529 blended
= to
.Blend(from
, 1.5);
531 expected
.Append(FilterOperation::CreateBlurFilter(3.f
));
532 expected
.Append(FilterOperation::CreateSaturateFilter(0.f
));
533 expected
.Append(FilterOperation::CreateZoomFilter(14.f
, 13));
534 EXPECT_EQ(blended
, expected
);
537 TEST(FilterOperationsTest
, BlendEmptyAndNonEmptySequences
) {
538 FilterOperations empty
;
539 FilterOperations filters
;
541 filters
.Append(FilterOperation::CreateGrayscaleFilter(0.75f
));
542 filters
.Append(FilterOperation::CreateBrightnessFilter(2.f
));
543 filters
.Append(FilterOperation::CreateHueRotateFilter(10.0f
));
545 FilterOperations blended
= empty
.Blend(filters
, -0.75);
546 FilterOperations expected
;
547 expected
.Append(FilterOperation::CreateGrayscaleFilter(1.f
));
548 expected
.Append(FilterOperation::CreateBrightnessFilter(2.75f
));
549 expected
.Append(FilterOperation::CreateHueRotateFilter(17.5f
));
550 EXPECT_EQ(blended
, expected
);
552 blended
= empty
.Blend(filters
, 0.75);
554 expected
.Append(FilterOperation::CreateGrayscaleFilter(0.1875f
));
555 expected
.Append(FilterOperation::CreateBrightnessFilter(1.25f
));
556 expected
.Append(FilterOperation::CreateHueRotateFilter(2.5f
));
557 EXPECT_EQ(blended
, expected
);
559 blended
= empty
.Blend(filters
, 1.5);
561 expected
.Append(FilterOperation::CreateGrayscaleFilter(0.f
));
562 expected
.Append(FilterOperation::CreateBrightnessFilter(0.5f
));
563 expected
.Append(FilterOperation::CreateHueRotateFilter(-5.f
));
564 EXPECT_EQ(blended
, expected
);
566 blended
= filters
.Blend(empty
, -0.75);
568 expected
.Append(FilterOperation::CreateGrayscaleFilter(0.f
));
569 expected
.Append(FilterOperation::CreateBrightnessFilter(0.25f
));
570 expected
.Append(FilterOperation::CreateHueRotateFilter(-7.5f
));
571 EXPECT_EQ(blended
, expected
);
573 blended
= filters
.Blend(empty
, 0.75);
575 expected
.Append(FilterOperation::CreateGrayscaleFilter(0.5625f
));
576 expected
.Append(FilterOperation::CreateBrightnessFilter(1.75f
));
577 expected
.Append(FilterOperation::CreateHueRotateFilter(7.5f
));
578 EXPECT_EQ(blended
, expected
);
580 blended
= filters
.Blend(empty
, 1.5);
582 expected
.Append(FilterOperation::CreateGrayscaleFilter(1.f
));
583 expected
.Append(FilterOperation::CreateBrightnessFilter(2.5f
));
584 expected
.Append(FilterOperation::CreateHueRotateFilter(15.f
));
585 EXPECT_EQ(blended
, expected
);
588 TEST(FilterOperationsTest
, BlendEmptySequences
) {
589 FilterOperations empty
;
591 FilterOperations blended
= empty
.Blend(empty
, -0.75);
592 EXPECT_EQ(blended
, empty
);
594 blended
= empty
.Blend(empty
, 0.75);
595 EXPECT_EQ(blended
, empty
);
597 blended
= empty
.Blend(empty
, 1.5);
598 EXPECT_EQ(blended
, empty
);
601 // Tests blending non-empty sequences that either have different lengths or
602 // have non-matching operations.
603 TEST(FilterOperationsTest
, BlendNonMatchingSequences
) {
604 FilterOperations from
;
607 from
.Append(FilterOperation::CreateSaturateFilter(3.f
));
608 from
.Append(FilterOperation::CreateBlurFilter(2.f
));
609 to
.Append(FilterOperation::CreateSaturateFilter(4.f
));
611 FilterOperations blended
= to
.Blend(from
, -0.75);
612 EXPECT_EQ(to
, blended
);
613 blended
= to
.Blend(from
, 0.75);
614 EXPECT_EQ(to
, blended
);
615 blended
= to
.Blend(from
, 1.5);
616 EXPECT_EQ(to
, blended
);
618 to
.Append(FilterOperation::CreateHueRotateFilter(0.5f
));
619 blended
= to
.Blend(from
, -0.75);
620 EXPECT_EQ(to
, blended
);
621 blended
= to
.Blend(from
, 0.75);
622 EXPECT_EQ(to
, blended
);
623 blended
= to
.Blend(from
, 1.5);
624 EXPECT_EQ(to
, blended
);