Mike Klein | d352529 | 2020-01-28 13:12:50 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 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 "gm/gm.h" |
| 9 | #include "include/core/SkBitmap.h" |
| 10 | #include "include/core/SkCanvas.h" |
| 11 | |
| 12 | // This GM should draw two yellow boxes; the bug drew one in cyan. |
| 13 | |
| 14 | DEF_SIMPLE_GM(skbug_9819, c, 256, 256) { |
| 15 | auto info = SkImageInfo::Make(1,1, kUnknown_SkColorType, kPremul_SkAlphaType); |
| 16 | SkBitmap rgba, |
| 17 | bgra; |
| 18 | rgba.allocPixels(info.makeColorType(kRGBA_8888_SkColorType)); |
| 19 | bgra.allocPixels(info.makeColorType(kBGRA_8888_SkColorType)); |
| 20 | |
| 21 | SkColor yellow = 0xffffff00; |
| 22 | rgba.eraseColor(yellow); |
| 23 | bgra.eraseColor(yellow); |
| 24 | |
| 25 | c->save(); |
| 26 | c->scale(128,128); |
| 27 | c->drawBitmap(rgba, 0,0); |
| 28 | c->drawBitmap(bgra, 0,1); |
| 29 | c->restore(); |
| 30 | |
| 31 | auto grade = [&](int x, int y){ |
| 32 | SkBitmap bm; |
| 33 | bm.allocPixels(SkImageInfo::Make(1,1, |
Mike Klein | 5e58f94 | 2020-01-28 15:43:04 -0600 | [diff] [blame] | 34 | kGray_8_SkColorType, |
Mike Klein | d352529 | 2020-01-28 13:12:50 -0600 | [diff] [blame] | 35 | kUnpremul_SkAlphaType, |
| 36 | SkColorSpace::MakeSRGB())); |
| 37 | if (!c->readPixels(bm, x,y)) { |
| 38 | // Picture-backed canvases, that sort of thing. Just assume they're good. |
| 39 | MarkGMGood(c, x+128, y); |
| 40 | return; |
| 41 | } |
| 42 | |
Mike Klein | 5e58f94 | 2020-01-28 15:43:04 -0600 | [diff] [blame] | 43 | // We test only luma so that grayscale destinations are also correctly graded: |
| 44 | // - yellow (good) is around 237 |
| 45 | // - cyan (bad) is around 202 |
| 46 | uint8_t gray = *bm.getAddr8(0,0); |
| 47 | (abs(gray - 237) > 2 ? MarkGMBad |
| 48 | : MarkGMGood)(c, x+128,y); |
Mike Klein | d352529 | 2020-01-28 13:12:50 -0600 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | grade(64, 64); |
| 52 | grade(64, 192); |
| 53 | } |