blob: a1a12dc3885b41ce7e368c6830e1f0bd57800965 [file] [log] [blame]
robertphillips@google.comd5c9e992012-03-20 14:51:47 +00001/*
2 * Copyright 2012 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.h"
tfarinabcbc1782014-06-18 14:32:48 -07009
10#include "Resources.h"
robertphillips@google.comd5c9e992012-03-20 14:51:47 +000011#include "SkCanvas.h"
12#include "SkImageDecoder.h"
13#include "SkStream.h"
14
15namespace skiagm {
16
17/** Draw a CMYK encoded jpeg - libjpeg doesn't support CMYK->RGB
18 conversion so this tests Skia's internal processing
19*/
20class CMYKJpegGM : public GM {
21public:
scroggo@google.com9f686f32012-11-29 21:05:37 +000022 CMYKJpegGM() {}
23
24protected:
25 virtual void onOnceBeforeDraw() SK_OVERRIDE {
robertphillips@google.comd5c9e992012-03-20 14:51:47 +000026 // parameters to the "decode" call
27 bool dither = false;
robertphillips@google.comd5c9e992012-03-20 14:51:47 +000028
tfarinabcbc1782014-06-18 14:32:48 -070029 SkString resourcePath = GetResourcePath();
30 if (!resourcePath.endsWith("/") && !resourcePath.endsWith("\\")) {
31 resourcePath.append("/");
robertphillips@google.comd5c9e992012-03-20 14:51:47 +000032 }
33
tfarinabcbc1782014-06-18 14:32:48 -070034 resourcePath.append("CMYK.jpg");
robertphillips@google.comd5c9e992012-03-20 14:51:47 +000035
tfarinabcbc1782014-06-18 14:32:48 -070036 SkFILEStream stream(resourcePath.c_str());
bungeman@google.comdc8e6e82013-05-29 14:53:48 +000037 if (!stream.isValid()) {
38 SkDebugf("Could not find CMYK.jpg, please set --resourcePath correctly.\n");
39 return;
40 }
skia.committer@gmail.coma5d3e772013-05-30 07:01:29 +000041
robertphillips@google.comd5c9e992012-03-20 14:51:47 +000042 SkImageDecoder* codec = SkImageDecoder::Factory(&stream);
43 if (codec) {
44 stream.rewind();
45 codec->setDitherImage(dither);
reedbfefc7c2014-06-12 17:40:00 -070046 codec->decode(&stream, &fBitmap, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode);
scroggo@google.com9f752082012-07-31 16:37:11 +000047 SkDELETE(codec);
robertphillips@google.comd5c9e992012-03-20 14:51:47 +000048 }
49 }
50
robertphillips@google.comd5c9e992012-03-20 14:51:47 +000051 virtual SkString onShortName() {
52 return SkString("cmykjpeg");
53 }
54
55 virtual SkISize onISize() {
tfarinaf5393182014-06-09 23:59:03 -070056 return SkISize::Make(640, 480);
robertphillips@google.comd5c9e992012-03-20 14:51:47 +000057 }
58
59 virtual void onDraw(SkCanvas* canvas) {
60
61 canvas->translate(20*SK_Scalar1, 20*SK_Scalar1);
62 canvas->drawBitmap(fBitmap, 0, 0);
63 }
64
65private:
66 SkBitmap fBitmap;
67
68 typedef GM INHERITED;
69};
70
robertphillips@google.comd5c9e992012-03-20 14:51:47 +000071//////////////////////////////////////////////////////////////////////////////
72
73static GM* MyFactory(void*) { return new CMYKJpegGM; }
74static GMRegistry reg(MyFactory);
75
76}