blob: d4fb2faa1c23fec509b6ed412c416cf9d147656e [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:
mtklein36352bf2015-03-25 18:17:31 -070025 void onOnceBeforeDraw() 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
tfarinac846f4a2014-07-01 12:35:49 -070029 SkString jpgFilename = GetResourcePath("CMYK.jpg");
30 SkFILEStream stream(jpgFilename.c_str());
bungeman@google.comdc8e6e82013-05-29 14:53:48 +000031 if (!stream.isValid()) {
32 SkDebugf("Could not find CMYK.jpg, please set --resourcePath correctly.\n");
33 return;
34 }
skia.committer@gmail.coma5d3e772013-05-30 07:01:29 +000035
robertphillips@google.comd5c9e992012-03-20 14:51:47 +000036 SkImageDecoder* codec = SkImageDecoder::Factory(&stream);
37 if (codec) {
38 stream.rewind();
39 codec->setDitherImage(dither);
reedbfefc7c2014-06-12 17:40:00 -070040 codec->decode(&stream, &fBitmap, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode);
halcanary385fe4d2015-08-26 13:07:48 -070041 delete codec;
robertphillips@google.comd5c9e992012-03-20 14:51:47 +000042 }
43 }
44
mtklein36352bf2015-03-25 18:17:31 -070045 virtual SkString onShortName() override {
robertphillips@google.comd5c9e992012-03-20 14:51:47 +000046 return SkString("cmykjpeg");
47 }
48
mtklein36352bf2015-03-25 18:17:31 -070049 virtual SkISize onISize() override {
tfarinaf5393182014-06-09 23:59:03 -070050 return SkISize::Make(640, 480);
robertphillips@google.comd5c9e992012-03-20 14:51:47 +000051 }
52
mtklein36352bf2015-03-25 18:17:31 -070053 virtual void onDraw(SkCanvas* canvas) override {
robertphillips@google.comd5c9e992012-03-20 14:51:47 +000054
55 canvas->translate(20*SK_Scalar1, 20*SK_Scalar1);
56 canvas->drawBitmap(fBitmap, 0, 0);
57 }
58
59private:
60 SkBitmap fBitmap;
61
62 typedef GM INHERITED;
63};
64
robertphillips@google.comd5c9e992012-03-20 14:51:47 +000065//////////////////////////////////////////////////////////////////////////////
66
67static GM* MyFactory(void*) { return new CMYKJpegGM; }
68static GMRegistry reg(MyFactory);
69
70}