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