robertphillips@google.com | d5c9e99 | 2012-03-20 14:51:47 +0000 | [diff] [blame] | 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 | |
| 13 | namespace skiagm { |
| 14 | |
| 15 | /** Draw a CMYK encoded jpeg - libjpeg doesn't support CMYK->RGB |
| 16 | conversion so this tests Skia's internal processing |
| 17 | */ |
| 18 | class CMYKJpegGM : public GM { |
| 19 | public: |
| 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 | |
| 43 | protected: |
| 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 | |
| 58 | private: |
| 59 | SkBitmap fBitmap; |
| 60 | |
| 61 | typedef GM INHERITED; |
| 62 | }; |
| 63 | |
caryclark@google.com | 1313086 | 2012-06-06 12:10:45 +0000 | [diff] [blame] | 64 | void forceLinking(); |
| 65 | |
robertphillips@google.com | ec51cb8 | 2012-03-23 18:13:47 +0000 | [diff] [blame] | 66 | void forceLinking() { |
| 67 | SkImageDecoder *creator = CreateJPEGImageDecoder(); |
caryclark@google.com | 1313086 | 2012-06-06 12:10:45 +0000 | [diff] [blame] | 68 | SkASSERT(creator); |
robertphillips@google.com | ec51cb8 | 2012-03-23 18:13:47 +0000 | [diff] [blame] | 69 | } |
| 70 | |
robertphillips@google.com | d5c9e99 | 2012-03-20 14:51:47 +0000 | [diff] [blame] | 71 | ////////////////////////////////////////////////////////////////////////////// |
| 72 | |
| 73 | static GM* MyFactory(void*) { return new CMYKJpegGM; } |
| 74 | static GMRegistry reg(MyFactory); |
| 75 | |
| 76 | } |