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

Unified Diff: gm/downsamplebitmap.cpp

Issue 18978014: Working plumb of image scaling: (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: nits from robert Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/downsamplebitmap.cpp
diff --git a/gm/filterbitmap.cpp b/gm/downsamplebitmap.cpp
similarity index 50%
copy from gm/filterbitmap.cpp
copy to gm/downsamplebitmap.cpp
index 0afcb951018847528adb76e8c61413aff8d0ace1..7f8a6babc41be0df6f98b8fa59b60f29ba1afe31 100644
--- a/gm/filterbitmap.cpp
+++ b/gm/downsamplebitmap.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2011 Google Inc.
+ * Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
@@ -16,52 +16,17 @@ static void setTypeface(SkPaint* paint, const char name[], SkTypeface::Style sty
SkSafeUnref(paint->setTypeface(SkTypeface::CreateFromName(name, style)));
}
-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_col(SkCanvas* canvas, const SkBitmap& bm, const SkMatrix& mat,
- SkScalar dx) {
- SkPaint paint;
-
- SkAutoCanvasRestore acr(canvas, true);
-
- canvas->drawBitmapMatrix(bm, mat, &paint);
-
- paint.setFilterBitmap(true);
- canvas->translate(dx, 0);
- canvas->drawBitmapMatrix(bm, mat, &paint);
-
- paint.setFlags(paint.getFlags() | SkPaint::kHighQualityFilterBitmap_Flag);
- canvas->translate(dx, 0);
- canvas->drawBitmapMatrix(bm, mat, &paint);
-}
-
-class FilterBitmapGM : public skiagm::GM {
- void onOnceBeforeDraw() {
-
- make_bitmap();
-
- SkScalar cx = SkScalarHalf(fBM.width());
- SkScalar cy = SkScalarHalf(fBM.height());
- SkScalar scale = get_scale();
-
-
- fMatrix[0].setScale(scale, scale);
- fMatrix[1].setRotate(30, cx, cy); fMatrix[1].postScale(scale, scale);
- }
+class DownsampleBitmapGM : public skiagm::GM {
public:
SkBitmap fBM;
- SkMatrix fMatrix[2];
SkString fName;
-
- FilterBitmapGM()
+ bool fBitmapMade;
+
+ DownsampleBitmapGM()
{
this->setBGColor(0xFFDDDDDD);
+ fBitmapMade = false;
}
void setName(const char name[]) {
@@ -74,47 +39,63 @@ protected:
}
virtual SkISize onISize() SK_OVERRIDE {
- return SkISize::Make(920, 480);
+ make_bitmap_wrapper();
+ return SkISize::Make(4 * fBM.width(), fBM.height());
+ }
+
+ void make_bitmap_wrapper() {
+ if (!fBitmapMade) {
+ fBitmapMade = true;
+ make_bitmap();
+ }
}
virtual void make_bitmap() = 0;
- virtual SkScalar get_scale() = 0;
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_col(canvas, fBM, fMatrix[i], size.fWidth);
- canvas->translate(0, size.fHeight);
- }
+ make_bitmap_wrapper();
+
+ int curX = 0;
+ int curWidth;
+ float curScale = 1;
+ do {
+
+ SkMatrix matrix;
+ matrix.setScale( curScale, curScale );
+
+ SkPaint paint;
+ paint.setFilterBitmap(true);
+ paint.setFlags( paint.getFlags() | SkPaint::kHighQualityFilterBitmap_Flag );
+
+ canvas->save();
+ canvas->translate( curX, 0 );
+ canvas->drawBitmapMatrix( fBM, matrix, &paint );
+ canvas->restore();
+
+ curWidth = (int) (fBM.width() * curScale + 2);
+ curX += curWidth;
+ curScale *= 0.75;
+ } while (curX < 4*fBM.width());
}
private:
typedef skiagm::GM INHERITED;
};
-class FilterBitmapTextGM: public FilterBitmapGM {
+class DownsampleBitmapTextGM: public DownsampleBitmapGM {
public:
- FilterBitmapTextGM(float textSize)
+ DownsampleBitmapTextGM(float textSize)
: fTextSize(textSize)
{
char name[1024];
- sprintf(name, "filterbitmap_text_%.2fpt", fTextSize);
+ sprintf(name, "downsamplebitmap_text_%.2fpt", fTextSize);
setName(name);
}
protected:
float fTextSize;
- SkScalar get_scale() SK_OVERRIDE {
- return 32.f/fTextSize;
- }
-
- void make_bitmap() SK_OVERRIDE {
+ virtual void make_bitmap() SK_OVERRIDE {
fBM.setConfig(SkBitmap::kARGB_8888_Config, int(fTextSize * 8), int(fTextSize * 6));
fBM.allocPixels();
SkCanvas canvas(fBM);
@@ -135,16 +116,16 @@ class FilterBitmapTextGM: public FilterBitmapGM {
canvas.drawText("Hamburgefons", 12, fTextSize/2, 4.8f*fTextSize, paint);
}
private:
- typedef FilterBitmapGM INHERITED;
+ typedef DownsampleBitmapGM INHERITED;
};
-class FilterBitmapCheckerboardGM: public FilterBitmapGM {
+class DownsampleBitmapCheckerboardGM: public DownsampleBitmapGM {
public:
- FilterBitmapCheckerboardGM(int size, int num_checks)
- : fSize(size), fNumChecks(num_checks)
+ DownsampleBitmapCheckerboardGM(int size, int numChecks)
+ : fSize(size), fNumChecks(numChecks)
{
char name[1024];
- sprintf(name, "filterbitmap_checkerboard_%d_%d", fSize, fNumChecks);
+ sprintf(name, "downsamplebitmap_checkerboard_%d_%d", fSize, fNumChecks);
setName(name);
}
@@ -152,16 +133,12 @@ class FilterBitmapCheckerboardGM: public FilterBitmapGM {
int fSize;
int fNumChecks;
- SkScalar get_scale() SK_OVERRIDE {
- return 192.f/fSize;
- }
-
- void make_bitmap() SK_OVERRIDE {
+ virtual void make_bitmap() SK_OVERRIDE {
fBM.setConfig(SkBitmap::kARGB_8888_Config, fSize, fSize);
fBM.allocPixels();
SkAutoLockPixels lock(fBM);
- for (int y = 0; y < fSize; y ++) {
- for (int x = 0; x < fSize; x ++) {
+ for (int y = 0; y < fSize; ++y) {
+ for (int x = 0; x < fSize; ++x) {
SkPMColor* s = fBM.getAddr32(x, y);
int cx = (x * fNumChecks) / fSize;
int cy = (y * fNumChecks) / fSize;
@@ -174,16 +151,16 @@ class FilterBitmapCheckerboardGM: public FilterBitmapGM {
}
}
private:
- typedef FilterBitmapGM INHERITED;
+ typedef DownsampleBitmapGM INHERITED;
};
-class FilterBitmapImageGM: public FilterBitmapGM {
+class DownsampleBitmapImageGM: public DownsampleBitmapGM {
public:
- FilterBitmapImageGM(const char filename[])
+ DownsampleBitmapImageGM(const char filename[])
: fFilename(filename)
{
char name[1024];
- sprintf(name, "filterbitmap_image_%s", filename);
+ sprintf(name, "downsamplebitmap_image_%s", filename);
setName(name);
}
@@ -191,11 +168,7 @@ class FilterBitmapImageGM: public FilterBitmapGM {
SkString fFilename;
int fSize;
- SkScalar get_scale() SK_OVERRIDE {
- return 192.f/fSize;
- }
-
- void make_bitmap() SK_OVERRIDE {
+ virtual void make_bitmap() SK_OVERRIDE {
SkString path(skiagm::GM::gResourcePath);
path.append("/");
path.append(fFilename);
@@ -218,22 +191,11 @@ class FilterBitmapImageGM: public FilterBitmapGM {
fSize = fBM.height();
}
private:
- typedef FilterBitmapGM INHERITED;
+ typedef DownsampleBitmapGM INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
-DEF_GM( return new FilterBitmapTextGM(3); )
-DEF_GM( return new FilterBitmapTextGM(7); )
-DEF_GM( return new FilterBitmapTextGM(10); )
-DEF_GM( return new FilterBitmapCheckerboardGM(4,4); )
-DEF_GM( return new FilterBitmapCheckerboardGM(32,32); )
-DEF_GM( return new FilterBitmapCheckerboardGM(32,8); )
-DEF_GM( return new FilterBitmapCheckerboardGM(32,2); )
-DEF_GM( return new FilterBitmapCheckerboardGM(192,192); )
-DEF_GM( return new FilterBitmapImageGM("mandrill_16.png"); )
-DEF_GM( return new FilterBitmapImageGM("mandrill_32.png"); )
-DEF_GM( return new FilterBitmapImageGM("mandrill_64.png"); )
-DEF_GM( return new FilterBitmapImageGM("mandrill_128.png"); )
-DEF_GM( return new FilterBitmapImageGM("mandrill_256.png"); )
-DEF_GM( return new FilterBitmapImageGM("mandrill_512.png"); )
+DEF_GM( return new DownsampleBitmapTextGM(72); )
+DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256); )
+DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png"); )
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698