OLD | NEW |
| (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(©, 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 } | |
OLD | NEW |