需要实现的功能:将一张yuv420格式的图片,以(x,y)为圆心,r为半径的圆外所有像素点设置成黑色的。圆内保持不变。
(以下代码新建一个yuv图片,圆内的像素颜色默认,圆外rgb黑色)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<iostream>
#include <math.h>
//背景色
#define R 0
#define G 0
#define B 0
#define Y 0.299*R + 0.587*G + 0.114*B
#define U -0.1687*R - 0.3313*G + 0.5*B + 128
#define V 0.5*R - 0.4187*G - 0.0813*B + 128
int main()
{
int width = 256;
int height = 256;
FILE *fp=fopen("F:/yuv/256x256.yuv","wb");
unsigned char *pic = (unsigned char *)malloc(width*height*3/2);
memset(pic, 0, width*height*3/2);
//圆心 半径
double centerHX = 128;
double centerWY = 128;
float radius = 50.0;
for(int i = 0; i < height; i++)
{
for(int j = 0; j < width; j++)
{
float nLength = 0.0;
nLength = sqrt(pow(centerHX - i, 2) + pow(centerWY - j, 2));
if(nLength > radius)
{
pic[i*width + j]=Y;
pic[width*height + i*(width/4) + j/4] = U;
pic[width*height*5/4 + i*(width/4) + j/4] = V;
}
}
}
fwrite(pic,width*height*3/2,1,fp);
fclose(fp);
free(pic);
return 0;
}
编译通过,得到的结果确不对,有没有大神帮忙看下,问题出现在什么地方???