OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "Test.h" | 8 #include "Test.h" |
9 | 9 |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 bitmap.allocN32Pixels(1,1); | 38 bitmap.allocN32Pixels(1,1); |
39 | 39 |
40 SkCanvas canvas(bitmap); | 40 SkCanvas canvas(bitmap); |
41 SkPaint paint; | 41 SkPaint paint; |
42 | 42 |
43 SkScalar blueToCyan[20] = { | 43 SkScalar blueToCyan[20] = { |
44 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, | 44 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, |
45 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, | 45 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, |
46 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, | 46 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, |
47 0.0f, 0.0f, 0.0f, 1.0f, 0.0f }; | 47 0.0f, 0.0f, 0.0f, 1.0f, 0.0f }; |
48 paint.setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(blueToCyan))
; | 48 paint.setColorFilter(SkColorMatrixFilter::Create(blueToCyan))->unref(); |
49 | 49 |
50 paint.setColor(SK_ColorBLUE); | 50 paint.setColor(SK_ColorBLUE); |
51 canvas.drawPoint(0, 0, paint); | 51 canvas.drawPoint(0, 0, paint); |
52 assert_color(reporter, SK_ColorCYAN, bitmap.getColor(0, 0)); | 52 assert_color(reporter, SK_ColorCYAN, bitmap.getColor(0, 0)); |
53 | 53 |
54 paint.setColor(SK_ColorGREEN); | 54 paint.setColor(SK_ColorGREEN); |
55 canvas.drawPoint(0, 0, paint); | 55 canvas.drawPoint(0, 0, paint); |
56 assert_color(reporter, SK_ColorGREEN, bitmap.getColor(0, 0)); | 56 assert_color(reporter, SK_ColorGREEN, bitmap.getColor(0, 0)); |
57 | 57 |
58 paint.setColor(SK_ColorRED); | 58 paint.setColor(SK_ColorRED); |
59 canvas.drawPoint(0, 0, paint); | 59 canvas.drawPoint(0, 0, paint); |
60 assert_color(reporter, SK_ColorRED, bitmap.getColor(0, 0)); | 60 assert_color(reporter, SK_ColorRED, bitmap.getColor(0, 0)); |
61 | 61 |
62 // color components are clipped, not scaled | 62 // color components are clipped, not scaled |
63 paint.setColor(SK_ColorMAGENTA); | 63 paint.setColor(SK_ColorMAGENTA); |
64 canvas.drawPoint(0, 0, paint); | 64 canvas.drawPoint(0, 0, paint); |
65 assert_color(reporter, SK_ColorWHITE, bitmap.getColor(0, 0)); | 65 assert_color(reporter, SK_ColorWHITE, bitmap.getColor(0, 0)); |
66 | 66 |
67 SkScalar transparentRedAddBlue[20] = { | 67 SkScalar transparentRedAddBlue[20] = { |
68 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, | 68 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, |
69 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, | 69 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, |
70 0.0f, 0.0f, 1.0f, 0.0f, 64.0f, | 70 0.0f, 0.0f, 1.0f, 0.0f, 64.0f, |
71 -0.5f, 0.0f, 0.0f, 1.0f, 0.0f | 71 -0.5f, 0.0f, 0.0f, 1.0f, 0.0f |
72 }; | 72 }; |
73 paint.setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(transparentR
edAddBlue)); | 73 paint.setColorFilter(SkColorMatrixFilter::Create(transparentRedAddBlue))->un
ref(); |
74 bitmap.eraseColor(SK_ColorTRANSPARENT); | 74 bitmap.eraseColor(SK_ColorTRANSPARENT); |
75 | 75 |
76 paint.setColor(SK_ColorRED); | 76 paint.setColor(SK_ColorRED); |
77 canvas.drawPoint(0, 0, paint); | 77 canvas.drawPoint(0, 0, paint); |
78 assert_color(reporter, SkColorSetARGB(128, 255, 0, 64), bitmap.getColor(0, 0
), 2); | 78 assert_color(reporter, SkColorSetARGB(128, 255, 0, 64), bitmap.getColor(0, 0
), 2); |
79 | 79 |
80 paint.setColor(SK_ColorCYAN); | 80 paint.setColor(SK_ColorCYAN); |
81 canvas.drawPoint(0, 0, paint); | 81 canvas.drawPoint(0, 0, paint); |
82 // blue gets clipped | 82 // blue gets clipped |
83 assert_color(reporter, SK_ColorCYAN, bitmap.getColor(0, 0)); | 83 assert_color(reporter, SK_ColorCYAN, bitmap.getColor(0, 0)); |
84 | 84 |
85 // change array to filter out green | 85 // change array to filter out green |
86 REPORTER_ASSERT(reporter, 1.0f == transparentRedAddBlue[6]); | 86 REPORTER_ASSERT(reporter, 1.0f == transparentRedAddBlue[6]); |
87 transparentRedAddBlue[6] = 0.0f; | 87 transparentRedAddBlue[6] = 0.0f; |
88 | 88 |
89 // check that changing the array has no effect | 89 // check that changing the array has no effect |
90 canvas.drawPoint(0, 0, paint); | 90 canvas.drawPoint(0, 0, paint); |
91 assert_color(reporter, SK_ColorCYAN, bitmap.getColor(0, 0)); | 91 assert_color(reporter, SK_ColorCYAN, bitmap.getColor(0, 0)); |
92 | 92 |
93 // create a new filter with the changed matrix | 93 // create a new filter with the changed matrix |
94 paint.setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(transparentR
edAddBlue)); | 94 paint.setColorFilter(SkColorMatrixFilter::Create(transparentRedAddBlue))->un
ref(); |
95 canvas.drawPoint(0, 0, paint); | 95 canvas.drawPoint(0, 0, paint); |
96 assert_color(reporter, SK_ColorBLUE, bitmap.getColor(0, 0)); | 96 assert_color(reporter, SK_ColorBLUE, bitmap.getColor(0, 0)); |
97 } | 97 } |
98 | 98 |
99 DEF_TEST(ColorMatrix, reporter) { | 99 DEF_TEST(ColorMatrix, reporter) { |
100 test_colorMatrixCTS(reporter); | 100 test_colorMatrixCTS(reporter); |
101 } | 101 } |
OLD | NEW |