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

Side by Side Diff: samplecode/SampleIdentityScale.cpp

Issue 454913002: add an animated test to verify that high-quality identity scaling doesn't change the image (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix windows build Created 6 years, 4 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 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "gm.h"
9
10 #include "Resources.h"
11 #include "SampleCode.h"
12 #include "SkBlurMaskFilter.h"
13 #include "SkCanvas.h"
14 #include "SkColorPriv.h"
15 #include "SkImageDecoder.h"
16 #include "SkRandom.h"
17 #include "SkStream.h"
18 #include "SkTime.h"
19
20 // Intended to exercise pixel snapping observed with scaled images (and
21 // with non-scaled images, but for a different reason): Bug 1145
22
23 class IdentityScaleView : public SampleView {
24 public:
25 IdentityScaleView(const char imageFilename[]) {
26 SkString resourcePath = GetResourcePath(imageFilename);
27 SkImageDecoder* codec = NULL;
28 SkFILEStream stream(resourcePath.c_str());
29 if (stream.isValid()) {
30 codec = SkImageDecoder::Factory(&stream);
31 }
32 if (codec) {
33 stream.rewind();
34 codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDecode Pixels_Mode);
35 SkDELETE(codec);
36 } else {
37 fBM.allocN32Pixels(1, 1);
38 *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad
39 }
40 }
41
42 protected:
43 SkBitmap fBM;
44
45 // overrides from SkEventSink
46 virtual bool onQuery(SkEvent* evt) SK_OVERRIDE {
47 if (SampleCode::TitleQ(*evt)) {
48 SampleCode::TitleR(evt, "IdentityScale");
49 return true;
50 }
51 return this->INHERITED::onQuery(evt);
52 }
53
54 virtual void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
55
56 SkPaint paint;
57
58 paint.setAntiAlias(true);
59 paint.setTextSize(48);
60 paint.setFilterLevel(SkPaint::kHigh_FilterLevel);
61
62 SkTime::DateTime time;
63 SkTime::GetDateTime(&time);
64
65 bool use_scale = (time.fSecond % 2 == 1);
66 const char *text;
67
68 canvas->save();
69 if (use_scale) {
70 text = "Scaled = 1";
71 } else {
72
73 SkRect r = { 100, 100, 356, 356 };
74 SkPath clipPath;
75 clipPath.addRoundRect(r, SkIntToScalar(5), SkIntToScalar(5));
76 canvas->clipPath(clipPath, SkRegion::kIntersect_Op, SkToBool(1));
77 text = "Scaled = 0";
78 }
79 canvas->drawBitmap( fBM, 100, 100, &paint );
80 canvas->restore();
81 canvas->drawText( text, strlen(text), 100, 400, paint );
82 this->inval(NULL);
83 }
84
85 private:
86 typedef SampleView INHERITED;
87 };
88
89 //////////////////////////////////////////////////////////////////////////////
90
91 static SkView* MyFactory() { return new IdentityScaleView("mandrill_256.png"); }
92 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