cmykjpeg.cpp revision 80bacfeb4bda06541e8695bd502229727bccfeab
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            SkDELETE(codec);
41        }
42    }
43
44protected:
45    virtual SkString onShortName() {
46        return SkString("cmykjpeg");
47    }
48
49    virtual SkISize onISize() {
50        return make_isize(640, 480);
51    }
52
53    virtual void onDraw(SkCanvas* canvas) {
54
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
65void forceLinking();
66
67void forceLinking() {
68    SkImageDecoder *creator = CreateJPEGImageDecoder();
69    SkASSERT(creator);
70}
71
72//////////////////////////////////////////////////////////////////////////////
73
74static GM* MyFactory(void*) { return new CMYKJpegGM; }
75static GMRegistry reg(MyFactory);
76
77}
78