colorwheel.cpp revision 3e5c2b1041b15641931638d1d78b30d3c435fc71
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 "gm.h"
11#include "sk_tool_utils.h"
12
13static void draw_bitmap(SkCanvas* canvas, const char* resource, int x, int y) {
14    SkBitmap bitmap;
15    if (GetResourceAsBitmap(resource, &bitmap)) {
16        canvas->drawBitmap(bitmap, SkIntToScalar(x), SkIntToScalar(y));
17    } else {
18        SkDebugf("\nCould not decode file '%s'. Did you forget"
19                 " to set the resourcePath?\n", resource);
20    }
21}
22
23/*
24  This GM tests whether the image decoders properly decode each color
25  channel.  Four copies of the same image should appear in the GM, and
26  the letter R should be red, B should be blue, G green, C cyan, M
27  magenta, Y yellow, and K black. In all but the JPEG version of the
28  image, the letters should be on a white disc on a transparent
29  background (rendered as a checkerboard).  The JPEG image has a grey
30  background and compression artifacts.
31 */
32DEF_SIMPLE_GM(colorwheel, canvas, 256, 256) {
33    sk_tool_utils::draw_checkerboard(canvas);
34    draw_bitmap(canvas, "color_wheel.png", 0, 0);  // top left
35    draw_bitmap(canvas, "color_wheel.gif", 128, 0);  // top right
36    draw_bitmap(canvas, "color_wheel.webp", 0, 128);  // bottom left
37    draw_bitmap(canvas, "color_wheel.jpg", 128, 128);  // bottom right
38}
39
40DEF_SIMPLE_GM(colorwheelnative, canvas, 128, 28) {
41    SkPaint paint;
42    sk_tool_utils::set_portable_typeface(&paint, NULL, SkTypeface::kBold);
43    paint.setTextSize(18.0f);
44
45    canvas->clear(SK_ColorLTGRAY);
46    paint.setColor(SK_ColorRED);
47    canvas->drawText("R", 1, 8.0f, 20.0f, paint);
48    paint.setColor(SK_ColorGREEN);
49    canvas->drawText("G", 1, 24.0f, 20.0f, paint);
50    paint.setColor(SK_ColorBLUE);
51    canvas->drawText("B", 1, 40.0f, 20.0f, paint);
52    paint.setColor(SK_ColorCYAN);
53    canvas->drawText("C", 1, 56.0f, 20.0f, paint);
54    paint.setColor(SK_ColorMAGENTA);
55    canvas->drawText("M", 1, 72.0f, 20.0f, paint);
56    paint.setColor(SK_ColorYELLOW);
57    canvas->drawText("Y", 1, 88.0f, 20.0f, paint);
58    paint.setColor(SK_ColorBLACK);
59    canvas->drawText("K", 1, 104.0f, 20.0f, paint);
60}
61