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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | src/pdf/SkPDFImage.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "gm.h"
9 #include "SkBitmap.h"
10 #include "SkCanvas.h"
11 #include "SkColorPriv.h"
12
13 /**
14 * This GM checks that bitmap pixels are unpremultiplied before being exported
15 * to other formats. If unpremultiplication is implemented properly, this
16 * GM should come out completely white. If not, this GM looks like two
17 * sets of greyscale gradients.
18 * This tests both the ARGB4444 and ARGB8888 bitmap configurations.
19 */
20
21 static const int SLIDE_SIZE = 256;
22 static const int PIXEL_SIZE_8888 = SLIDE_SIZE / 256;
23 static const int PIXEL_SIZE_4444 = SLIDE_SIZE / 16;
24
25 static SkBitmap init_bitmap(SkBitmap::Config config) {
26 SkBitmap bitmap;
27 bitmap.setConfig(config, SLIDE_SIZE, SLIDE_SIZE);
28 bitmap.allocPixels();
29 bitmap.eraseColor(SK_ColorWHITE);
30 return bitmap;
31 }
32
33 static void populate_argb8888(SkBitmap* bitmap) {
34 uint8_t rowColor = 0;
35 for (int y = 0; y < SLIDE_SIZE; y++) {
36 uint32_t* dst = bitmap->getAddr32(0, y);
37 for (int x = 0; x < SLIDE_SIZE; x++) {
38 dst[x] = SkPackARGB32(rowColor, rowColor,
39 rowColor, rowColor);
40 }
41 if (y % PIXEL_SIZE_8888 == PIXEL_SIZE_8888 - 1) {
42 rowColor++;
43 }
44 }
45 }
46
47 static void populate_argb4444(SkBitmap* bitmap) {
48 uint8_t rowColor = 0;
49 for (int y = 0; y < SLIDE_SIZE; y++) {
50 uint16_t* dst = bitmap->getAddr16(0, y);
51 for (int x = 0; x < SLIDE_SIZE; x++) {
52 dst[x] = SkPackARGB4444(rowColor, rowColor,
53 rowColor, rowColor);
54 }
55 if (y % PIXEL_SIZE_4444 == PIXEL_SIZE_4444 - 1) {
56 rowColor++;
57 }
58 }
59 }
60
61 namespace skiagm {
62
63 class BitmapPremulGM : public GM {
64 public:
65 BitmapPremulGM() {
66 this->setBGColor(0xFFFFFFFF);
67 }
68
69 protected:
70 SkString onShortName() SK_OVERRIDE {
71 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.
72 }
73
74 virtual SkISize onISize() SK_OVERRIDE {
75 return SkISize::Make(512, 256);
76 }
77
78 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
79 SkBitmap bitmap8888 = init_bitmap(SkBitmap::kARGB_8888_Config);
80 populate_argb8888(&bitmap8888);
81 SkBitmap bitmap4444 = init_bitmap(SkBitmap::kARGB_4444_Config);
82 populate_argb4444(&bitmap4444);
83
84 canvas->drawBitmap(bitmap8888, 0, 0);
85 canvas->drawBitmap(bitmap4444, SLIDE_SIZE, 0);
86 }
87
88 private:
89 typedef GM INHERITED;
90 };
91
92 DEF_GM( return new BitmapPremulGM; )
93 }
OLDNEW
« 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