blob: 3097d658fcfd9014117ccf701c284bba0a6a951f [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"
Mike Reed568f0ae2021-01-24 08:57:23 -050011#include "include/core/SkImage.h"
Mike Kleind3525292020-01-28 13:12:50 -060012
13// This GM should draw two yellow boxes; the bug drew one in cyan.
14
15DEF_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 Reed568f0ae2021-01-24 08:57:23 -050028 c->drawImage(rgba.asImage(), 0,0);
29 c->drawImage(bgra.asImage(), 0,1);
Mike Kleind3525292020-01-28 13:12:50 -060030 c->restore();
31
32 auto grade = [&](int x, int y){
33 SkBitmap bm;
34 bm.allocPixels(SkImageInfo::Make(1,1,
Mike Klein5e58f942020-01-28 15:43:04 -060035 kGray_8_SkColorType,
Mike Kleind3525292020-01-28 13:12:50 -060036 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 Klein5e58f942020-01-28 15:43:04 -060044 // 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 Kleind3525292020-01-28 13:12:50 -060050 };
51
52 grade(64, 64);
53 grade(64, 192);
54}