2014-10-26 12:23:53 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Resources.h"
|
|
|
|
#include "SkData.h"
|
2015-08-21 14:47:23 +00:00
|
|
|
#include "SkImage.h"
|
2014-10-26 12:23:53 +00:00
|
|
|
#include "gm.h"
|
2014-12-02 19:00:40 +00:00
|
|
|
#include "sk_tool_utils.h"
|
2014-10-26 12:23:53 +00:00
|
|
|
|
2015-08-21 14:47:23 +00:00
|
|
|
static void draw_image(SkCanvas* canvas, const char* resource, int x, int y) {
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image(GetResourceAsImage(resource));
|
2015-08-21 14:47:23 +00:00
|
|
|
if (image) {
|
|
|
|
canvas->drawImage(image, SkIntToScalar(x), SkIntToScalar(y));
|
2014-10-26 12:23:53 +00:00
|
|
|
} else {
|
|
|
|
SkDebugf("\nCould not decode file '%s'. Did you forget"
|
|
|
|
" to set the resourcePath?\n", resource);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
This GM tests whether the image decoders properly decode each color
|
|
|
|
channel. Four copies of the same image should appear in the GM, and
|
|
|
|
the letter R should be red, B should be blue, G green, C cyan, M
|
|
|
|
magenta, Y yellow, and K black. In all but the JPEG version of the
|
|
|
|
image, the letters should be on a white disc on a transparent
|
|
|
|
background (rendered as a checkerboard). The JPEG image has a grey
|
|
|
|
background and compression artifacts.
|
|
|
|
*/
|
|
|
|
DEF_SIMPLE_GM(colorwheel, canvas, 256, 256) {
|
2015-01-26 20:49:00 +00:00
|
|
|
sk_tool_utils::draw_checkerboard(canvas);
|
2015-08-21 14:47:23 +00:00
|
|
|
draw_image(canvas, "color_wheel.png", 0, 0); // top left
|
|
|
|
draw_image(canvas, "color_wheel.gif", 128, 0); // top right
|
|
|
|
draw_image(canvas, "color_wheel.webp", 0, 128); // bottom left
|
|
|
|
draw_image(canvas, "color_wheel.jpg", 128, 128); // bottom right
|
2014-10-26 12:23:53 +00:00
|
|
|
}
|
2014-12-02 17:37:17 +00:00
|
|
|
|
|
|
|
DEF_SIMPLE_GM(colorwheelnative, canvas, 128, 28) {
|
|
|
|
SkPaint paint;
|
2017-07-27 14:45:29 +00:00
|
|
|
sk_tool_utils::set_portable_typeface(&paint, "sans-serif", SkFontStyle::Bold());
|
2014-12-02 17:37:17 +00:00
|
|
|
paint.setTextSize(18.0f);
|
|
|
|
|
2015-07-15 16:29:32 +00:00
|
|
|
canvas->clear(sk_tool_utils::color_to_565(SK_ColorLTGRAY));
|
2014-12-02 17:37:17 +00:00
|
|
|
paint.setColor(SK_ColorRED);
|
2017-04-28 19:35:12 +00:00
|
|
|
canvas->drawString("R", 8.0f, 20.0f, paint);
|
2014-12-02 17:37:17 +00:00
|
|
|
paint.setColor(SK_ColorGREEN);
|
2017-04-28 19:35:12 +00:00
|
|
|
canvas->drawString("G", 24.0f, 20.0f, paint);
|
2014-12-02 17:37:17 +00:00
|
|
|
paint.setColor(SK_ColorBLUE);
|
2017-04-28 19:35:12 +00:00
|
|
|
canvas->drawString("B", 40.0f, 20.0f, paint);
|
2014-12-02 17:37:17 +00:00
|
|
|
paint.setColor(SK_ColorCYAN);
|
2017-04-28 19:35:12 +00:00
|
|
|
canvas->drawString("C", 56.0f, 20.0f, paint);
|
2014-12-02 17:37:17 +00:00
|
|
|
paint.setColor(SK_ColorMAGENTA);
|
2017-04-28 19:35:12 +00:00
|
|
|
canvas->drawString("M", 72.0f, 20.0f, paint);
|
2014-12-02 17:37:17 +00:00
|
|
|
paint.setColor(SK_ColorYELLOW);
|
2017-04-28 19:35:12 +00:00
|
|
|
canvas->drawString("Y", 88.0f, 20.0f, paint);
|
2014-12-02 17:37:17 +00:00
|
|
|
paint.setColor(SK_ColorBLACK);
|
2017-04-28 19:35:12 +00:00
|
|
|
canvas->drawString("K", 104.0f, 20.0f, paint);
|
2014-12-02 17:37:17 +00:00
|
|
|
}
|