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

Side by Side Diff: gm/colorwheel.cpp

Issue 680533002: add gm: colorwheel (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: refactor checkerboard() fn for simplicity Created 6 years, 1 month 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 | « no previous file | gm/gm.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "Resources.h"
9 #include "SkData.h"
10 #include "SkDecodingImageGenerator.h"
11 #include "gm.h"
12
13 static void checkerboard(
14 SkCanvas* canvas, int w, int h, int size, SkColor c1, SkColor c2) {
15 SkAutoCanvasRestore autoCanvasRestore(canvas, true);
16 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(w), SkIntToScalar(h)));
17 canvas->drawColor(c1);
18 SkPaint paint;
19 paint.setColor(c2);
20 SkScalar s = SkIntToScalar(size);
21 for (int y = 0; y < h; y += size) {
22 SkScalar ty = SkIntToScalar(y);
23 bool oddRow = (y % (2 * size)) != 0;
24 for (int x = oddRow ? size : 0; x < w; x += (2 * size)) {
25 SkScalar tx = SkIntToScalar(x);
26 canvas->drawRect(SkRect::MakeXYWH(tx, ty, s, s), paint);
27 }
28 }
29 }
30
31 static void draw_bitmap(SkCanvas* canvas, const char* resource, int x, int y) {
32 SkBitmap bitmap;
33 if (GetResourceAsBitmap(resource, &bitmap)) {
34 canvas->drawBitmap(bitmap, SkIntToScalar(x), SkIntToScalar(y));
35 } else {
36 SkDebugf("\nCould not decode file '%s'. Did you forget"
37 " to set the resourcePath?\n", resource);
38 }
39 }
40
41 /*
42 This GM tests whether the image decoders properly decode each color
43 channel. Four copies of the same image should appear in the GM, and
44 the letter R should be red, B should be blue, G green, C cyan, M
45 magenta, Y yellow, and K black. In all but the JPEG version of the
46 image, the letters should be on a white disc on a transparent
47 background (rendered as a checkerboard). The JPEG image has a grey
48 background and compression artifacts.
49 */
50 DEF_SIMPLE_GM(colorwheel, canvas, 256, 256) {
51 canvas->clear(SK_ColorWHITE);
52 checkerboard(canvas, 256, 556, 8, 0xFF999999, 0xFF666666);
53 draw_bitmap(canvas, "color_wheel.png", 0, 0); // top left
54 draw_bitmap(canvas, "color_wheel.gif", 128, 0); // top right
55 draw_bitmap(canvas, "color_wheel.webp", 0, 128); // bottom left
56 draw_bitmap(canvas, "color_wheel.jpg", 128, 128); // bottom right
57 }
OLDNEW
« no previous file with comments | « no previous file | gm/gm.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698