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

Unified Diff: gm/bitmappremul.cpp

Issue 22329003: Unpremultiply SkBitmaps for PDF output (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Add GM Created 7 years, 4 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 | gyp/gmslides.gypi » ('j') | src/pdf/SkPDFImage.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/bitmappremul.cpp
diff --git a/gm/bitmappremul.cpp b/gm/bitmappremul.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..f486554d8544b356975e665cb59514fd9192a37f
--- /dev/null
+++ b/gm/bitmappremul.cpp
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "gm.h"
+#include "SkBitmap.h"
+#include "SkCanvas.h"
+#include "SkColorPriv.h"
+
+/**
+ * This GM checks that bitmap pixels are unpremultiplied before being exported
+ * to other formats. If unpremultiplication is implemented properly, this
+ * GM should come out completely white. If not, this GM looks like two
+ * sets of greyscale gradients.
+ * This tests both the ARGB4444 and ARGB8888 bitmap configurations.
+ */
+
+static const int SLIDE_SIZE = 256;
+static const int PIXEL_SIZE_8888 = SLIDE_SIZE / 256;
+static const int PIXEL_SIZE_4444 = SLIDE_SIZE / 16;
+
+static SkBitmap init_bitmap(SkBitmap::Config config) {
+ SkBitmap bitmap;
+ bitmap.setConfig(config, SLIDE_SIZE, SLIDE_SIZE);
+ bitmap.allocPixels();
+ bitmap.eraseColor(SK_ColorWHITE);
+ return bitmap;
+}
+
+static void populate_argb8888(SkBitmap* bitmap) {
+ uint8_t rowColor = 0;
+ for (int y = 0; y < SLIDE_SIZE; y++) {
+ uint32_t* dst = bitmap->getAddr32(0, y);
+ for (int x = 0; x < SLIDE_SIZE; x++) {
+ dst[x] = SkPackARGB32(rowColor, rowColor,
+ rowColor, rowColor);
+ }
+ if (y % PIXEL_SIZE_8888 == PIXEL_SIZE_8888 - 1) {
+ rowColor++;
+ }
+ }
+}
+
+static void populate_argb4444(SkBitmap* bitmap) {
+ uint8_t rowColor = 0;
+ for (int y = 0; y < SLIDE_SIZE; y++) {
+ uint16_t* dst = bitmap->getAddr16(0, y);
+ for (int x = 0; x < SLIDE_SIZE; x++) {
+ dst[x] = SkPackARGB4444(rowColor, rowColor,
+ rowColor, rowColor);
+ }
+ if (y % PIXEL_SIZE_4444 == PIXEL_SIZE_4444 - 1) {
+ rowColor++;
+ }
+ }
+}
+
+namespace skiagm {
+
+class BitmapPremulGM : public GM {
+public:
+ BitmapPremulGM() {
+ this->setBGColor(0xFFFFFFFF);
+ }
+
+protected:
+ SkString onShortName() SK_OVERRIDE {
+ return SkString("bitmap-premul");
vandebo (ex-Chrome) 2013/08/07 18:11:07 short names tend to use _ and not -
ducky 2013/08/08 03:35:11 Done.
+ }
+
+ virtual SkISize onISize() SK_OVERRIDE {
+ return SkISize::Make(512, 256);
+ }
+
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+ SkBitmap bitmap8888 = init_bitmap(SkBitmap::kARGB_8888_Config);
+ populate_argb8888(&bitmap8888);
+ SkBitmap bitmap4444 = init_bitmap(SkBitmap::kARGB_4444_Config);
+ populate_argb4444(&bitmap4444);
+
+ canvas->drawBitmap(bitmap8888, 0, 0);
+ canvas->drawBitmap(bitmap4444, SLIDE_SIZE, 0);
+ }
+
+private:
+ typedef GM INHERITED;
+};
+
+DEF_GM( return new BitmapPremulGM; )
+}
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | src/pdf/SkPDFImage.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698