1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "blur_large_rrects.h"
16 #include <native_drawing/drawing_color.h>
17 #include <native_drawing/drawing_brush.h>
18 #include <native_drawing/drawing_matrix.h>
19 #include <native_drawing/drawing_path.h>
20 #include <native_drawing/drawing_pen.h>
21 #include <native_drawing/drawing_mask_filter.h>
22 #include <native_drawing/drawing_filter.h>
23 #include <native_drawing/drawing_round_rect.h>
24 #include <native_drawing/drawing_round_rect.h>
25 #include <hilog/log.h>
26 #include "common/log_common.h"
27 #include "test_common.h"
28
BlurLargeRrects()29 BlurLargeRrects::BlurLargeRrects()
30 {
31 bitmapWidth_ = 300; // 300宽度
32 bitmapHeight_ = 300; // 300高度
33 fileName_ = "blur_large_rrects";
34 }
35
~BlurLargeRrects()36 BlurLargeRrects::~BlurLargeRrects() {}
37
38 // 用例名: blurlargerrects 测试 OH_Drawing_CanvasDrawRoundRect
39 // 迁移基于源码 gm\blurroundrect.cpp->dm\blur_large_rrects.cpp
OnTestFunction(OH_Drawing_Canvas * canvas)40 void BlurLargeRrects::OnTestFunction(OH_Drawing_Canvas *canvas)
41 {
42 DRAWING_LOGI("BlurLargeRrects::OnTestFunction start");
43 // 创建一个brush对象
44 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
45 // 创建一个滤波器对象
46 OH_Drawing_Filter *filter = OH_Drawing_FilterCreate();
47 // 创建一个模板滤波器
48 float sigma = 20.f;
49 OH_Drawing_MaskFilter *maskFilter = OH_Drawing_MaskFilterCreateBlur(OH_Drawing_BlurType::NORMAL, sigma, true);
50 // 为滤波器设置模板
51 OH_Drawing_FilterSetMaskFilter(filter, maskFilter);
52 // 设置画笔滤波器
53 OH_Drawing_BrushSetFilter(brush, filter);
54 // 创建矩形、圆角矩形
55 float left = 5.f;
56 float top = -20000.f;
57 float right = 240.f;
58 float bottom = 25.f;
59 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(left, top, right, bottom);
60 float xRad = 40.f;
61 float yRad = 40.f;
62 OH_Drawing_RoundRect *rrect = OH_Drawing_RoundRectCreate(rect, xRad, yRad);
63 int maxCount = 4;
64 for (int i = 0; i < maxCount; ++i) {
65 // 设置画笔颜色
66 // i = 0:蓝色。1的二进制是01,2的二进制是10.红色分量00与01相与的结果是00分量是0x00.绿色也是0x00.蓝色分量:(0 <
67 // 2)为真,分量是0xFF.
68 // i = 1:紫色。根据二进制红色01与01结果是01分量是0xFF绿色01与10结果00蓝色为真.故最终颜色是(0xFF, 0x00, 0xFF,
69 // 0xFF),即一个完全不透明的紫色(红色+蓝色混合).
70 // i = 2;绿色。计算与上面同理,红色00绿色10蓝色为假.
71 // i = 3;黄色。3的二进制是11红色11与01相与结果01分量0xFF,绿色也是0xFF,蓝色是0x00,最终颜色是(0xFF, 0xFF, 0x00,
72 // 0xFF),即一个完全不透明的黄色(红色和绿色).
73 int bitwise1 = 1;
74 int bitwise2 = 2;
75 OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(0xFF, (i & bitwise1) ? 0xFF : 0x00,
76 (i & bitwise2) ? 0xFF : 0x00, (i < bitwise2) ? 0xFF : 0x00));
77 DRAWING_LOGI("BlurLargeRrects::OnTestFunction The number of times i = %{public}d ,The value of i = %{public}u",
78 i,
79 OH_Drawing_ColorSetArgb(0xFF, (i & bitwise1) ? 0xFF : 0x00, (i & bitwise2) ? 0xFF : 0x00,
80 (i < bitwise2) ? 0xFF : 0x00));
81 // 上画布
82 OH_Drawing_CanvasAttachBrush(canvas, brush);
83 // 画一个圆角矩形
84 OH_Drawing_CanvasDrawRoundRect(canvas, rrect);
85 // 设置画布旋转角度
86 float degrees = 90.f;
87 float px = 150.f;
88 float py = 150.f;
89 OH_Drawing_CanvasRotate(canvas, degrees, px, py);
90 }
91
92 // 释放内存
93 OH_Drawing_MaskFilterDestroy(maskFilter);
94 OH_Drawing_FilterDestroy(filter);
95 OH_Drawing_CanvasDetachBrush(canvas);
96 OH_Drawing_RectDestroy(rect);
97 OH_Drawing_RoundRectDestroy(rrect);
98 OH_Drawing_BrushDestroy(brush);
99 brush = nullptr;
100 DRAWING_LOGI("BlurLargeRrects::OnTestFunction end");
101 }
102