首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

求教有关YUV文件处理有关问题,总是提示数组访问越界(libyuv库函数调用)

2013-07-04 
求教有关YUV文件处理问题,总是提示数组访问越界(libyuv库函数调用)#include stdafx.h#include stdio.h

求教有关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);



 if( libyuv::I420Rotate(TmpY,WIDTH,TmpU,WIDTH/2,TmpV,WIDTH/2,Des_TmpY,WIDTH,Des_TmpU, WIDTH/2,Des_TmpV, WIDTH/2,WIDTH,HEIGHT, libyuv::kRotate180) == 1)
 printf("YUV has rotate succeed!");
 ///////////////////////////////目的空间赋值/////////////////////////////

 //memcpy(Des_TmpY + ImgSize*(sizeof(unsigned char)),Des_TmpY,ImgSize/4*(sizeof(unsigned char)));
 memcpy(Des_TmpY + ImgSize*(sizeof(unsigned char)),Des_TmpU,ImgSize/4*(sizeof(unsigned char)));
 memcpy(Des_TmpY + 5*ImgSize/4*(sizeof(unsigned char)),Des_TmpV,ImgSize/4*(sizeof(unsigned char)));

 ///////////////////////////////结果写入文件/////////////////////////////
 file_output = fopen("D:\\result.txt", "w");
 if(!file_output)
 {
  printf("create and open file failed\n");
  exit(-1);
 }
 else
 {
  for(i= 0;i<ImgSize;i++)
  {
  ///////////////////////////////读出结果/////////////////////////////
   fprintf(file_output,"%ld\n",*(Des_TmpY + i));
  }
  fclose(file_output);
 }
 return 0;
}



结果总是提示数组访问越界~
Unhandled exception at 0x10231f1a (msvcr80d.dll) in YUV_Test.exe: 0xC0000005: Access violation reading location 0x103d6c50.
然后定位到memcpy.asm中的这一行   rep     movsd   ;N - move all of our dwords
求大神指点
yuv 图像处理 stride 数组越界 libyuv
[解决办法]
整个工程发过来包括资源:228330140@qq.com

热点排行