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