cmykjpeg.cpp revision d5c9e996dff7169cd6bfbf5c6d1543fca512c1a5
1/*
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
64//////////////////////////////////////////////////////////////////////////////
65
66static GM* MyFactory(void*) { return new CMYKJpegGM; }
67static GMRegistry reg(MyFactory);
68
69}
70