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

Side by Side Diff: gm/all_bitmap_configs.cpp

Issue 1024113002: Revert of PDF: remove last use of SkPDFImage (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 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 "sk_tool_utils.h"
9 #include "SkSurface.h"
10 #include "Resources.h"
11 #include "gm.h"
12
13 static SkBitmap copy_bitmap(const SkBitmap& src, SkColorType colorType) {
14 SkBitmap copy;
15 src.copyTo(&copy, colorType);
16 copy.setImmutable();
17 return copy;
18 }
19
20 // Make either A8 or gray8 bitmap.
21 static SkBitmap make_bitmap(bool alpha) {
22 SkBitmap bm;
23 SkImageInfo info = alpha ? SkImageInfo::MakeA8(128, 128)
24 : SkImageInfo::Make(128, 128, kGray_8_SkColorType,
25 kOpaque_SkAlphaType);
26 bm.allocPixels(info);
27 SkAutoLockPixels autoLockPixels(bm);
28 uint8_t spectrum[256];
29 for (int y = 0; y < 256; ++y) {
30 spectrum[y] = y;
31 }
32 for (int y = 0; y < 128; ++y) {
33 // Shift over one byte each scanline.
34 memcpy(bm.getAddr8(0, y), &spectrum[y], 128);
35 }
36 bm.setImmutable();
37 return bm;
38 }
39
40 static void draw(SkCanvas* canvas,
41 const SkPaint& p,
42 const SkBitmap& src,
43 SkColorType colorType,
44 const char text[]) {
45 SkASSERT(src.colorType() == colorType);
46 canvas->drawBitmap(src, 0.0f, 0.0f);
47 canvas->drawText(text, strlen(text), 0.0f, 12.0f, p);
48 }
49
50 #define SCALE 128
51 DEF_SIMPLE_GM(all_bitmap_configs, canvas, SCALE, 6 * SCALE) {
52 SkAutoCanvasRestore autoCanvasRestore(canvas, true);
53 SkPaint p;
54 p.setColor(SK_ColorBLACK);
55 p.setAntiAlias(true);
56 sk_tool_utils::set_portable_typeface(&p, NULL, SkTypeface::kBold);
57
58 sk_tool_utils::draw_checkerboard(canvas, SK_ColorLTGRAY, SK_ColorWHITE, 8);
59
60 SkBitmap bitmap;
61 if (GetResourceAsBitmap("color_wheel.png", &bitmap)) {
62 bitmap.setImmutable();
63 draw(canvas, p, bitmap, kN32_SkColorType, "Native 32");
64
65 canvas->translate(0.0f, SkIntToScalar(SCALE));
66 SkBitmap copy565 = copy_bitmap(bitmap, kRGB_565_SkColorType);
67 p.setColor(SK_ColorRED);
68 draw(canvas, p, copy565, kRGB_565_SkColorType, "RGB 565");
69 p.setColor(SK_ColorBLACK);
70
71 canvas->translate(0.0f, SkIntToScalar(SCALE));
72 SkBitmap copy4444 = copy_bitmap(bitmap, kARGB_4444_SkColorType);
73 draw(canvas, p, copy4444, kARGB_4444_SkColorType, "ARGB 4444");
74 } else {
75 canvas->translate(0.0f, SkIntToScalar(2 * SCALE));
76 }
77
78 canvas->translate(0.0f, SkIntToScalar(SCALE));
79 SkBitmap bitmapIndexed;
80 if (GetResourceAsBitmap("color_wheel.gif", &bitmapIndexed)) {
81 bitmapIndexed.setImmutable();
82 draw(canvas, p, bitmapIndexed, kIndex_8_SkColorType, "Index 8");
83 }
84
85 canvas->translate(0.0f, SkIntToScalar(SCALE));
86 SkBitmap bitmapA8 = make_bitmap(true);
87 draw(canvas, p, bitmapA8, kAlpha_8_SkColorType, "Alpha 8");
88
89 p.setColor(SK_ColorRED);
90 canvas->translate(0.0f, SkIntToScalar(SCALE));
91 SkBitmap bitmapG8 = make_bitmap(false);
92 draw(canvas, p, bitmapG8, kGray_8_SkColorType, "Gray 8");
93 }
OLDNEW
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698