codecheck

Signed-off-by: ustc-tianyu <dutianyu4@huawei.com>
This commit is contained in:
ustc-tianyu 2024-02-28 20:07:30 +08:00
parent 0df3cb4908
commit 53b6d28399
5 changed files with 40 additions and 14 deletions

View File

@ -20,21 +20,27 @@ using namespace OHOS::Media;
namespace OHOS {
namespace Rosen {
namespace Drawing {
static constexpr int32_t BITMAP_WIDTH = 200;
static constexpr int32_t BITMAP_HEIGHT = 200;
static constexpr scalar STROKE_WIDTH = 10;
static constexpr scalar POSITION_X = 500;
static constexpr scalar POSITION_Y = 500;
using TestFunc = std::function<void(Canvas&, uint32_t, uint32_t)>;
void BitmapTest::TestDrawBitmap(Canvas& canvas, uint32_t width, uint32_t height)
{
LOGI("+++++++ TestDrawBitmap");
Bitmap bmp;
BitmapFormat format { COLORTYPE_RGBA_8888, ALPHATYPE_OPAQUE };
bmp.Build(200, 200, format); // bitmap width and height
bmp.Build(BITMAP_WIDTH, BITMAP_HEIGHT, format); // bitmap width and height
bmp.ClearWithColor(Drawing::Color::COLOR_BLUE);
Pen pen;
pen.SetAntiAlias(true);
pen.SetColor(Drawing::Color::COLOR_BLUE);
pen.SetWidth(10); // The thickness of the pen is 10
pen.SetWidth(STROKE_WIDTH); // The thickness of the pen is 10
canvas.AttachPen(pen);
canvas.DrawBitmap(bmp, 500, 500); // draw bitmap at (fx, fy)
canvas.DrawBitmap(bmp, POSITION_X, POSITION_Y); // draw bitmap at (fx, fy)
LOGI("------- TestDrawBitmap");
}

View File

@ -18,6 +18,8 @@
namespace OHOS {
namespace Rosen {
namespace Drawing {
static constexpr scalar POSITION_RIGHT = 500;
static constexpr scalar POSITION_BOTTOM = 500;
void CameraTest::TestCamera(Canvas& canvas, uint32_t width, uint32_t height)
{
LOGI("+++++++ TestCamera");
@ -31,7 +33,7 @@ void CameraTest::TestCamera(Canvas& canvas, uint32_t width, uint32_t height)
camera.RotateXDegrees(-25); // Set camera to rotate by degrees -25 at x-aixs.
camera.RotateYDegrees(45); // Set camera to rotate by degrees 45 at y-aixs.
camera.Translate(-50, 50, 50); // Set camera to translate by (-50, 50, 50).
Drawing::Rect r(0, 0, 500, 500); // rect is set to (fLeft, fTop, fRight, fBottom)
Drawing::Rect r(0, 0, POSITION_RIGHT, POSITION_BOTTOM); // rect is set to (fLeft, fTop, fRight, fBottom)
canvas.Save();
camera.Save();

View File

@ -18,12 +18,22 @@
namespace OHOS {
namespace Rosen {
namespace Drawing {
static constexpr int32_t BITMAP_WIDTH = 300;
static constexpr int32_t BITMAP_HEIGHT = 300;
static constexpr scalar RECT1_POSITION_LEFT = 100;
static constexpr scalar RECT1_POSITION_TOP = 100;
static constexpr scalar RECT1_POSITION_RIGHT = 200;
static constexpr scalar RECT1_POSITION_BOTTOM = 200;
static constexpr scalar RECT2_POSITION_LEFT = 300;
static constexpr scalar RECT2_POSITION_TOP = 300;
static constexpr scalar RECT2_POSITION_RIGHT = 500;
static constexpr scalar RECT2_POSITION_BOTTOM = 500;
void ImageTest::TestDrawImage(Canvas& canvas, uint32_t width, uint32_t height)
{
LOGI("+++++++ TestDrawImage");
Bitmap bmp;
BitmapFormat format { COLORTYPE_RGBA_8888, ALPHATYPE_OPAQUE };
bmp.Build(300, 300, format); // bitmap width and height
bmp.Build(BITMAP_WIDTH, BITMAP_HEIGHT, format); // bitmap width and height
bmp.ClearWithColor(Drawing::Color::COLOR_BLUE);
Image image;
@ -57,13 +67,13 @@ void ImageTest::TestDrawImageRect(Canvas& canvas, uint32_t width, uint32_t heigh
LOGI("+++++++ TestDrawImageRect");
Bitmap bmp;
BitmapFormat format { COLORTYPE_RGBA_8888, ALPHATYPE_OPAQUE };
bmp.Build(300, 300, format); // bitmap width and height
bmp.Build(BITMAP_WIDTH, BITMAP_HEIGHT, format); // bitmap width and height
bmp.ClearWithColor(Drawing::Color::COLOR_BLUE);
Image image;
image.BuildFromBitmap(bmp);
Drawing::Rect r1(100, 100, 200, 200); // rect is set to (fLeft, fTop, fRight, fBottom)
Drawing::Rect r2(300, 300, 500, 500);
Drawing::Rect r1(RECT1_POSITION_LEFT, RECT1_POSITION_TOP, RECT1_POSITION_RIGHT, RECT1_POSITION_BOTTOM);
Drawing::Rect r2(RECT2_POSITION_LEFT, RECT2_POSITION_TOP, RECT2_POSITION_RIGHT, RECT2_POSITION_BOTTOM);
SamplingOptions sampling = SamplingOptions(Drawing::FilterMode::NEAREST, Drawing::MipmapMode::NEAREST);
Brush brush;

View File

@ -18,7 +18,8 @@
namespace OHOS {
namespace Rosen {
namespace Drawing {
constexpr static float MARGINE_SCALE_SIZE = 10.0f;
static constexpr float MARGINE_SCALE_SIZE = 10.0f;
static constexpr float MATH_TWO = 2.0f;
void PathTest::TestDrawStar(Canvas& canvas, uint32_t width, uint32_t height)
{
LOGI("+++++++ TestDrawStar");
@ -38,11 +39,11 @@ void PathTest::TestDrawStar(Canvas& canvas, uint32_t width, uint32_t height)
c.SetY(d.GetY());
Point b;
b.SetX(a.GetX() + (len / 2.0)); // half of len, for point position calculation
b.SetY(a.GetY() + std::sqrt((c.GetX() - d.GetX()) * (c.GetX() - d.GetX()) + (len / 2.0) * (len / 2.0)));
b.SetX(a.GetX() + (len / MATH_TWO)); // half of len, for point position calculation
b.SetY(a.GetY() + std::sqrt((c.GetX() - d.GetX()) * (c.GetX() - d.GetX()) + (len / MATH_TWO) * (len / MATH_TWO)));
Point e;
e.SetX(a.GetX() - (len / 2.0)); // half of len, for point position calculation
e.SetX(a.GetX() - (len / MATH_TWO)); // half of len, for point position calculation
e.SetY(b.GetY());
Path path;

View File

@ -57,13 +57,20 @@ bool PathOpFuzzTest(const uint8_t* data, size_t size)
g_size = size;
g_pos = 0;
Path path1, path2, ending, out, op;
Path path1;
Path ending;
Path out;
uint32_t weight = GetObject<uint32_t>();
path1.Interpolate(ending, weight, out);
uint32_t px = GetObject<uint32_t>();
uint32_t py = GetObject<uint32_t>();
path1.Interpolate(ending, weight, out);
path1.LineTo(px, py);
Path op;
op.MoveTo(px, py);
Path path2;
path2.Op(op, path1, PathOp::DIFFERENCE);
path1.Close();
path2.Reset();