diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-05-27 20:54:04 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-05-27 20:54:04 +0000 |
commit | 44f41293ac94530d08fca2ce8484a7248e7a5e97 (patch) | |
tree | e73cfb7f119225876abbb90589f8c771eb022c22 /gm | |
parent | 61a03b78d6abefdf86889e988d4596181488f981 (diff) |
floating point scale factors for images
New version of https://codereview.chromium.org/298243003/ made to deal with binary file being lost.
BUG=
TBR=bsalomon
NOTRY=true
Author: humper@google.com
Review URL: https://codereview.chromium.org/307553005
git-svn-id: http://skia.googlecode.com/svn/trunk@14905 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm')
-rw-r--r-- | gm/filterindiabox.cpp | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/gm/filterindiabox.cpp b/gm/filterindiabox.cpp new file mode 100644 index 0000000000..01a46d2ce0 --- /dev/null +++ b/gm/filterindiabox.cpp @@ -0,0 +1,139 @@ +/* + * 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" +#include "SkStream.h" + +#include "SkImageEncoder.h" +#include "SkBitmapScaler.h" +#include "SkBitmapProcState.h" + +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()); +} + +static void draw_row(SkCanvas* canvas, const SkBitmap& bm, const SkMatrix& mat, SkScalar dx) { + SkPaint paint; + + SkAutoCanvasRestore acr(canvas, true); + + canvas->drawBitmapMatrix(bm, mat, &paint); + + paint.setFilterLevel(SkPaint::kLow_FilterLevel); + canvas->translate(dx, 0); + canvas->drawBitmapMatrix(bm, mat, &paint); + + paint.setFilterLevel(SkPaint::kMedium_FilterLevel); + canvas->translate(dx, 0); + canvas->drawBitmapMatrix(bm, mat, &paint); + + paint.setFilterLevel(SkPaint::kHigh_FilterLevel); + canvas->translate(dx, 0); + canvas->drawBitmapMatrix(bm, mat, &paint); +} + +class FilterIndiaBoxGM : public skiagm::GM { + void onOnceBeforeDraw() { + + this->makeBitmap(); + + SkScalar cx = SkScalarHalf(fBM.width()); + SkScalar cy = SkScalarHalf(fBM.height()); + + float vertScale = 30.0/55.0; + float horizScale = 150.0/200.0; + + fMatrix[0].setScale(horizScale, vertScale); + fMatrix[1].setRotate(30, cx, cy); fMatrix[1].postScale(horizScale, vertScale); + } + +public: + SkBitmap fBM; + SkMatrix fMatrix[2]; + SkString fName; + + FilterIndiaBoxGM() + { + this->setBGColor(0xFFDDDDDD); + } + + FilterIndiaBoxGM(const char filename[]) + : fFilename(filename) + { + fName.printf("filterindiabox"); + } + +protected: + virtual uint32_t onGetFlags() const SK_OVERRIDE { + return kSkipTiled_Flag; + } + + virtual SkString onShortName() SK_OVERRIDE { + return fName; + } + + virtual SkISize onISize() SK_OVERRIDE { + return SkISize::Make(1024, 768); + } + + virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { + + 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() { + SkString path(skiagm::GM::gResourcePath); + path.append("/"); + path.append(fFilename); + + SkImageDecoder *codec = NULL; + SkFILEStream stream(path.c_str()); + if (stream.isValid()) { + codec = SkImageDecoder::Factory(&stream); + } + if (codec) { + stream.rewind(); + codec->decode(&stream, &fBM, SkBitmap::kARGB_8888_Config, + SkImageDecoder::kDecodePixels_Mode); + SkDELETE(codec); + } else { + fBM.allocN32Pixels(1, 1); + *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad + } + fSize = fBM.height(); + } + private: + typedef skiagm::GM INHERITED; +}; + +////////////////////////////////////////////////////////////////////////////// + + +DEF_GM( return new FilterIndiaBoxGM("box.gif"); ) |