xref: /aosp_15_r20/external/skia/gm/imagefiltersunpremul.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2023 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/SkColor.h"
12 #include "include/core/SkImage.h"
13 #include "include/core/SkPaint.h"
14 #include "include/effects/SkImageFilters.h"
15 
16 DEF_SIMPLE_GM_BG(imagefiltersunpremul, canvas, 64, 64, SK_ColorBLACK) {
17     // Draw an kUnpremul_SkAlphaType image using SkImageFilters::Image() and
18     // verify alpha channel was blended correctly.
19     SkBitmap bitmap;
20     bitmap.allocPixels(SkImageInfo::Make(64, 64, kRGBA_8888_SkColorType, kUnpremul_SkAlphaType));
21     bitmap.eraseColor(SkColorSetARGB(50, 255, 0, 0));
22     SkPaint paint;
23     paint.setImageFilter(SkImageFilters::Image(SkImages::RasterFromBitmap(bitmap),
24                                                SkCubicResampler::Mitchell()));
25     canvas->drawPaint(paint);
26 }
27