| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "sk_tool_utils.h" | 8 #include "sk_tool_utils.h" |
| 9 #include "SkSurface.h" | 9 #include "SkSurface.h" |
| 10 #include "Resources.h" | 10 #include "Resources.h" |
| 11 #include "gm.h" | 11 #include "gm.h" |
| 12 | 12 |
| 13 #include "SkMath.h" | 13 #include "SkMath.h" |
| 14 #include "SkColorPriv.h" | 14 #include "SkColorPriv.h" |
| 15 | 15 |
| 16 static SkBitmap copy_bitmap(const SkBitmap& src, SkColorType colorType) { | 16 static SkBitmap copy_bitmap(const SkBitmap& src, SkColorType colorType) { |
| 17 SkBitmap copy; | 17 SkBitmap copy; |
| 18 src.copyTo(©, colorType); | 18 src.copyTo(©, colorType); |
| 19 copy.setImmutable(); | 19 copy.setImmutable(); |
| 20 return copy; | 20 return skstd::move(copy); |
| 21 } | 21 } |
| 22 | 22 |
| 23 #define SCALE 128 | 23 #define SCALE 128 |
| 24 | 24 |
| 25 // Make either A8 or gray8 bitmap. | 25 // Make either A8 or gray8 bitmap. |
| 26 static SkBitmap make_bitmap(SkColorType ct) { | 26 static SkBitmap make_bitmap(SkColorType ct) { |
| 27 SkBitmap bm; | 27 SkBitmap bm; |
| 28 switch (ct) { | 28 switch (ct) { |
| 29 case kAlpha_8_SkColorType: | 29 case kAlpha_8_SkColorType: |
| 30 bm.allocPixels(SkImageInfo::MakeA8(SCALE, SCALE)); | 30 bm.allocPixels(SkImageInfo::MakeA8(SCALE, SCALE)); |
| 31 break; | 31 break; |
| 32 case kGray_8_SkColorType: | 32 case kGray_8_SkColorType: |
| 33 bm.allocPixels( | 33 bm.allocPixels( |
| 34 SkImageInfo::Make(SCALE, SCALE, ct, kOpaque_SkAlphaType)); | 34 SkImageInfo::Make(SCALE, SCALE, ct, kOpaque_SkAlphaType)); |
| 35 break; | 35 break; |
| 36 default: | 36 default: |
| 37 SkASSERT(false); | 37 SkASSERT(false); |
| 38 return bm; | 38 return bm; |
| 39 } | 39 } |
| 40 SkAutoLockPixels autoLockPixels(bm); | 40 SkAutoLockPixels autoLockPixels(bm); |
| 41 uint8_t spectrum[256]; | 41 uint8_t spectrum[256]; |
| 42 for (int y = 0; y < 256; ++y) { | 42 for (int y = 0; y < 256; ++y) { |
| 43 spectrum[y] = y; | 43 spectrum[y] = y; |
| 44 } | 44 } |
| 45 for (int y = 0; y < 128; ++y) { | 45 for (int y = 0; y < 128; ++y) { |
| 46 // Shift over one byte each scanline. | 46 // Shift over one byte each scanline. |
| 47 memcpy(bm.getAddr8(0, y), &spectrum[y], 128); | 47 memcpy(bm.getAddr8(0, y), &spectrum[y], 128); |
| 48 } | 48 } |
| 49 bm.setImmutable(); | 49 bm.setImmutable(); |
| 50 return bm; | 50 return skstd::move(bm); |
| 51 } | 51 } |
| 52 | 52 |
| 53 static void draw_center_letter(char c, | 53 static void draw_center_letter(char c, |
| 54 SkPaint* p, | 54 SkPaint* p, |
| 55 SkColor color, | 55 SkColor color, |
| 56 SkScalar x, | 56 SkScalar x, |
| 57 SkScalar y, | 57 SkScalar y, |
| 58 SkCanvas* canvas) { | 58 SkCanvas* canvas) { |
| 59 SkRect bounds; | 59 SkRect bounds; |
| 60 p->setColor(color); | 60 p->setColor(color); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 bm.allocPixels(info, nullptr, ctable); | 130 bm.allocPixels(info, nullptr, ctable); |
| 131 SkAutoLockPixels autoLockPixels1(n32bitmap); | 131 SkAutoLockPixels autoLockPixels1(n32bitmap); |
| 132 SkAutoLockPixels autoLockPixels2(bm); | 132 SkAutoLockPixels autoLockPixels2(bm); |
| 133 for (int y = 0; y < SCALE; ++y) { | 133 for (int y = 0; y < SCALE; ++y) { |
| 134 for (int x = 0; x < SCALE; ++x) { | 134 for (int x = 0; x < SCALE; ++x) { |
| 135 SkPMColor c = *n32bitmap.getAddr32(x, y); | 135 SkPMColor c = *n32bitmap.getAddr32(x, y); |
| 136 int idx = find(pmColors, SK_ARRAY_COUNT(pmColors), c); | 136 int idx = find(pmColors, SK_ARRAY_COUNT(pmColors), c); |
| 137 *bm.getAddr8(x, y) = SkClampMax(idx, SK_ARRAY_COUNT(pmColors) - 1); | 137 *bm.getAddr8(x, y) = SkClampMax(idx, SK_ARRAY_COUNT(pmColors) - 1); |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 return bm; | 140 return skstd::move(bm); |
| 141 } | 141 } |
| 142 | 142 |
| 143 static void draw(SkCanvas* canvas, | 143 static void draw(SkCanvas* canvas, |
| 144 const SkPaint& p, | 144 const SkPaint& p, |
| 145 const SkBitmap& src, | 145 const SkBitmap& src, |
| 146 SkColorType colorType, | 146 SkColorType colorType, |
| 147 const char text[]) { | 147 const char text[]) { |
| 148 SkASSERT(src.colorType() == colorType); | 148 SkASSERT(src.colorType() == colorType); |
| 149 canvas->drawBitmap(src, 0.0f, 0.0f); | 149 canvas->drawBitmap(src, 0.0f, 0.0f); |
| 150 canvas->drawText(text, strlen(text), 0.0f, 12.0f, p); | 150 canvas->drawText(text, strlen(text), 0.0f, 12.0f, p); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 SkASSERT(notN32bitmap.colorType() == ct); | 209 SkASSERT(notN32bitmap.colorType() == ct); |
| 210 return SkImage::NewFromBitmap(notN32bitmap); | 210 return SkImage::NewFromBitmap(notN32bitmap); |
| 211 } | 211 } |
| 212 | 212 |
| 213 DEF_SIMPLE_GM(not_native32_bitmap_config, canvas, SCALE, SCALE) { | 213 DEF_SIMPLE_GM(not_native32_bitmap_config, canvas, SCALE, SCALE) { |
| 214 SkAutoTUnref<SkImage> notN32image(make_not_native32_color_wheel()); | 214 SkAutoTUnref<SkImage> notN32image(make_not_native32_color_wheel()); |
| 215 SkASSERT(notN32image); | 215 SkASSERT(notN32image); |
| 216 sk_tool_utils::draw_checkerboard(canvas, SK_ColorLTGRAY, SK_ColorWHITE, 8); | 216 sk_tool_utils::draw_checkerboard(canvas, SK_ColorLTGRAY, SK_ColorWHITE, 8); |
| 217 canvas->drawImage(notN32image, 0.0f, 0.0f); | 217 canvas->drawImage(notN32image, 0.0f, 0.0f); |
| 218 } | 218 } |
| OLD | NEW |