OLD | NEW |
1 ο»Ώ/* | 1 ο»Ώ/* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "sk_tool_utils.h" | 8 #include "sk_tool_utils.h" |
9 #include "sk_tool_utils_flags.h" | 9 #include "sk_tool_utils_flags.h" |
10 | 10 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 tf->reset(SkTypeface::CreateFromName("Apple Color Emoji", SkTypeface::kN
ormal)); | 84 tf->reset(SkTypeface::CreateFromName("Apple Color Emoji", SkTypeface::kN
ormal)); |
85 return; | 85 return; |
86 } | 86 } |
87 tf->reset(nullptr); | 87 tf->reset(nullptr); |
88 return; | 88 return; |
89 } | 89 } |
90 | 90 |
91 const char* emoji_sample_text() { | 91 const char* emoji_sample_text() { |
92 if (!strcmp(sk_tool_utils::platform_os_emoji(), "CBDT")) { | 92 if (!strcmp(sk_tool_utils::platform_os_emoji(), "CBDT")) { |
93 return "Hamburgefons"; | 93 return "Hamburgefons"; |
94 } | 94 } |
95 if (!strcmp(sk_tool_utils::platform_os_emoji(), "SBIX")) { | 95 if (!strcmp(sk_tool_utils::platform_os_emoji(), "SBIX")) { |
96 return "\xF0\x9F\x92\xB0" "\xF0\x9F\x8F\xA1" "\xF0\x9F\x8E\x85" // π°π‘π
| 96 return "\xF0\x9F\x92\xB0" "\xF0\x9F\x8F\xA1" "\xF0\x9F\x8E\x85" // π°π‘π
|
97 "\xF0\x9F\x8D\xAA" "\xF0\x9F\x8D\x95" "\xF0\x9F\x9A\x80" // πͺππ | 97 "\xF0\x9F\x8D\xAA" "\xF0\x9F\x8D\x95" "\xF0\x9F\x9A\x80" // πͺππ |
98 "\xF0\x9F\x9A\xBB" "\xF0\x9F\x92\xA9" "\xF0\x9F\x93\xB7" // π»π©π· | 98 "\xF0\x9F\x9A\xBB" "\xF0\x9F\x92\xA9" "\xF0\x9F\x93\xB7" // π»π©π· |
99 "\xF0\x9F\x93\xA6" // π¦ | 99 "\xF0\x9F\x93\xA6" // π¦ |
100 "\xF0\x9F\x87\xBA" "\xF0\x9F\x87\xB8" "\xF0\x9F\x87\xA6"; // πΊπΈπ¦ | 100 "\xF0\x9F\x87\xBA" "\xF0\x9F\x87\xB8" "\xF0\x9F\x87\xA6"; // πΊπΈπ¦ |
101 } | 101 } |
102 return ""; | 102 return ""; |
103 } | 103 } |
104 | 104 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 } | 160 } |
161 | 161 |
162 SkTypeface* create_portable_typeface(const char* name, SkTypeface::Style style)
{ | 162 SkTypeface* create_portable_typeface(const char* name, SkTypeface::Style style)
{ |
163 return create_font(name, style); | 163 return create_font(name, style); |
164 } | 164 } |
165 | 165 |
166 void set_portable_typeface(SkPaint* paint, const char* name, SkTypeface::Style s
tyle) { | 166 void set_portable_typeface(SkPaint* paint, const char* name, SkTypeface::Style s
tyle) { |
167 SkTypeface* face = create_font(name, style); | 167 SkTypeface* face = create_font(name, style); |
168 SkSafeUnref(paint->setTypeface(face)); | 168 SkSafeUnref(paint->setTypeface(face)); |
169 } | 169 } |
170 | 170 |
171 void write_pixels(SkCanvas* canvas, const SkBitmap& bitmap, int x, int y, | 171 void write_pixels(SkCanvas* canvas, const SkBitmap& bitmap, int x, int y, |
172 SkColorType colorType, SkAlphaType alphaType) { | 172 SkColorType colorType, SkAlphaType alphaType) { |
173 SkBitmap tmp(bitmap); | 173 SkBitmap tmp(bitmap); |
174 tmp.lockPixels(); | 174 tmp.lockPixels(); |
175 | 175 |
176 const SkImageInfo info = SkImageInfo::Make(tmp.width(), tmp.height(), colorT
ype, alphaType); | 176 const SkImageInfo info = SkImageInfo::Make(tmp.width(), tmp.height(), colorT
ype, alphaType); |
177 | 177 |
178 canvas->writePixels(info, tmp.getPixels(), tmp.rowBytes(), x, y); | 178 canvas->writePixels(info, tmp.getPixels(), tmp.rowBytes(), x, y); |
179 } | 179 } |
180 | 180 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 const SkPoint center = SkPoint::Make(dst.fLeft + (dst.width() / 2.0f), | 249 const SkPoint center = SkPoint::Make(dst.fLeft + (dst.width() / 2.0f), |
250 dst.fTop + (dst.height() / 2.0f)); | 250 dst.fTop + (dst.height() / 2.0f)); |
251 const SkPoint halfSize = SkPoint::Make(dst.width() / 2.0f, dst.height() / 2.
0f); | 251 const SkPoint halfSize = SkPoint::Make(dst.width() / 2.0f, dst.height() / 2.
0f); |
252 | 252 |
253 SkVector3 norm; | 253 SkVector3 norm; |
254 | 254 |
255 for (int y = dst.fTop; y < dst.fBottom; ++y) { | 255 for (int y = dst.fTop; y < dst.fBottom; ++y) { |
256 for (int x = dst.fLeft; x < dst.fRight; ++x) { | 256 for (int x = dst.fLeft; x < dst.fRight; ++x) { |
257 norm.fX = (x + 0.5f - center.fX) / halfSize.fX; | 257 norm.fX = (x + 0.5f - center.fX) / halfSize.fX; |
258 norm.fY = (y + 0.5f - center.fY) / halfSize.fY; | 258 norm.fY = (y + 0.5f - center.fY) / halfSize.fY; |
259 | 259 |
260 SkScalar tmp = norm.fX * norm.fX + norm.fY * norm.fY; | 260 SkScalar tmp = norm.fX * norm.fX + norm.fY * norm.fY; |
261 if (tmp >= 1.0f) { | 261 if (tmp >= 1.0f) { |
262 norm.set(0.0f, 0.0f, 1.0f); | 262 norm.set(0.0f, 0.0f, 1.0f); |
263 } else { | 263 } else { |
264 norm.fZ = sqrtf(1.0f - tmp); | 264 norm.fZ = sqrtf(1.0f - tmp); |
265 } | 265 } |
266 | 266 |
267 norm_to_rgb(bm, x, y, norm); | 267 norm_to_rgb(bm, x, y, norm); |
268 } | 268 } |
269 } | 269 } |
(...skipping 18 matching lines...) Expand all Loading... |
288 norm.set(0.0f, 0.0f, 1.0f); | 288 norm.set(0.0f, 0.0f, 1.0f); |
289 } else { | 289 } else { |
290 SkScalar locX = x + 0.5f - center.fX; | 290 SkScalar locX = x + 0.5f - center.fX; |
291 SkScalar locY = y + 0.5f - center.fY; | 291 SkScalar locY = y + 0.5f - center.fY; |
292 | 292 |
293 if (locX >= 0.0f) { | 293 if (locX >= 0.0f) { |
294 if (locY > 0.0f) { | 294 if (locY > 0.0f) { |
295 norm = locX >= locY ? right : down; // LR corner | 295 norm = locX >= locY ? right : down; // LR corner |
296 } else { | 296 } else { |
297 norm = locX > -locY ? right : up; // UR corner | 297 norm = locX > -locY ? right : up; // UR corner |
298 } | 298 } |
299 } else { | 299 } else { |
300 if (locY > 0.0f) { | 300 if (locY > 0.0f) { |
301 norm = -locX > locY ? left : down; // LL corner | 301 norm = -locX > locY ? left : down; // LL corner |
302 } else { | 302 } else { |
303 norm = locX > locY ? up : left; // UL corner | 303 norm = locX > locY ? up : left; // UL corner |
304 } | 304 } |
305 } | 305 } |
306 } | 306 } |
307 | 307 |
308 norm_to_rgb(bm, x, y, norm); | 308 norm_to_rgb(bm, x, y, norm); |
309 } | 309 } |
310 } | 310 } |
311 } | 311 } |
312 | 312 |
313 void create_tetra_normal_map(SkBitmap* bm, const SkIRect& dst) { | 313 void create_tetra_normal_map(SkBitmap* bm, const SkIRect& dst) { |
314 const SkPoint center = SkPoint::Make(dst.fLeft + (dst.width() / 2.0f), | 314 const SkPoint center = SkPoint::Make(dst.fLeft + (dst.width() / 2.0f), |
315 dst.fTop + (dst.height() / 2.0f)); | 315 dst.fTop + (dst.height() / 2.0f)); |
316 | 316 |
317 static const SkScalar k1OverRoot3 = 0.5773502692f; | 317 static const SkScalar k1OverRoot3 = 0.5773502692f; |
318 | 318 |
319 SkPoint3 norm; | 319 SkPoint3 norm; |
320 const SkPoint3 leftUp = SkPoint3::Make(-k1OverRoot3, -k1OverRoot3, k1OverRo
ot3); | 320 const SkPoint3 leftUp = SkPoint3::Make(-k1OverRoot3, -k1OverRoot3, k1OverRo
ot3); |
321 const SkPoint3 rightUp = SkPoint3::Make(k1OverRoot3, -k1OverRoot3, k1OverRo
ot3); | 321 const SkPoint3 rightUp = SkPoint3::Make(k1OverRoot3, -k1OverRoot3, k1OverRo
ot3); |
322 const SkPoint3 down = SkPoint3::Make(0.0f, SK_ScalarRoot2Over2, SK_ScalarR
oot2Over2); | 322 const SkPoint3 down = SkPoint3::Make(0.0f, SK_ScalarRoot2Over2, SK_ScalarR
oot2Over2); |
323 | 323 |
324 for (int y = dst.fTop; y < dst.fBottom; ++y) { | 324 for (int y = dst.fTop; y < dst.fBottom; ++y) { |
325 for (int x = dst.fLeft; x < dst.fRight; ++x) { | 325 for (int x = dst.fLeft; x < dst.fRight; ++x) { |
326 SkScalar locX = x + 0.5f - center.fX; | 326 SkScalar locX = x + 0.5f - center.fX; |
327 SkScalar locY = y + 0.5f - center.fY; | 327 SkScalar locY = y + 0.5f - center.fY; |
328 | 328 |
329 if (locX >= 0.0f) { | 329 if (locX >= 0.0f) { |
330 if (locY > 0.0f) { | 330 if (locY > 0.0f) { |
331 norm = locX >= locY ? rightUp : down; // LR corner | 331 norm = locX >= locY ? rightUp : down; // LR corner |
332 } else { | 332 } else { |
333 norm = rightUp; | 333 norm = rightUp; |
334 } | 334 } |
335 } else { | 335 } else { |
336 if (locY > 0.0f) { | 336 if (locY > 0.0f) { |
337 norm = -locX > locY ? leftUp : down; // LL corner | 337 norm = -locX > locY ? leftUp : down; // LL corner |
338 } else { | 338 } else { |
339 norm = leftUp; | 339 norm = leftUp; |
340 } | 340 } |
341 } | 341 } |
342 | 342 |
343 norm_to_rgb(bm, x, y, norm); | 343 norm_to_rgb(bm, x, y, norm); |
344 } | 344 } |
345 } | 345 } |
346 } | 346 } |
347 | 347 |
348 void make_big_path(SkPath& path) { | 348 void make_big_path(SkPath& path) { |
349 #include "BigPathBench.inc" | 349 #include "BigPathBench.inc" |
350 } | 350 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 dst.allocN32Pixels(src.width(), src.height(), true); | 432 dst.allocN32Pixels(src.width(), src.height(), true); |
433 | 433 |
434 int wh; | 434 int wh; |
435 SkAutoTDeleteArray<float> kernel(create_2d_kernel(sigma, &wh)); | 435 SkAutoTDeleteArray<float> kernel(create_2d_kernel(sigma, &wh)); |
436 | 436 |
437 for (int y = 0; y < src.height(); ++y) { | 437 for (int y = 0; y < src.height(); ++y) { |
438 for (int x = 0; x < src.width(); ++x) { | 438 for (int x = 0; x < src.width(); ++x) { |
439 *dst.getAddr32(x, y) = blur_pixel(src, x, y, kernel.get(), wh); | 439 *dst.getAddr32(x, y) = blur_pixel(src, x, y, kernel.get(), wh); |
440 } | 440 } |
441 } | 441 } |
442 | 442 |
443 return dst; | 443 return dst; |
444 } | 444 } |
445 | 445 |
446 } // namespace sk_tool_utils | 446 } // namespace sk_tool_utils |
OLD | NEW |