aboutsummaryrefslogtreecommitdiffhomepage
path: root/samplecode
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-07-03 13:36:17 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-03 19:07:25 +0000
commita920d367bf9b3724f66173e4aa702ca09f680dea (patch)
tree6f1501e4c0c1c9568b99428d201adb19e281390e /samplecode
parent0401c0d1d3ad9db5d3eecb3096bd569dfe5c2498 (diff)
remove unneeded code for index8 imagse
Bug: skia:6828 Change-Id: I039d6bc35a1ed93ce747247f32fe4e9d5b09da0c Reviewed-on: https://skia-review.googlesource.com/21400 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'samplecode')
-rw-r--r--samplecode/DecodeFile.h1
-rw-r--r--samplecode/SampleBlur.cpp37
-rw-r--r--samplecode/SampleDitherBitmap.cpp144
-rw-r--r--samplecode/SampleFilter.cpp119
-rw-r--r--samplecode/SampleTinyBitmap.cpp72
5 files changed, 1 insertions, 372 deletions
diff --git a/samplecode/DecodeFile.h b/samplecode/DecodeFile.h
index 450c1fb3d7..1ae98a4a72 100644
--- a/samplecode/DecodeFile.h
+++ b/samplecode/DecodeFile.h
@@ -16,7 +16,6 @@
static inline bool decode_file(const char* filename, SkBitmap* bitmap,
SkColorType colorType = kN32_SkColorType,
bool requireUnpremul = false) {
- SkASSERT(kIndex_8_SkColorType != colorType);
sk_sp<SkData> data(SkData::MakeFromFileName(filename));
std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(data));
if (!codec) {
diff --git a/samplecode/SampleBlur.cpp b/samplecode/SampleBlur.cpp
index a2f90a7746..507c57e29d 100644
--- a/samplecode/SampleBlur.cpp
+++ b/samplecode/SampleBlur.cpp
@@ -14,45 +14,10 @@
#include "SkUtils.h"
#include "SkView.h"
-static SkBitmap make_bitmap() {
- SkPMColor c[256];
- for (int i = 0; i < 256; i++) {
- c[i] = SkPackARGB32(255 - i, 0, 0, 0);
- }
-
- SkBitmap bm;
- bm.allocPixels(SkImageInfo::Make(256, 256, kIndex_8_SkColorType,
- kPremul_SkAlphaType),
- SkColorTable::Make(c, 256));
-
- const float cx = bm.width() * 0.5f;
- const float cy = bm.height() * 0.5f;
- for (int y = 0; y < bm.height(); y++) {
- float dy = y - cy;
- dy *= dy;
- uint8_t* p = bm.getAddr8(0, y);
- for (int x = 0; x < 256; x++) {
- float dx = x - cx;
- dx *= dx;
- float d = (dx + dy) / (cx/2);
- int id = (int)d;
- if (id > 255) {
- id = 255;
- }
- p[x] = id;
- }
- }
- return bm;
-}
-
class BlurView : public SampleView {
SkBitmap fBM;
public:
- BlurView() {
- if (false) { // avoid bit rot, suppress warning
- fBM = make_bitmap();
- }
- }
+ BlurView() {}
protected:
// overrides from SkEventSink
diff --git a/samplecode/SampleDitherBitmap.cpp b/samplecode/SampleDitherBitmap.cpp
deleted file mode 100644
index 2f3de35fd6..0000000000
--- a/samplecode/SampleDitherBitmap.cpp
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SampleCode.h"
-#include "SkCanvas.h"
-#include "SkColorPriv.h"
-#include "SkGradientShader.h"
-#include "SkPath.h"
-#include "SkRegion.h"
-#include "SkUtils.h"
-#include "SkView.h"
-#include "sk_tool_utils.h"
-
-static void draw_rect(SkCanvas* canvas, const SkRect& r, const SkPaint& p) {
- canvas->drawRect(r, p);
-
- SkPaint frame(p);
- frame.setShader(nullptr);
- frame.setStyle(SkPaint::kStroke_Style);
- canvas->drawRect(r, frame);
-}
-
-static void draw_gradient(SkCanvas* canvas) {
- SkRect r = { 0, 0, SkIntToScalar(256), SkIntToScalar(32) };
- SkPoint pts[] = { { r.fLeft, r.fTop }, { r.fRight, r.fTop } };
- SkColor colors[] = { 0xFF000000, 0xFFFF0000 };
- SkPaint p;
- p.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode));
- draw_rect(canvas, r, p);
-
- canvas->translate(0, SkIntToScalar(40));
- p.setDither(true);
- draw_rect(canvas, r, p);
-}
-
-static bool test_pathregion() {
- SkPath path;
- SkRegion region;
- path.moveTo(25071800.f, -141823808.f);
- path.lineTo(25075500.f, -141824000.f);
- path.lineTo(25075400.f, -141827712.f);
- path.lineTo(25071810.f, -141827600.f);
- path.close();
-
- SkIRect bounds;
- path.getBounds().round(&bounds);
- SkRegion clip(bounds);
- return region.setPath(path, clip); // <-- !! DOWN !!
-}
-
-static SkBitmap make_bitmap() {
- SkPMColor c[256];
- for (int i = 0; i < 256; i++) {
- c[i] = SkPackARGB32(0xFF, i, 0, 0);
- }
- SkBitmap bm;
- bm.allocPixels(SkImageInfo::Make(256, 32, kIndex_8_SkColorType, kPremul_SkAlphaType),
- SkColorTable::Make(c, 256));
-
- for (int y = 0; y < bm.height(); y++) {
- uint8_t* p = bm.getAddr8(0, y);
- for (int x = 0; x < 256; x++) {
- p[x] = x;
- }
- }
- return bm;
-}
-
-class DitherBitmapView : public SampleView {
- SkBitmap fBM8;
- SkBitmap fBM32;
- bool fResult;
-public:
- DitherBitmapView() {
- fResult = test_pathregion();
- fBM8 = make_bitmap();
- sk_tool_utils::copy_to(&fBM32, kN32_SkColorType, fBM8);
-
- this->setBGColor(0xFFDDDDDD);
- }
-
-protected:
- // overrides from SkEventSink
- virtual bool onQuery(SkEvent* evt) {
- if (SampleCode::TitleQ(*evt)) {
- SampleCode::TitleR(evt, "DitherBitmap");
- return true;
- }
- return this->INHERITED::onQuery(evt);
- }
-
- static void setBitmapOpaque(SkBitmap* bm, bool isOpaque) {
- bm->setAlphaType(isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
- }
-
- static void draw2(SkCanvas* canvas, const SkBitmap& bm) {
- SkPaint paint;
- SkBitmap bitmap(bm);
-
- setBitmapOpaque(&bitmap, false);
- paint.setDither(false);
- canvas->drawBitmap(bitmap, 0, 0, &paint);
- paint.setDither(true);
- canvas->drawBitmap(bitmap, 0, SkIntToScalar(bm.height() + 10), &paint);
-
- setBitmapOpaque(&bitmap, true);
- SkScalar x = SkIntToScalar(bm.width() + 10);
- paint.setDither(false);
- canvas->drawBitmap(bitmap, x, 0, &paint);
- paint.setDither(true);
- canvas->drawBitmap(bitmap, x, SkIntToScalar(bm.height() + 10), &paint);
- }
-
- virtual void onDrawContent(SkCanvas* canvas) {
- canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
-
- draw2(canvas, fBM8);
- canvas->translate(0, SkIntToScalar(fBM8.height() *3));
- draw2(canvas, fBM32);
-
- canvas->translate(0, SkIntToScalar(fBM8.height() *3));
- draw_gradient(canvas);
-
- char resultTrue[] = "SkRegion::setPath returned true";
- char resultFalse[] = "SkRegion::setPath returned false";
- SkPaint p;
- if (fResult)
- canvas->drawText(resultTrue, sizeof(resultTrue) - 1, 0, 50, p);
- else
- canvas->drawText(resultFalse, sizeof(resultFalse) - 1, 0, 50, p);
- }
-
-private:
- typedef SampleView INHERITED;
-};
-
-//////////////////////////////////////////////////////////////////////////////
-
-static SkView* MyFactory() { return new DitherBitmapView; }
-static SkViewRegister reg(MyFactory);
diff --git a/samplecode/SampleFilter.cpp b/samplecode/SampleFilter.cpp
deleted file mode 100644
index 60dd7e090d..0000000000
--- a/samplecode/SampleFilter.cpp
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#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"
-#include "sk_tool_utils.h"
-
-static void make_bm(SkBitmap* bm) {
- const SkPMColor colors[] = {
- SkPreMultiplyColor(SK_ColorRED), SkPreMultiplyColor(SK_ColorGREEN),
- SkPreMultiplyColor(SK_ColorBLUE), SkPreMultiplyColor(SK_ColorWHITE)
- };
- bm->allocPixels(SkImageInfo::Make(2, 2, kIndex_8_SkColorType,
- kOpaque_SkAlphaType),
- SkColorTable::Make(colors, 4));
-
- *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) {
- canvas->drawBitmap(bm, x, y, paint);
- return SkIntToScalar(bm.width()) * 5/4;
-}
-
-static SkScalar draw_set(SkCanvas* c, const SkBitmap& bm, SkScalar x, SkPaint* p) {
- x += draw_bm(c, bm, x, 0, p);
- p->setFilterQuality(kLow_SkFilterQuality);
- x += draw_bm(c, bm, x, 0, p);
- p->setDither(true);
- return x + draw_bm(c, bm, x, 0, p);
-}
-
-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 = sk_tool_utils::colortype_name(bm.colorType());
- canvas->drawString(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 SampleView {
-public:
- SkBitmap fBM8, fBM4444, fBM16, fBM32;
-
- FilterView() {
- make_bm(&fBM8);
- sk_tool_utils::copy_to(&fBM4444, kARGB_4444_SkColorType, fBM8);
- sk_tool_utils::copy_to(&fBM16, kRGB_565_SkColorType, fBM8);
- sk_tool_utils::copy_to(&fBM32, kN32_SkColorType, fBM8);
-
- this->setBGColor(0xFFDDDDDD);
- }
-
-protected:
- // overrides from SkEventSink
- virtual bool onQuery(SkEvent* evt) {
- if (SampleCode::TitleQ(*evt)) {
- SampleCode::TitleR(evt, "Filter");
- return true;
- }
- return this->INHERITED::onQuery(evt);
- }
-
- virtual void onDrawContent(SkCanvas* 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);
- }
-
-private:
- typedef SampleView INHERITED;
-};
-
-//////////////////////////////////////////////////////////////////////////////
-
-static SkView* MyFactory() { return new FilterView; }
-static SkViewRegister reg(MyFactory);
diff --git a/samplecode/SampleTinyBitmap.cpp b/samplecode/SampleTinyBitmap.cpp
deleted file mode 100644
index 2212cbec23..0000000000
--- a/samplecode/SampleTinyBitmap.cpp
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SampleCode.h"
-#include "SkColorPriv.h"
-#include "SkShader.h"
-#include "SkView.h"
-#include "SkCanvas.h"
-#include "SkUtils.h"
-
-static SkBitmap make_bitmap() {
- const int N = 1;
-
- SkPMColor c[N];
- for (int i = 0; i < N; i++) {
- c[i] = SkPackARGB32(0x80, 0x80, 0, 0);
- }
-
- SkBitmap bm;
- bm.allocPixels(SkImageInfo::Make(1, 1, kIndex_8_SkColorType,
- kPremul_SkAlphaType),
- SkColorTable::Make(c, N));
-
- for (int y = 0; y < bm.height(); y++) {
- uint8_t* p = bm.getAddr8(0, y);
- for (int x = 0; x < bm.width(); x++) {
- p[x] = 0;
- }
- }
- return bm;
-}
-
-class TinyBitmapView : public SampleView {
- SkBitmap fBM;
-public:
- TinyBitmapView() {
- fBM = make_bitmap();
- this->setBGColor(0xFFDDDDDD);
- }
-
-protected:
- bool onQuery(SkEvent* evt) override {
- if (SampleCode::TitleQ(*evt)) {
- SampleCode::TitleR(evt, "TinyBitmap");
- return true;
- }
- return this->INHERITED::onQuery(evt);
- }
-
- static void setBitmapOpaque(SkBitmap* bm, bool isOpaque) {
- bm->setAlphaType(isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
- }
-
- void onDrawContent(SkCanvas* canvas) override {
- SkPaint paint;
- paint.setShader(SkShader::MakeBitmapShader(fBM, SkShader::kRepeat_TileMode,
- SkShader::kMirror_TileMode));
- canvas->drawPaint(paint);
- }
-
-private:
- typedef SkView INHERITED;
-};
-
-//////////////////////////////////////////////////////////////////////////////
-
-static SkView* MyFactory() { return new TinyBitmapView; }
-static SkViewRegister reg(MyFactory);