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: |
scroggo@google.com | 9f686f3 | 2012-11-29 21:05:37 +0000 | [diff] [blame] | 20 | CMYKJpegGM() {} |
| 21 | |
| 22 | protected: |
| 23 | virtual void onOnceBeforeDraw() SK_OVERRIDE { |
robertphillips@google.com | d5c9e99 | 2012-03-20 14:51:47 +0000 | [diff] [blame] | 24 | |
| 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()); |
bungeman@google.com | dc8e6e8 | 2013-05-29 14:53:48 +0000 | [diff] [blame] | 37 | if (!stream.isValid()) { |
| 38 | SkDebugf("Could not find CMYK.jpg, please set --resourcePath correctly.\n"); |
| 39 | return; |
| 40 | } |
skia.committer@gmail.com | a5d3e77 | 2013-05-30 07:01:29 +0000 | [diff] [blame] | 41 | |
robertphillips@google.com | d5c9e99 | 2012-03-20 14:51:47 +0000 | [diff] [blame] | 42 | SkImageDecoder* codec = SkImageDecoder::Factory(&stream); |
| 43 | if (codec) { |
| 44 | stream.rewind(); |
| 45 | codec->setDitherImage(dither); |
| 46 | codec->decode(&stream, &fBitmap, prefConfig, |
| 47 | SkImageDecoder::kDecodePixels_Mode); |
scroggo@google.com | 9f75208 | 2012-07-31 16:37:11 +0000 | [diff] [blame] | 48 | SkDELETE(codec); |
robertphillips@google.com | d5c9e99 | 2012-03-20 14:51:47 +0000 | [diff] [blame] | 49 | } |
| 50 | } |
| 51 | |
robertphillips@google.com | d5c9e99 | 2012-03-20 14:51:47 +0000 | [diff] [blame] | 52 | virtual SkString onShortName() { |
| 53 | return SkString("cmykjpeg"); |
| 54 | } |
| 55 | |
| 56 | virtual SkISize onISize() { |
| 57 | return make_isize(640, 480); |
| 58 | } |
| 59 | |
| 60 | virtual void onDraw(SkCanvas* canvas) { |
| 61 | |
| 62 | canvas->translate(20*SK_Scalar1, 20*SK_Scalar1); |
| 63 | canvas->drawBitmap(fBitmap, 0, 0); |
| 64 | } |
| 65 | |
| 66 | private: |
| 67 | SkBitmap fBitmap; |
| 68 | |
| 69 | typedef GM INHERITED; |
| 70 | }; |
| 71 | |
robertphillips@google.com | d5c9e99 | 2012-03-20 14:51:47 +0000 | [diff] [blame] | 72 | ////////////////////////////////////////////////////////////////////////////// |
| 73 | |
| 74 | static GM* MyFactory(void*) { return new CMYKJpegGM; } |
| 75 | static GMRegistry reg(MyFactory); |
| 76 | |
| 77 | } |