aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/all_bitmap_configs.cpp
diff options
context:
space:
mode:
authorGravatar halcanary <halcanary@google.com>2015-03-20 09:10:56 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-03-20 09:10:56 -0700
commit86ad8d643624a55b02e529100bbe4e2940115fa1 (patch)
treeb27f7f6eea0207145ac170d994b1a25f3c7ea957 /gm/all_bitmap_configs.cpp
parentd4bb991df84357ad77b7858ae6c5dd00347b7ba6 (diff)
PDF: remove last use of SkPDFImage
Add a GM. BUG=skia:255 Review URL: https://codereview.chromium.org/950633003
Diffstat (limited to 'gm/all_bitmap_configs.cpp')
-rw-r--r--gm/all_bitmap_configs.cpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/gm/all_bitmap_configs.cpp b/gm/all_bitmap_configs.cpp
new file mode 100644
index 0000000000..95568f2ecf
--- /dev/null
+++ b/gm/all_bitmap_configs.cpp
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "sk_tool_utils.h"
+#include "SkSurface.h"
+#include "Resources.h"
+#include "gm.h"
+
+static SkBitmap copy_bitmap(const SkBitmap& src, SkColorType colorType) {
+ SkBitmap copy;
+ src.copyTo(&copy, colorType);
+ copy.setImmutable();
+ return copy;
+}
+
+// Make either A8 or gray8 bitmap.
+static SkBitmap make_bitmap(bool alpha) {
+ SkBitmap bm;
+ SkImageInfo info = alpha ? SkImageInfo::MakeA8(128, 128)
+ : SkImageInfo::Make(128, 128, kGray_8_SkColorType,
+ kOpaque_SkAlphaType);
+ bm.allocPixels(info);
+ SkAutoLockPixels autoLockPixels(bm);
+ uint8_t spectrum[256];
+ for (int y = 0; y < 256; ++y) {
+ spectrum[y] = y;
+ }
+ for (int y = 0; y < 128; ++y) {
+ // Shift over one byte each scanline.
+ memcpy(bm.getAddr8(0, y), &spectrum[y], 128);
+ }
+ bm.setImmutable();
+ return bm;
+}
+
+static void draw(SkCanvas* canvas,
+ const SkPaint& p,
+ const SkBitmap& src,
+ SkColorType colorType,
+ const char text[]) {
+ SkASSERT(src.colorType() == colorType);
+ canvas->drawBitmap(src, 0.0f, 0.0f);
+ canvas->drawText(text, strlen(text), 0.0f, 12.0f, p);
+}
+
+#define SCALE 128
+DEF_SIMPLE_GM(all_bitmap_configs, canvas, SCALE, 6 * SCALE) {
+ SkAutoCanvasRestore autoCanvasRestore(canvas, true);
+ SkPaint p;
+ p.setColor(SK_ColorBLACK);
+ p.setAntiAlias(true);
+ sk_tool_utils::set_portable_typeface(&p, NULL, SkTypeface::kBold);
+
+ sk_tool_utils::draw_checkerboard(canvas, SK_ColorLTGRAY, SK_ColorWHITE, 8);
+
+ SkBitmap bitmap;
+ if (GetResourceAsBitmap("color_wheel.png", &bitmap)) {
+ bitmap.setImmutable();
+ draw(canvas, p, bitmap, kN32_SkColorType, "Native 32");
+
+ canvas->translate(0.0f, SkIntToScalar(SCALE));
+ SkBitmap copy565 = copy_bitmap(bitmap, kRGB_565_SkColorType);
+ p.setColor(SK_ColorRED);
+ draw(canvas, p, copy565, kRGB_565_SkColorType, "RGB 565");
+ p.setColor(SK_ColorBLACK);
+
+ canvas->translate(0.0f, SkIntToScalar(SCALE));
+ SkBitmap copy4444 = copy_bitmap(bitmap, kARGB_4444_SkColorType);
+ draw(canvas, p, copy4444, kARGB_4444_SkColorType, "ARGB 4444");
+ } else {
+ canvas->translate(0.0f, SkIntToScalar(2 * SCALE));
+ }
+
+ canvas->translate(0.0f, SkIntToScalar(SCALE));
+ SkBitmap bitmapIndexed;
+ if (GetResourceAsBitmap("color_wheel.gif", &bitmapIndexed)) {
+ bitmapIndexed.setImmutable();
+ draw(canvas, p, bitmapIndexed, kIndex_8_SkColorType, "Index 8");
+ }
+
+ canvas->translate(0.0f, SkIntToScalar(SCALE));
+ SkBitmap bitmapA8 = make_bitmap(true);
+ draw(canvas, p, bitmapA8, kAlpha_8_SkColorType, "Alpha 8");
+
+ p.setColor(SK_ColorRED);
+ canvas->translate(0.0f, SkIntToScalar(SCALE));
+ SkBitmap bitmapG8 = make_bitmap(false);
+ draw(canvas, p, bitmapG8, kGray_8_SkColorType, "Gray 8");
+}