YUV資料畫矩形和直線

2021-07-04 22:06:23 字數 1904 閱讀 5442

劃線函式用breshenham演算法,yuv資料格式為 422sp 。

//在yuvsp422資料上畫直線,imgdata是 yuv資料指標, int width, int height,yuv影象大小。 startpoint,endpoint 直線量端點,color 顏色。目前直線需要偶數其實位址

unsigned char cyf_breshenhamline(unsigned char* imgdata, int width, int height, my_cvpoint startpoint, my_cvpoint endpoint, my_cvcolor color)

if (width < 0 || height < 0 )

if (startpoint.x

<0 || startpoint.x > width || startpoint.y

< 0 || startpoint.y > height || endpoint.x

< 0 || endpoint.x > width || endpoint.y

< 0 || endpoint.y > height)

int imgsize = width*height;

int t;

intx0 = startpoint.x, x1 = endpoint.x;

inty0 = startpoint.y, y1 = endpoint.y;

int dy = abs(y1 - y

0); int dx = abs(x1 - x

0); hi_bool steep = dy>dx ?hi_true:hi_false;

hi_bool bisvertical =hi_false; //預設不是豎直的線,豎直的線對列上的uv分量不減少

if (x

0 == x1) //如果是豎線的話

if (steep)

if (x

0 > x1)

int deltax = x1 - x

0; int deltay = abs(y1 - y

0); int error = deltax/2;

int ystep;

inty = y

0; int

x; if (y

0< y1)

ystep = 1;

else

ystep = -1;

for (x = x

0; x

< x1; x++)

else

else}}

else

else

}error -= deltay;

if (error < 0)

}return

1;}

畫框

//畫矩形,my_cvrect 需要2對齊

void cyf_drawrect_to_yuvsp422(unsigned char *src ,int srcwidth,int srcheight,my_cvrect rect_rio,my_cvcolor color)

*/cyf_breshenhamline(src, srcwidth, srcheight, point[0],point[1], color);

cyf_breshenhamline(src, srcwidth, srcheight, point[1],point[2], color);

cyf_breshenhamline(src, srcwidth, srcheight, point[3],point[2], color);

cyf_breshenhamline(src, srcwidth, srcheight, point[0],point[3], color);

}

iOS畫矩形 直線 文字的方法

7488353 cgpoint畫直線 cgcontextref ctx uigraphicsgetcurrentcontext cgcontextmovetopoint ctx,point1.x,point1.y cgcontextaddlinetopoint ctx,point2.x,point2...

iOS畫矩形 直線 文字的方法

cgpoint畫直線 cgcontextref ctx uigraphicsgetcurrentcontext cgcontextmovetopoint ctx,point1.x,point1.y cgcontextaddlinetopoint ctx,point2.x,point2.y 畫曲線 用...

Canvas 直線 矩形和圓

const mycanvas document.getelementbyid mycanvas const ctx mycanvas.getcontext 2d ctx.moveto 0 0 ctx.lineto 100 100 ctx.stroke moveto是移動,可以理解為移動畫筆。line...