io.c

来自「h.263编解码源程序」· C语言 代码 · 共 85 行

C
85
字号
#include"sim.h"void WriteImage(PictImage *image, char *filename){  int status;  FILE *f_out;  /* Opening file */  if ((f_out = fopen(filename,"ab")) == NULL) 
  {    fprintf(stderr,"%s%s\n","Error in opening file: ",filename);    exit(-1);  }  /* Writing lum to file */  if ((status = fwrite(image->lum,sizeof(char),pels*lines,f_out))       != pels*lines) 
  {    fprintf(stderr,"%s%s\n","Error in writing to file: ",filename);    exit(-1);  }  /* Writing Cb to file */  if ((status = fwrite(image->Cb,sizeof(char),pels*lines/4,f_out))       != pels*lines/4) 
  {    fprintf(stderr,"%s%s\n","Error in writing to file: ",filename);    exit(-1);  }  /* Writing Cr to file */  if ((status = fwrite(image->Cr,sizeof(char),pels*lines/4,f_out))       != pels*lines/4)
  {    fprintf(stderr,"%s%s\n","Error in writing to file: ",filename);    exit(-1);  }  fclose(f_out);  return;}PictImage *InitImage(int size){  PictImage *newpic;  if ((newpic = (PictImage *)malloc(sizeof(PictImage))) == NULL) 
  {    fprintf(stderr,"Couldn't allocate (PictImage *)\n");    exit(-1);  }  if ((newpic->lum = (unsigned char *)malloc(sizeof(char)*size))       == NULL) 
  {    fprintf(stderr,"Couldn't allocate memory for luminance\n");    exit(-1);  }  if ((newpic->Cr = (unsigned char *)malloc(sizeof(char)*size/4))       == NULL) 
  {    fprintf(stderr,"Couldn't allocate memory for Cr\n");    exit(-1);  }  if ((newpic->Cb = (unsigned char *)malloc(sizeof(char)*size/4))       == NULL) 
  {    fprintf(stderr,"Couldn't allocate memory for Cb\n");    exit(-1);  }  return newpic;}void FreeImage(PictImage *image){  free(image->lum);  free(image->Cr);  free(image->Cb);  free(image);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?