Example #1
0
/* ----------------------------- MNI Header -----------------------------------
@NAME       : RewindMPEG
@INPUT      : MPEGfile - the input stream where the MPEG's coming from
              Image    - image descriptor (just passed to OpenMPEG ())
@OUTPUT     : (none)
@RETURNS    : (void)
@DESCRIPTION: Resets things so that the caller can start reading the MPEG
              stream from the start again.  Note that the caller does NOT
	      need to call OpenMPEG() again -- after a call to RewindMPEG(),
	      the next call to GetMPEGFrame() will return the first frame
	      of the MPEG.
@METHOD     :
@GLOBALS    : EOF_flag, curBits, bitOffset, bufLength, bitBuffer, totNumFrames
@CALLS      :
@CREATED    : 94/7/20, Greg Ward
@MODIFIED   :
@COMMENTS   : The global variables declared in this function should
              not normally be used by the front end to the MPEG
              decoder.  However, I've chosen to bend the rules for
              just this one function.  N.B.: EOF_flag comes from
              globals.c; curBits, bitOffset, bufLength, and bitBuffer
              from util.c; and totNumFrames is defined in this file.
---------------------------------------------------------------------------- */
Boolean RewindMPEG (FILE *MPEGfile, ImageDesc *Image) {
    CloseMPEG ();
    rewind (MPEGfile);
    bitBuffer = NULL;
    totNumFrames = 0;

    return (OpenMPEG (MPEGfile, Image));
}
Example #2
0
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);
}
Example #3
0
File: mpeg.c Project: E-LLP/QuIP
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);
}