blob: 224aaecbbb048f955d817e14a435b4b1d34625e1 [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"
9#include "SkCanvas.h"
10#include "SkImageDecoder.h"
11#include "SkStream.h"
12
13namespace skiagm {
14
15/** Draw a CMYK encoded jpeg - libjpeg doesn't support CMYK->RGB
16 conversion so this tests Skia's internal processing
17*/
18class CMYKJpegGM : public GM {
19public:
20 CMYKJpegGM() {
21
22 // parameters to the "decode" call
23 bool dither = false;
24 SkBitmap::Config prefConfig = SkBitmap::kARGB_8888_Config;
25
26 SkString filename(INHERITED::gResourcePath);
27 if (!filename.endsWith("/") && !filename.endsWith("\\")) {
28 filename.append("/");
29 }
30
31 filename.append("CMYK.jpg");
32
33 SkFILEStream stream(filename.c_str());
34 SkImageDecoder* codec = SkImageDecoder::Factory(&stream);
35 if (codec) {
36 stream.rewind();
37 codec->setDitherImage(dither);
38 codec->decode(&stream, &fBitmap, prefConfig,
39 SkImageDecoder::kDecodePixels_Mode);
40 }
41 }
42
43protected:
44 virtual SkString onShortName() {
45 return SkString("cmykjpeg");
46 }
47
48 virtual SkISize onISize() {
49 return make_isize(640, 480);
50 }
51
52 virtual void onDraw(SkCanvas* canvas) {
53
54 canvas->translate(20*SK_Scalar1, 20*SK_Scalar1);
55 canvas->drawBitmap(fBitmap, 0, 0);
56 }
57
58private:
59 SkBitmap fBitmap;
60
61 typedef GM INHERITED;
62};
63
robertphillips@google.comec51cb82012-03-23 18:13:47 +000064void forceLinking() {
65 SkImageDecoder *creator = CreateJPEGImageDecoder();
66}
67
robertphillips@google.comd5c9e992012-03-20 14:51:47 +000068//////////////////////////////////////////////////////////////////////////////
69
70static GM* MyFactory(void*) { return new CMYKJpegGM; }
71static GMRegistry reg(MyFactory);
72
73}