Main Page | Class List | File List | Class Members | File Members

vid_io.c File Reference

#include "vid_sim.h"
#include "video_codec.h"

Go to the source code of this file.

Functions

unsigned char * ReadImage (char *filename, int frame_no, int headerlength)
PictImageFillImage (unsigned char *in)
void WriteImage (PictImage *image, char *filename)
PictImageInitImage (int size)
void FreeImage (PictImage *image)

Variables

video_codecVidSt


Function Documentation

PictImage* FillImage unsigned char *  in  ) 
 

Definition at line 114 of file vid_io.c.

References InitImage(), video_codec::lines, video_codec::pels, Pict, PictImage, and VidSt.

Referenced by code_video().

00115 {
00116   PictImage *Pict;
00117 
00118   Pict = InitImage((VidSt->pels)*(VidSt->lines));
00119 
00120   memcpy(Pict->lum, in, (VidSt->pels)*(VidSt->lines));
00121   memcpy(Pict->Cb, in + (VidSt->pels)*(VidSt->lines), (VidSt->pels)*(VidSt->lines)/4);
00122   memcpy(Pict->Cr, in + (VidSt->pels)*(VidSt->lines) + (VidSt->pels)*(VidSt->lines)/4, (VidSt->pels)*(VidSt->lines)/4);
00123 
00124   free(in);
00125   return(Pict);
00126 }

void FreeImage PictImage image  ) 
 

Definition at line 232 of file vid_io.c.

References pict_image::Cb, pict_image::Cr, pict_image::lum, and PictImage.

Referenced by close_video_codec(), code_video(), and CodeOneOrTwo().

00234 {
00235   free(image->lum);
00236   free(image->Cr);
00237   free(image->Cb);
00238   free(image);
00239 }

PictImage* InitImage int  size  ) 
 

Definition at line 191 of file vid_io.c.

References PictImage.

Referenced by code_video(), CodeOneIntra(), CodeOneOrTwo(), and FillImage().

00192 {
00193   PictImage *new;
00194 
00195   if ((new = (PictImage *)malloc(sizeof(PictImage))) == NULL) {
00196     fprintf(stderr,"Couldn't allocate (PictImage *)\n");
00197     exit(-1);
00198   }
00199   if ((new->lum = (unsigned char *)malloc(sizeof(char)*size)) 
00200       == NULL) {
00201     fprintf(stderr,"Couldn't allocate memory for luminance\n");
00202     exit(-1);
00203   }
00204   if ((new->Cr = (unsigned char *)malloc(sizeof(char)*size/4)) 
00205       == NULL) {
00206     fprintf(stderr,"Couldn't allocate memory for Cr\n");
00207     exit(-1);
00208   }
00209   if ((new->Cb = (unsigned char *)malloc(sizeof(char)*size/4)) 
00210       == NULL) {
00211     fprintf(stderr,"Couldn't allocate memory for Cb\n");
00212     exit(-1);
00213   }
00214 
00215   return new;
00216 }

unsigned char* ReadImage char *  filename,
int  frame_no,
int  headerlength
 

Definition at line 62 of file vid_io.c.

References video_codec::lines, video_codec::pels, and VidSt.

Referenced by code_video().

00064 {
00065   FILE *im_file = NULL;
00066   int im_size = (VidSt->pels)*(VidSt->lines)*3/2;
00067   unsigned char *raw;
00068   int status;
00069 
00070   if ((raw = (unsigned char *)malloc(sizeof(char)*im_size)) == NULL) {
00071     fprintf(stderr,"Couldn't allocate memory to image\n");
00072     exit(-1);
00073   }
00074   if ((im_file = fopen(filename,"rb")) == NULL) {
00075     fprintf(stderr,"Unable to open image_file: %s\n",filename);
00076     exit(-1);
00077   }
00078   rewind(im_file);
00079   /* Find the correct image */
00080   status = fseek(im_file,headerlength + (frame_no) * im_size,0);
00081   if (status != 0) {
00082     fprintf(stderr,"Error in seeking image no: %d\n",frame_no);
00083     fprintf(stderr,"From file: %s\n",filename);
00084     exit(-1);
00085   }
00086   /* Read image */
00087   fprintf(stdout,"Reading image no: %d\n",frame_no);
00088   if ((status = fread(raw, sizeof(char), 
00089               im_size, im_file)) != im_size) {
00090     fprintf(stderr,"Error in reading image no: %d\n",frame_no);
00091     fprintf(stderr,"From file: %s\n",filename);
00092     exit(-1);
00093   }
00094 
00095   fclose(im_file);
00096   return raw;
00097 }

void WriteImage PictImage image,
char *  filename
 

Definition at line 142 of file vid_io.c.

References pict_image::Cb, pict_image::Cr, video_codec::lines, pict_image::lum, video_codec::pels, PictImage, and VidSt.

Referenced by code_video().

00144 {
00145   int status;
00146   FILE *f_out;
00147 
00148   /* Opening file */
00149   if ((f_out = fopen(filename,"ab")) == NULL) {
00150     fprintf(stderr,"%s%s\n","Error in opening file: ",filename);
00151     exit(-1);
00152   }
00153 
00154   /* Writing lum to file */
00155   if ((status = fwrite(image->lum,sizeof(char),(VidSt->pels)*(VidSt->lines),f_out)) 
00156       != (VidSt->pels)*(VidSt->lines)) {
00157     fprintf(stderr,"%s%s\n","Error in writing to file: ",filename);
00158     exit(-1);
00159   }
00160   /* Writing Cb to file */
00161   if ((status = fwrite(image->Cb,sizeof(char),(VidSt->pels)*(VidSt->lines)/4,f_out)) 
00162       != (VidSt->pels)*(VidSt->lines)/4) {
00163     fprintf(stderr,"%s%s\n","Error in writing to file: ",filename);
00164     exit(-1);
00165   }
00166   /* Writing Cr to file */
00167   if ((status = fwrite(image->Cr,sizeof(char),(VidSt->pels)*(VidSt->lines)/4,f_out)) 
00168       != (VidSt->pels)*(VidSt->lines)/4) {
00169     fprintf(stderr,"%s%s\n","Error in writing to file: ",filename);
00170     exit(-1);
00171   }
00172 
00173   fclose(f_out);
00174   return;
00175 }


Variable Documentation

video_codec* VidSt
 

Definition at line 16 of file vid_wrapper.c.


Generated on Sun Jul 16 16:27:47 2006 by  doxygen 1.3.9.1