diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 18:28:36 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 18:28:36 -0800 |
commit | 6eb364108744656fcd23a96a478aa772cd4e85bc (patch) | |
tree | 4b825dc642cb6eb9a060e54bf8d69288fbee4904 /samplecode/SampleFilter.cpp | |
parent | a23c4e24d873b11674987f97f1946e1c4d97e782 (diff) | |
download | external_skia-6eb364108744656fcd23a96a478aa772cd4e85bc.zip external_skia-6eb364108744656fcd23a96a478aa772cd4e85bc.tar.gz external_skia-6eb364108744656fcd23a96a478aa772cd4e85bc.tar.bz2 |
auto import from //depot/cupcake/@135843
Diffstat (limited to 'samplecode/SampleFilter.cpp')
-rw-r--r-- | samplecode/SampleFilter.cpp | 163 |
1 files changed, 0 insertions, 163 deletions
diff --git a/samplecode/SampleFilter.cpp b/samplecode/SampleFilter.cpp deleted file mode 100644 index 49d9c48..0000000 --- a/samplecode/SampleFilter.cpp +++ /dev/null @@ -1,163 +0,0 @@ -#include "SampleCode.h" -#include "SkView.h" -#include "SkCanvas.h" -#include "SkGradientShader.h" -#include "SkPath.h" -#include "SkRegion.h" -#include "SkShader.h" -#include "SkUtils.h" -#include "Sk1DPathEffect.h" -#include "SkCornerPathEffect.h" -#include "SkPathMeasure.h" -#include "SkRandom.h" -#include "SkColorPriv.h" -#include "SkColorFilter.h" -#include "SkDither.h" - -static void make_bm(SkBitmap* bm) -{ - const SkColor colors[] = { - SK_ColorRED, SK_ColorGREEN, - SK_ColorBLUE, SK_ColorWHITE - }; - SkColorTable* ctable = new SkColorTable(colors, 4); - bm->setConfig(SkBitmap::kIndex8_Config, 2, 2); - bm->allocPixels(ctable); - ctable->unref(); - - *bm->getAddr8(0, 0) = 0; - *bm->getAddr8(1, 0) = 1; - *bm->getAddr8(0, 1) = 2; - *bm->getAddr8(1, 1) = 3; -} - -static SkScalar draw_bm(SkCanvas* canvas, const SkBitmap& bm, - SkScalar x, SkScalar y, SkPaint* paint) -{ -#if 1 - canvas->drawBitmap(bm, x, y, paint); - return SkIntToScalar(bm.width()) * 5/4; -#else - SkRect r; - - r.set(x, y, - x + SkIntToScalar(bm.width() * 2), - y + SkIntToScalar(bm.height() * 2)); - SkShader* s = SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode, - SkShader::kRepeat_TileMode); - paint->setShader(s)->unref(); - canvas->drawRect(r, *paint); - paint->setShader(NULL); - return r.width() * 5/4; -#endif -} - -static SkScalar draw_set(SkCanvas* c, const SkBitmap& bm, SkScalar x, SkPaint* p) -{ - x += draw_bm(c, bm, x, 0, p); - p->setFilterBitmap(true); - x += draw_bm(c, bm, x, 0, p); - p->setDither(true); - return x + draw_bm(c, bm, x, 0, p); -} - -static const char* gConfigNames[] = { - "unknown config", - "A1", - "A8", - "Index8", - "565", - "4444", - "8888" -}; - -static SkScalar draw_row(SkCanvas* canvas, const SkBitmap& bm) -{ - SkAutoCanvasRestore acr(canvas, true); - - SkPaint paint; - SkScalar x = 0; - const int scale = 32; - - paint.setAntiAlias(true); - const char* name = gConfigNames[bm.config()]; - canvas->drawText(name, strlen(name), x, SkIntToScalar(bm.height())*scale*5/8, - paint); - canvas->translate(SkIntToScalar(48), 0); - - canvas->scale(SkIntToScalar(scale), SkIntToScalar(scale)); - - x += draw_set(canvas, bm, 0, &paint); - paint.reset(); - paint.setAlpha(0x80); - draw_set(canvas, bm, x, &paint); - return x * scale / 3; -} - -class FilterView : public SkView { -public: - SkBitmap fBM8, fBM4444, fBM16, fBM32; - - FilterView() - { - make_bm(&fBM8); - fBM8.copyTo(&fBM4444, SkBitmap::kARGB_4444_Config); - fBM8.copyTo(&fBM16, SkBitmap::kRGB_565_Config); - fBM8.copyTo(&fBM32, SkBitmap::kARGB_8888_Config); - } - -protected: - // overrides from SkEventSink - virtual bool onQuery(SkEvent* evt) - { - if (SampleCode::TitleQ(*evt)) - { - SampleCode::TitleR(evt, "Filter"); - return true; - } - return this->INHERITED::onQuery(evt); - } - - void drawBG(SkCanvas* canvas) - { - canvas->drawColor(0xFFDDDDDD); - } - - virtual void onDraw(SkCanvas* canvas) - { - this->drawBG(canvas); - - SkScalar x = SkIntToScalar(10); - SkScalar y = SkIntToScalar(10); - - canvas->translate(x, y); - y = draw_row(canvas, fBM8); - canvas->translate(0, y); - y = draw_row(canvas, fBM4444); - canvas->translate(0, y); - y = draw_row(canvas, fBM16); - canvas->translate(0, y); - draw_row(canvas, fBM32); - } - - virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) - { - // fSweep += SK_Scalar1; - this->inval(NULL); - return this->INHERITED::onFindClickHandler(x, y); - } - - virtual bool onClick(Click* click) - { - return this->INHERITED::onClick(click); - } - -private: - typedef SkView INHERITED; -}; - -////////////////////////////////////////////////////////////////////////////// - -static SkView* MyFactory() { return new FilterView; } -static SkViewRegister reg(MyFactory); - |