skia2/gm/alpha_image.cpp
Mike Reed b286bc2da8 Introduce new factory for SkColorFilters
Idea: transition callers to this, so we can later typedef SkColorFilter
and SkShader to the same thing.

Bug: skia:8937
Change-Id: I000c882e11622091aa44c141aa6ddd1216414f46
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/206685
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Mike Reed <reed@google.com>
2019-04-08 21:03:59 +00:00

55 lines
1.5 KiB
C++

/*
* 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 "SkColorFilter.h"
#include "SkImage.h"
#include "SkMaskFilter.h"
#include "SkShader.h"
static SkBitmap make_alpha_image(int w, int h) {
SkBitmap bm;
bm.allocPixels(SkImageInfo::MakeA8(w, h));
bm.eraseARGB(10, 0, 0 , 0);
for (int y = 0; y < bm.height(); ++y) {
for (int x = y; x < bm.width(); ++x) {
*bm.getAddr8(x, y) = 0xFF;
}
}
bm.setImmutable();
return bm;
}
static sk_sp<SkColorFilter> make_color_filter() {
SkScalar colorMatrix[20] = {
1, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 0.5, 0.5, 0,
0, 0, 0.5, 0.5, 0}; // mix G and A.
return SkColorFilters::MatrixRowMajor255(colorMatrix);
}
DEF_SIMPLE_GM(alpha_image, canvas, 256, 256) {
auto image = SkImage::MakeFromBitmap(make_alpha_image(96, 96));
SkPaint paint;
paint.setColorFilter(make_color_filter());
paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 10.0f));
canvas->drawImage(image.get(), 16, 16, &paint);
paint.setColorFilter(nullptr);
paint.setShader(SkShader::MakeColorShader(SK_ColorCYAN));
canvas->drawImage(image.get(), 144, 16, &paint);
paint.setColorFilter(make_color_filter());
canvas->drawImage(image.get(), 16, 144, &paint);
paint.setMaskFilter(nullptr);
canvas->drawImage(image.get(), 144, 144, &paint);
}