blob: 4d3be140bfa21bdbc3743cfeed4815e8250292d1 [file] [log] [blame]
Mike Kleind3525292020-01-28 13:12:50 -06001/*
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
14DEF_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 Klein5e58f942020-01-28 15:43:04 -060034 kGray_8_SkColorType,
Mike Kleind3525292020-01-28 13:12:50 -060035 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 Klein5e58f942020-01-28 15:43:04 -060043 // 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 Kleind3525292020-01-28 13:12:50 -060049 };
50
51 grade(64, 64);
52 grade(64, 192);
53}