求教有关YUV文件处理有关问题,总是提示数组访问越界(libyuv库函数调用)
求教有关YUV文件处理问题,总是提示数组访问越界(libyuv库函数调用)
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include "convert.h"
#include "rotate.h"
#include "Scale.h"
这个我有个文件,就1帧,可以理解为图片吧,我这代码的问题,求帮忙查看,谢谢!
#define WIDTH 176
#define HEIGHT 144
using namespace libyuv;
long get_file_size(char* filename )
{
FILE* fp = fopen( filename, "r" );
if (fp==NULL) return -1;
fseek( fp, 0L, SEEK_END );
return ftell(fp);
}
int _tmain(int argc, _TCHAR* argv[])
{
int FileSize = get_file_size("D:\\TEST\\carphone001.yuv");
printf("the size if file is %d\n",FileSize);
unsigned int ImgSize = WIDTH*HEIGHT;
unsigned char *FileArray=(unsigned char *)malloc(FileSize*(sizeof(unsigned char)));
int ArraySize = ImgSize + (ImgSize >> 1);
int FrameSize = FileSize/ArraySize;
printf("the num of Frame is %d\n",FrameSize);
printf("the num of Frame is %d\n",ImgSize);
int i;
FILE *file_input;
FILE *file_output;
file_input= fopen ("D:\\TEST\\carphone001.yuv", "r");
if(!file_input) {
printf("open file failed error!");
exit(0);
}
if(fread (FileArray, 1, FileSize , file_input) == FileSize)
printf("read the file succesed!\n");
///////////////////////////////指针分配源空间/////////////////////////////
unsigned char *TmpY=(unsigned char *)malloc(ImgSize*(sizeof(unsigned char)));
unsigned char *TmpU=(unsigned char *)malloc(ImgSize/4*(sizeof(unsigned char)));
unsigned char *TmpV=(unsigned char *)malloc(ImgSize/4*(sizeof(unsigned char)));
///////////////////////////////给分配空间赋值/////////////////////////////
memcpy(TmpY ,file_input,ImgSize*(sizeof(unsigned char)));
memcpy(TmpU ,file_input + ImgSize*(sizeof(unsigned char)),ImgSize/4*(sizeof(unsigned char)));
memcpy(TmpV ,file_input + 5*ImgSize*(sizeof(unsigned char)/4),ImgSize/4*(sizeof(unsigned char)));
///////////////////////////////指针分配目的空间/////////////////////////////
unsigned char *Des_TmpY=(unsigned char *)malloc(3*ImgSize*(sizeof(unsigned char))/2);
unsigned char *Des_TmpU=(unsigned char *)malloc(ImgSize/4*(sizeof(unsigned char)));
unsigned char *Des_TmpV=(unsigned char *)malloc(ImgSize/4*(sizeof(unsigned char)));
//////////////////////////////调用函数I420Rotate//////////////////////////////////////////////////////////////////////////
//int I420Rotate(const uint8* src_y, int src_stride_y, const uint8* src_u, int src_stride_u, const uint8* src_v,
// int src_stride_v, uint8* dst_y, int dst_stride_y,uint8* dst_u, int dst_stride_u,uint8* dst_v, int dst_stride_v,
// int src_width, int src_height, enum RotationMode mode);
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include "convert.h"
#include "rotate.h"
#include "Scale.h"
这个我有个文件,就1帧,可以理解为图片吧,我这代码的问题,求帮忙查看,谢谢!
#define WIDTH 176
#define HEIGHT 144
using namespace libyuv;
long get_file_size(char* filename )
{
FILE* fp = fopen( filename, "r" );
if (fp==NULL) return -1;
fseek( fp, 0L, SEEK_END );
return ftell(fp);
}
int _tmain(int argc, _TCHAR* argv[])
{
int FileSize = get_file_size("D:\\TEST\\carphone001.yuv");
printf("the size if file is %d\n",FileSize);
unsigned int ImgSize = WIDTH*HEIGHT;
unsigned char *FileArray=(unsigned char *)malloc(FileSize*(sizeof(unsigned char)));
int ArraySize = ImgSize + (ImgSize >> 1);
int FrameSize = FileSize/ArraySize;
printf("the num of Frame is %d\n",FrameSize);
printf("the num of Frame is %d\n",ImgSize);
int i;
FILE *file_input;
FILE *file_output;
file_input= fopen ("D:\\TEST\\carphone001.yuv", "r");
if(!file_input) {
printf("open file failed error!");
exit(0);
}
if(fread (FileArray, 1, FileSize , file_input) == FileSize)
printf("read the file succesed!\n");
///////////////////////////////指针分配源空间/////////////////////////////
unsigned char *TmpY=(unsigned char *)malloc(ImgSize*(sizeof(unsigned char)));
unsigned char *TmpU=(unsigned char *)malloc(ImgSize/4*(sizeof(unsigned char)));
unsigned char *TmpV=(unsigned char *)malloc(ImgSize/4*(sizeof(unsigned char)));
///////////////////////////////给分配空间赋值/////////////////////////////
memcpy(TmpY ,file_input,ImgSize*(sizeof(unsigned char)));
memcpy(TmpU ,file_input + ImgSize*(sizeof(unsigned char)),ImgSize/4*(sizeof(unsigned char)));
memcpy(TmpV ,file_input + 5*ImgSize*(sizeof(unsigned char)/4),ImgSize/4*(sizeof(unsigned char)));
///////////////////////////////指针分配目的空间/////////////////////////////
unsigned char *Des_TmpY=(unsigned char *)malloc(3*ImgSize*(sizeof(unsigned char))/2);
unsigned char *Des_TmpU=(unsigned char *)malloc(ImgSize/4*(sizeof(unsigned char)));
unsigned char *Des_TmpV=(unsigned char *)malloc(ImgSize/4*(sizeof(unsigned char)));
//////////////////////////////调用函数I420Rotate//////////////////////////////////////////////////////////////////////////
//int I420Rotate(const uint8* src_y, int src_stride_y, const uint8* src_u, int src_stride_u, const uint8* src_v,
// int src_stride_v, uint8* dst_y, int dst_stride_y,uint8* dst_u, int dst_stride_u,uint8* dst_v, int dst_stride_v,
// int src_width, int src_height, enum RotationMode mode);