Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: samplecode/SampleSubpixelTranslate.cpp

Issue 303123003: new animated sample to show subpixel translate bug with high quality scaling (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: nits from Robert Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gyp/SampleApp.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1
2 /*
3 * Copyright 2014 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9 #include "gm.h"
10 #include "SampleCode.h"
11 #include "SkBlurMaskFilter.h"
12 #include "SkColorPriv.h"
13 #include "SkCanvas.h"
14 #include "SkImageDecoder.h"
15 #include "SkRandom.h"
16 #include "SkStream.h"
17
18 // Intended to exercise pixel snapping observed with scaled images (and
19 // with non-scaled images, but for a different reason): Bug 1145
20
21 class SubpixelTranslateView : public SampleView {
22 public:
23 SubpixelTranslateView(const char imageFilename[],
24 float horizontalVelocity,
25 float verticalVelocity)
26 : fFilename(imageFilename),
27 fHorizontalVelocity(horizontalVelocity),
28 fVerticalVelocity(verticalVelocity) {
29 SkString path(skiagm::GM::GetResourcePath());
30 path.append("/");
31 path.append(fFilename);
32
33 SkImageDecoder *codec = NULL;
34 SkFILEStream stream(path.c_str());
35 if (stream.isValid()) {
36 codec = SkImageDecoder::Factory(&stream);
37 }
38 if (codec) {
39 stream.rewind();
40 codec->decode(&stream, &fBM, SkBitmap::kARGB_8888_Config,
41 SkImageDecoder::kDecodePixels_Mode);
42 SkDELETE(codec);
43 } else {
44 fBM.allocN32Pixels(1, 1);
45 *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad
46 }
47 fCurPos = SkPoint::Make(0,0);
48 fSize = 200;
49 }
50
51 protected:
52 SkBitmap fBM;
53 SkString fFilename;
54 int fSize;
55 float fHorizontalVelocity, fVerticalVelocity;
56
57 SkPoint fCurPos;
58
59 // overrides from SkEventSink
60 virtual bool onQuery(SkEvent* evt) SK_OVERRIDE {
61 if (SampleCode::TitleQ(*evt)) {
62 SampleCode::TitleR(evt, "SubpixelTranslate");
63 return true;
64 }
65 return this->INHERITED::onQuery(evt);
66 }
67
68 virtual void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
69
70 static const SkPaint::FilterLevel gLevels[] = {
71 SkPaint::kNone_FilterLevel,
72 SkPaint::kLow_FilterLevel,
73 SkPaint::kMedium_FilterLevel,
74 SkPaint::kHigh_FilterLevel
75 };
76
77 SkPaint paint;
78 paint.setTextSize(48);
79
80 paint.setAntiAlias(true);
81 for (size_t i = 0; i < SK_ARRAY_COUNT(gLevels); ++i) {
82 paint.setFilterLevel(gLevels[i]);
83 SkRect r = SkRect::MakeXYWH( fCurPos.fX + i * (fSize + 10), fCurPos. fY, fSize, fSize );
84 canvas->drawBitmapRect( fBM, r, &paint );
85 }
86
87 canvas->drawText( "AA Scaled", strlen("AA Scaled"), fCurPos.fX + SK_ARRA Y_COUNT(gLevels) * (fSize + 10), fCurPos.fY + fSize/2, paint );
88
89 paint.setAntiAlias(false);
90 for (size_t i = 0; i < SK_ARRAY_COUNT(gLevels); ++i) {
91 paint.setFilterLevel(gLevels[i]);
92 SkRect r = SkRect::MakeXYWH( fCurPos.fX + i * (fSize + 10), fCurPos. fY + fSize + 10, fSize, fSize );
93 canvas->drawBitmapRect( fBM, r, &paint );
94 }
95 canvas->drawText( "Scaled", strlen("Scaled"), fCurPos.fX + SK_ARRAY_COUN T(gLevels) * (fSize + 10), fCurPos.fY + fSize + 10 + fSize/2, paint );
96
97 paint.setAntiAlias(true);
98 for (size_t i = 0; i < SK_ARRAY_COUNT(gLevels); ++i) {
99 paint.setFilterLevel(gLevels[i]);
100 canvas->drawBitmap( fBM, fCurPos.fX + i * (fBM.width() + 10), fCurPo s.fY + 2*(fSize + 10), &paint );
101 }
102
103 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 );
104
105 paint.setAntiAlias(false);
106 for (size_t i = 0; i < SK_ARRAY_COUNT(gLevels); ++i) {
107 paint.setFilterLevel(gLevels[i]);
108 canvas->drawBitmap( fBM, fCurPos.fX + i * (fBM.width() + 10), fCurPo s.fY + 2*(fSize + 10) + fBM.height() + 10, &paint );
109 }
110
111 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 );
112
113
114 fCurPos.fX += fHorizontalVelocity;
115 fCurPos.fY += fVerticalVelocity;
116 this->inval(NULL);
117 }
118
119 private:
120 typedef SampleView INHERITED;
121 };
122
123 //////////////////////////////////////////////////////////////////////////////
124
125 static SkView* MyFactory() { return new SubpixelTranslateView("mandrill_256.png" , .05, .05); }
126 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « gyp/SampleApp.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698