• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 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.h"
9 #include "SkColor.h"
10 
11 DEF_SIMPLE_GM(unpremul, canvas, 200, 200) {
12     const SkColor color = 0xbf400000;
13 
__anon4a2aa7120102(int x, int y)14     auto grade = [&](int x, int y){
15         SkBitmap bm;
16         bm.allocPixels(SkImageInfo::Make(1,1,
17                                          kBGRA_8888_SkColorType,
18                                          kUnpremul_SkAlphaType,
19                                          SkColorSpace::MakeSRGB()));
20         if (!canvas->readPixels(bm, x,y)) {
21             // Picture-backed canvases, that sort of thing.  Just assume they're good.
22             MarkGMGood(canvas, 140,40);
23             return;
24         }
25 
26         SkColor pixel;
27         memcpy(&pixel, bm.getAddr(0,0), sizeof(pixel));
28 
29         auto close = [](int x, int y) {
30             return x-y < 2
31                 && y-x < 2;
32         };
33 
34         if (close(SkColorGetR(pixel), SkColorGetR(color)) &&
35             close(SkColorGetG(pixel), SkColorGetG(color)) &&
36             close(SkColorGetB(pixel), SkColorGetB(color)) &&
37             close(SkColorGetA(pixel), SkColorGetA(color))) {
38 
39             MarkGMGood(canvas, 140,40);
40         } else {
41             MarkGMBad(canvas, 140,40);
42         }
43     };
44 
45     {
46         SkPaint paint;
47         paint.setBlendMode(SkBlendMode::kSrc);
48         paint.setColor(color);
49 
50         canvas->drawRect({0,0,100,100}, paint);
51         grade(50,50);
52     }
53 
54     canvas->translate(0,100);
55 
56     {
57         SkPaint paint;
58         paint.setBlendMode(SkBlendMode::kSrc);
59 
60         SkBitmap bm;
61         bm.allocPixels(SkImageInfo::Make(100,100, kRGBA_8888_SkColorType, kUnpremul_SkAlphaType));
62         bm.eraseColor(color);
63 
64         canvas->drawBitmap(bm, 0,0, &paint);
65         grade(50,150);
66     }
67 
68 }
69