blob: 4d628b411ed1a4c1119bb359d6e70a3c0bfaf123 [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
caryclark@google.com13130862012-06-06 12:10:45 +000064void forceLinking();
65
robertphillips@google.comec51cb82012-03-23 18:13:47 +000066void forceLinking() {
67 SkImageDecoder *creator = CreateJPEGImageDecoder();
caryclark@google.com13130862012-06-06 12:10:45 +000068 SkASSERT(creator);
robertphillips@google.comec51cb82012-03-23 18:13:47 +000069}
70
robertphillips@google.comd5c9e992012-03-20 14:51:47 +000071//////////////////////////////////////////////////////////////////////////////
72
73static GM* MyFactory(void*) { return new CMYKJpegGM; }
74static GMRegistry reg(MyFactory);
75
76}