More general GM for testing bitmap filtering, including checkerboards, images, and text.
Review URL: https://codereview.chromium.org/15755019 git-svn-id: http://skia.googlecode.com/svn/trunk@9361 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
1922c2e62e
commit
04db31641b
@ -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"); )
|
||||
|
BIN
resources/mandrill_128.png
Normal file
BIN
resources/mandrill_128.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 37 KiB |
BIN
resources/mandrill_16.png
Normal file
BIN
resources/mandrill_16.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 952 B |
BIN
resources/mandrill_256.png
Normal file
BIN
resources/mandrill_256.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 150 KiB |
BIN
resources/mandrill_32.png
Normal file
BIN
resources/mandrill_32.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.6 KiB |
BIN
resources/mandrill_512.png
Normal file
BIN
resources/mandrill_512.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 611 KiB |
BIN
resources/mandrill_64.png
Normal file
BIN
resources/mandrill_64.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.4 KiB |
Loading…
Reference in New Issue
Block a user