static inline void malib_mpegfile_init (MalibMpegFile* mpegfile) { MalibFrame* frame_info; if ((mpegfile->fp = fopen (mpegfile->filename, "r")) == NULL) { g_error ("MalibMpegFile: file open"); exit (-1); } SetMPEGOption (MALIB_STD_MPEG_DITHER, MALIB_STD_MPEG_COLOR); OpenMPEG (mpegfile->fp, &mpegfile->img); mpegfile->pixels = (unsigned char*) malloc (mpegfile->img.Size * sizeof(unsigned char)); frame_info = malib_frame_new (MALIB_FRAME_COLORMODEL_RGB, mpegfile->img.Width, mpegfile->img.Height, mpegfile->img.Depth, (int*)0); malib_source_set_frame_info ((MalibSource*)mpegfile, frame_info); }
Image_File * mpeg_open(const char *name,int rw) { Image_File *ifp; ImageDesc *idp; #ifdef QUIP_DEBUG printf("mpeg_open: IN\n"); #endif /* QUIP_DEBUG */ ifp = IMG_FILE_CREAT(name,rw,IFT_MPEG); if( ifp==NO_IMAGE_FILE ) return(ifp); ifp->hdr = (Mpeg_Hdr *)getbuf( sizeof(Mpeg_Hdr) ); if( IS_READABLE(ifp) ) { ifp->hdr->idp = (ImageDesc *)malloc( sizeof(ImageDesc) ); idp = ifp->hdr->idp; SetMPEGOption (MPEG_DITHER, FULL_COLOR_DITHER); if (!OpenMPEG(ifp->if_fp, idp)) { advise("ERROR: OpenMPEG failed"); exit(1); } /* fill in some basic header info */ ifp->hdr->width = idp->Width; ifp->hdr->height = idp->Height; #ifdef BPP_3 ifp->hdr->depth = idp->Depth/8; #else ifp->hdr->depth = idp->PixelSize/8; #endif /* BUG: we need a more efficient way of counting frames! */ ifp->hdr->frames = get_n_frs(ifp); // ifp->hdr->frames = get_n_of_frms(ifp->if_pathname); mpeg_to_dp(ifp->if_dp,ifp->hdr); #ifdef QUIP_DEBUG_USING_SDL { char buf[32]; /* Initialize SDL */ if ((SDL_Init(SDL_INIT_VIDEO) < 0) || !SDL_VideoDriverName(buf, 1)) { sprintf(error_string,"Couldn't init SDL video: %s\n", SDL_GetError()); warn(error_string); } //screen = SDL_SetVideoMode(idp->Width, idp->Height, 0, 0); screen = SDL_SetVideoMode(idp->Width, idp->Height, ifp->hdr->depth*8, SDL_HWSURFACE/*video surface in hardware mem*/); if ( screen == NULL ) { fprintf(stderr, "Unable to set %dx%d video mode: %s\n", idp->Width, idp->Height, SDL_GetError()); return NULL; } } #endif /* QUIP_DEBUG_USING_SDL */ } else { ifp->hdr->enc_opts = (MPEGe_options *)malloc( sizeof(MPEGe_options) ); /* Set default options. These can be changed later, if desired. */ MPEGe_default_options(ifp->hdr->enc_opts); /* Start the library with default options */ if( !MPEGe_open(ifp->if_fp, ifp->hdr->enc_opts) ) { warn("MPEGe lib initialization failure"); return NULL; } /* It doesn't make sense to initialize the header for writing. */ } #ifdef QUIP_DEBUG printf("mpeg_open: OUT\n"); #endif /* QUIP_DEBUG */ return(ifp); }