| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "gm.h" | 8 #include "gm.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| 11 #include "SkColorPriv.h" | 11 #include "SkColorPriv.h" |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * This GM checks that bitmap pixels are unpremultiplied before being exported | 14 * This GM checks that bitmap pixels are unpremultiplied before being exported |
| 15 * to other formats. If unpremultiplication is implemented properly, this | 15 * to other formats. If unpremultiplication is implemented properly, this |
| 16 * GM should come out completely white. If not, this GM looks like a row of two | 16 * GM should come out completely white. If not, this GM looks like a row of two |
| 17 * greyscale gradients above a row of grey lines. | 17 * greyscale gradients above a row of grey lines. |
| 18 * This tests both the ARGB4444 and ARGB8888 bitmap configurations. | 18 * This tests both the ARGB4444 and ARGB8888 bitmap configurations. |
| 19 */ | 19 */ |
| 20 | 20 |
| 21 static const int SLIDE_SIZE = 256; | 21 static const int SLIDE_SIZE = 256; |
| 22 static const int PIXEL_SIZE_8888 = SLIDE_SIZE / 256; | 22 static const int PIXEL_SIZE_8888 = SLIDE_SIZE / 256; |
| 23 static const int PIXEL_SIZE_4444 = SLIDE_SIZE / 16; | 23 static const int PIXEL_SIZE_4444 = SLIDE_SIZE / 16; |
| 24 | 24 |
| 25 static void init_bitmap(SkBitmap::Config config, SkBitmap* bitmap) { | 25 static void init_bitmap(SkColorType ct, SkBitmap* bitmap) { |
| 26 bitmap->allocConfigPixels(config, SLIDE_SIZE, SLIDE_SIZE); | 26 bitmap->allocPixels(SkImageInfo::Make(SLIDE_SIZE, SLIDE_SIZE, ct, |
| 27 kPremul_SkAlphaType)); |
| 27 bitmap->eraseColor(SK_ColorWHITE); | 28 bitmap->eraseColor(SK_ColorWHITE); |
| 28 } | 29 } |
| 29 | 30 |
| 30 static SkBitmap make_argb8888_gradient() { | 31 static SkBitmap make_argb8888_gradient() { |
| 31 SkBitmap bitmap; | 32 SkBitmap bitmap; |
| 32 init_bitmap(SkBitmap::kARGB_8888_Config, &bitmap); | 33 init_bitmap(kPMColor_SkColorType, &bitmap); |
| 33 uint8_t rowColor = 0; | 34 uint8_t rowColor = 0; |
| 34 for (int y = 0; y < SLIDE_SIZE; y++) { | 35 for (int y = 0; y < SLIDE_SIZE; y++) { |
| 35 uint32_t* dst = bitmap.getAddr32(0, y); | 36 uint32_t* dst = bitmap.getAddr32(0, y); |
| 36 for (int x = 0; x < SLIDE_SIZE; x++) { | 37 for (int x = 0; x < SLIDE_SIZE; x++) { |
| 37 dst[x] = SkPackARGB32(rowColor, rowColor, | 38 dst[x] = SkPackARGB32(rowColor, rowColor, |
| 38 rowColor, rowColor); | 39 rowColor, rowColor); |
| 39 } | 40 } |
| 40 if (y % PIXEL_SIZE_8888 == PIXEL_SIZE_8888 - 1) { | 41 if (y % PIXEL_SIZE_8888 == PIXEL_SIZE_8888 - 1) { |
| 41 rowColor++; | 42 rowColor++; |
| 42 } | 43 } |
| 43 } | 44 } |
| 44 return bitmap; | 45 return bitmap; |
| 45 } | 46 } |
| 46 | 47 |
| 47 static SkBitmap make_argb4444_gradient() { | 48 static SkBitmap make_argb4444_gradient() { |
| 48 SkBitmap bitmap; | 49 SkBitmap bitmap; |
| 49 init_bitmap(SkBitmap::kARGB_4444_Config, &bitmap); | 50 init_bitmap(kARGB_4444_SkColorType, &bitmap); |
| 50 uint8_t rowColor = 0; | 51 uint8_t rowColor = 0; |
| 51 for (int y = 0; y < SLIDE_SIZE; y++) { | 52 for (int y = 0; y < SLIDE_SIZE; y++) { |
| 52 uint16_t* dst = bitmap.getAddr16(0, y); | 53 uint16_t* dst = bitmap.getAddr16(0, y); |
| 53 for (int x = 0; x < SLIDE_SIZE; x++) { | 54 for (int x = 0; x < SLIDE_SIZE; x++) { |
| 54 dst[x] = SkPackARGB4444(rowColor, rowColor, | 55 dst[x] = SkPackARGB4444(rowColor, rowColor, |
| 55 rowColor, rowColor); | 56 rowColor, rowColor); |
| 56 } | 57 } |
| 57 if (y % PIXEL_SIZE_4444 == PIXEL_SIZE_4444 - 1) { | 58 if (y % PIXEL_SIZE_4444 == PIXEL_SIZE_4444 - 1) { |
| 58 rowColor++; | 59 rowColor++; |
| 59 } | 60 } |
| 60 } | 61 } |
| 61 return bitmap; | 62 return bitmap; |
| 62 } | 63 } |
| 63 | 64 |
| 64 static SkBitmap make_argb8888_stripes() { | 65 static SkBitmap make_argb8888_stripes() { |
| 65 SkBitmap bitmap; | 66 SkBitmap bitmap; |
| 66 init_bitmap(SkBitmap::kARGB_8888_Config, &bitmap); | 67 init_bitmap(kPMColor_SkColorType, &bitmap); |
| 67 uint8_t rowColor = 0; | 68 uint8_t rowColor = 0; |
| 68 for (int y = 0; y < SLIDE_SIZE; y++) { | 69 for (int y = 0; y < SLIDE_SIZE; y++) { |
| 69 uint32_t* dst = bitmap.getAddr32(0, y); | 70 uint32_t* dst = bitmap.getAddr32(0, y); |
| 70 for (int x = 0; x < SLIDE_SIZE; x++) { | 71 for (int x = 0; x < SLIDE_SIZE; x++) { |
| 71 dst[x] = SkPackARGB32(rowColor, rowColor, | 72 dst[x] = SkPackARGB32(rowColor, rowColor, |
| 72 rowColor, rowColor); | 73 rowColor, rowColor); |
| 73 } | 74 } |
| 74 if (rowColor == 0) { | 75 if (rowColor == 0) { |
| 75 rowColor = 255; | 76 rowColor = 255; |
| 76 } else { | 77 } else { |
| 77 rowColor = 0; | 78 rowColor = 0; |
| 78 } | 79 } |
| 79 } | 80 } |
| 80 return bitmap; | 81 return bitmap; |
| 81 } | 82 } |
| 82 | 83 |
| 83 static SkBitmap make_argb4444_stripes() { | 84 static SkBitmap make_argb4444_stripes() { |
| 84 SkBitmap bitmap; | 85 SkBitmap bitmap; |
| 85 init_bitmap(SkBitmap::kARGB_4444_Config, &bitmap); | 86 init_bitmap(kARGB_4444_SkColorType, &bitmap); |
| 86 uint8_t rowColor = 0;; | 87 uint8_t rowColor = 0;; |
| 87 for (int y = 0; y < SLIDE_SIZE; y++) { | 88 for (int y = 0; y < SLIDE_SIZE; y++) { |
| 88 uint16_t* dst = bitmap.getAddr16(0, y); | 89 uint16_t* dst = bitmap.getAddr16(0, y); |
| 89 for (int x = 0; x < SLIDE_SIZE; x++) { | 90 for (int x = 0; x < SLIDE_SIZE; x++) { |
| 90 dst[x] = SkPackARGB4444(rowColor, rowColor, | 91 dst[x] = SkPackARGB4444(rowColor, rowColor, |
| 91 rowColor, rowColor); | 92 rowColor, rowColor); |
| 92 } | 93 } |
| 93 if (rowColor == 0) { | 94 if (rowColor == 0) { |
| 94 rowColor = 15; | 95 rowColor = 15; |
| 95 } else { | 96 } else { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 123 canvas->drawBitmap(make_argb8888_stripes(), 0, slideSize); | 124 canvas->drawBitmap(make_argb8888_stripes(), 0, slideSize); |
| 124 canvas->drawBitmap(make_argb4444_stripes(), slideSize, slideSize); | 125 canvas->drawBitmap(make_argb4444_stripes(), slideSize, slideSize); |
| 125 } | 126 } |
| 126 | 127 |
| 127 private: | 128 private: |
| 128 typedef GM INHERITED; | 129 typedef GM INHERITED; |
| 129 }; | 130 }; |
| 130 | 131 |
| 131 DEF_GM( return new BitmapPremulGM; ) | 132 DEF_GM( return new BitmapPremulGM; ) |
| 132 } | 133 } |
| OLD | NEW |