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

Side by Side Diff: samplecode/SampleFilterFuzz.cpp

Issue 169063002: use SkColorType instead of SkBitmap::Config in samplecode (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « samplecode/SampleFilter2.cpp ('k') | samplecode/SampleFontCache.cpp » ('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 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 #include "SampleCode.h" 7 #include "SampleCode.h"
8 #include "SkBicubicImageFilter.h" 8 #include "SkBicubicImageFilter.h"
9 #include "SkBitmapDevice.h" 9 #include "SkBitmapDevice.h"
10 #include "SkBitmapSource.h" 10 #include "SkBitmapSource.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 } 104 }
105 105
106 static SkPoint3 make_point() { 106 static SkPoint3 make_point() {
107 return SkPoint3(make_scalar(), make_scalar(), make_scalar(true)); 107 return SkPoint3(make_scalar(), make_scalar(), make_scalar(true));
108 } 108 }
109 109
110 static SkDisplacementMapEffect::ChannelSelectorType make_channel_selector_type() { 110 static SkDisplacementMapEffect::ChannelSelectorType make_channel_selector_type() {
111 return static_cast<SkDisplacementMapEffect::ChannelSelectorType>(R(4)+1); 111 return static_cast<SkDisplacementMapEffect::ChannelSelectorType>(R(4)+1);
112 } 112 }
113 113
114 static bool valid_for_raster_canvas(const SkImageInfo& info) {
115 switch (info.colorType()) {
116 case kAlpha_8_SkColorType:
117 case kRGB_565_SkColorType:
118 return true;
119 case kPMColor_SkColorType:
120 return kPremul_SkAlphaType == info.alphaType() ||
121 kOpaque_SkAlphaType == info.alphaType();
122 default:
123 break;
124 }
125 return false;
126 }
127
128 static SkColorType rand_colortype() {
129 return (SkColorType)R(kLastEnum_SkColorType + 1);
130 }
131
132 static void rand_bitmap_for_canvas(SkBitmap* bitmap) {
133 SkImageInfo info;
134 do {
135 info = SkImageInfo::Make(kBitmapSize, kBitmapSize, rand_colortype(),
136 kPremul_SkAlphaType);
137 } while (!valid_for_raster_canvas(info) || !bitmap->allocPixels(info));
138 }
139
114 static void make_g_bitmap(SkBitmap& bitmap) { 140 static void make_g_bitmap(SkBitmap& bitmap) {
115 bitmap.setConfig((SkBitmap::Config)R(SkBitmap::kConfigCount), kBitmapSize, k BitmapSize); 141 rand_bitmap_for_canvas(&bitmap);
116 while (!bitmap.allocPixels()) { 142
117 bitmap.setConfig((SkBitmap::Config)R(SkBitmap::kConfigCount), kBitmapSiz e, kBitmapSize); 143 SkCanvas canvas(bitmap);
118 }
119 SkBitmapDevice device(bitmap);
120 SkCanvas canvas(&device);
121 canvas.clear(0x00000000); 144 canvas.clear(0x00000000);
122 SkPaint paint; 145 SkPaint paint;
123 paint.setAntiAlias(true); 146 paint.setAntiAlias(true);
124 paint.setColor(0xFF884422); 147 paint.setColor(0xFF884422);
125 paint.setTextSize(SkIntToScalar(kBitmapSize/2)); 148 paint.setTextSize(SkIntToScalar(kBitmapSize/2));
126 const char* str = "g"; 149 const char* str = "g";
127 canvas.drawText(str, strlen(str), SkIntToScalar(kBitmapSize/8), 150 canvas.drawText(str, strlen(str), SkIntToScalar(kBitmapSize/8),
128 SkIntToScalar(kBitmapSize/4), paint); 151 SkIntToScalar(kBitmapSize/4), paint);
129 } 152 }
130 153
131 static bool valid_for_raster_canvas(const SkBitmap& bm) { 154 static void make_checkerboard_bitmap(SkBitmap& bitmap) {
132 SkImageInfo info; 155 rand_bitmap_for_canvas(&bitmap);
133 if (!bm.asImageInfo(&info)) {
134 return false;
135 }
136 switch (info.fColorType) {
137 case kAlpha_8_SkColorType:
138 case kRGB_565_SkColorType:
139 return true;
140 case kPMColor_SkColorType:
141 return kPremul_SkAlphaType == info.fAlphaType ||
142 kOpaque_SkAlphaType == info.fAlphaType;
143 default:
144 break;
145 }
146 return false;
147 }
148 156
149 static void make_checkerboard_bitmap(SkBitmap& bitmap) { 157 SkCanvas canvas(bitmap);
150 bitmap.setConfig((SkBitmap::Config)R(SkBitmap::kConfigCount), kBitmapSize, k BitmapSize);
151 while (valid_for_raster_canvas(bitmap) && !bitmap.allocPixels()) {
152 bitmap.setConfig((SkBitmap::Config)R(SkBitmap::kConfigCount), kBitmapSiz e, kBitmapSize);
153 }
154 SkBitmapDevice device(bitmap);
155 SkCanvas canvas(&device);
156 canvas.clear(0x00000000); 158 canvas.clear(0x00000000);
157 SkPaint darkPaint; 159 SkPaint darkPaint;
158 darkPaint.setColor(0xFF804020); 160 darkPaint.setColor(0xFF804020);
159 SkPaint lightPaint; 161 SkPaint lightPaint;
160 lightPaint.setColor(0xFF244484); 162 lightPaint.setColor(0xFF244484);
161 const int i = kBitmapSize / 8; 163 const int i = kBitmapSize / 8;
162 const SkScalar f = SkIntToScalar(i); 164 const SkScalar f = SkIntToScalar(i);
163 for (int y = 0; y < kBitmapSize; y += i) { 165 for (int y = 0; y < kBitmapSize; y += i) {
164 for (int x = 0; x < kBitmapSize; x += i) { 166 for (int x = 0; x < kBitmapSize; x += i) {
165 canvas.save(); 167 canvas.save();
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 } 427 }
426 428
427 private: 429 private:
428 typedef SkView INHERITED; 430 typedef SkView INHERITED;
429 }; 431 };
430 432
431 ////////////////////////////////////////////////////////////////////////////// 433 //////////////////////////////////////////////////////////////////////////////
432 434
433 static SkView* MyFactory() { return new ImageFilterFuzzView; } 435 static SkView* MyFactory() { return new ImageFilterFuzzView; }
434 static SkViewRegister reg(MyFactory); 436 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « samplecode/SampleFilter2.cpp ('k') | samplecode/SampleFontCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698