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

Side by Side Diff: gm/tablecolorfilter.cpp

Issue 776673002: Collapse consecutive SkTableColorFilters (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix another msvc warning Created 5 years, 11 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
« no previous file with comments | « bench/ImageFilterCollapse.cpp ('k') | gyp/bench.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 "gm.h" 8 #include "gm.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkColorFilterImageFilter.h"
10 #include "SkGradientShader.h" 11 #include "SkGradientShader.h"
11 #include "SkTableColorFilter.h" 12 #include "SkTableColorFilter.h"
12 13
13 static void make_bm0(SkBitmap* bm) { 14 static void make_bm0(SkBitmap* bm) {
14 int W = 120; 15 int W = 120;
15 int H = 120; 16 int H = 120;
16 bm->allocN32Pixels(W, H); 17 bm->allocN32Pixels(W, H);
17 bm->eraseColor(SK_ColorTRANSPARENT); 18 bm->eraseColor(SK_ColorTRANSPARENT);
18 19
19 SkCanvas canvas(*bm); 20 SkCanvas canvas(*bm);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 table[i] = i * i / 255; 62 table[i] = i * i / 255;
62 } 63 }
63 } 64 }
64 static void make_table2(uint8_t table[]) { 65 static void make_table2(uint8_t table[]) {
65 for (int i = 0; i < 256; ++i) { 66 for (int i = 0; i < 256; ++i) {
66 float fi = i / 255.0f; 67 float fi = i / 255.0f;
67 table[i] = static_cast<uint8_t>(sqrtf(fi) * 255); 68 table[i] = static_cast<uint8_t>(sqrtf(fi) * 255);
68 } 69 }
69 } 70 }
70 71
72 static SkColorFilter* make_null_cf() {
73 return NULL;
74 }
75
71 static SkColorFilter* make_cf0() { 76 static SkColorFilter* make_cf0() {
72 uint8_t table[256]; make_table0(table); 77 uint8_t table[256]; make_table0(table);
73 return SkTableColorFilter::Create(table); 78 return SkTableColorFilter::Create(table);
74 } 79 }
75 static SkColorFilter* make_cf1() { 80 static SkColorFilter* make_cf1() {
76 uint8_t table[256]; make_table1(table); 81 uint8_t table[256]; make_table1(table);
77 return SkTableColorFilter::Create(table); 82 return SkTableColorFilter::Create(table);
78 } 83 }
79 static SkColorFilter* make_cf2() { 84 static SkColorFilter* make_cf2() {
80 uint8_t table[256]; make_table2(table); 85 uint8_t table[256]; make_table2(table);
81 return SkTableColorFilter::Create(table); 86 return SkTableColorFilter::Create(table);
82 } 87 }
83 static SkColorFilter* make_cf3() { 88 static SkColorFilter* make_cf3() {
84 uint8_t table0[256]; make_table0(table0); 89 uint8_t table0[256]; make_table0(table0);
85 uint8_t table1[256]; make_table1(table1); 90 uint8_t table1[256]; make_table1(table1);
86 uint8_t table2[256]; make_table2(table2); 91 uint8_t table2[256]; make_table2(table2);
87 return SkTableColorFilter::CreateARGB(NULL, table0, table1, table2); 92 return SkTableColorFilter::CreateARGB(NULL, table0, table1, table2);
88 } 93 }
89 94
90 class TableColorFilterGM : public skiagm::GM { 95 class TableColorFilterGM : public skiagm::GM {
91 public: 96 public:
92 TableColorFilterGM() {} 97 TableColorFilterGM() {}
93 98
94 protected: 99 protected:
95 virtual SkString onShortName() { 100 virtual SkString onShortName() {
96 return SkString("tablecolorfilter"); 101 return SkString("tablecolorfilter");
97 } 102 }
98 103
99 virtual SkISize onISize() { 104 virtual SkISize onISize() {
100 return SkISize::Make(700, 300); 105 return SkISize::Make(700, 1650);
101 } 106 }
102 107
103 virtual void onDraw(SkCanvas* canvas) { 108 virtual void onDraw(SkCanvas* canvas) {
104 canvas->drawColor(0xFFDDDDDD); 109 canvas->drawColor(0xFFDDDDDD);
105 canvas->translate(20, 20); 110 canvas->translate(20, 20);
106 111
112
113 static SkColorFilter* (*gColorFilterMakers[])() = { make_null_cf, make_c f0, make_cf1,
114 make_cf2, make_cf3 };
115 static void (*gBitmapMakers[])(SkBitmap*) = { make_bm0, make_bm1 };
116
117 // This test will be done once for each bitmap with the results stacked vertically.
118 // For a single bitmap the resulting image will be the following:
119 // - A first line with the original bitmap, followed by the image drawn once
120 // with each of the N color filters
121 // - N lines of the bitmap drawn N times, this will cover all N*N combi nations of
122 // pair of color filters in order to test the collpsing of consecutive table
123 // color filters.
124 //
125 // Here is a graphical representation of the result for 2 bitmaps and 2 filters
126 // with the number corresponding to the number of filters the bitmap go es through:
127 //
128 // --bitmap1
129 // 011
130 // 22
131 // 22
132 // --bitmap2
133 // 011
134 // 22
135 // 22
136
107 SkScalar x = 0, y = 0; 137 SkScalar x = 0, y = 0;
138 for (size_t bitmapMaker = 0; bitmapMaker < SK_ARRAY_COUNT(gBitmapMakers) ; ++bitmapMaker) {
139 SkBitmap bm;
140 gBitmapMakers[bitmapMaker](&bm);
108 141
109 static void (*gMakers[])(SkBitmap*) = { make_bm0, make_bm1 }; 142 SkScalar xOffset = SkScalar(bm.width() * 9 / 8);
110 for (size_t maker = 0; maker < SK_ARRAY_COUNT(gMakers); ++maker) { 143 SkScalar yOffset = SkScalar(bm.height() * 9 / 8);
111 SkBitmap bm;
112 gMakers[maker](&bm);
113 144
145 // Draw the first element of the first line
146 x = 0;
114 SkPaint paint; 147 SkPaint paint;
115 x = 0;
116 canvas->drawBitmap(bm, x, y, &paint);
117 paint.setColorFilter(make_cf0())->unref(); x += bm.width() * 9 / 8;
118 canvas->drawBitmap(bm, x, y, &paint);
119 paint.setColorFilter(make_cf1())->unref(); x += bm.width() * 9 / 8;
120 canvas->drawBitmap(bm, x, y, &paint);
121 paint.setColorFilter(make_cf2())->unref(); x += bm.width() * 9 / 8;
122 canvas->drawBitmap(bm, x, y, &paint);
123 paint.setColorFilter(make_cf3())->unref(); x += bm.width() * 9 / 8;
124 canvas->drawBitmap(bm, x, y, &paint); 148 canvas->drawBitmap(bm, x, y, &paint);
125 149
126 y += bm.height() * 9 / 8; 150 // Draws the rest of the first line for this bitmap
151 // each draw being at xOffset of the previous one
152 for (unsigned i = 1; i < SK_ARRAY_COUNT(gColorFilterMakers); ++i) {
153 x += xOffset;
154 paint.setColorFilter(gColorFilterMakers[i]())->unref();
155 canvas->drawBitmap(bm, x, y, &paint);
156 }
157
158 paint.setColorFilter(NULL);
159
160 for (unsigned i = 0; i < SK_ARRAY_COUNT(gColorFilterMakers); ++i) {
161 SkAutoTUnref<SkColorFilter> colorFilter1(gColorFilterMakers[i]() );
162 SkAutoTUnref<SkImageFilter> imageFilter1(SkColorFilterImageFilte r::Create(
163 colorFilter1, NULL, NULL, 0));
164
165 // Move down to the next line and draw it
166 // each draw being at xOffset of the previous one
167 y += yOffset;
168 x = 0;
169 for (unsigned j = 1; j < SK_ARRAY_COUNT(gColorFilterMakers); ++j ) {
170 SkAutoTUnref<SkColorFilter> colorFilter2(gColorFilterMakers[ j]());
171 SkAutoTUnref<SkImageFilter> imageFilter2(SkColorFilterImageF ilter::Create(
172 colorFilter2, imageFilter1, NULL, 0));
173 paint.setImageFilter(imageFilter2);
174 canvas->drawBitmap(bm, x, y, &paint);
175 x += xOffset;
176 }
177 }
178
179 // Move down one line to the beginning of the block for next bitmap
180 y += yOffset;
127 } 181 }
128 } 182 }
129 183
130 private: 184 private:
131 typedef GM INHERITED; 185 typedef GM INHERITED;
132 }; 186 };
133 187
134 ////////////////////////////////////////////////////////////////////////////// 188 //////////////////////////////////////////////////////////////////////////////
135 189
136 static skiagm::GM* MyFactory(void*) { return new TableColorFilterGM; } 190 static skiagm::GM* MyFactory(void*) { return new TableColorFilterGM; }
137 static skiagm::GMRegistry reg(MyFactory); 191 static skiagm::GMRegistry reg(MyFactory);
OLDNEW
« no previous file with comments | « bench/ImageFilterCollapse.cpp ('k') | gyp/bench.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698