diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-05-28 15:29:25 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-05-28 15:29:25 +0000 |
commit | f2de1e286b8afd3dcdd74ea8e136d4b3800f458d (patch) | |
tree | 4784c6fdbc8a390852fd1033b5f4dcfa67f73b07 | |
parent | 9d33154b1362d89454297c21663b2403f1a75de5 (diff) |
add new gm for bicubic filtering
BUG=
Review URL: https://codereview.chromium.org/16123003
git-svn-id: http://skia.googlecode.com/svn/trunk@9291 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | gm/filterbitmap.cpp | 114 | ||||
-rw-r--r-- | gyp/gmslides.gypi | 1 |
2 files changed, 115 insertions, 0 deletions
diff --git a/gm/filterbitmap.cpp b/gm/filterbitmap.cpp new file mode 100644 index 0000000000..efb3d1077a --- /dev/null +++ b/gm/filterbitmap.cpp @@ -0,0 +1,114 @@ +/* + * Copyright 2011 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 "SkGradientShader.h" + +#include "SkTypeface.h" +#include "SkImageDecoder.h" +static void load_bm(SkBitmap* bm) { +// SkImageDecoder::DecodeFile("/skia/trunk/books.jpg", bm); + + bm->setConfig(SkBitmap::kARGB_8888_Config, 160, 120); + bm->allocPixels(); + SkCanvas canvas(*bm); + canvas.drawColor(SK_ColorWHITE); + + SkPaint paint; + paint.setAntiAlias(true); + paint.setSubpixelText(true); + paint.setTextSize(17); + + paint.setTypeface(SkTypeface::CreateFromName("Times", SkTypeface::kNormal))->unref(); + canvas.drawText("Hamburgefons", 12, 10, 25, paint); + paint.setTypeface(SkTypeface::CreateFromName("Times", SkTypeface::kItalic))->unref(); + canvas.drawText("Hamburgefons", 12, 10, 50, paint); + paint.setTypeface(SkTypeface::CreateFromName("Times", SkTypeface::kBold))->unref(); + canvas.drawText("Hamburgefons", 12, 10, 75, paint); + paint.setTypeface(SkTypeface::CreateFromName("Times", SkTypeface::kBoldItalic))->unref(); + canvas.drawText("Hamburgefons", 12, 10, 100, paint); +} + +static SkSize computeSize(const SkBitmap& bm, const SkMatrix& mat) { + SkRect bounds = { 0, 0, bm.width(), bm.height() }; + mat.mapRect(&bounds); + return SkSize::Make(bounds.width(), bounds.height()); +} + +static void draw_col(SkCanvas* canvas, const SkBitmap& bm, const SkMatrix& mat, + SkScalar dx) { + SkPaint paint; + + SkAutoCanvasRestore acr(canvas, true); + + canvas->drawBitmapMatrix(bm, mat, &paint); + + paint.setFilterBitmap(true); + canvas->translate(dx, 0); + canvas->drawBitmapMatrix(bm, mat, &paint); + + paint.setFlags(paint.getFlags() | SkPaint::kBicubicFilterBitmap_Flag); + canvas->translate(dx, 0); + canvas->drawBitmapMatrix(bm, mat, &paint); +} + +class FilterBitmapGM : public skiagm::GM { + bool fOnce; + void init() { + if (fOnce) { + return; + } + fOnce = true; + load_bm(&fBM); + + SkScalar cx = SkScalarHalf(fBM.width()); + SkScalar cy = SkScalarHalf(fBM.height()); + SkScalar scale = 1.6f; + + fMatrix[0].setScale(scale, scale); + fMatrix[1].setRotate(30, cx, cy); fMatrix[1].postScale(scale, scale); + } + +public: + SkBitmap fBM; + SkMatrix fMatrix[2]; + + FilterBitmapGM() : fOnce(false) { + this->setBGColor(0xFFDDDDDD); + } + +protected: + virtual SkString onShortName() SK_OVERRIDE { + return SkString("filterbitmap"); + } + + virtual SkISize onISize() SK_OVERRIDE { + return SkISize::Make(920, 480); + } + + virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { + this->init(); + + 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_col(canvas, fBM, fMatrix[i], size.fWidth); + canvas->translate(0, size.fHeight); + } + } + +private: + typedef skiagm::GM INHERITED; +}; + +////////////////////////////////////////////////////////////////////////////// + +DEF_GM( return new FilterBitmapGM; ) + diff --git a/gyp/gmslides.gypi b/gyp/gmslides.gypi index 607fc37b91..b37154c628 100644 --- a/gyp/gmslides.gypi +++ b/gyp/gmslides.gypi @@ -39,6 +39,7 @@ '../gm/factory.cpp', '../gm/filltypes.cpp', '../gm/filltypespersp.cpp', + '../gm/filterbitmap.cpp', '../gm/fontmgr.cpp', '../gm/fontscaler.cpp', '../gm/gammatext.cpp', |