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 "gm/gm.h"
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkColor.h"
11 #include "include/core/SkFont.h"
12 #include "include/core/SkFontStyle.h"
13 #include "include/core/SkImage.h"
14 #include "include/core/SkPaint.h"
15 #include "include/core/SkRefCnt.h"
16 #include "include/core/SkScalar.h"
17 #include "include/core/SkTypeface.h"
18 #include "include/core/SkTypes.h"
19 #include "tools/Resources.h"
20 #include "tools/ToolUtils.h"
21
draw_image(SkCanvas * canvas,const char * resource,int x,int y)22 static void draw_image(SkCanvas* canvas, const char* resource, int x, int y) {
23 sk_sp<SkImage> image(GetResourceAsImage(resource));
24 if (image) {
25 canvas->drawImage(image, SkIntToScalar(x), SkIntToScalar(y));
26 } else {
27 SkDebugf("\nCould not decode file '%s'. Did you forget"
28 " to set the resourcePath?\n", resource);
29 }
30 }
31
32 /*
33 This GM tests whether the image decoders properly decode each color
34 channel. Four copies of the same image should appear in the GM, and
35 the letter R should be red, B should be blue, G green, C cyan, M
36 magenta, Y yellow, and K black. In all but the JPEG version of the
37 image, the letters should be on a white disc on a transparent
38 background (rendered as a checkerboard). The JPEG image has a grey
39 background and compression artifacts.
40 */
41 DEF_SIMPLE_GM(colorwheel, canvas, 256, 256) {
42 ToolUtils::draw_checkerboard(canvas);
43 draw_image(canvas, "images/color_wheel.png", 0, 0); // top left
44 draw_image(canvas, "images/color_wheel.gif", 128, 0); // top right
45 draw_image(canvas, "images/color_wheel.webp", 0, 128); // bottom left
46 draw_image(canvas, "images/color_wheel.jpg", 128, 128); // bottom right
47 }
48
49 DEF_SIMPLE_GM(colorwheelnative, canvas, 128, 28) {
50 SkFont font(ToolUtils::create_portable_typeface("sans-serif", SkFontStyle::Bold()), 18);
51 font.setEdging(SkFont::Edging::kAlias);
52
53 canvas->clear(SK_ColorLTGRAY);
54 canvas->drawString("R", 8.0f, 20.0f, font, SkPaint(SkColors::kRed));
55 canvas->drawString("G", 24.0f, 20.0f, font, SkPaint(SkColors::kGreen));
56 canvas->drawString("B", 40.0f, 20.0f, font, SkPaint(SkColors::kBlue));
57 canvas->drawString("C", 56.0f, 20.0f, font, SkPaint(SkColors::kCyan));
58 canvas->drawString("M", 72.0f, 20.0f, font, SkPaint(SkColors::kMagenta));
59 canvas->drawString("Y", 88.0f, 20.0f, font, SkPaint(SkColors::kYellow));
60 canvas->drawString("K", 104.0f, 20.0f, font, SkPaint(SkColors::kBlack));
61 }
62