• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in comliance with the License.
5  * You may obtian 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 
16 #include "../../dtk_constants.h"
17 #include "../../dtk_test_ext.h"
18 #include "../../utils.h"
19 
20 namespace OHOS {
21 namespace Rosen {
22 
23 using namespace Drawing;
24 
25 // Pixmap_Scene_0001
26 // Pixmap构造接口:Pixmap_ImageInfo_01
27 // Pixmap操作接口:GetWidth
28 // cilp:ClipPath
29 // transform:ConcatMatrix
30 // 抗锯齿:AA
31 // 透明度:透明
32 // 视效:CreateLinearGradient
33 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 1)
34 {
35     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
36     Drawing::Brush brush;
37     brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
38 
39     // 2.Pixmap构造接口
40     auto colorspace = Drawing::ColorSpace::CreateSRGB();
41     ImageInfo imageInfo(512, 512, COLORTYPE_UNKNOWN, ALPHATYPE_UNKNOWN, colorspace); // 512 width * 512 height
42     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
43 
44     // 3.Pixmap操作接口
45     auto width = pixmap.GetWidth();
46 
47     Drawing::Bitmap bitmap1;
48     bitmap1.Build(imageInfo);
49     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
50     bitmap1.ClearWithColor(0x004567FA); // 透明效果,粉蓝色
51 
52     // 4.设置视效效果,将效果添加到笔刷
53     std::vector<Drawing::ColorQuad> colors = { Drawing::Color::COLOR_RED, Drawing::Color::COLOR_GREEN,
54         Drawing::Color::COLOR_BLUE };
55     std::vector<Drawing::scalar> pos = { 0.00f, 0.50f, 1.00f };
56     auto linearGradient =
57         Drawing::ShaderEffect::CreateLinearGradient({ 0, 0 }, { 1000, 1000 }, colors, pos, Drawing::TileMode::CLAMP);
58     brush.SetShaderEffect(linearGradient);
59 
60     // 5.组合transform函数
61     Drawing::Matrix matrix;
62     matrix.Rotate(15, 10, 10);
63     playbackCanvas_->ConcatMatrix(matrix);
64 
65     // 6.绘制结果
66     const void* pixel = pixmap.GetAddr();
67     bitmap1.SetPixels(const_cast<void*>(pixel));
68     playbackCanvas_->AttachBrush(brush);
69     playbackCanvas_->DrawRect(Rect(0, 0, width, 500)); // rect region (0, 0, width, 500)
70     playbackCanvas_->DrawBitmap(bitmap1, 250, 300);    // 250,300 is bitmap1 position
71     playbackCanvas_->DetachBrush();
72 
73     // 7.组合Clip函数,cilp也有抗锯齿效果,默认和笔刷效果保持一致
74     TestBase::ClipPath(true);
75 }
76 
77 // Pixmap_Scene_0002
78 // Pixmap构造接口:Pixmap_ImageInfo_01
79 // Pixmap操作接口:GetWidth
80 // cilp:ClipRoundRect(G2_capsule)
81 // transform:Scale(极大值)
82 // 抗锯齿:非AA
83 // 透明度:透明
84 // 视效:CreateBlendModeColorFilter
85 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 2)
86 {
87     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
88     Drawing::Brush brush;
89     brush.SetAntiAlias(false); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
90 
91     // 2.Pixmap构造接口
92     auto colorspace = Drawing::ColorSpace::CreateSRGB();
93     ImageInfo imageInfo(512, 512, COLORTYPE_UNKNOWN, ALPHATYPE_UNKNOWN, colorspace); // 512 width * 512 height
94     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
95 
96     // 3.Pixmap操作接口
97     auto width = pixmap.GetWidth();
98 
99     Drawing::Bitmap bitmap1;
100     bitmap1.Build(imageInfo);
101     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
102     bitmap1.ClearWithColor(0x004567FA); // 透明效果,粉蓝色
103 
104     // 4.组合transform函数
105     playbackCanvas_->Scale(1.0f, 10100.0f); // ratio
106 
107     int rectPos = 0;
108     brush.SetColor(0xFFFF0000);
109     for (auto blendMode : blendModes) {
110         std::shared_ptr<Drawing::ColorFilter> colorFilter =
111             Drawing::ColorFilter::CreateBlendModeColorFilter(0xFFFF0000, blendMode);
112         auto filter = Drawing::Filter();
113         // 5.设置视效效果,将效果添加到笔刷
114         filter.SetColorFilter(colorFilter);
115         brush.SetFilter(filter);
116         // 6.绘制结果
117         const void* pixel = pixmap.GetAddr();
118         bitmap1.SetPixels(const_cast<void*>(pixel));
119         playbackCanvas_->AttachBrush(brush);
120         playbackCanvas_->DrawRect(Rect(0 + (rectPos % VARIATION) * LEFT, 0 + (rectPos / VARIATION) * LEFT,
121             width + (rectPos % VARIATION) * LEFT,
122             500 + (rectPos / VARIATION) * LEFT)); // rect region (0, 0, width, 500)
123         playbackCanvas_->DrawBitmap(bitmap1, 250 + (rectPos % VARIATION) * LEFT,
124             300 + (rectPos / VARIATION) * RIGHT); // 250,300 is bitmap1 position
125         rectPos += 1;
126     }
127     playbackCanvas_->DetachBrush();
128 
129     // 7.组合Clip函数,cilp也有抗锯齿效果,默认和笔刷效果保持一致
130     TestBase::ClipRoundRectG2capsule(false);
131 }
132 
133 // Pixmap_Scene_0003
134 // Pixmap构造接口:Pixmap_ImageInfo_01
135 // Pixmap操作接口:GetHeight
136 // cilp:ClipRect
137 // transform:Rotate
138 // 抗锯齿:非AA
139 // 透明度:半透明
140 // 视效:CreateColorShader
141 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 3)
142 {
143     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
144     Drawing::Brush brush;
145     brush.SetAntiAlias(false); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
146 
147     // 2.Pixmap构造接口
148     auto colorspace = Drawing::ColorSpace::CreateSRGB();
149     ImageInfo imageInfo(512, 512, COLORTYPE_UNKNOWN, ALPHATYPE_UNKNOWN, colorspace); // 512 width * 512 height
150     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
151 
152     // 3.Pixmap操作接口
153     auto height = pixmap.GetHeight();
154 
155     Drawing::Bitmap bitmap1;
156     bitmap1.Build(imageInfo);
157     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
158     bitmap1.ClearWithColor(0x894567FA); // 半透明效果,粉蓝色
159 
160     // 4.设置视效效果,将效果添加到笔刷
161     brush.SetColor(0xFFFF0000);
162     auto colorShader = Drawing::ShaderEffect::CreateColorShader(Drawing::Color::COLOR_RED);
163     brush.SetShaderEffect(colorShader);
164 
165     // 5.组合transform函数
166     playbackCanvas_->Rotate(30, 10, 10); // 30 angle 10 position
167 
168     // 6.绘制结果
169     const void* pixel = pixmap.GetAddr();
170     bitmap1.SetPixels(const_cast<void*>(pixel));
171     playbackCanvas_->AttachBrush(brush);
172     playbackCanvas_->DrawRect(Rect(0, 0, 500, height)); // rect region (0, 0, 500, height)
173     playbackCanvas_->DrawBitmap(bitmap1, 250, 300);     // 250,300 is bitmap1 position
174     playbackCanvas_->DetachBrush();
175 
176     // 7.组合Clip函数,cilp也有抗锯齿效果,默认和笔刷效果保持一致
177     TestBase::ClipRect(false);
178 }
179 
180 // Pixmap_Scene_0004
181 // Pixmap构造接口:Pixmap_ImageInfo_01
182 // Pixmap操作接口:GetHeight
183 // cilp:ClipRoundRect(非G2)
184 // transform:Scale(极小值)
185 // 抗锯齿:AA
186 // 透明度:半透明
187 // 视效:CreateComposeColorFilter
188 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 4)
189 {
190     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
191     Drawing::Brush brush;
192     brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
193 
194     // 2.Pixmap构造接口
195     auto colorspace = Drawing::ColorSpace::CreateSRGB();
196     ImageInfo imageInfo(512, 512, COLORTYPE_UNKNOWN, ALPHATYPE_UNKNOWN, colorspace); // 512 width * 512 height
197     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
198 
199     // 3.Pixmap操作接口
200     auto height = pixmap.GetHeight();
201 
202     Drawing::Bitmap bitmap1;
203     bitmap1.Build(imageInfo);
204     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
205     bitmap1.ClearWithColor(0x894567FA); // 半透明效果,粉蓝色
206 
207     // 4.设置视效效果,将效果添加到笔刷
208     brush.SetColor(0xFFFF0000);
209     std::shared_ptr<Drawing::ColorFilter> colorFilter1 =
210         Drawing::ColorFilter::CreateBlendModeColorFilter(0xFFFF0000, Drawing::BlendMode::SRC_IN);
211     std::shared_ptr<Drawing::ColorFilter> colorFilter2 =
212         Drawing::ColorFilter::CreateBlendModeColorFilter(0xFFFF00FF, Drawing::BlendMode::MODULATE);
213     std::shared_ptr<Drawing::ColorFilter> colorFilter3 =
214         Drawing::ColorFilter::CreateComposeColorFilter(*colorFilter1, *colorFilter2);
215     auto filter = Drawing::Filter();
216     filter.SetColorFilter(colorFilter3);
217     brush.SetFilter(filter);
218 
219     // 5.组合transform函数
220     playbackCanvas_->Scale(10100.0f, 1.0f); // ratio
221 
222     // 6.绘制结果
223     const void* pixel = pixmap.GetAddr();
224     bitmap1.SetPixels(const_cast<void*>(pixel));
225     playbackCanvas_->AttachBrush(brush);
226     playbackCanvas_->DrawRect(Rect(0, 0, 500, height)); // rect region (0, 0, 500, height)
227     playbackCanvas_->DrawBitmap(bitmap1, 250, 300);     // 250,300 is bitmap1 position
228     playbackCanvas_->DetachBrush();
229 
230     // 7.组合Clip函数,cilp也有抗锯齿效果,默认和笔刷效果保持一致
231     TestBase::ClipRoundRectnotG2(true);
232 }
233 
234 // Pixmap_Scene_0005
235 // Pixmap构造接口:Pixmap_ImageInfo_01
236 // Pixmap操作接口:GetColorType
237 // cilp:ClipRoundRect(G2)
238 // transform:Scale(正常值)
239 // 抗锯齿:AA
240 // 透明度:不透明
241 // 视效:CreateBlurImageFilter
242 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 5)
243 {
244     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
245     Drawing::Brush brush;
246     brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
247 
248     // 2.Pixmap构造接口
249     auto colorspace = Drawing::ColorSpace::CreateSRGB();
250     ImageInfo imageInfo(512, 512, COLORTYPE_UNKNOWN, ALPHATYPE_UNKNOWN, colorspace); // 512 width * 512 height
251     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
252 
253     Drawing::Bitmap bitmap1;
254     bitmap1.Build(imageInfo);
255     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
256     bitmap1.ClearWithColor(0xFF4567FA); // 不透明效果,粉蓝色
257 
258     // 3.设置视效效果,将效果添加到笔刷
259     brush.SetColor(0xFFFF0000);
260     auto filter = Drawing::Filter();
261     filter.SetImageFilter(Drawing::ImageFilter::CreateBlurImageFilter(
262         10.0f, 10.0f, Drawing::TileMode::CLAMP, nullptr, Drawing::ImageBlurType::GAUSS));
263     brush.SetFilter(filter);
264 
265     // 4.组合transform函数
266     playbackCanvas_->Scale(2.0f, 2.0f); // ratio
267 
268     // 5.绘制结果
269     const void* pixel = pixmap.GetAddr();
270     bitmap1.SetPixels(const_cast<void*>(pixel));
271     playbackCanvas_->AttachBrush(brush);
272     // 6.Pixmap操作接口
273     if (pixmap.GetColorType() == COLORTYPE_UNKNOWN) {
274         playbackCanvas_->DrawRect(Drawing::Rect(800, 800, 1000, 1000)); // rect region (800, 800, 1000, 1000)
275     } else {
276         playbackCanvas_->DrawRect(Drawing::Rect(1000, 1000, 1200, 1200)); // rect region (1000, 1000, 1200, 1200)
277     }
278     playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap1 position
279     playbackCanvas_->DetachBrush();
280 
281     // 7.组合Clip函数,cilp也有抗锯齿效果,默认和笔刷效果保持一致
282     TestBase::ClipRoundRectG2(true);
283 }
284 
285 // Pixmap_Scene_0006
286 // Pixmap构造接口:Pixmap_ImageInfo_01
287 // Pixmap操作接口:GetColorType
288 // cilp:ClipRoundRect(G2)
289 // transform:Scale(正常值)
290 // 抗锯齿:AA
291 // 透明度:不透明
292 // 视效:CreateBlurMaskFilter
293 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 6)
294 {
295     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
296     Drawing::Brush brush;
297     brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
298 
299     // 2.Pixmap构造接口
300     auto colorspace = Drawing::ColorSpace::CreateSRGB();
301     ImageInfo imageInfo(512, 512, COLORTYPE_UNKNOWN, ALPHATYPE_UNKNOWN, colorspace); // 512 width * 512 height
302     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
303 
304     Drawing::Bitmap bitmap1;
305     bitmap1.Build(imageInfo);
306     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
307     bitmap1.ClearWithColor(0xFF4567FA); // 不透明效果,粉蓝色
308 
309     // 3.组合transform函数
310     playbackCanvas_->Scale(2.0f, 2.0f); // ratio
311 
312     int rectPos = 0;
313     brush.SetColor(0xFFFF0000);
314     for (auto& blurType : blurTypes) {
315         auto filter = Drawing::Filter();
316         // 4.设置视效效果,将效果添加到笔刷
317         filter.SetMaskFilter(Drawing::MaskFilter::CreateBlurMaskFilter(blurType, 10.0f, true));
318         brush.SetFilter(filter);
319         // 5.绘制结果
320         const void* pixel = pixmap.GetAddr();
321         bitmap1.SetPixels(const_cast<void*>(pixel));
322         playbackCanvas_->AttachBrush(brush);
323         // 6.Pixmap操作接口
324         if (pixmap.GetColorType() == COLORTYPE_UNKNOWN) {
325             playbackCanvas_->DrawRect(Drawing::Rect(800 + (rectPos % VARIATION) * LEFT,
326                 800 + (rectPos / VARIATION) * LEFT, 1000 + (rectPos % VARIATION) * LEFT,
327                 1000 + (rectPos / VARIATION) * LEFT)); // rect region (800, 800, 1000, 1000)
328         } else {
329             playbackCanvas_->DrawRect(Drawing::Rect(1000 + (rectPos % VARIATION) * LEFT,
330                 1000 + (rectPos / VARIATION) * LEFT, 1200 + (rectPos % VARIATION) * LEFT,
331                 1200 + (rectPos / VARIATION) * LEFT)); // rect region (1000, 1000, 1200, 1200)
332         }
333         playbackCanvas_->DrawBitmap(bitmap1, 250 + (rectPos % VARIATION) * LEFT,
334             300 + (rectPos / VARIATION) * RIGHT); // 250,300 is bitmap1 position
335         rectPos += 200;
336     }
337     playbackCanvas_->DetachBrush();
338 
339     // 7.组合Clip函数,cilp也有抗锯齿效果,默认和笔刷效果保持一致
340     TestBase::ClipRoundRectG2(true);
341 }
342 
343 // Pixmap_Scene_0007
344 // Pixmap构造接口:Pixmap_ImageInfo_01
345 // Pixmap操作接口:GetAlphaType
346 // cilp:ClipRoundRect(G2_capsule)
347 // transform:Scale(极大值)
348 // 抗锯齿:非AA
349 // 透明度:透明
350 // 视效:null
351 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 7)
352 {
353     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
354     Drawing::Brush brush;
355     brush.SetAntiAlias(false); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
356 
357     // 2.Pixmap构造接口
358     auto colorspace = Drawing::ColorSpace::CreateSRGB();
359     ImageInfo imageInfo(512, 512, COLORTYPE_UNKNOWN, ALPHATYPE_UNKNOWN, colorspace); // 512 width * 512 height
360     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
361 
362     Drawing::Bitmap bitmap1;
363     bitmap1.Build(imageInfo);
364     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
365     bitmap1.ClearWithColor(0x004567FA); // 透明效果,粉蓝色
366 
367     // 3.组合transform函数
368     playbackCanvas_->Scale(1.0f, 10100.0f); // ratio
369 
370     // 4.绘制结果
371     const void* pixel = pixmap.GetAddr();
372     bitmap1.SetPixels(const_cast<void*>(pixel));
373     playbackCanvas_->AttachBrush(brush);
374     // 5.Pixmap操作接口
375     if (pixmap.GetAlphaType() == ALPHATYPE_UNKNOWN) {
376         playbackCanvas_->DrawRect(Drawing::Rect(800, 800, 1000, 1000)); // rect region(800, 800, 1000, 1000)
377     } else {
378         playbackCanvas_->DrawRect(Drawing::Rect(1000, 1000, 1200, 1200)); // rect region(1000, 1000, 1200, 1200)
379     }
380     playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap1 position
381     playbackCanvas_->DetachBrush();
382 
383     // 6.组合Clip函数,cilp也有抗锯齿效果,默认和笔刷效果保持一致
384     TestBase::ClipRoundRectG2capsule(false);
385 }
386 
387 // Pixmap_Scene_0008
388 // Pixmap构造接口:Pixmap_ImageInfo_01
389 // Pixmap操作接口:GetAlphaType
390 // cilp:null
391 // transform:Translate
392 // 抗锯齿:非AA
393 // 透明度:不透明
394 // 视效:CreateMatrixColorFilter
395 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 8)
396 {
397     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
398     Drawing::Brush brush;
399     brush.SetAntiAlias(false); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
400 
401     // 2.Pixmap构造接口
402     auto colorspace = Drawing::ColorSpace::CreateSRGB();
403     ImageInfo imageInfo(512, 512, COLORTYPE_UNKNOWN, ALPHATYPE_UNKNOWN, colorspace); // 512 width * 512 height
404     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
405 
406     Drawing::Bitmap bitmap1;
407     bitmap1.Build(imageInfo);
408     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
409     bitmap1.ClearWithColor(0xFF4567FA); // 不透明效果,粉蓝色
410 
411     // 3.设置视效效果,将效果添加到笔刷
412     Drawing::ColorMatrix matrix;
413     matrix.SetArray(ARR);
414     auto cf = Drawing::ColorFilter::CreateMatrixColorFilter(matrix);
415     auto filter = Drawing::Filter();
416     filter.SetImageFilter(Drawing::ImageFilter::CreateColorFilterImageFilter(*cf, nullptr));
417     brush.SetFilter(filter);
418 
419     // 4.组合transform函数
420     playbackCanvas_->Translate(200, 200); // 200 distance
421 
422     // 5.绘制结果
423     const void* pixel = pixmap.GetAddr();
424     bitmap1.SetPixels(const_cast<void*>(pixel));
425     playbackCanvas_->AttachBrush(brush);
426     // 6.Pixmap操作接口
427     if (pixmap.GetAlphaType() == ALPHATYPE_UNKNOWN) {
428         playbackCanvas_->DrawRect(Drawing::Rect(800, 800, 1000, 1000)); // rect region(800, 800, 1000, 1000)
429     } else {
430         playbackCanvas_->DrawRect(Drawing::Rect(1000, 1000, 1200, 1200)); // rect region(1000, 1000, 1200, 1200)
431     }
432     playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap1 position
433     playbackCanvas_->DetachBrush();
434 }
435 
436 // Pixmap_Scene_0009
437 // Pixmap构造接口:Pixmap_ImageInfo_01
438 // Pixmap操作接口:GetColorSpace
439 // cilp:ClipPath
440 // transform:Shear
441 // 抗锯齿:AA
442 // 透明度:透明
443 // 视效:CreateLinearToSrgbGamma
444 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 9)
445 {
446     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
447     Drawing::Brush brush;
448     brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
449 
450     // 2.Pixmap构造接口
451     auto colorspace = Drawing::ColorSpace::CreateSRGB();
452     ImageInfo imageInfo(512, 512, COLORTYPE_UNKNOWN, ALPHATYPE_UNKNOWN, colorspace); // 512 width * 512 height
453     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
454 
455     Drawing::Bitmap bitmap1;
456     bitmap1.Build(imageInfo);
457     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
458     bitmap1.ClearWithColor(0x004567FA); // 透明效果,粉蓝色
459 
460     // 3.设置视效效果,将效果添加到笔刷
461     brush.SetColor(0xFF4F7091);
462     auto filter = Drawing::Filter();
463     filter.SetColorFilter(Drawing::ColorFilter::CreateLinearToSrgbGamma());
464     brush.SetFilter(filter);
465 
466     // 4.组合transform函数
467     playbackCanvas_->Shear(10.0f, 10.0f); // slope
468 
469     // 5.绘制结果
470     const void* pixel = pixmap.GetAddr();
471     bitmap1.SetPixels(const_cast<void*>(pixel));
472     playbackCanvas_->AttachBrush(brush);
473     // 6.Pixmap操作接口
474     if (pixmap.GetColorSpace() == colorspace) {
475         playbackCanvas_->DrawRect(Drawing::Rect(800, 800, 1000, 1000)); // rect region(800, 800, 1000, 1000)
476     } else {
477         playbackCanvas_->DrawRect(Drawing::Rect(1000, 1000, 1200, 1200)); // rect region(1000, 1000, 1200, 1200)
478     }
479     playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap1 position
480     playbackCanvas_->DetachBrush();
481 
482     // 7.组合Clip函数,cilp也有抗锯齿效果,默认和笔刷效果保持一致
483     TestBase::ClipPath(true);
484 }
485 
486 // Pixmap_Scene_0010
487 // Pixmap构造接口:Pixmap_ImageInfo_01
488 // Pixmap操作接口:GetRowBytes
489 // cilp:ClipRect
490 // transform:null
491 // 抗锯齿:非AA
492 // 透明度:半透明
493 // 视效:CreateSrgbGammaToLinear
494 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 10)
495 {
496     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
497     Drawing::Brush brush;
498     brush.SetAntiAlias(false); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
499 
500     // 2.Pixmap构造接口
501     auto colorspace = Drawing::ColorSpace::CreateSRGB();
502     ImageInfo imageInfo(512, 512, COLORTYPE_UNKNOWN, ALPHATYPE_UNKNOWN, colorspace); // 512 width * 512 height
503     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
504 
505     // 3.Pixmap操作接口
506     ImageInfo imageInfo1(1, 1, COLORTYPE_RGBA_8888, ALPHATYPE_PREMUL);
507     uint32_t pixel[] = { 0xFF123456 };
508     Pixmap pixmap1(imageInfo, pixel, sizeof(pixel));
509     std::shared_ptr<Data> data = std::make_shared<Data>();
510     data->BuildWithCopy(pixmap1.GetAddr(), pixmap1.GetRowBytes() * pixmap1.GetHeight());
511     auto image = Image::MakeRasterData(imageInfo1, data, pixmap1.GetRowBytes());
512 
513     Drawing::Bitmap bitmap1;
514     bitmap1.Build(imageInfo);
515     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
516     bitmap1.ClearWithColor(0x894567FA); // 半透明效果,粉蓝色
517 
518     // 4.设置视效效果,将效果添加到笔刷
519     brush.SetColor(0xFF4F7091);
520     auto filter = Drawing::Filter();
521     filter.SetColorFilter(Drawing::ColorFilter::CreateSrgbGammaToLinear());
522     brush.SetFilter(filter);
523 
524     // 5.绘制结果
525     const void* pixel1 = pixmap.GetAddr();
526     bitmap1.SetPixels(const_cast<void*>(pixel1));
527     playbackCanvas_->AttachBrush(brush);
528     playbackCanvas_->DrawImageNine(image.get(), Drawing::RectI(0, 0, 1, 1),
529         Rect(100, 100, 500, 500), // Rect(100, 100, 500, 500) & RectI(0, 0, 1, 1)
530         FilterMode::NEAREST);
531     playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap1 position
532     playbackCanvas_->DetachBrush();
533 
534     // 6.组合Clip函数,cilp也有抗锯齿效果,默认和笔刷效果保持一致
535     TestBase::ClipRect(false);
536 }
537 
538 // Pixmap_Scene_0011
539 // Pixmap构造接口:Pixmap_ImageInfo_01
540 // Pixmap操作接口:GetAddr
541 // cilp:ClipRoundRect(G2)
542 // transform:ConcatMatrix
543 // 抗锯齿:非AA
544 // 透明度:透明
545 // 视效:CreateLumaColorFilter
546 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 11)
547 {
548     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
549     Drawing::Brush brush;
550     brush.SetAntiAlias(false); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
551 
552     // 2.Pixmap构造接口
553     auto colorspace = Drawing::ColorSpace::CreateSRGB();
554     ImageInfo imageInfo(512, 512, COLORTYPE_UNKNOWN, ALPHATYPE_UNKNOWN, colorspace); // 512 width * 512 height
555     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
556 
557     // 3.Pixmap操作接口
558     Drawing::Bitmap bitmap1;
559     const void* pixel = pixmap.GetAddr();
560     bitmap1.SetPixels(const_cast<void*>(pixel));
561 
562     bitmap1.Build(imageInfo);
563     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
564     bitmap1.ClearWithColor(0x004567FA); // 透明效果,粉蓝色
565 
566     // 4.设置视效效果,将效果添加到笔刷
567     brush.SetColor(0xFF0000FF);
568     auto filter = Drawing::Filter();
569     filter.SetColorFilter(Drawing::ColorFilter::CreateLumaColorFilter());
570     brush.SetFilter(filter);
571 
572     // 5.组合transform函数
573     Drawing::Matrix matrix;
574     matrix.Rotate(15, 10, 10); // 15 angle 10 position
575     playbackCanvas_->ConcatMatrix(matrix);
576 
577     // 6.绘制结果
578     playbackCanvas_->AttachBrush(brush);
579     playbackCanvas_->DrawBitmap(bitmap1, 300, 300); // 300,300 is bitmap1 position
580     playbackCanvas_->DetachBrush();
581 
582     // 7.组合Clip函数,cilp也有抗锯齿效果,默认和笔刷效果保持一致
583     TestBase::ClipRoundRectG2(false);
584 }
585 
586 // Pixmap_Scene_0012
587 // Pixmap构造接口:Pixmap_ImageInfo_01
588 // Pixmap操作接口:GetColor
589 // cilp:ClipRoundRect(G2_capsule)
590 // transform:Rotate
591 // 抗锯齿:AA
592 // 透明度:半透明
593 // 视效:CreateBlendImageFilter
594 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 12)
595 {
596     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
597     Drawing::Brush brush;
598     brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
599 
600     // 2.Pixmap构造接口
601     auto colorspace = Drawing::ColorSpace::CreateSRGB();
602     ImageInfo imageInfo(512, 512, COLORTYPE_UNKNOWN, ALPHATYPE_UNKNOWN, colorspace); // 512 width * 512 height
603     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
604 
605     // 3.Pixmap操作接口
606     Drawing::Pen pen;
607     pen.SetWidth(8.5f);
608     pen.SetColor(pixmap.GetColor(imageInfo.GetWidth() / 2, imageInfo.GetHeight() / 2));
609 
610     Drawing::Bitmap bitmap1;
611     bitmap1.Build(imageInfo);
612     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
613     bitmap1.ClearWithColor(0x894567FA); // 半透明效果,粉蓝色
614 
615     // 4.组合transform函数
616     playbackCanvas_->Rotate(30, 10, 10); // 30 angle 10 position
617 
618     int rectPos = 0;
619     brush.SetColor(0x4CB21933);
620     for (auto blendMode : blendModes) {
621         auto background = Drawing::ImageFilter::CreateBlurImageFilter(
622             1.0f, 1.0f, Drawing::TileMode::REPEAT, nullptr, Drawing::ImageBlurType::GAUSS);
623         auto foreground = Drawing::ImageFilter::CreateBlurImageFilter(
624             1.0f, 1.0f, Drawing::TileMode::REPEAT, nullptr, Drawing::ImageBlurType::GAUSS);
625         auto filter = Drawing::Filter();
626         // 5.设置视效效果,将效果添加到笔刷
627         filter.SetImageFilter(Drawing::ImageFilter::CreateBlendImageFilter(blendMode, background, foreground));
628         brush.SetFilter(filter);
629         // 6.绘制结果
630         const void* pixel = pixmap.GetAddr();
631         bitmap1.SetPixels(const_cast<void*>(pixel));
632         playbackCanvas_->Save();
633         playbackCanvas_->AttachBrush(brush);
634         playbackCanvas_->AttachPen(pen);
635         auto p1 = Drawing::Point(
636             800 + (rectPos % VARIATION) * LEFT, 800 + (rectPos / VARIATION) * RIGHT); // point position(800, 800)
637         auto p2 = Drawing::Point(
638             1000 + (rectPos % VARIATION) * LEFT, 1000 + (rectPos / VARIATION) * RIGHT); // point position(1000, 1000)
639         playbackCanvas_->DrawLine(p1, p2);
640         playbackCanvas_->DetachPen();
641         playbackCanvas_->DrawBitmap(bitmap1, 250 + (rectPos % VARIATION) * LEFT,
642             300 + (rectPos / VARIATION) * RIGHT); // 250,300 is bitmap1 position
643         playbackCanvas_->Restore();
644         rectPos += 1;
645     }
646     playbackCanvas_->DetachBrush();
647 
648     // 7.组合Clip函数,cilp也有抗锯齿效果,默认和笔刷效果保持一致
649     TestBase::ClipRoundRectG2capsule(true);
650 }
651 
652 // Pixmap_Scene_0013
653 // Pixmap构造接口:Pixmap_ImageInfo_01
654 // Pixmap操作接口:ScalePixels
655 // cilp:ClipRoundRect(非G2)
656 // transform:Scale(正常值)
657 // 抗锯齿:非AA
658 // 透明度:透明
659 // 视效:CreateBlendShader
660 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 13)
661 {
662     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
663     Drawing::Brush brush;
664     brush.SetAntiAlias(false); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
665 
666     // 2.Pixmap构造接口
667     auto colorspace = Drawing::ColorSpace::CreateSRGB();
668     ImageInfo imageInfo(512, 512, COLORTYPE_UNKNOWN, ALPHATYPE_UNKNOWN, colorspace); // 512 width * 512 height
669     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
670 
671     // 3.Pixmap操作接口
672     ImageInfo imageinfo2 = ImageInfo::MakeN32Premul(4, 4); // pixel row and col(4, 4)
673     uint32_t data[16];
674     Pixmap dst(imageinfo2, data, sizeof(uint32_t) * imageinfo2.GetWidth());
675 
676     Drawing::Bitmap bitmap1;
677     bitmap1.Build(imageInfo);
678     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
679     bitmap1.ClearWithColor(0x004567FA); // 透明效果,粉蓝色
680 
681     // 4.组合transform函数
682     playbackCanvas_->Scale(2.0f, 2.0f); // ratio
683 
684     int rectPos = 0;
685     brush.SetColor(0xFFFF0000);
686     auto dst1 = Drawing::ShaderEffect::CreateColorShader(Drawing::Color::COLOR_RED);
687     auto src = Drawing::ShaderEffect::CreateColorShader(Drawing::Color::COLOR_GREEN);
688     for (auto BlendMode : blendModes) {
689         auto blendShader = Drawing::ShaderEffect::CreateBlendShader(*dst1, *src, BlendMode);
690         // 5.设置视效效果,将效果添加到笔刷
691         brush.SetShaderEffect(blendShader);
692         // 6.绘制结果
693         const void* pixel = pixmap.GetAddr();
694         bitmap1.SetPixels(const_cast<void*>(pixel));
695         playbackCanvas_->AttachBrush(brush);
696         if (pixmap.ScalePixels(dst, SamplingOptions())) {
697             playbackCanvas_->DrawRect(Drawing::Rect(800 + (rectPos % VARIATION) * LEFT,
698                 800 + (rectPos / VARIATION) * LEFT, 1000 + (rectPos % VARIATION) * LEFT,
699                 1000 + (rectPos / VARIATION) * LEFT)); // rect region(800, 800, 1000, 1000)
700         } else {
701             playbackCanvas_->DrawRect(Drawing::Rect(1000 + (rectPos % VARIATION) * LEFT,
702                 1000 + (rectPos / VARIATION) * LEFT, 1200 + (rectPos % VARIATION) * LEFT,
703                 1200 + (rectPos / VARIATION) * LEFT)); // rect region(1000, 1000, 1200, 1200)
704         }
705         playbackCanvas_->DrawBitmap(bitmap1, 250 + (rectPos % VARIATION) * LEFT,
706             300 + (rectPos / VARIATION) * RIGHT); // 250,300 is bitmap1 position
707         rectPos += 1;
708     }
709     playbackCanvas_->DetachBrush();
710 
711     // 7.组合Clip函数,cilp也有抗锯齿效果,默认和笔刷效果保持一致
712     TestBase::ClipRoundRectnotG2(false);
713 }
714 
715 // Pixmap_Scene_0014
716 // Pixmap构造接口:Pixmap_ImageInfo_02
717 // Pixmap操作接口:GetWidth
718 // cilp:null
719 // transform:Scale(极小值)
720 // 抗锯齿:AA
721 // 透明度:不透明
722 // 视效:CreateBlurMaskFilter
723 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 14)
724 {
725     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
726     Drawing::Brush brush;
727     brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
728 
729     // 2.Pixmap构造接口
730     auto colorspace = Drawing::ColorSpace::CreateSRGBLinear();
731     ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_UNKNOWN, Drawing::AlphaType::ALPHATYPE_UNKNOWN,
732         colorspace); // 512 width * 512 height
733     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
734 
735     // 3.Pixmap操作接口
736     auto width = pixmap.GetWidth();
737 
738     Drawing::Bitmap bitmap1;
739     bitmap1.Build(imageInfo);
740     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
741     bitmap1.ClearWithColor(0xFF4567FA); // 不透明效果,粉蓝色
742 
743     // 4.组合transform函数
744     playbackCanvas_->Scale(10100.0f, 1.0f); // ratio
745 
746     int rectPos = 0;
747     brush.SetColor(0xFFFF0000);
748     for (auto& blurType : blurTypes) {
749         auto filter = Drawing::Filter();
750         // 5.设置视效效果,将效果添加到笔刷
751         filter.SetMaskFilter(Drawing::MaskFilter::CreateBlurMaskFilter(blurType, 10.0f, true));
752         brush.SetFilter(filter);
753         // 6.绘制结果
754         const void* pixel = pixmap.GetAddr();
755         bitmap1.SetPixels(const_cast<void*>(pixel));
756         playbackCanvas_->AttachBrush(brush);
757         playbackCanvas_->DrawRect(Rect(0 + (rectPos % VARIATION) * LEFT, 0 + (rectPos / VARIATION) * LEFT,
758             width + (rectPos % VARIATION) * LEFT, 500 + (rectPos / VARIATION) * LEFT)); // width * 500 height
759         playbackCanvas_->DrawBitmap(bitmap1, 250 + (rectPos % VARIATION) * LEFT,
760             300 + (rectPos / VARIATION) * RIGHT); // 250,300 is bitmap1 position
761         rectPos += 200;
762     }
763     playbackCanvas_->DetachBrush();
764 }
765 
766 // Pixmap_Scene_0015
767 // Pixmap构造接口:Pixmap_ImageInfo_02
768 // Pixmap操作接口:GetHeight
769 // cilp:ClipPath
770 // transform:Translate
771 // 抗锯齿:非AA
772 // 透明度:透明
773 // 视效:null
774 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 15)
775 {
776     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
777     Drawing::Brush brush;
778     brush.SetAntiAlias(false); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
779 
780     // 2.Pixmap构造接口
781     auto colorspace = Drawing::ColorSpace::CreateSRGBLinear();
782     ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_UNKNOWN, Drawing::AlphaType::ALPHATYPE_UNKNOWN,
783         colorspace); // 512 width * 512 height
784     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
785 
786     // 3.Pixmap操作接口
787     auto height = pixmap.GetHeight();
788 
789     Drawing::Bitmap bitmap1;
790     bitmap1.Build(imageInfo);
791     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
792     bitmap1.ClearWithColor(0x004567FA); // 透明效果,粉蓝色
793 
794     // 4.组合transform函数
795     playbackCanvas_->Translate(200, 200); // 200 distance
796 
797     // 5.绘制结果
798     const void* pixel = pixmap.GetAddr();
799     bitmap1.SetPixels(const_cast<void*>(pixel));
800     playbackCanvas_->AttachBrush(brush);
801     playbackCanvas_->DrawRect(Rect(0, 0, 500, height)); // rect region (0, 0, 500, height)
802     playbackCanvas_->DrawBitmap(bitmap1, 250, 300);     // 250,300 is bitmap1 position
803     playbackCanvas_->DetachBrush();
804 
805     // 6.组合Clip函数,cilp也有抗锯齿效果,默认和笔刷效果保持一致
806     TestBase::ClipPath(false);
807 }
808 
809 // Pixmap_Scene_0016
810 // Pixmap构造接口:Pixmap_ImageInfo_02
811 // Pixmap操作接口:GetColorType
812 // cilp:ClipRect
813 // transform:Shear
814 // 抗锯齿:非AA
815 // 透明度:半透明
816 // 视效:CreateLinearGradient
817 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 16)
818 {
819     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
820     Drawing::Brush brush;
821     brush.SetAntiAlias(false); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
822 
823     // 2.Pixmap构造接口
824     auto colorspace = Drawing::ColorSpace::CreateSRGBLinear();
825     ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_UNKNOWN, Drawing::AlphaType::ALPHATYPE_UNKNOWN,
826         colorspace); // 512 width * 512 height
827     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
828 
829     Drawing::Bitmap bitmap1;
830     bitmap1.Build(imageInfo);
831     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
832     bitmap1.ClearWithColor(0x894567FA); // 半透明效果,粉蓝色
833 
834     // 3.设置视效效果,将效果添加到笔刷
835     std::vector<Drawing::ColorQuad> colors = { Drawing::Color::COLOR_RED, Drawing::Color::COLOR_GREEN,
836         Drawing::Color::COLOR_BLUE };
837     std::vector<Drawing::scalar> pos = { 0.00f, 0.50f, 1.00f };
838     auto linearGradient = Drawing::ShaderEffect::CreateLinearGradient(
839         { 0, 0 }, { 1000, 1000 }, colors, pos, Drawing::TileMode::CLAMP); // 0 start pos & 1000 end pos
840     brush.SetShaderEffect(linearGradient);
841 
842     // 4.组合transform函数
843     playbackCanvas_->Shear(10.0f, 10.0f); // slope
844 
845     // 5.绘制结果
846     const void* pixel = pixmap.GetAddr();
847     bitmap1.SetPixels(const_cast<void*>(pixel));
848     playbackCanvas_->AttachBrush(brush);
849     // 6.Pixmap操作接口
850     if (pixmap.GetColorType() == COLORTYPE_UNKNOWN) {
851         playbackCanvas_->DrawRect(Drawing::Rect(800, 800, 1000, 1000)); // rect region(800, 800, 1000, 1000)
852     } else {
853         playbackCanvas_->DrawRect(Drawing::Rect(1000, 1000, 1200, 1200)); // rect region(1000, 1000, 1200, 1200)
854     }
855     playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap1 position
856     playbackCanvas_->DetachBrush();
857 
858     // 7.组合Clip函数,cilp也有抗锯齿效果,默认和笔刷效果保持一致
859     TestBase::ClipRect(false);
860 }
861 
862 // Pixmap_Scene_0017
863 // Pixmap构造接口:Pixmap_ImageInfo_02
864 // Pixmap操作接口:GetAlphaType
865 // cilp:ClipRoundRect(G2)
866 // transform:null
867 // 抗锯齿:AA
868 // 透明度:透明
869 // 视效:CreateColorShader
870 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 17)
871 {
872     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
873     Drawing::Brush brush;
874     brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
875 
876     // 2.Pixmap构造接口
877     auto colorspace = Drawing::ColorSpace::CreateSRGBLinear();
878     ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_UNKNOWN, Drawing::AlphaType::ALPHATYPE_UNKNOWN,
879         colorspace); // 512 width * 512 height
880     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
881 
882     Drawing::Bitmap bitmap1;
883     bitmap1.Build(imageInfo);
884     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
885     bitmap1.ClearWithColor(0x004567FA); // 透明效果,粉蓝色
886 
887     // 3.设置视效效果,将效果添加到笔刷
888     brush.SetColor(0xFFFF0000);
889     auto colorShader = Drawing::ShaderEffect::CreateColorShader(Drawing::Color::COLOR_RED);
890     brush.SetShaderEffect(colorShader);
891 
892     // 4.绘制结果
893     const void* pixel = pixmap.GetAddr();
894     bitmap1.SetPixels(const_cast<void*>(pixel));
895     playbackCanvas_->AttachBrush(brush);
896     // 5.Pixmap操作接口
897     if (pixmap.GetAlphaType() == ALPHATYPE_UNKNOWN) {
898         playbackCanvas_->DrawRect(Drawing::Rect(800, 800, 1000, 1000)); // rect region(800, 800, 1000, 1000)
899     } else {
900         playbackCanvas_->DrawRect(Drawing::Rect(1000, 1000, 1200, 1200)); // rect region(1000, 1000, 1200, 1200)
901     }
902     playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap1 position
903     playbackCanvas_->DetachBrush();
904 
905     // 6.组合Clip函数,cilp也有抗锯齿效果,默认和笔刷效果保持一致
906     TestBase::ClipRoundRectG2(true);
907 }
908 
909 // Pixmap_Scene_0018
910 // Pixmap构造接口:Pixmap_ImageInfo_02
911 // Pixmap操作接口:GetColorSpace
912 // cilp:ClipRoundRect(G2_capsule)
913 // transform:ConcatMatrix
914 // 抗锯齿:非AA
915 // 透明度:不透明
916 // 视效:CreateComposeColorFilter
917 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 18)
918 {
919     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
920     Drawing::Brush brush;
921     brush.SetAntiAlias(false); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
922 
923     // 2.Pixmap构造接口
924     auto colorspace = Drawing::ColorSpace::CreateSRGBLinear();
925     ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_UNKNOWN, Drawing::AlphaType::ALPHATYPE_UNKNOWN,
926         colorspace); // 512 width * 512 height
927     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
928 
929     Drawing::Bitmap bitmap1;
930     bitmap1.Build(imageInfo);
931     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
932     bitmap1.ClearWithColor(0xFF4567FA); // 不透明效果,粉蓝色
933 
934     // 3.设置视效效果,将效果添加到笔刷
935     brush.SetColor(0xFFFF0000);
936     std::shared_ptr<Drawing::ColorFilter> colorFilter1 =
937         Drawing::ColorFilter::CreateBlendModeColorFilter(0xFFFF0000, Drawing::BlendMode::SRC_IN);
938     std::shared_ptr<Drawing::ColorFilter> colorFilter2 =
939         Drawing::ColorFilter::CreateBlendModeColorFilter(0xFFFF00FF, Drawing::BlendMode::MODULATE);
940     std::shared_ptr<Drawing::ColorFilter> colorFilter3 =
941         Drawing::ColorFilter::CreateComposeColorFilter(*colorFilter1, *colorFilter2);
942     auto filter = Drawing::Filter();
943     filter.SetColorFilter(colorFilter3);
944     brush.SetFilter(filter);
945 
946     // 4.组合transform函数
947     Drawing::Matrix matrix;
948     matrix.Rotate(15, 10, 10); // 15 angle 10 position
949     playbackCanvas_->ConcatMatrix(matrix);
950 
951     // 5.绘制结果
952     const void* pixel = pixmap.GetAddr();
953     bitmap1.SetPixels(const_cast<void*>(pixel));
954     playbackCanvas_->AttachBrush(brush);
955     // 6.Pixmap操作接口
956     if (pixmap.GetColorSpace() == colorspace) {
957         playbackCanvas_->DrawRect(Drawing::Rect(800, 800, 1000, 1000)); // rect region(800, 800, 1000, 1000)
958     } else {
959         playbackCanvas_->DrawRect(Drawing::Rect(1000, 1000, 1200, 1200)); // rect region(1000, 1000, 1200, 1200)
960     }
961     playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap1 position
962     playbackCanvas_->DetachBrush();
963 
964     // 7.组合Clip函数,cilp也有抗锯齿效果,默认和笔刷效果保持一致
965     TestBase::ClipRoundRectG2capsule(false);
966 }
967 
968 // Pixmap_Scene_0019
969 // Pixmap构造接口:Pixmap_ImageInfo_02
970 // Pixmap操作接口:GetColorSpace
971 // cilp:ClipRoundRect(非G2)
972 // transform:Scale(极小值)
973 // 抗锯齿:AA
974 // 透明度:半透明
975 // 视效:CreateBlurImageFilter
976 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 19)
977 {
978     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
979     Drawing::Brush brush;
980     brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
981 
982     // 2.Pixmap构造接口
983     auto colorspace = Drawing::ColorSpace::CreateSRGBLinear();
984     ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_UNKNOWN, Drawing::AlphaType::ALPHATYPE_UNKNOWN,
985         colorspace); // 512 width * 512 height
986     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
987 
988     Drawing::Bitmap bitmap1;
989     bitmap1.Build(imageInfo);
990     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
991     bitmap1.ClearWithColor(0x894567FA); // 半透明效果,粉蓝色
992 
993     // 3.设置视效效果,将效果添加到笔刷
994     brush.SetColor(0xFFFF0000);
995     auto filter = Drawing::Filter();
996     filter.SetImageFilter(Drawing::ImageFilter::CreateBlurImageFilter(
997         10.0f, 10.0f, Drawing::TileMode::CLAMP, nullptr, Drawing::ImageBlurType::GAUSS));
998     brush.SetFilter(filter);
999 
1000     // 4.组合transform函数
1001     playbackCanvas_->Scale(10100.0f, 1.0f); // ratio
1002 
1003     // 5.绘制结果
1004     const void* pixel = pixmap.GetAddr();
1005     bitmap1.SetPixels(const_cast<void*>(pixel));
1006     playbackCanvas_->AttachBrush(brush);
1007     // 6.Pixmap操作接口
1008     if (pixmap.GetColorSpace() == colorspace) {
1009         playbackCanvas_->DrawRect(Drawing::Rect(800, 800, 1000, 1000)); // rect region(800, 800, 1000, 1000)
1010     } else {
1011         playbackCanvas_->DrawRect(Drawing::Rect(1000, 1000, 1200, 1200)); // rect region(1000, 1000, 1200, 1200)
1012     }
1013     playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap1 position
1014     playbackCanvas_->DetachBrush();
1015 
1016     // 7.组合Clip函数,cilp也有抗锯齿效果,默认和笔刷效果保持一致
1017     TestBase::ClipRoundRectnotG2(true);
1018 }
1019 
1020 // Pixmap_Scene_0020
1021 // Pixmap构造接口:Pixmap_ImageInfo_02
1022 // Pixmap操作接口:GetRowBytes
1023 // cilp:ClipRoundRect(非G2)
1024 // transform:Rotate
1025 // 抗锯齿:AA
1026 // 透明度:不透明
1027 // 视效:CreateBlendModeColorFilter
1028 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 20)
1029 {
1030     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
1031     Drawing::Brush brush;
1032     brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
1033 
1034     // 2.Pixmap构造接口
1035     auto colorspace = Drawing::ColorSpace::CreateSRGBLinear();
1036     ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_UNKNOWN, Drawing::AlphaType::ALPHATYPE_UNKNOWN,
1037         colorspace); // 512 width * 512 height
1038     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
1039 
1040     // 3.Pixmap操作接口
1041     ImageInfo imageInfo1(1, 1, COLORTYPE_RGBA_8888, ALPHATYPE_PREMUL);
1042     uint32_t pixel[] = { 0xFF123456 };
1043     Pixmap pixmap1(imageInfo1, pixel, sizeof(pixel));
1044     std::shared_ptr<Data> data = std::make_shared<Data>();
1045     data->BuildWithCopy(pixmap1.GetAddr(), pixmap1.GetRowBytes() * pixmap1.GetHeight());
1046     auto image = Image::MakeRasterData(imageInfo1, data, pixmap.GetRowBytes());
1047 
1048     Drawing::Bitmap bitmap1;
1049     bitmap1.Build(imageInfo);
1050     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
1051     bitmap1.ClearWithColor(0xFF4567FA); // 不透明效果,粉蓝色
1052 
1053     // 4.组合transform函数
1054     playbackCanvas_->Rotate(30, 10, 10); // 30 angle 10 position
1055 
1056     int rectPos = 0;
1057     brush.SetColor(0xFFFF0000);
1058     for (auto blendMode : blendModes) {
1059         std::shared_ptr<Drawing::ColorFilter> colorFilter =
1060             Drawing::ColorFilter::CreateBlendModeColorFilter(0xFFFF0000, blendMode);
1061         auto filter = Drawing::Filter();
1062         // 5.设置视效效果,将效果添加到笔刷
1063         filter.SetColorFilter(colorFilter);
1064         brush.SetFilter(filter);
1065         // 6.绘制结果
1066         const void* pixel = pixmap.GetAddr();
1067         bitmap1.SetPixels(const_cast<void*>(pixel));
1068         playbackCanvas_->AttachBrush(brush);
1069         playbackCanvas_->DrawImageNine(image.get(),
1070             Drawing::RectI(0 + (rectPos % VARIATION) * LEFT, 0 + (rectPos / VARIATION) * LEFT,
1071                 1 + (rectPos % VARIATION) * LEFT, 1 + (rectPos / VARIATION) * LEFT),
1072             Rect(100 + (rectPos % VARIATION) * LEFT, 100 + (rectPos / VARIATION) * LEFT,
1073                 500 + (rectPos % VARIATION) * LEFT,
1074                 500 + (rectPos / VARIATION) * LEFT), // Rect(100, 100, 500, 500) & RectI(0, 0, 1, 1)
1075             FilterMode::NEAREST);
1076         playbackCanvas_->DrawBitmap(bitmap1, 250 + (rectPos % VARIATION) * LEFT,
1077             300 + (rectPos / VARIATION) * RIGHT); // 250,300 is bitmap1 position
1078         rectPos += 1;
1079     }
1080     playbackCanvas_->DetachBrush();
1081 
1082     // 7.组合Clip函数,cilp也有抗锯齿效果,默认和笔刷效果保持一致
1083     TestBase::ClipRoundRectnotG2(true);
1084 }
1085 
1086 // Pixmap_Scene_0021
1087 // Pixmap构造接口:Pixmap_ImageInfo_02
1088 // Pixmap操作接口:GetRowBytes
1089 // cilp:null
1090 // transform:Translate
1091 // 抗锯齿:非AA
1092 // 透明度:不透明
1093 // 视效:CreateLinearToSrgbGamma
1094 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 21)
1095 {
1096     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
1097     Drawing::Brush brush;
1098     brush.SetAntiAlias(false); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
1099 
1100     // 2.Pixmap构造接口
1101     auto colorspace = Drawing::ColorSpace::CreateSRGBLinear();
1102     ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_UNKNOWN, Drawing::AlphaType::ALPHATYPE_UNKNOWN,
1103         colorspace); // 512 width * 512 height
1104     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
1105 
1106     // 3.Pixmap操作接口
1107     ImageInfo imageInfo1(1, 1, COLORTYPE_RGBA_8888, ALPHATYPE_PREMUL);
1108     uint32_t pixel[] = { 0xFF123456 };
1109     Pixmap pixmap1(imageInfo1, pixel, sizeof(pixel));
1110     std::shared_ptr<Data> data = std::make_shared<Data>();
1111     data->BuildWithCopy(pixmap1.GetAddr(), pixmap1.GetRowBytes() * pixmap1.GetHeight());
1112     auto image = Image::MakeRasterData(imageInfo1, data, pixmap1.GetRowBytes());
1113 
1114     Drawing::Bitmap bitmap1;
1115     bitmap1.Build(imageInfo);
1116     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
1117     bitmap1.ClearWithColor(0xFF4567FA); // 不透明效果,粉蓝色
1118 
1119     // 4.设置视效效果,将效果添加到笔刷
1120     brush.SetColor(0xFF4F7091);
1121     auto filter = Drawing::Filter();
1122     filter.SetColorFilter(Drawing::ColorFilter::CreateLinearToSrgbGamma());
1123 
1124     // 5.组合transform函数
1125     playbackCanvas_->Translate(200, 200); // 200 distance
1126 
1127     // 6.绘制结果
1128     const void* pixel1 = pixmap.GetAddr();
1129     bitmap1.SetPixels(const_cast<void*>(pixel1));
1130     playbackCanvas_->AttachBrush(brush);
1131     playbackCanvas_->DrawImageNine(image.get(), Drawing::RectI(0, 0, 1, 1),
1132         Rect(100, 100, 500, 500), // Rect(100, 100, 500, 500) & RectI(0, 0, 1, 1)
1133         FilterMode::NEAREST);
1134     playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap1 position
1135     playbackCanvas_->DetachBrush();
1136 }
1137 
1138 // Pixmap_Scene_0022
1139 // Pixmap构造接口:Pixmap_ImageInfo_02
1140 // Pixmap操作接口:GetAddr
1141 // cilp:ClipPath
1142 // transform:Shear
1143 // 抗锯齿:AA
1144 // 透明度:透明
1145 // 视效:CreateBlendImageFilter
1146 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 22)
1147 {
1148     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
1149     Drawing::Brush brush;
1150     brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
1151 
1152     // 2.Pixmap构造接口
1153     auto colorspace = Drawing::ColorSpace::CreateSRGBLinear();
1154     ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_UNKNOWN, Drawing::AlphaType::ALPHATYPE_UNKNOWN,
1155         colorspace); // 512 width * 512 height
1156     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
1157 
1158     // 3.Pixmap操作接口
1159     Drawing::Bitmap bitmap1;
1160     const void* pixel = pixmap.GetAddr();
1161     bitmap1.SetPixels(const_cast<void*>(pixel));
1162 
1163     bitmap1.Build(imageInfo);
1164     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
1165     bitmap1.ClearWithColor(0x004567FA); // 透明效果,粉蓝色
1166 
1167     // 4.组合transform函数
1168     playbackCanvas_->Shear(10.0f, 10.0f); // slope
1169 
1170     int rectPos = 0;
1171     brush.SetColor(0x4CB21933);
1172     for (auto blendMode : blendModes) {
1173         auto background = Drawing::ImageFilter::CreateBlurImageFilter(
1174             1.0f, 1.0f, Drawing::TileMode::REPEAT, nullptr, Drawing::ImageBlurType::GAUSS);
1175         auto foreground = Drawing::ImageFilter::CreateBlurImageFilter(
1176             1.0f, 1.0f, Drawing::TileMode::REPEAT, nullptr, Drawing::ImageBlurType::GAUSS);
1177         auto filter = Drawing::Filter();
1178         // 5.设置视效效果,将效果添加到笔刷
1179         filter.SetImageFilter(Drawing::ImageFilter::CreateBlendImageFilter(blendMode, background, foreground));
1180         brush.SetFilter(filter);
1181         // 6.绘制结果
1182         playbackCanvas_->Save();
1183         playbackCanvas_->AttachBrush(brush);
1184         playbackCanvas_->DrawBitmap(bitmap1, 300 + (rectPos % VARIATION) * LEFT,
1185             300 + (rectPos / VARIATION) * RIGHT); // 300,300 is bitmap1 position
1186         playbackCanvas_->Restore();
1187         rectPos += 1;
1188     }
1189     playbackCanvas_->DetachBrush();
1190 
1191     // 7.组合Clip函数,cilp也有抗锯齿效果,默认和笔刷效果保持一致
1192     TestBase::ClipPath(true);
1193 }
1194 
1195 // Pixmap_Scene_0023
1196 // Pixmap构造接口:Pixmap_ImageInfo_02
1197 // Pixmap操作接口:GetAddr
1198 // cilp:null
1199 // transform:Scale(正常值)
1200 // 抗锯齿:AA
1201 // 透明度:半透明
1202 // 视效:CreateMatrixColorFilter
1203 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 23)
1204 {
1205     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
1206     Drawing::Brush brush;
1207     brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
1208 
1209     // 2.Pixmap构造接口
1210     auto colorspace = Drawing::ColorSpace::CreateSRGBLinear();
1211     ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_UNKNOWN, Drawing::AlphaType::ALPHATYPE_UNKNOWN,
1212         colorspace); // 512 width * 512 height
1213     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
1214 
1215     // 3.Pixmap操作接口
1216     Drawing::Bitmap bitmap1;
1217     const void* pixel = pixmap.GetAddr();
1218     bitmap1.SetPixels(const_cast<void*>(pixel));
1219 
1220     bitmap1.Build(imageInfo);
1221     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
1222     bitmap1.ClearWithColor(0x894567FA); // 半透明效果,粉蓝色
1223 
1224     // 4.设置视效效果,将效果添加到笔刷
1225     Drawing::ColorMatrix matrix;
1226     matrix.SetArray(ARR);
1227     auto cf = Drawing::ColorFilter::CreateMatrixColorFilter(matrix);
1228     auto filter = Drawing::Filter();
1229     filter.SetImageFilter(Drawing::ImageFilter::CreateColorFilterImageFilter(*cf, nullptr));
1230     brush.SetFilter(filter);
1231 
1232     // 5.组合transform函数
1233     playbackCanvas_->Scale(2.0f, 2.0f); // ratio
1234 
1235     // 6.绘制结果
1236     playbackCanvas_->AttachBrush(brush);
1237     playbackCanvas_->DrawBitmap(bitmap1, 300, 300); // 300,300 is bitmap1 position
1238     playbackCanvas_->DetachBrush();
1239 }
1240 
1241 // Pixmap_Scene_0024
1242 // Pixmap构造接口:Pixmap_ImageInfo_02
1243 // Pixmap操作接口:GetColor
1244 // cilp:ClipPath
1245 // transform:Scale(极大值)
1246 // 抗锯齿:AA
1247 // 透明度:不透明
1248 // 视效:CreateSrgbGammaToLinear
1249 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 24)
1250 {
1251     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
1252     Drawing::Brush brush;
1253     brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
1254 
1255     // 2.Pixmap构造接口
1256     auto colorspace = Drawing::ColorSpace::CreateSRGBLinear();
1257     ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_UNKNOWN, Drawing::AlphaType::ALPHATYPE_UNKNOWN,
1258         colorspace); // 512 width * 512 height
1259     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
1260 
1261     // 3.Pixmap操作接口
1262     Drawing::Pen pen;
1263     pen.SetWidth(8.5f);
1264     pen.SetColor(pixmap.GetColor(imageInfo.GetWidth() / 2, imageInfo.GetHeight() / 2));
1265 
1266     Drawing::Bitmap bitmap1;
1267     bitmap1.Build(imageInfo);
1268     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
1269     bitmap1.ClearWithColor(0xFF4567FA); // 不透明效果,粉蓝色
1270 
1271     // 4.设置视效效果,将效果添加到笔刷
1272     brush.SetColor(0xFF4F7091);
1273     auto filter = Drawing::Filter();
1274     filter.SetColorFilter(Drawing::ColorFilter::CreateSrgbGammaToLinear());
1275     brush.SetFilter(filter);
1276 
1277     // 5.组合transform函数
1278     playbackCanvas_->Scale(1.0f, 10100.0f); // ratio
1279 
1280     // 6.绘制结果
1281     const void* pixel = pixmap.GetAddr();
1282     bitmap1.SetPixels(const_cast<void*>(pixel));
1283     playbackCanvas_->AttachBrush(brush);
1284     playbackCanvas_->AttachPen(pen);
1285     auto p1 = Drawing::Point(800, 800);   // point position(800, 800)
1286     auto p2 = Drawing::Point(1000, 1000); // point position(1000, 1000)
1287     playbackCanvas_->DrawLine(p1, p2);
1288     playbackCanvas_->DetachPen();
1289     playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap1 position
1290     playbackCanvas_->DetachBrush();
1291 
1292     // 7.组合Clip函数,cilp也有抗锯齿效果,默认和笔刷效果保持一致
1293     TestBase::ClipPath(true);
1294 }
1295 
1296 // Pixmap_Scene_0025
1297 // Pixmap构造接口:Pixmap_ImageInfo_02
1298 // Pixmap操作接口:GetColor
1299 // cilp:ClipRect
1300 // transform:null
1301 // 抗锯齿:非AA
1302 // 透明度:半透明
1303 // 视效:CreateBlendShader
1304 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 25)
1305 {
1306     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
1307     Drawing::Brush brush;
1308     brush.SetAntiAlias(false); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
1309 
1310     // 2.Pixmap构造接口
1311     auto colorspace = Drawing::ColorSpace::CreateSRGBLinear();
1312     ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_UNKNOWN, Drawing::AlphaType::ALPHATYPE_UNKNOWN,
1313         colorspace); // 512 width * 512 height
1314     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
1315 
1316     // 3.Pixmap操作接口
1317     Drawing::Pen pen;
1318     pen.SetWidth(8.5f);
1319     pen.SetColor(pixmap.GetColor(imageInfo.GetWidth() / 2, imageInfo.GetHeight() / 2));
1320 
1321     Drawing::Bitmap bitmap1;
1322     bitmap1.Build(imageInfo);
1323     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
1324     bitmap1.ClearWithColor(0x894567FA); // 半透明效果,粉蓝色
1325 
1326     int rectPos = 0;
1327     brush.SetColor(0xFFFF0000);
1328     auto dst = Drawing::ShaderEffect::CreateColorShader(Drawing::Color::COLOR_RED);
1329     auto src = Drawing::ShaderEffect::CreateColorShader(Drawing::Color::COLOR_GREEN);
1330     for (auto BlendMode : blendModes) {
1331         auto blendShader = Drawing::ShaderEffect::CreateBlendShader(*dst, *src, BlendMode);
1332         // 4.设置视效效果,将效果添加到笔刷
1333         brush.SetShaderEffect(blendShader);
1334         // 5.绘制结果
1335         const void* pixel = pixmap.GetAddr();
1336         bitmap1.SetPixels(const_cast<void*>(pixel));
1337         playbackCanvas_->AttachBrush(brush);
1338         playbackCanvas_->AttachPen(pen);
1339         auto p1 = Drawing::Point(
1340             800 + (rectPos % VARIATION) * LEFT, 800 + (rectPos / VARIATION) * RIGHT); // point position(800, 800)
1341         auto p2 = Drawing::Point(
1342             1000 + (rectPos % VARIATION) * LEFT, 1000 + (rectPos / VARIATION) * RIGHT); // point position(1000, 1000)
1343         playbackCanvas_->DrawLine(p1, p2);
1344         playbackCanvas_->DetachPen();
1345         playbackCanvas_->DrawBitmap(bitmap1, 250 + (rectPos % VARIATION) * LEFT,
1346             300 + (rectPos / VARIATION) * RIGHT); // 250,300 is bitmap1 position
1347         rectPos += 1;
1348     }
1349     playbackCanvas_->DetachBrush();
1350 
1351     // 6.组合Clip函数,cilp也有抗锯齿效果,默认和笔刷效果保持一致
1352     TestBase::ClipRect(false);
1353 }
1354 
1355 // Pixmap_Scene_0026
1356 // Pixmap构造接口:Pixmap_ImageInfo_02
1357 // Pixmap操作接口:ScalePixels
1358 // cilp:ClipRect
1359 // transform:Scale(极大值)
1360 // 抗锯齿:AA
1361 // 透明度:半透明
1362 // 视效:CreateLumaColorFilter
1363 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 26)
1364 {
1365     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
1366     Drawing::Brush brush;
1367     brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
1368 
1369     // 2.Pixmap构造接口
1370     auto colorspace = Drawing::ColorSpace::CreateSRGBLinear();
1371     ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_UNKNOWN, Drawing::AlphaType::ALPHATYPE_UNKNOWN,
1372         colorspace); // 512 width * 512 height
1373     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
1374 
1375     // 3.Pixmap操作接口
1376     ImageInfo imageinfo2 = ImageInfo::MakeN32Premul(4, 4); // pixel row and col(4, 4)
1377     uint32_t data[16];
1378     Pixmap dst(imageinfo2, data, sizeof(uint32_t) * imageinfo2.GetWidth());
1379 
1380     Drawing::Bitmap bitmap1;
1381     bitmap1.Build(imageInfo);
1382     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
1383     bitmap1.ClearWithColor(0x894567FA); // 半透明效果,粉蓝色
1384 
1385     // 4.设置视效效果,将效果添加到笔刷
1386     brush.SetColor(0xFF0000FF);
1387     auto filter = Drawing::Filter();
1388     filter.SetColorFilter(Drawing::ColorFilter::CreateLumaColorFilter());
1389     brush.SetFilter(filter);
1390 
1391     // 5.组合transform函数
1392     playbackCanvas_->Scale(1.0f, 10100.0f); // ratio
1393 
1394     // 6.绘制结果
1395     const void* pixel = pixmap.GetAddr();
1396     bitmap1.SetPixels(const_cast<void*>(pixel));
1397     playbackCanvas_->AttachBrush(brush);
1398     if (pixmap.ScalePixels(dst, SamplingOptions())) {
1399         playbackCanvas_->DrawRect(Drawing::Rect(800, 800, 1000, 1000)); // rect region(800, 800, 1000, 1000)
1400     } else {
1401         playbackCanvas_->DrawRect(Drawing::Rect(1000, 1000, 1200, 1200)); // rect region(1000, 1000, 1200, 1200)
1402     }
1403     playbackCanvas_->DrawBitmap(bitmap1, 250, 300); // 250,300 is bitmap1 position
1404     playbackCanvas_->DetachBrush();
1405 
1406     // 7.组合Clip函数,cilp也有抗锯齿效果,默认和笔刷效果保持一致
1407     TestBase::ClipRect(true);
1408 }
1409 
1410 // Pixmap_Scene_0027
1411 // Pixmap构造接口:Pixmap_ImageInfo_03
1412 // colorspace构造接口:CreateRefImage_L0_0
1413 // Pixmap操作接口:GetWidth
1414 // cilp:ClipPath
1415 // transform:Scale(正常值)
1416 // 抗锯齿:AA
1417 // 透明度:透明
1418 // 视效:CreateLumaColorFilter
1419 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 27)
1420 {
1421     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
1422     Drawing::Brush brush;
1423     brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
1424 
1425     // 2.Pixmap构造接口
1426     auto colorspace0 = Drawing::ColorSpace::CreateRGB(CMSTransferFuncType::DOT2, CMSMatrixType::DCIP3);
1427     ImageInfo imageinfo0(512, 512, COLORTYPE_RGBA_8888, ALPHATYPE_PREMUL, colorspace0); // 512 width * 512 height
1428     Bitmap bitmap0;
1429     bitmap0.Build(imageinfo0);
1430     bitmap0.ClearWithColor(0xABCDEF78);
1431     Image image;
1432     image.BuildFromBitmap(bitmap0);
1433     auto colorspace = Drawing::ColorSpace::CreateRefImage(image);
1434     ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_UNKNOWN, Drawing::AlphaType::ALPHATYPE_UNKNOWN,
1435         colorspace); // 512 width * 512 height
1436     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
1437 
1438     // 3.Pixmap操作接口
1439     auto width1 = pixmap.GetWidth();
1440 
1441     Drawing::Bitmap bitmap1;
1442     bitmap1.Build(imageInfo);
1443     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
1444     bitmap1.ClearWithColor(0x004567FA); // 透明效果,粉蓝色
1445 
1446     // 4.设置视效效果,将效果添加到笔刷
1447     brush.SetColor(0xFF0000FF);
1448     auto filter = Drawing::Filter();
1449     filter.SetColorFilter(Drawing::ColorFilter::CreateLumaColorFilter());
1450     brush.SetFilter(filter);
1451 
1452     // 5.组合transform函数
1453     playbackCanvas_->Scale(2.0f, 2.0f); // ratio
1454 
1455     // 6.绘制结果
1456     const void* pixel = pixmap.GetAddr();
1457     bitmap1.SetPixels(const_cast<void*>(pixel));
1458     playbackCanvas_->AttachBrush(brush);
1459     playbackCanvas_->DrawRect(Rect(0, 0, width1, 500)); // width1 * 500 height
1460     playbackCanvas_->DrawBitmap(bitmap1, 250, 300);     // 250,300 is bitmap1 position
1461     playbackCanvas_->DetachBrush();
1462 
1463     // 7.组合Clip函数,cilp也有抗锯齿效果,默认和笔刷效果保持一致
1464     TestBase::ClipPath(true);
1465 }
1466 
1467 // Pixmap_Scene_0028
1468 // Pixmap构造接口:Pixmap_ImageInfo_03
1469 // colorspace构造接口:CreateRefImage_L0_0
1470 // Pixmap操作接口:GetWidth
1471 // cilp:ClipRoundRect(G2)
1472 // transform:Translate
1473 // 抗锯齿:AA
1474 // 透明度:半透明
1475 // 视效:CreateBlendShader
1476 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 28)
1477 {
1478     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
1479     Drawing::Brush brush;
1480     brush.SetAntiAlias(true); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
1481 
1482     // 2.Pixmap构造接口
1483     auto colorspace0 = Drawing::ColorSpace::CreateRGB(CMSTransferFuncType::DOT2, CMSMatrixType::DCIP3);
1484     ImageInfo imageinfo0(512, 512, COLORTYPE_RGBA_8888, ALPHATYPE_PREMUL, colorspace0); // 512 width * 512 height
1485     Bitmap bitmap0;
1486     bitmap0.Build(imageinfo0);
1487     bitmap0.ClearWithColor(0xABCDEF78);
1488     Image image;
1489     image.BuildFromBitmap(bitmap0);
1490     auto colorspace = Drawing::ColorSpace::CreateRefImage(image);
1491     ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_UNKNOWN, Drawing::AlphaType::ALPHATYPE_UNKNOWN,
1492         colorspace); // 512 width * 512 height
1493     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
1494 
1495     // 3.Pixmap操作接口
1496     auto width1 = pixmap.GetWidth();
1497 
1498     Drawing::Bitmap bitmap1;
1499     bitmap1.Build(imageInfo);
1500     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
1501     bitmap1.ClearWithColor(0x894567FA); // 半透明效果,粉蓝色
1502 
1503     // 4.组合transform函数
1504     playbackCanvas_->Translate(200, 200); // 200 distance
1505 
1506     int rectPos = 0;
1507     brush.SetColor(0xFFFF0000);
1508     auto dst = Drawing::ShaderEffect::CreateColorShader(Drawing::Color::COLOR_RED);
1509     auto src = Drawing::ShaderEffect::CreateColorShader(Drawing::Color::COLOR_GREEN);
1510     for (auto BlendMode : blendModes) {
1511         auto blendShader = Drawing::ShaderEffect::CreateBlendShader(*dst, *src, BlendMode);
1512         // 5.设置视效效果,将效果添加到笔刷
1513         brush.SetShaderEffect(blendShader);
1514         // 6.绘制结果
1515         const void* pixel = pixmap.GetAddr();
1516         bitmap1.SetPixels(const_cast<void*>(pixel));
1517         playbackCanvas_->AttachBrush(brush);
1518         playbackCanvas_->DrawRect(Rect(0 + (rectPos % VARIATION) * LEFT, 0 + (rectPos / VARIATION) * LEFT,
1519             width1 + (rectPos % VARIATION) * LEFT, 500 + (rectPos / VARIATION) * LEFT)); // width1 * 500 height
1520         playbackCanvas_->DrawBitmap(bitmap1, 250 + (rectPos % VARIATION) * LEFT,
1521             300 + (rectPos / VARIATION) * RIGHT); // 250,300 is bitmap1 position
1522         rectPos += 1;
1523     }
1524     playbackCanvas_->DetachBrush();
1525 
1526     // 7.组合Clip函数,cilp也有抗锯齿效果,默认和笔刷效果保持一致
1527     TestBase::ClipRoundRectG2(true);
1528 }
1529 
1530 // Pixmap_Scene_0029
1531 // Pixmap构造接口:Pixmap_ImageInfo_03
1532 // colorspace构造接口:CreateRefImage_L0_0
1533 // Pixmap操作接口:GetWidth
1534 // cilp:ClipRoundRect(G2_capsule)
1535 // transform:Rotate
1536 // 抗锯齿:非AA
1537 // 透明度:透明
1538 // 视效:CreateComposeColorFilter
1539 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 29)
1540 {
1541     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
1542     Drawing::Brush brush;
1543     brush.SetAntiAlias(false); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
1544 
1545     // 2.Pixmap构造接口
1546     auto colorspace0 = Drawing::ColorSpace::CreateRGB(CMSTransferFuncType::DOT2, CMSMatrixType::DCIP3);
1547     ImageInfo imageinfo0(512, 512, COLORTYPE_RGBA_8888, ALPHATYPE_PREMUL, colorspace0); // 512 width * 512 height
1548     Bitmap bitmap0;
1549     bitmap0.Build(imageinfo0);
1550     bitmap0.ClearWithColor(0xABCDEF78);
1551     Image image;
1552     image.BuildFromBitmap(bitmap0);
1553     auto colorspace = Drawing::ColorSpace::CreateRefImage(image);
1554     ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_UNKNOWN, Drawing::AlphaType::ALPHATYPE_UNKNOWN,
1555         colorspace); // 512 width * 512 height
1556     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
1557 
1558     // 3.Pixmap操作接口
1559     auto width1 = pixmap.GetWidth();
1560 
1561     Drawing::Bitmap bitmap1;
1562     bitmap1.Build(imageInfo);
1563     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
1564     bitmap1.ClearWithColor(0x004567FA); // 透明效果,粉蓝色
1565 
1566     // 4.设置视效效果,将效果添加到笔刷
1567     brush.SetColor(0xFFFF0000);
1568     std::shared_ptr<Drawing::ColorFilter> colorFilter1 =
1569         Drawing::ColorFilter::CreateBlendModeColorFilter(0xFFFF0000, Drawing::BlendMode::SRC_IN);
1570     std::shared_ptr<Drawing::ColorFilter> colorFilter2 =
1571         Drawing::ColorFilter::CreateBlendModeColorFilter(0xFFFF00FF, Drawing::BlendMode::MODULATE);
1572     std::shared_ptr<Drawing::ColorFilter> colorFilter3 =
1573         Drawing::ColorFilter::CreateComposeColorFilter(*colorFilter1, *colorFilter2);
1574     auto filter = Drawing::Filter();
1575     filter.SetColorFilter(colorFilter3);
1576     brush.SetFilter(filter);
1577 
1578     // 5.组合transform函数
1579     playbackCanvas_->Rotate(30, 10, 10); // 30 angle 10 position
1580 
1581     // 6.绘制结果
1582     const void* pixel = pixmap.GetAddr();
1583     bitmap1.SetPixels(const_cast<void*>(pixel));
1584     playbackCanvas_->AttachBrush(brush);
1585     playbackCanvas_->DrawRect(Rect(0, 0, width1, 500)); // width1 * 500 height
1586     playbackCanvas_->DrawBitmap(bitmap1, 250, 300);     // 250,300 is bitmap1 position
1587     playbackCanvas_->DetachBrush();
1588 
1589     // 7.组合Clip函数,cilp也有抗锯齿效果,默认和笔刷效果保持一致
1590     TestBase::ClipRoundRectG2capsule(false);
1591 }
1592 
1593 // Pixmap_Scene_0030
1594 // Pixmap构造接口:Pixmap_ImageInfo_03
1595 // colorspace构造接口:CreateRefImage_L0_0
1596 // Pixmap操作接口:GetHeight
1597 // cilp:ClipRoundRect(G2_capsule)
1598 // transform:Shear
1599 // 抗锯齿:非AA
1600 // 透明度:不透明
1601 // 视效:CreateColorShader
1602 DEF_DTK(Pixmap_Scene1, TestLevel::L2, 30)
1603 {
1604     // 1.创建笔刷,设置笔刷是否为抗锯齿效果
1605     Drawing::Brush brush;
1606     brush.SetAntiAlias(false); // 设置笔刷抗锯齿,true为AA(抗锯齿),false为非AA(不抗锯齿)
1607 
1608     // 2.Pixmap构造接口
1609     auto colorspace0 = Drawing::ColorSpace::CreateRGB(CMSTransferFuncType::DOT2, CMSMatrixType::DCIP3);
1610     ImageInfo imageinfo0(512, 512, COLORTYPE_RGBA_8888, ALPHATYPE_PREMUL, colorspace0); // 512 width * 512 height
1611     Bitmap bitmap0;
1612     bitmap0.Build(imageinfo0);
1613     bitmap0.ClearWithColor(0xABCDEF78);
1614     Image image;
1615     image.BuildFromBitmap(bitmap0);
1616     auto colorspace = Drawing::ColorSpace::CreateRefImage(image);
1617     ImageInfo imageInfo(512, 512, Drawing::ColorType::COLORTYPE_UNKNOWN, Drawing::AlphaType::ALPHATYPE_UNKNOWN,
1618         colorspace); // 512 width * 512 height
1619     Pixmap pixmap(imageInfo, nullptr, imageInfo.GetBytesPerPixel() * imageInfo.GetWidth());
1620 
1621     // 3.Pixmap操作接口
1622     auto height1 = pixmap.GetHeight();
1623 
1624     Drawing::Bitmap bitmap1;
1625     bitmap1.Build(imageInfo);
1626     // 设置透明度, 由填充的颜色值的前两位控制,00为透明效果,89为半透明,FF为不透明
1627     bitmap1.ClearWithColor(0xFF4567FA); // 不透明效果,粉蓝色
1628 
1629     // 4.设置视效效果,将效果添加到笔刷
1630     brush.SetColor(0xFFFF0000);
1631     auto colorShader = Drawing::ShaderEffect::CreateColorShader(Drawing::Color::COLOR_RED);
1632     brush.SetShaderEffect(colorShader);
1633 
1634     // 5.组合transform函数
1635     playbackCanvas_->Shear(10.0f, 10.0f); // slope
1636 
1637     // 6.绘制结果
1638     const void* pixel = pixmap.GetAddr();
1639     bitmap1.SetPixels(const_cast<void*>(pixel));
1640     playbackCanvas_->AttachBrush(brush);
1641     playbackCanvas_->DrawRect(Rect(0, 0, 500, height1)); // 500 width * height1
1642     playbackCanvas_->DrawBitmap(bitmap1, 250, 300);      // 250,300 is bitmap1 position
1643     playbackCanvas_->DetachBrush();
1644 
1645     // 7.组合Clip函数,cilp也有抗锯齿效果,默认和笔刷效果保持一致
1646     TestBase::ClipRoundRectG2capsule(false);
1647 }
1648 
1649 } // namespace Rosen
1650 } // namespace OHOS