skia2/gm/cmykjpeg.cpp
tfarina c846f4a96b Cleanup usage of GetResourcePath() after commit bcbc1788b4.
There was a clean up opportunity left over after
https://skia.googlesource.com/skia/+/bcbc1788b478b1e54079318ad073e8490aa66fae, that could make use of the default parameter of GetResourcePath() function to make some call sites cleaner.

We decided to make it in a separate CL to make reviewer's and author's life easier, so we could catch errors and/or mistakes easily.

BUG=None
TEST=make all && out/Debug/dm && out/Debug/SampleApp
R=mtklein@google.com

Author: tfarina@chromium.org

Review URL: https://codereview.chromium.org/351133003
2014-07-01 12:35:49 -07:00

71 lines
1.7 KiB
C++

/*
* 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"
#include "Resources.h"
#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:
CMYKJpegGM() {}
protected:
virtual void onOnceBeforeDraw() SK_OVERRIDE {
// parameters to the "decode" call
bool dither = false;
SkString jpgFilename = GetResourcePath("CMYK.jpg");
SkFILEStream stream(jpgFilename.c_str());
if (!stream.isValid()) {
SkDebugf("Could not find CMYK.jpg, please set --resourcePath correctly.\n");
return;
}
SkImageDecoder* codec = SkImageDecoder::Factory(&stream);
if (codec) {
stream.rewind();
codec->setDitherImage(dither);
codec->decode(&stream, &fBitmap, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode);
SkDELETE(codec);
}
}
virtual SkString onShortName() {
return SkString("cmykjpeg");
}
virtual SkISize onISize() {
return SkISize::Make(640, 480);
}
virtual void onDraw(SkCanvas* canvas) {
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);
}