AVDataProcess/yuv420p_half_y.cpp

42 lines
935 B
C++
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef int BOOL;
#define TRUE 1
#define FALSE 0
//分离YUV420P像素数据中的亮度分量Y的数值减半降低图像的亮度
BOOL yuv420p_half_y(const char *file, int width, int height)
{
if (file == NULL) {
return FALSE;
}
FILE *fp = fopen(file, "rb+");
FILE *fp0 = fopen("./out/output_420p_half_y.yuv", "wb+");
unsigned char *data = (unsigned char *)malloc(width*height*3/2);
memset(data, 0, width*height*3/2);
fread(data, 1, width*height*3/2, fp);
for(int i=0; i<width*height; i++) {
data[i] = data[i] / 2; //Y分量减半
}
fwrite(data, 1, width*height*3/2, fp0);
free(data);
fclose(fp);
fclose(fp0);
return TRUE;
}
int main(int argc, char *argv[])
{
if (argc == 4) {
yuv420p_half_y(argv[1], atoi(argv[2]), atoi(argv[3]));
}
return 0;
}