2014-05-28 17:30:02 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-03-20 16:12:10 +00:00
|
|
|
#include "ToolUtils.h"
|
2014-05-28 17:30:02 +00:00
|
|
|
#include "gm.h"
|
|
|
|
|
2014-06-18 21:32:48 +00:00
|
|
|
#include "Resources.h"
|
|
|
|
#include "SkBitmapProcState.h"
|
|
|
|
#include "SkGradientShader.h"
|
2014-05-28 17:30:02 +00:00
|
|
|
#include "SkImageEncoder.h"
|
2014-06-18 21:32:48 +00:00
|
|
|
#include "SkStream.h"
|
|
|
|
#include "SkTypeface.h"
|
2014-05-28 17:30:02 +00:00
|
|
|
|
|
|
|
static SkSize computeSize(const SkBitmap& bm, const SkMatrix& mat) {
|
|
|
|
SkRect bounds = SkRect::MakeWH(SkIntToScalar(bm.width()),
|
|
|
|
SkIntToScalar(bm.height()));
|
|
|
|
mat.mapRect(&bounds);
|
|
|
|
return SkSize::Make(bounds.width(), bounds.height());
|
|
|
|
}
|
|
|
|
|
2014-12-10 17:02:16 +00:00
|
|
|
static void draw_cell(SkCanvas* canvas, const SkBitmap& bm, const SkMatrix& mat, SkScalar dx,
|
2015-03-16 17:08:34 +00:00
|
|
|
SkFilterQuality lvl) {
|
2014-05-28 17:30:02 +00:00
|
|
|
SkPaint paint;
|
2015-03-16 17:08:34 +00:00
|
|
|
paint.setFilterQuality(lvl);
|
2014-05-28 17:30:02 +00:00
|
|
|
|
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
|
|
|
|
canvas->translate(dx, 0);
|
2014-12-10 17:02:16 +00:00
|
|
|
canvas->concat(mat);
|
|
|
|
canvas->drawBitmap(bm, 0, 0, &paint);
|
|
|
|
}
|
2014-05-28 17:30:02 +00:00
|
|
|
|
2014-12-10 17:02:16 +00:00
|
|
|
static void draw_row(SkCanvas* canvas, const SkBitmap& bm, const SkMatrix& mat, SkScalar dx) {
|
2015-03-16 17:08:34 +00:00
|
|
|
draw_cell(canvas, bm, mat, 0 * dx, kNone_SkFilterQuality);
|
|
|
|
draw_cell(canvas, bm, mat, 1 * dx, kLow_SkFilterQuality);
|
|
|
|
draw_cell(canvas, bm, mat, 2 * dx, kMedium_SkFilterQuality);
|
|
|
|
draw_cell(canvas, bm, mat, 3 * dx, kHigh_SkFilterQuality);
|
2014-05-28 17:30:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class FilterIndiaBoxGM : public skiagm::GM {
|
2015-03-26 01:17:31 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2014-05-28 17:30:02 +00:00
|
|
|
this->makeBitmap();
|
|
|
|
|
|
|
|
SkScalar cx = SkScalarHalf(fBM.width());
|
|
|
|
SkScalar cy = SkScalarHalf(fBM.height());
|
|
|
|
|
|
|
|
float vertScale = 30.0f/55.0f;
|
|
|
|
float horizScale = 150.0f/200.0f;
|
|
|
|
|
|
|
|
fMatrix[0].setScale(horizScale, vertScale);
|
|
|
|
fMatrix[1].setRotate(30, cx, cy); fMatrix[1].postScale(horizScale, vertScale);
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
SkBitmap fBM;
|
|
|
|
SkMatrix fMatrix[2];
|
|
|
|
SkString fName;
|
|
|
|
|
2019-03-20 16:12:10 +00:00
|
|
|
FilterIndiaBoxGM() { this->setBGColor(ToolUtils::color_to_565(0xFFDDDDDD)); }
|
2014-05-28 17:30:02 +00:00
|
|
|
|
2014-06-13 00:40:00 +00:00
|
|
|
FilterIndiaBoxGM(const char filename[]) : fFilename(filename) {
|
2014-05-28 17:30:02 +00:00
|
|
|
fName.printf("filterindiabox");
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2014-05-28 17:30:02 +00:00
|
|
|
return fName;
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2017-07-19 21:20:37 +00:00
|
|
|
return SkISize::Make(680, 130);
|
2014-05-28 17:30:02 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2014-05-28 17:30:02 +00:00
|
|
|
canvas->translate(10, 10);
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(fMatrix); ++i) {
|
|
|
|
SkSize size = computeSize(fBM, fMatrix[i]);
|
|
|
|
size.fWidth += 20;
|
|
|
|
size.fHeight += 20;
|
|
|
|
|
|
|
|
draw_row(canvas, fBM, fMatrix[i], size.fWidth);
|
|
|
|
canvas->translate(0, size.fHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkString fFilename;
|
|
|
|
int fSize;
|
|
|
|
|
|
|
|
SkScalar getScale() {
|
|
|
|
return 192.f/fSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
void makeBitmap() {
|
2016-03-18 19:13:47 +00:00
|
|
|
if (!GetResourceAsBitmap(fFilename.c_str(), &fBM)) {
|
|
|
|
fBM.allocN32Pixels(1, 1);
|
|
|
|
fBM.eraseARGB(255, 255, 0 , 0); // red == bad
|
|
|
|
}
|
|
|
|
fSize = fBM.height();
|
2014-05-28 17:30:02 +00:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef skiagm::GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2017-12-08 15:21:31 +00:00
|
|
|
DEF_GM( return new FilterIndiaBoxGM("images/box.gif"); )
|