blob: 7ac42592a86bf76aee40af88c5d63b3b9ef93ec8 [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:
scroggo@google.com9f686f32012-11-29 21:05:37 +000020 CMYKJpegGM() {}
21
22protected:
23 virtual void onOnceBeforeDraw() SK_OVERRIDE {
robertphillips@google.comd5c9e992012-03-20 14:51:47 +000024
25 // parameters to the "decode" call
26 bool dither = false;
27 SkBitmap::Config prefConfig = SkBitmap::kARGB_8888_Config;
28
29 SkString filename(INHERITED::gResourcePath);
30 if (!filename.endsWith("/") && !filename.endsWith("\\")) {
31 filename.append("/");
32 }
33
34 filename.append("CMYK.jpg");
35
36 SkFILEStream stream(filename.c_str());
37 SkImageDecoder* codec = SkImageDecoder::Factory(&stream);
38 if (codec) {
39 stream.rewind();
40 codec->setDitherImage(dither);
41 codec->decode(&stream, &fBitmap, prefConfig,
42 SkImageDecoder::kDecodePixels_Mode);
scroggo@google.com9f752082012-07-31 16:37:11 +000043 SkDELETE(codec);
robertphillips@google.comd5c9e992012-03-20 14:51:47 +000044 }
45 }
46
robertphillips@google.comd5c9e992012-03-20 14:51:47 +000047 virtual SkString onShortName() {
48 return SkString("cmykjpeg");
49 }
50
51 virtual SkISize onISize() {
52 return make_isize(640, 480);
53 }
54
55 virtual void onDraw(SkCanvas* canvas) {
56
57 canvas->translate(20*SK_Scalar1, 20*SK_Scalar1);
58 canvas->drawBitmap(fBitmap, 0, 0);
59 }
60
61private:
62 SkBitmap fBitmap;
63
64 typedef GM INHERITED;
65};
66
caryclark@google.com13130862012-06-06 12:10:45 +000067void forceLinking();
68
robertphillips@google.comec51cb82012-03-23 18:13:47 +000069void forceLinking() {
humper@google.com0e515772013-01-07 19:54:40 +000070 SkDEBUGCODE(SkImageDecoder *creator = ) CreateJPEGImageDecoder();
caryclark@google.com13130862012-06-06 12:10:45 +000071 SkASSERT(creator);
robertphillips@google.comec51cb82012-03-23 18:13:47 +000072}
73
robertphillips@google.comd5c9e992012-03-20 14:51:47 +000074//////////////////////////////////////////////////////////////////////////////
75
76static GM* MyFactory(void*) { return new CMYKJpegGM; }
77static GMRegistry reg(MyFactory);
78
79}