static int get_n_frs(Image_File *ifp) { int n_frames=0; char *pixels; ImageDesc *idp; Boolean moreframes = TRUE; #ifdef QUIP_DEBUG printf("get_n_frs: IN\n"); #endif /* QUIP_DEBUG */ idp = ifp->hdr->idp; pixels = (char *)malloc(idp->Size * sizeof(char)); /* get frames until the movie ends */ while (moreframes) { /* GetMPEGFrame returns FALSE after last frame is decoded */ moreframes = GetMPEGFrame(pixels); n_frames++; } free(pixels); if(verbose) printf("n_frames calculated: %d\n", n_frames); RewindMPEG (ifp->if_fp, idp); #ifdef QUIP_DEBUG printf("get_n_frs: OUT\n"); #endif /* QUIP_DEBUG */ return n_frames; }
static void malib_mpegfile_get_next_frame (MalibMpegFile* mpegfile, MalibFrame* frame) { unsigned int i; unsigned char* buf = mpegfile->pixels; struct timeval* tp = &(((MalibSource*) mpegfile) -> tp); /* the flag whether we need to create new image */ int need_increment = 0; g_return_if_fail (mpegfile && frame); /* GetMPEGFrame returns TRUE if more frames are still remaining */ MALIB_OBJECT_COUNT_REFERENCES (mpegfile, need_increment); if (need_increment) { int flag = GetMPEGFrame (buf); /* Mark timestamp at the moment of capturing */ gettimeofday (tp, NULL); if (flag != TRUE) { RewindMPEG (mpegfile->fp, &mpegfile->img); } } /* copy data from buf into frame->data with re-allocation */ for(i = 0; i < mpegfile->img.Size/4; i++) { *((int*)frame->data + i*3) = (int) *(buf+i*4); *((int*)frame->data + i*3+1) = (int) *(buf+i*4+1); *((int*)frame->data + i*3+2) = (int) *(buf+i*4+2); } /* copy timestamp into following frames */ frame->timestamp . tv_sec = tp -> tv_sec; frame->timestamp . tv_usec = tp -> tv_usec; }
void mpeg_rd(Data_Obj *dp,Image_File *ifp,index_t x_offset, index_t y_offset,index_t t_offset) { static char *data_ptr; char *pixels; int i; #ifdef BPP_3 int actual_fr_size; #endif /* BPP_3 */ #ifdef QUIP_DEBUG printf("mpeg_rd: IN\n"); #endif /* QUIP_DEBUG */ /* make sure that the sizes match */ if( ! dp_same_dim(dp,ifp->if_dp,0) ) return; /* same # components? */ if( ! dp_same_dim(dp,ifp->if_dp,1) ) return; /* same # columns? */ if( ! dp_same_dim(dp,ifp->if_dp,2) ) return; /* same # rows? */ #ifdef FOOBAR #ifdef BPP_3 /* we don't need to alloate mem for the unused byte, hence 0.75 */ actual_fr_size = ifp->hdr->idp->Size * 0.75 * sizeof(char); data_ptr = dp->dt_data = (char *)malloc(actual_fr_size); #else data_ptr = dp->dt_data = (char *)malloc(ifp->hdr->idp->Size); #endif /* BPP_3 */ #endif /* FOOBAR */ /* Saad must have written that code resetting dp->dt_data!? */ /* note that it was never free'd */ data_ptr = (char *)dp->dt_data; /* mem for decoded image */ pixels = (char *)malloc(ifp->hdr->idp->Size * sizeof(char)); /* Get a single MPEG frame */ GetMPEGFrame(pixels); /* Copy frame to the data object */ for(i=0; i<ifp->hdr->idp->Size; i+=4) { /* For full colour dithering, there are four bytes per pixel: * red, green, blue, and unused. */ *(data_ptr) = *(pixels+i+2); *(data_ptr+1) = *(pixels+i+1); *(data_ptr+2) = *(pixels+i+0); #ifdef BPP_3 data_ptr+=3; #else data_ptr+=4; #endif /* BPP_3 */ } #ifdef QUIP_DEBUG_USING_SDL #ifdef BPP_3 screen->pixels = (char *)memcpy(screen->pixels, dp->dt_data, actual_fr_size); #else screen->pixels = (char *)memcpy(screen->pixels, dp->dt_data, ifp->hdr->idp->Size); #endif /* BPP_3 */ SDL_UpdateRect(screen, 0, 0, 0, 0); #endif /* QUIP_DEBUG_USING_SDL */ // dp->dt_data = (char *)memcpy(dp->dt_data, pixels, ifp->hdr->idp->Size); free(pixels); ifp->if_nfrms ++; if( FILE_FINISHED(ifp) ){ /* BUG? if autoclose is set to no, do we make sure we don't read past eof? */ if( verbose ){ sprintf(error_string, "closing file \"%s\" after reading %ld frames", ifp->if_name,ifp->if_nfrms); advise(error_string); } mpeg_close(ifp); } #ifdef QUIP_DEBUG printf("mpeg_rd: OUT\n"); #endif /* QUIP_DEBUG */ }