blob: a1ca021b162863ed7f798c4a377567981edecde8 [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
8#include "Resources.h"
9#include "SkData.h"
halcanary2f0a7282015-08-21 07:47:23 -070010#include "SkImage.h"
halcanary30b83d42014-10-26 05:23:53 -070011#include "gm.h"
halcanary8b896e72014-12-02 11:00:40 -080012#include "sk_tool_utils.h"
halcanary30b83d42014-10-26 05:23:53 -070013
halcanary2f0a7282015-08-21 07:47:23 -070014static void draw_image(SkCanvas* canvas, const char* resource, int x, int y) {
reed9ce9d672016-03-17 10:51:11 -070015 sk_sp<SkImage> image(GetResourceAsImage(resource));
halcanary2f0a7282015-08-21 07:47:23 -070016 if (image) {
17 canvas->drawImage(image, SkIntToScalar(x), SkIntToScalar(y));
halcanary30b83d42014-10-26 05:23:53 -070018 } else {
19 SkDebugf("\nCould not decode file '%s'. Did you forget"
20 " to set the resourcePath?\n", resource);
21 }
22}
23
24/*
25 This GM tests whether the image decoders properly decode each color
26 channel. Four copies of the same image should appear in the GM, and
27 the letter R should be red, B should be blue, G green, C cyan, M
28 magenta, Y yellow, and K black. In all but the JPEG version of the
29 image, the letters should be on a white disc on a transparent
30 background (rendered as a checkerboard). The JPEG image has a grey
31 background and compression artifacts.
32 */
33DEF_SIMPLE_GM(colorwheel, canvas, 256, 256) {
halcanaryb0cce2c2015-01-26 12:49:00 -080034 sk_tool_utils::draw_checkerboard(canvas);
halcanary2f0a7282015-08-21 07:47:23 -070035 draw_image(canvas, "color_wheel.png", 0, 0); // top left
36 draw_image(canvas, "color_wheel.gif", 128, 0); // top right
37 draw_image(canvas, "color_wheel.webp", 0, 128); // bottom left
38 draw_image(canvas, "color_wheel.jpg", 128, 128); // bottom right
halcanary30b83d42014-10-26 05:23:53 -070039}
halcanary5abbc422014-12-02 09:37:17 -080040
41DEF_SIMPLE_GM(colorwheelnative, canvas, 128, 28) {
42 SkPaint paint;
mbocee6a9912016-05-31 11:42:36 -070043 sk_tool_utils::set_portable_typeface(&paint, "sans-serif",
44 SkFontStyle::FromOldStyle(SkTypeface::kBold));
halcanary5abbc422014-12-02 09:37:17 -080045 paint.setTextSize(18.0f);
46
caryclark3aaa0db2015-07-15 09:29:32 -070047 canvas->clear(sk_tool_utils::color_to_565(SK_ColorLTGRAY));
halcanary5abbc422014-12-02 09:37:17 -080048 paint.setColor(SK_ColorRED);
49 canvas->drawText("R", 1, 8.0f, 20.0f, paint);
50 paint.setColor(SK_ColorGREEN);
51 canvas->drawText("G", 1, 24.0f, 20.0f, paint);
52 paint.setColor(SK_ColorBLUE);
53 canvas->drawText("B", 1, 40.0f, 20.0f, paint);
54 paint.setColor(SK_ColorCYAN);
55 canvas->drawText("C", 1, 56.0f, 20.0f, paint);
56 paint.setColor(SK_ColorMAGENTA);
57 canvas->drawText("M", 1, 72.0f, 20.0f, paint);
58 paint.setColor(SK_ColorYELLOW);
59 canvas->drawText("Y", 1, 88.0f, 20.0f, paint);
60 paint.setColor(SK_ColorBLACK);
61 canvas->drawText("K", 1, 104.0f, 20.0f, paint);
62}