2012-03-20 14:51:47 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm.h"
|
2014-06-18 21:32:48 +00:00
|
|
|
|
|
|
|
#include "Resources.h"
|
2012-03-20 14:51:47 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkImageDecoder.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
/** Draw a CMYK encoded jpeg - libjpeg doesn't support CMYK->RGB
|
|
|
|
conversion so this tests Skia's internal processing
|
|
|
|
*/
|
|
|
|
class CMYKJpegGM : public GM {
|
|
|
|
public:
|
2012-11-29 21:05:37 +00:00
|
|
|
CMYKJpegGM() {}
|
|
|
|
|
|
|
|
protected:
|
2015-01-09 18:06:39 +00:00
|
|
|
void onOnceBeforeDraw() SK_OVERRIDE {
|
2012-03-20 14:51:47 +00:00
|
|
|
// parameters to the "decode" call
|
|
|
|
bool dither = false;
|
|
|
|
|
2014-07-01 19:35:49 +00:00
|
|
|
SkString jpgFilename = GetResourcePath("CMYK.jpg");
|
|
|
|
SkFILEStream stream(jpgFilename.c_str());
|
2013-05-29 14:53:48 +00:00
|
|
|
if (!stream.isValid()) {
|
|
|
|
SkDebugf("Could not find CMYK.jpg, please set --resourcePath correctly.\n");
|
|
|
|
return;
|
|
|
|
}
|
2013-05-30 07:01:29 +00:00
|
|
|
|
2012-03-20 14:51:47 +00:00
|
|
|
SkImageDecoder* codec = SkImageDecoder::Factory(&stream);
|
|
|
|
if (codec) {
|
|
|
|
stream.rewind();
|
|
|
|
codec->setDitherImage(dither);
|
2014-06-13 00:40:00 +00:00
|
|
|
codec->decode(&stream, &fBitmap, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode);
|
2012-07-31 16:37:11 +00:00
|
|
|
SkDELETE(codec);
|
2012-03-20 14:51:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-02 20:08:18 +00:00
|
|
|
virtual SkString onShortName() SK_OVERRIDE {
|
2012-03-20 14:51:47 +00:00
|
|
|
return SkString("cmykjpeg");
|
|
|
|
}
|
|
|
|
|
2015-02-02 20:08:18 +00:00
|
|
|
virtual SkISize onISize() SK_OVERRIDE {
|
2014-06-10 06:59:03 +00:00
|
|
|
return SkISize::Make(640, 480);
|
2012-03-20 14:51:47 +00:00
|
|
|
}
|
|
|
|
|
2015-02-02 20:08:18 +00:00
|
|
|
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
2012-03-20 14:51:47 +00:00
|
|
|
|
|
|
|
canvas->translate(20*SK_Scalar1, 20*SK_Scalar1);
|
|
|
|
canvas->drawBitmap(fBitmap, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkBitmap fBitmap;
|
|
|
|
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static GM* MyFactory(void*) { return new CMYKJpegGM; }
|
|
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
|
|
|
|
}
|