diff options
author | humper@google.com <humper@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-07-09 17:48:15 +0000 |
---|---|---|
committer | humper@google.com <humper@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-07-09 17:48:15 +0000 |
commit | 25fc6b9bfb3f9c2839b463b69b86ce9ed206c763 (patch) | |
tree | f4c6f78e86f69872343f937c15c1747538531976 /bench | |
parent | 64527e9caa4d38c0c113ce3de3ccf3c6e40eef05 (diff) |
More general image filter interface; tested implementation of standalone
image scaler (not yet plumbed). High quality downsampler. Fast SSE
resampler.
BUG=
R=reed@google.com
Review URL: https://codereview.chromium.org/17381008
git-svn-id: http://skia.googlecode.com/svn/trunk@9936 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'bench')
-rw-r--r-- | bench/BitmapBench.cpp | 8 | ||||
-rw-r--r-- | bench/BitmapScaleBench.cpp | 135 |
2 files changed, 139 insertions, 4 deletions
diff --git a/bench/BitmapBench.cpp b/bench/BitmapBench.cpp index 3bf6b779cb..d8363fcb9d 100644 --- a/bench/BitmapBench.cpp +++ b/bench/BitmapBench.cpp @@ -149,7 +149,7 @@ protected: int count = N; #ifdef SK_RELEASE // in DEBUG, N is always 1 - if (paint.getFlags() & SkPaint::kBicubicFilterBitmap_Flag) { + if (paint.getFlags() & SkPaint::kHighQualityFilterBitmap_Flag) { count /= BICUBIC_DUR_SCALE; } #endif @@ -170,7 +170,7 @@ protected: #ifdef SK_DEBUG return 1; #else - return (paint.getFlags() & SkPaint::kBicubicFilterBitmap_Flag) ? + return (paint.getFlags() & SkPaint::kHighQualityFilterBitmap_Flag) ? (float)BICUBIC_DUR_SCALE : 1; #endif } @@ -266,12 +266,12 @@ protected: } uint32_t orMask = 0; - uint32_t clearMask = SkPaint::kFilterBitmap_Flag | SkPaint::kBicubicFilterBitmap_Flag; + uint32_t clearMask = SkPaint::kFilterBitmap_Flag | SkPaint::kHighQualityFilterBitmap_Flag; if (fFlags & kBilerp_Flag) { orMask |= SkPaint::kFilterBitmap_Flag; } if (fFlags & kBicubic_Flag) { - orMask |= SkPaint::kBicubicFilterBitmap_Flag; + orMask |= SkPaint::kHighQualityFilterBitmap_Flag; } this->setPaintMasks(orMask, clearMask); diff --git a/bench/BitmapScaleBench.cpp b/bench/BitmapScaleBench.cpp new file mode 100644 index 0000000000..45ea1b46ef --- /dev/null +++ b/bench/BitmapScaleBench.cpp @@ -0,0 +1,135 @@ +/* + * Copyright 2013 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkBenchmark.h" +#include "SkCanvas.h" +#include "SkPaint.h" +#include "SkRandom.h" +#include "SkShader.h" +#include "SkString.h" +#include "SkBlurMask.h" + +class BitmapScaleBench: public SkBenchmark { + int fLoopCount; + int fInputSize; + int fOutputSize; + SkString fName; + +public: + BitmapScaleBench(void *param, int is, int os) : INHERITED(param) { + fInputSize = is; + fOutputSize = os; + + fLoopCount = 100; + } + +protected: + + SkBitmap fInputBitmap, fOutputBitmap; + SkMatrix fMatrix; + + virtual const char* onGetName() { + return fName.c_str(); + } + + int inputSize() const { + return fInputSize; + } + + int outputSize() const { + return fOutputSize; + } + + float scale() const { + return float(outputSize())/inputSize(); + } + + SkIPoint onGetSize() SK_OVERRIDE { + return SkIPoint::Make( fOutputSize, fOutputSize ); + } + + void setName(const char * name) { + fName.printf( "bitmap_scale_%s_%d_%d", name, fInputSize, fOutputSize ); + } + + virtual void onPreDraw() { + fInputBitmap.setConfig(SkBitmap::kARGB_8888_Config, fInputSize, fInputSize); + fInputBitmap.allocPixels(); + fInputBitmap.eraseColor(SK_ColorWHITE); + fInputBitmap.setIsOpaque(true); + + fOutputBitmap.setConfig(SkBitmap::kARGB_8888_Config, fOutputSize, fOutputSize); + fOutputBitmap.allocPixels(); + fOutputBitmap.setIsOpaque(true); + + fMatrix.setScale( scale(), scale() ); + } + + virtual void onDraw(SkCanvas*) { + SkPaint paint; + this->setupPaint(&paint); + + preBenchSetup(); + + for (int i = 0; i < SkBENCHLOOP(fLoopCount); i++) { + doScaleImage(); + } + } + + virtual void doScaleImage() = 0; + virtual void preBenchSetup() {} +private: + typedef SkBenchmark INHERITED; +}; + +class BitmapFilterScaleBench: public BitmapScaleBench { + public: + BitmapFilterScaleBench(void *param, int is, int os) : INHERITED(param, is, os) { + setName( "filter" ); + } +protected: + virtual void doScaleImage() SK_OVERRIDE { + SkCanvas canvas( fOutputBitmap ); + SkPaint paint; + + paint.setFlags( SkPaint::kHighQualityFilterBitmap_Flag | SkPaint::kFilterBitmap_Flag ); + + canvas.drawBitmapMatrix( fInputBitmap, fMatrix, &paint ); + } +private: + typedef BitmapScaleBench INHERITED; +}; + +class BitmapDirectScaleBench: public BitmapScaleBench { + public: + BitmapDirectScaleBench(void *param, int is, int os) : INHERITED(param, is, os) { + setName( "direct" ); + } +protected: + virtual void doScaleImage() SK_OVERRIDE { + fInputBitmap.scale( &fOutputBitmap ); + } +private: + typedef BitmapScaleBench INHERITED; +}; + + +DEF_BENCH(return new BitmapFilterScaleBench(p, 10, 90);) +DEF_BENCH(return new BitmapFilterScaleBench(p, 30, 90);) +DEF_BENCH(return new BitmapFilterScaleBench(p, 80, 90);) +// DEF_BENCH(return new BitmapFilterScaleBench(p, 90, 90);) +// DEF_BENCH(return new BitmapFilterScaleBench(p, 90, 80);) +// DEF_BENCH(return new BitmapFilterScaleBench(p, 90, 30);) +// DEF_BENCH(return new BitmapFilterScaleBench(p, 90, 10);) + +DEF_BENCH(return new BitmapDirectScaleBench(p, 10, 90);) +DEF_BENCH(return new BitmapDirectScaleBench(p, 30, 90);) +DEF_BENCH(return new BitmapDirectScaleBench(p, 80, 90);) +// DEF_BENCH(return new BitmapDirectScaleBench(p, 90, 90);) +// DEF_BENCH(return new BitmapDirectScaleBench(p, 90, 80);) +// DEF_BENCH(return new BitmapDirectScaleBench(p, 90, 30);) +// DEF_BENCH(return new BitmapDirectScaleBench(p, 90, 10);) |