aboutsummaryrefslogtreecommitdiffhomepage
path: root/samplecode
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-05-29 22:01:08 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-05-29 22:01:08 +0000
commit1803f4eb341dd0209dde8cc7ee0fa4b409fb2704 (patch)
tree88821eea4720cebf71f1705df6fbb4245a5b1197 /samplecode
parent6eac42e3ab68b085117d7f91621276a722b5a3a7 (diff)
new animated sample to show subpixel translate bug with high quality scaling
BUG=1445 R=reed@google.com, robertphillips@google.com Author: humper@google.com Review URL: https://codereview.chromium.org/303123003 git-svn-id: http://skia.googlecode.com/svn/trunk@14981 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'samplecode')
-rw-r--r--samplecode/SampleSubpixelTranslate.cpp126
1 files changed, 126 insertions, 0 deletions
diff --git a/samplecode/SampleSubpixelTranslate.cpp b/samplecode/SampleSubpixelTranslate.cpp
new file mode 100644
index 0000000000..dd1ba110a6
--- /dev/null
+++ b/samplecode/SampleSubpixelTranslate.cpp
@@ -0,0 +1,126 @@
+
+/*
+ * Copyright 2014 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 "SampleCode.h"
+#include "SkBlurMaskFilter.h"
+#include "SkColorPriv.h"
+#include "SkCanvas.h"
+#include "SkImageDecoder.h"
+#include "SkRandom.h"
+#include "SkStream.h"
+
+// Intended to exercise pixel snapping observed with scaled images (and
+// with non-scaled images, but for a different reason): Bug 1145
+
+class SubpixelTranslateView : public SampleView {
+public:
+ SubpixelTranslateView(const char imageFilename[],
+ float horizontalVelocity,
+ float verticalVelocity)
+ : fFilename(imageFilename),
+ fHorizontalVelocity(horizontalVelocity),
+ fVerticalVelocity(verticalVelocity) {
+ SkString path(skiagm::GM::GetResourcePath());
+ 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
+ }
+ fCurPos = SkPoint::Make(0,0);
+ fSize = 200;
+ }
+
+protected:
+ SkBitmap fBM;
+ SkString fFilename;
+ int fSize;
+ float fHorizontalVelocity, fVerticalVelocity;
+
+ SkPoint fCurPos;
+
+ // overrides from SkEventSink
+ virtual bool onQuery(SkEvent* evt) SK_OVERRIDE {
+ if (SampleCode::TitleQ(*evt)) {
+ SampleCode::TitleR(evt, "SubpixelTranslate");
+ return true;
+ }
+ return this->INHERITED::onQuery(evt);
+ }
+
+ virtual void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
+
+ static const SkPaint::FilterLevel gLevels[] = {
+ SkPaint::kNone_FilterLevel,
+ SkPaint::kLow_FilterLevel,
+ SkPaint::kMedium_FilterLevel,
+ SkPaint::kHigh_FilterLevel
+ };
+
+ SkPaint paint;
+ paint.setTextSize(48);
+
+ paint.setAntiAlias(true);
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gLevels); ++i) {
+ paint.setFilterLevel(gLevels[i]);
+ SkRect r = SkRect::MakeXYWH( fCurPos.fX + i * (fSize + 10), fCurPos.fY, fSize, fSize );
+ canvas->drawBitmapRect( fBM, r, &paint );
+ }
+
+ canvas->drawText( "AA Scaled", strlen("AA Scaled"), fCurPos.fX + SK_ARRAY_COUNT(gLevels) * (fSize + 10), fCurPos.fY + fSize/2, paint );
+
+ paint.setAntiAlias(false);
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gLevels); ++i) {
+ paint.setFilterLevel(gLevels[i]);
+ SkRect r = SkRect::MakeXYWH( fCurPos.fX + i * (fSize + 10), fCurPos.fY + fSize + 10, fSize, fSize );
+ canvas->drawBitmapRect( fBM, r, &paint );
+ }
+ canvas->drawText( "Scaled", strlen("Scaled"), fCurPos.fX + SK_ARRAY_COUNT(gLevels) * (fSize + 10), fCurPos.fY + fSize + 10 + fSize/2, paint );
+
+ paint.setAntiAlias(true);
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gLevels); ++i) {
+ paint.setFilterLevel(gLevels[i]);
+ canvas->drawBitmap( fBM, fCurPos.fX + i * (fBM.width() + 10), fCurPos.fY + 2*(fSize + 10), &paint );
+ }
+
+ canvas->drawText( "AA No Scale", strlen("AA No Scale"), fCurPos.fX + SK_ARRAY_COUNT(gLevels) * (fBM.width() + 10), fCurPos.fY + 2*(fSize + 10) + fSize/2, paint );
+
+ paint.setAntiAlias(false);
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gLevels); ++i) {
+ paint.setFilterLevel(gLevels[i]);
+ canvas->drawBitmap( fBM, fCurPos.fX + i * (fBM.width() + 10), fCurPos.fY + 2*(fSize + 10) + fBM.height() + 10, &paint );
+ }
+
+ canvas->drawText( "No Scale", strlen("No Scale"), fCurPos.fX + SK_ARRAY_COUNT(gLevels) * (fBM.width() + 10), fCurPos.fY + 2*(fSize + 10) + fBM.height() + 10 + fSize/2, paint );
+
+
+ fCurPos.fX += fHorizontalVelocity;
+ fCurPos.fY += fVerticalVelocity;
+ this->inval(NULL);
+ }
+
+private:
+ typedef SampleView INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static SkView* MyFactory() { return new SubpixelTranslateView("mandrill_256.png", .05, .05); }
+static SkViewRegister reg(MyFactory);