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" |
tfarina | bcbc178 | 2014-06-18 14:32:48 -0700 | [diff] [blame] | 9 | |
| 10 | #include "Resources.h" |
robertphillips@google.com | d5c9e99 | 2012-03-20 14:51:47 +0000 | [diff] [blame] | 11 | #include "SkCanvas.h" |
| 12 | #include "SkImageDecoder.h" |
| 13 | #include "SkStream.h" |
| 14 | |
| 15 | namespace skiagm { |
| 16 | |
| 17 | /** Draw a CMYK encoded jpeg - libjpeg doesn't support CMYK->RGB |
| 18 | conversion so this tests Skia's internal processing |
| 19 | */ |
| 20 | class CMYKJpegGM : public GM { |
| 21 | public: |
scroggo@google.com | 9f686f3 | 2012-11-29 21:05:37 +0000 | [diff] [blame] | 22 | CMYKJpegGM() {} |
| 23 | |
| 24 | protected: |
| 25 | virtual void onOnceBeforeDraw() SK_OVERRIDE { |
robertphillips@google.com | d5c9e99 | 2012-03-20 14:51:47 +0000 | [diff] [blame] | 26 | // parameters to the "decode" call |
| 27 | bool dither = false; |
robertphillips@google.com | d5c9e99 | 2012-03-20 14:51:47 +0000 | [diff] [blame] | 28 | |
tfarina | c846f4a | 2014-07-01 12:35:49 -0700 | [diff] [blame] | 29 | SkString jpgFilename = GetResourcePath("CMYK.jpg"); |
| 30 | SkFILEStream stream(jpgFilename.c_str()); |
bungeman@google.com | dc8e6e8 | 2013-05-29 14:53:48 +0000 | [diff] [blame] | 31 | if (!stream.isValid()) { |
| 32 | SkDebugf("Could not find CMYK.jpg, please set --resourcePath correctly.\n"); |
| 33 | return; |
| 34 | } |
skia.committer@gmail.com | a5d3e77 | 2013-05-30 07:01:29 +0000 | [diff] [blame] | 35 | |
robertphillips@google.com | d5c9e99 | 2012-03-20 14:51:47 +0000 | [diff] [blame] | 36 | SkImageDecoder* codec = SkImageDecoder::Factory(&stream); |
| 37 | if (codec) { |
| 38 | stream.rewind(); |
| 39 | codec->setDitherImage(dither); |
reed | bfefc7c | 2014-06-12 17:40:00 -0700 | [diff] [blame] | 40 | codec->decode(&stream, &fBitmap, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode); |
scroggo@google.com | 9f75208 | 2012-07-31 16:37:11 +0000 | [diff] [blame] | 41 | SkDELETE(codec); |
robertphillips@google.com | d5c9e99 | 2012-03-20 14:51:47 +0000 | [diff] [blame] | 42 | } |
| 43 | } |
| 44 | |
robertphillips@google.com | d5c9e99 | 2012-03-20 14:51:47 +0000 | [diff] [blame] | 45 | virtual SkString onShortName() { |
| 46 | return SkString("cmykjpeg"); |
| 47 | } |
| 48 | |
| 49 | virtual SkISize onISize() { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 50 | return SkISize::Make(640, 480); |
robertphillips@google.com | d5c9e99 | 2012-03-20 14:51:47 +0000 | [diff] [blame] | 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 | |
| 59 | private: |
| 60 | SkBitmap fBitmap; |
| 61 | |
| 62 | typedef GM INHERITED; |
| 63 | }; |
| 64 | |
robertphillips@google.com | d5c9e99 | 2012-03-20 14:51:47 +0000 | [diff] [blame] | 65 | ////////////////////////////////////////////////////////////////////////////// |
| 66 | |
| 67 | static GM* MyFactory(void*) { return new CMYKJpegGM; } |
| 68 | static GMRegistry reg(MyFactory); |
| 69 | |
| 70 | } |