add a GM to demo dither
Change-Id: Idbed35f2c5a1420b66b68725761a7ceea8cdd3ba Reviewed-on: https://skia-review.googlesource.com/66461 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Mike Klein <mtklein@chromium.org>
This commit is contained in:
parent
b718fbb7f4
commit
2afe7873d8
34
gm/dither.cpp
Normal file
34
gm/dither.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2017 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "gm.h"
|
||||
#include "SkSurface.h"
|
||||
#include "SkGradientShader.h"
|
||||
|
||||
// This GM should make dithering somewhat visible when drawn into 565.
|
||||
|
||||
DEF_SIMPLE_GM(dither, canvas, 256,256) {
|
||||
// Create a compatible surface that's 8x8, as large as the largest dither pattern we use.
|
||||
auto surface = canvas->makeSurface(canvas->imageInfo().makeWH(8,8));
|
||||
if (!surface) {
|
||||
surface = SkSurface::MakeRasterN32Premul(8,8);
|
||||
}
|
||||
|
||||
// Draw a vertical red->green gradient.
|
||||
SkPaint paint;
|
||||
paint.setBlendMode(SkBlendMode::kSrc);
|
||||
paint.setDither(true);
|
||||
SkPoint pts[] = { {0,0}, {0,8} };
|
||||
SkColor colors[] = { 0xffff0000, 0xff00ff00 };
|
||||
paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2,
|
||||
SkShader::kClamp_TileMode));
|
||||
surface->getCanvas()->drawPaint(paint);
|
||||
|
||||
// Snap that and draw with a 32x zoom.
|
||||
canvas->scale(32,32);
|
||||
canvas->drawImage(surface->makeImageSnapshot(), 0,0);
|
||||
}
|
Loading…
Reference in New Issue
Block a user