Chromium Code Reviews| 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 DEF_SIMPLE_GM(all_bitmap_configs, canvas, 128, 640) { | |
| 14 SkPaint p; | |
| 15 p.setColor(SK_ColorBLACK); | |
| 16 sk_tool_utils::set_portable_typeface(&p); | |
| 17 | |
| 18 sk_tool_utils::draw_checkerboard(canvas, SK_ColorLTGRAY, SK_ColorWHITE, 8); | |
| 19 | |
| 20 SkBitmap bitmap; | |
| 21 if (GetResourceAsBitmap("color_wheel.png", &bitmap)) { | |
| 22 bitmap.setImmutable(); | |
| 23 SkASSERT(bitmap.colorType() == kN32_SkColorType); | |
| 24 canvas->drawBitmap(bitmap, 0.0f, 0.0f); | |
| 25 const char kN32[] = "Native 32"; | |
| 26 canvas->drawText(kN32, strlen(kN32), 0, 12, p); | |
| 27 | |
| 28 SkAutoTUnref<SkSurface> surf565(SkSurface::NewRaster(SkImageInfo::Make( | |
|
mtklein
2015/02/23 14:26:52
Why not use SkBitmap::copyTo() here too?
hal.canary
2015/03/20 01:09:45
Done.
| |
| 29 128, 128, kRGB_565_SkColorType, kOpaque_SkAlphaType))); | |
| 30 SkCanvas* canvas565 = surf565->getCanvas(); | |
| 31 canvas565->drawColor(SK_ColorLTGRAY); | |
| 32 canvas565->drawBitmap(bitmap, 0.0f, 0.0f); | |
| 33 surf565->draw(canvas, 0.0f, 128.0f, NULL); | |
| 34 const char kRGB565[] = "RGB 565"; | |
| 35 canvas->drawText(kRGB565, strlen(kRGB565), 0, 140, p); | |
| 36 | |
| 37 SkBitmap copy4444; | |
| 38 bitmap.copyTo(©4444, kARGB_4444_SkColorType); | |
| 39 copy4444.setImmutable(); | |
| 40 SkASSERT(copy4444.colorType() == kARGB_4444_SkColorType); | |
| 41 canvas->drawBitmap(copy4444, 0.0f, 256.0f); | |
| 42 const char kARGB4444[] = "ARGB 4444"; | |
| 43 canvas->drawText(kARGB4444, strlen(kARGB4444), 0, 268, p); | |
| 44 } | |
| 45 | |
| 46 SkBitmap bitmapIndexed; | |
| 47 if (GetResourceAsBitmap("color_wheel.gif", &bitmapIndexed)) { | |
| 48 bitmapIndexed.setImmutable(); | |
| 49 SkASSERT(bitmapIndexed.colorType() == kIndex_8_SkColorType); | |
| 50 canvas->drawBitmap(bitmapIndexed, 0.0f, 384.0f); | |
| 51 const char kIndex8[] = "Index 8"; | |
| 52 canvas->drawText(kIndex8, strlen(kIndex8), 0, 396, p); | |
| 53 } | |
| 54 | |
| 55 SkBitmap bitmapA8; | |
| 56 bitmapA8.allocPixels(SkImageInfo::MakeA8(128, 128)); | |
| 57 SkAutoLockPixels autoLockPixels(bitmapA8); | |
| 58 uint8_t spectrum[256]; | |
|
mtklein
2015/02/23 14:26:52
Seems fine, but we really only need 128, right?
hal.canary
2015/03/20 01:09:45
I'm shifting it over one pixel for each scanline.
| |
| 59 for (int y = 0; y < 256; ++y) { | |
| 60 spectrum[y] = y; | |
| 61 } | |
| 62 for (int y = 0; y < 128; ++y) { | |
| 63 memcpy(bitmapA8.getAddr8(0, y), &spectrum[y], 128); | |
| 64 } | |
| 65 bitmapA8.setImmutable(); | |
| 66 SkASSERT(bitmapA8.colorType() == kAlpha_8_SkColorType); | |
| 67 canvas->drawBitmap(bitmapA8, 0.0f, 512.0f); | |
| 68 const char kAlpha8[] = "Alpha 8"; | |
| 69 canvas->drawText(kAlpha8, strlen(kAlpha8), 0, 524, p); | |
| 70 } | |
| OLD | NEW |