blob: 41265f5d4e5fd8722693238949320de7fc398208 [file] [log] [blame]
halcanary30b83d42014-10-26 05:23:53 -07001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -04009#include "include/core/SkCanvas.h"
10#include "include/core/SkColor.h"
11#include "include/core/SkFont.h"
12#include "include/core/SkFontStyle.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "include/core/SkImage.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040014#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"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050019#include "tools/Resources.h"
20#include "tools/ToolUtils.h"
halcanary30b83d42014-10-26 05:23:53 -070021
halcanary2f0a7282015-08-21 07:47:23 -070022static void draw_image(SkCanvas* canvas, const char* resource, int x, int y) {
reed9ce9d672016-03-17 10:51:11 -070023 sk_sp<SkImage> image(GetResourceAsImage(resource));
halcanary2f0a7282015-08-21 07:47:23 -070024 if (image) {
25 canvas->drawImage(image, SkIntToScalar(x), SkIntToScalar(y));
halcanary30b83d42014-10-26 05:23:53 -070026 } 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 */
41DEF_SIMPLE_GM(colorwheel, canvas, 256, 256) {
Mike Kleinea3f0142019-03-20 11:12:10 -050042 ToolUtils::draw_checkerboard(canvas);
Hal Canaryc465d132017-12-08 10:21:31 -050043 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
halcanary30b83d42014-10-26 05:23:53 -070047}
halcanary5abbc422014-12-02 09:37:17 -080048
49DEF_SIMPLE_GM(colorwheelnative, canvas, 128, 28) {
Hal Canary0a7b3932019-05-02 11:31:28 -040050 SkFont font(ToolUtils::create_portable_typeface("sans-serif", SkFontStyle::Bold()), 18);
Mike Reed4de2f1f2019-01-05 16:35:13 -050051 font.setEdging(SkFont::Edging::kAlias);
halcanary5abbc422014-12-02 09:37:17 -080052
Mike Kleind46dce32018-08-16 10:17:03 -040053 canvas->clear(SK_ColorLTGRAY);
Hal Canary0a7b3932019-05-02 11:31:28 -040054 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));
halcanary5abbc422014-12-02 09:37:17 -080061}