2018-10-31 14:49:38 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkBlendMode.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkColor.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkColorSpace.h"
|
2021-01-25 00:49:21 +00:00
|
|
|
#include "include/core/SkImage.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkImageInfo.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
2018-10-31 14:49:38 +00:00
|
|
|
|
|
|
|
DEF_SIMPLE_GM(unpremul, canvas, 200, 200) {
|
|
|
|
const SkColor color = 0xbf400000;
|
|
|
|
|
|
|
|
auto grade = [&](int x, int y){
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocPixels(SkImageInfo::Make(1,1,
|
|
|
|
kBGRA_8888_SkColorType,
|
|
|
|
kUnpremul_SkAlphaType,
|
|
|
|
SkColorSpace::MakeSRGB()));
|
|
|
|
if (!canvas->readPixels(bm, x,y)) {
|
|
|
|
// Picture-backed canvases, that sort of thing. Just assume they're good.
|
|
|
|
MarkGMGood(canvas, 140,40);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkColor pixel;
|
|
|
|
memcpy(&pixel, bm.getAddr(0,0), sizeof(pixel));
|
|
|
|
|
|
|
|
auto close = [](int x, int y) {
|
|
|
|
return x-y < 2
|
|
|
|
&& y-x < 2;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (close(SkColorGetR(pixel), SkColorGetR(color)) &&
|
|
|
|
close(SkColorGetG(pixel), SkColorGetG(color)) &&
|
|
|
|
close(SkColorGetB(pixel), SkColorGetB(color)) &&
|
|
|
|
close(SkColorGetA(pixel), SkColorGetA(color))) {
|
|
|
|
|
|
|
|
MarkGMGood(canvas, 140,40);
|
|
|
|
} else {
|
|
|
|
MarkGMBad(canvas, 140,40);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setBlendMode(SkBlendMode::kSrc);
|
|
|
|
paint.setColor(color);
|
|
|
|
|
|
|
|
canvas->drawRect({0,0,100,100}, paint);
|
|
|
|
grade(50,50);
|
|
|
|
}
|
|
|
|
|
|
|
|
canvas->translate(0,100);
|
|
|
|
|
|
|
|
{
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setBlendMode(SkBlendMode::kSrc);
|
|
|
|
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocPixels(SkImageInfo::Make(100,100, kRGBA_8888_SkColorType, kUnpremul_SkAlphaType));
|
|
|
|
bm.eraseColor(color);
|
|
|
|
|
2021-01-25 00:49:21 +00:00
|
|
|
canvas->drawImage(bm.asImage(), 0,0, SkSamplingOptions(), &paint);
|
2018-10-31 14:49:38 +00:00
|
|
|
grade(50,150);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|