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

Unified Diff: gm/filterbitmap.cpp

Issue 15755019: more general GM setup for testing image filtering -- now with checkerboards, images, and text. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: switch from lena to mandrill Created 7 years, 7 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 | resources/mandrill_128.png » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/filterbitmap.cpp
diff --git a/gm/filterbitmap.cpp b/gm/filterbitmap.cpp
index c858aff76697b8f4dc88bec03a3204b026a45ece..9e86b54c0308e7810d68a69233c3091136092e7e 100644
--- a/gm/filterbitmap.cpp
+++ b/gm/filterbitmap.cpp
@@ -10,34 +10,12 @@
#include "SkTypeface.h"
#include "SkImageDecoder.h"
+#include "SkStream.h"
static void setTypeface(SkPaint* paint, const char name[], SkTypeface::Style style) {
SkSafeUnref(paint->setTypeface(SkTypeface::CreateFromName(name, style)));
}
-static void load_bm(SkBitmap* bm) {
-// SkImageDecoder::DecodeFile("/skia/trunk/books.jpg", bm);
-
- bm->setConfig(SkBitmap::kARGB_8888_Config, 160, 120);
- bm->allocPixels();
- SkCanvas canvas(*bm);
- canvas.drawColor(SK_ColorWHITE);
-
- SkPaint paint;
- paint.setAntiAlias(true);
- paint.setSubpixelText(true);
- paint.setTextSize(17);
-
- setTypeface(&paint, "Times", SkTypeface::kNormal);
- canvas.drawText("Hamburgefons", 12, 10, 25, paint);
- setTypeface(&paint, "Times", SkTypeface::kBold);
- canvas.drawText("Hamburgefons", 12, 10, 50, paint);
- setTypeface(&paint, "Times", SkTypeface::kItalic);
- canvas.drawText("Hamburgefons", 12, 10, 75, paint);
- setTypeface(&paint, "Times", SkTypeface::kBoldItalic);
- canvas.drawText("Hamburgefons", 12, 10, 100, paint);
-}
-
static SkSize computeSize(const SkBitmap& bm, const SkMatrix& mat) {
SkRect bounds = SkRect::MakeWH(SkIntToScalar(bm.width()),
SkIntToScalar(bm.height()));
@@ -63,17 +41,14 @@ static void draw_col(SkCanvas* canvas, const SkBitmap& bm, const SkMatrix& mat,
}
class FilterBitmapGM : public skiagm::GM {
- bool fOnce;
- void init() {
- if (fOnce) {
- return;
- }
- fOnce = true;
- load_bm(&fBM);
-
+ void onOnceBeforeDraw() {
+
+ make_bitmap();
+
SkScalar cx = SkScalarHalf(fBM.width());
SkScalar cy = SkScalarHalf(fBM.height());
- SkScalar scale = 1.6f;
+ SkScalar scale = get_scale();
+
fMatrix[0].setScale(scale, scale);
fMatrix[1].setRotate(30, cx, cy); fMatrix[1].postScale(scale, scale);
@@ -82,22 +57,30 @@ class FilterBitmapGM : public skiagm::GM {
public:
SkBitmap fBM;
SkMatrix fMatrix[2];
-
- FilterBitmapGM() : fOnce(false) {
+ SkString fName;
+
+ FilterBitmapGM()
+ {
this->setBGColor(0xFFDDDDDD);
}
+ void setName( const char name[] ) {
+ fName.set(name);
+ }
+
protected:
virtual SkString onShortName() SK_OVERRIDE {
- return SkString("filterbitmap");
+ return fName;
}
virtual SkISize onISize() SK_OVERRIDE {
return SkISize::Make(920, 480);
}
-
+
+ virtual void make_bitmap() = 0;
+ virtual SkScalar get_scale() = 0;
+
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
- this->init();
canvas->translate(10, 10);
for (size_t i = 0; i < SK_ARRAY_COUNT(fMatrix); ++i) {
@@ -114,6 +97,143 @@ private:
typedef skiagm::GM INHERITED;
};
+class FilterBitmapTextGM: public FilterBitmapGM {
+ public:
+ FilterBitmapTextGM( float textSize )
+ : fTextSize( textSize )
+ {
+ char name[1024];
+ sprintf( name, "filterbitmap_text_%.2fpt", fTextSize );
+ setName( name );
+ }
+
+ protected:
+ float fTextSize;
+
+ SkScalar get_scale() SK_OVERRIDE {
+ return 32.f/fTextSize;
+ }
+
+ void make_bitmap() SK_OVERRIDE {
+ fBM.setConfig(SkBitmap::kARGB_8888_Config, fTextSize * 8, fTextSize * 6);
+ fBM.allocPixels();
+ SkCanvas canvas(fBM);
+ canvas.drawColor(SK_ColorWHITE);
+
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setSubpixelText(true);
+ paint.setTextSize(fTextSize);
+
+ setTypeface(&paint, "Times", SkTypeface::kNormal);
+ canvas.drawText("Hamburgefons", 12, fTextSize/2, 1.2*fTextSize, paint);
+ setTypeface(&paint, "Times", SkTypeface::kBold);
+ canvas.drawText("Hamburgefons", 12, fTextSize/2, 2.4*fTextSize, paint);
+ setTypeface(&paint, "Times", SkTypeface::kItalic);
+ canvas.drawText("Hamburgefons", 12, fTextSize/2, 3.6*fTextSize, paint);
+ setTypeface(&paint, "Times", SkTypeface::kBoldItalic);
+ canvas.drawText("Hamburgefons", 12, fTextSize/2, 4.8*fTextSize, paint);
+ }
+ private:
+ typedef FilterBitmapGM INHERITED;
+};
+
+class FilterBitmapCheckerboardGM: public FilterBitmapGM {
+ public:
+ FilterBitmapCheckerboardGM( int size, int num_checks )
+ : fSize( size ), fNumChecks( num_checks )
+ {
+ char name[1024];
+ sprintf( name, "filterbitmap_checkerboard_%d_%d", fSize, fNumChecks );
+ setName( name );
+ }
+
+ protected:
+ int fSize;
+ int fNumChecks;
+
+ SkScalar get_scale() SK_OVERRIDE {
+ return 192.f/fSize;
+ }
+
+ 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 ++) {
+ SkPMColor* s = fBM.getAddr32(x, y);
+ int cx = (x * fNumChecks) / fSize;
+ int cy = (y * fNumChecks) / fSize;
+ if ((cx+cy)%2) {
+ *s = 0xFFFFFFFF;
+ } else {
+ *s = 0xFF000000;
+ }
+ }
+ }
+ }
+ private:
+ typedef FilterBitmapGM INHERITED;
+};
+
+class FilterBitmapImageGM: public FilterBitmapGM {
+ public:
+ FilterBitmapImageGM( const char filename[] )
+ : fFilename( filename )
+ {
+ char name[1024];
+ sprintf( name, "filterbitmap_image_%s", filename );
+ setName( name );
+ }
+
+ protected:
+ SkString fFilename;
+ int fSize;
+
+ SkScalar get_scale() SK_OVERRIDE {
+ return 192.f/fSize;
+ }
+
+ void make_bitmap() SK_OVERRIDE {
+ SkString path(skiagm::GM::gResourcePath);
+ 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.setConfig(SkBitmap::kARGB_8888_Config, 1, 1);
+ fBM.allocPixels();
+ *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad
+ }
+ fSize = fBM.height();
+ }
+ private:
+ typedef FilterBitmapGM INHERITED;
+};
+
//////////////////////////////////////////////////////////////////////////////
-DEF_GM( return new FilterBitmapGM; )
+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"); )
« no previous file with comments | « no previous file | resources/mandrill_128.png » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698