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/SkImage.h" 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); 28 c->drawImage(rgba.asImage(), 0,0); 29 c->drawImage(bgra.asImage(), 0,1); 30 c->restore(); 31 __anonacfd2ce40102(int x, int y)32 auto grade = [&](int x, int y){ 33 SkBitmap bm; 34 bm.allocPixels(SkImageInfo::Make(1,1, 35 kGray_8_SkColorType, 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 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); 50 }; 51 52 grade(64, 64); 53 grade(64, 192); 54 } 55