| 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(SkColorType ct, SkBitmap* bitmap) { | 25 static SkBitmap make_bitmap(SkColorType ct) { |
| 26 bitmap->allocPixels(SkImageInfo::Make(SLIDE_SIZE, SLIDE_SIZE, ct, | 26 SkBitmap bitmap; |
| 27 kPremul_SkAlphaType)); | 27 bitmap.allocPixels(SkImageInfo::Make(SLIDE_SIZE, SLIDE_SIZE, ct, |
| 28 bitmap->eraseColor(SK_ColorWHITE); | 28 kPremul_SkAlphaType)); |
| 29 bitmap.eraseColor(SK_ColorWHITE); |
| 30 return skstd::move(bitmap); |
| 29 } | 31 } |
| 30 | 32 |
| 31 static SkBitmap make_argb8888_gradient() { | 33 static SkBitmap make_argb8888_gradient() { |
| 32 SkBitmap bitmap; | 34 SkBitmap bitmap(make_bitmap(kN32_SkColorType)); |
| 33 init_bitmap(kN32_SkColorType, &bitmap); | |
| 34 uint8_t rowColor = 0; | 35 uint8_t rowColor = 0; |
| 35 for (int y = 0; y < SLIDE_SIZE; y++) { | 36 for (int y = 0; y < SLIDE_SIZE; y++) { |
| 36 uint32_t* dst = bitmap.getAddr32(0, y); | 37 uint32_t* dst = bitmap.getAddr32(0, y); |
| 37 for (int x = 0; x < SLIDE_SIZE; x++) { | 38 for (int x = 0; x < SLIDE_SIZE; x++) { |
| 38 dst[x] = SkPackARGB32(rowColor, rowColor, | 39 dst[x] = SkPackARGB32(rowColor, rowColor, |
| 39 rowColor, rowColor); | 40 rowColor, rowColor); |
| 40 } | 41 } |
| 41 if (y % PIXEL_SIZE_8888 == PIXEL_SIZE_8888 - 1) { | 42 if (y % PIXEL_SIZE_8888 == PIXEL_SIZE_8888 - 1) { |
| 42 rowColor++; | 43 rowColor++; |
| 43 } | 44 } |
| 44 } | 45 } |
| 45 return bitmap; | 46 return skstd::move(bitmap); |
| 46 } | 47 } |
| 47 | 48 |
| 48 static SkBitmap make_argb4444_gradient() { | 49 static SkBitmap make_argb4444_gradient() { |
| 49 SkBitmap bitmap; | 50 SkBitmap bitmap(make_bitmap(kARGB_4444_SkColorType)); |
| 50 init_bitmap(kARGB_4444_SkColorType, &bitmap); | |
| 51 uint8_t rowColor = 0; | 51 uint8_t rowColor = 0; |
| 52 for (int y = 0; y < SLIDE_SIZE; y++) { | 52 for (int y = 0; y < SLIDE_SIZE; y++) { |
| 53 uint16_t* dst = bitmap.getAddr16(0, y); | 53 uint16_t* dst = bitmap.getAddr16(0, y); |
| 54 for (int x = 0; x < SLIDE_SIZE; x++) { | 54 for (int x = 0; x < SLIDE_SIZE; x++) { |
| 55 dst[x] = SkPackARGB4444(rowColor, rowColor, | 55 dst[x] = SkPackARGB4444(rowColor, rowColor, |
| 56 rowColor, rowColor); | 56 rowColor, rowColor); |
| 57 } | 57 } |
| 58 if (y % PIXEL_SIZE_4444 == PIXEL_SIZE_4444 - 1) { | 58 if (y % PIXEL_SIZE_4444 == PIXEL_SIZE_4444 - 1) { |
| 59 rowColor++; | 59 rowColor++; |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 return bitmap; | 62 return skstd::move(bitmap); |
| 63 } | 63 } |
| 64 | 64 |
| 65 static SkBitmap make_argb8888_stripes() { | 65 static SkBitmap make_argb8888_stripes() { |
| 66 SkBitmap bitmap; | 66 SkBitmap bitmap(make_bitmap(kN32_SkColorType)); |
| 67 init_bitmap(kN32_SkColorType, &bitmap); | |
| 68 uint8_t rowColor = 0; | 67 uint8_t rowColor = 0; |
| 69 for (int y = 0; y < SLIDE_SIZE; y++) { | 68 for (int y = 0; y < SLIDE_SIZE; y++) { |
| 70 uint32_t* dst = bitmap.getAddr32(0, y); | 69 uint32_t* dst = bitmap.getAddr32(0, y); |
| 71 for (int x = 0; x < SLIDE_SIZE; x++) { | 70 for (int x = 0; x < SLIDE_SIZE; x++) { |
| 72 dst[x] = SkPackARGB32(rowColor, rowColor, | 71 dst[x] = SkPackARGB32(rowColor, rowColor, |
| 73 rowColor, rowColor); | 72 rowColor, rowColor); |
| 74 } | 73 } |
| 75 if (rowColor == 0) { | 74 if (rowColor == 0) { |
| 76 rowColor = 255; | 75 rowColor = 255; |
| 77 } else { | 76 } else { |
| 78 rowColor = 0; | 77 rowColor = 0; |
| 79 } | 78 } |
| 80 } | 79 } |
| 81 return bitmap; | 80 return skstd::move(bitmap); |
| 82 } | 81 } |
| 83 | 82 |
| 84 static SkBitmap make_argb4444_stripes() { | 83 static SkBitmap make_argb4444_stripes() { |
| 85 SkBitmap bitmap; | 84 SkBitmap bitmap(make_bitmap(kARGB_4444_SkColorType)); |
| 86 init_bitmap(kARGB_4444_SkColorType, &bitmap); | |
| 87 uint8_t rowColor = 0; | 85 uint8_t rowColor = 0; |
| 88 for (int y = 0; y < SLIDE_SIZE; y++) { | 86 for (int y = 0; y < SLIDE_SIZE; y++) { |
| 89 uint16_t* dst = bitmap.getAddr16(0, y); | 87 uint16_t* dst = bitmap.getAddr16(0, y); |
| 90 for (int x = 0; x < SLIDE_SIZE; x++) { | 88 for (int x = 0; x < SLIDE_SIZE; x++) { |
| 91 dst[x] = SkPackARGB4444(rowColor, rowColor, | 89 dst[x] = SkPackARGB4444(rowColor, rowColor, |
| 92 rowColor, rowColor); | 90 rowColor, rowColor); |
| 93 } | 91 } |
| 94 if (rowColor == 0) { | 92 if (rowColor == 0) { |
| 95 rowColor = 15; | 93 rowColor = 15; |
| 96 } else { | 94 } else { |
| 97 rowColor = 0; | 95 rowColor = 0; |
| 98 } | 96 } |
| 99 } | 97 } |
| 100 return bitmap; | 98 return skstd::move(bitmap); |
| 101 } | 99 } |
| 102 | 100 |
| 103 namespace skiagm { | 101 namespace skiagm { |
| 104 | 102 |
| 105 class BitmapPremulGM : public GM { | 103 class BitmapPremulGM : public GM { |
| 106 public: | 104 public: |
| 107 BitmapPremulGM() { | 105 BitmapPremulGM() { |
| 108 this->setBGColor(SK_ColorWHITE); | 106 this->setBGColor(SK_ColorWHITE); |
| 109 } | 107 } |
| 110 | 108 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 124 canvas->drawBitmap(make_argb8888_stripes(), 0, slideSize); | 122 canvas->drawBitmap(make_argb8888_stripes(), 0, slideSize); |
| 125 canvas->drawBitmap(make_argb4444_stripes(), slideSize, slideSize); | 123 canvas->drawBitmap(make_argb4444_stripes(), slideSize, slideSize); |
| 126 } | 124 } |
| 127 | 125 |
| 128 private: | 126 private: |
| 129 typedef GM INHERITED; | 127 typedef GM INHERITED; |
| 130 }; | 128 }; |
| 131 | 129 |
| 132 DEF_GM( return new BitmapPremulGM; ) | 130 DEF_GM( return new BitmapPremulGM; ) |
| 133 } | 131 } |
| OLD | NEW |