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