void load_framedraw_image(LiVESPixbuf *pixbuf) { // this is for the single frame framedraw widget // it should be called whenever mainw->framedraw_bitmap changes weed_timecode_t tc; if (mainw->framedraw_frame>cfile->frames) mainw->framedraw_frame=cfile->frames; if (pixbuf==NULL) { const char *img_ext=get_image_ext_for_type(cfile->img_type); // can happen if we preview for rendered generators if ((mainw->multitrack==NULL||mainw->current_file!=mainw->multitrack->render_file)&&mainw->framedraw_frame==0) return; tc=((mainw->framedraw_frame-1.))/cfile->fps*U_SECL; pixbuf=pull_lives_pixbuf_at_size(mainw->current_file,mainw->framedraw_frame,img_ext,tc, (double)cfile->hsize,(double)cfile->vsize, LIVES_INTERP_BEST); } if (pixbuf!=NULL) { if (mainw->fd_layer_orig!=NULL) { weed_layer_free(mainw->fd_layer_orig); } mainw->fd_layer_orig=weed_layer_new(0,0,NULL,WEED_PALETTE_END); if (!pixbuf_to_layer(mainw->fd_layer_orig,pixbuf)) lives_object_unref(pixbuf); } if (mainw->fd_layer!=NULL) weed_layer_free(mainw->fd_layer); mainw->fd_layer=NULL; }
void load_framedraw_image(LiVESPixbuf *pixbuf) { // this is for the single frame framedraw widget // it should be called whenever mainw->framedraw_bitmap changes weed_timecode_t tc; boolean needs_unlock=FALSE; if (mainw->framedraw_frame>cfile->frames) mainw->framedraw_frame=cfile->frames; if (pixbuf==NULL) { const char *img_ext=get_image_ext_for_type(cfile->img_type); // can happen if we preview for rendered generators if ((mainw->multitrack==NULL||mainw->current_file!=mainw->multitrack->render_file)&&mainw->framedraw_frame==0) return; tc=((mainw->framedraw_frame-1.))/cfile->fps*U_SECL; pixbuf=pull_lives_pixbuf_at_size(mainw->current_file,mainw->framedraw_frame,img_ext,tc, (double)cfile->hsize,(double)cfile->vsize, LIVES_INTERP_BEST); } if (pixbuf!=NULL) { if (mainw->fd_layer_orig!=NULL) { weed_layer_free(mainw->fd_layer_orig); } mainw->fd_layer_orig=weed_layer_new(0,0,NULL,WEED_PALETTE_END); if (pixbuf_to_layer(mainw->fd_layer_orig,pixbuf)) { mainw->do_not_free=(livespointer)lives_pixbuf_get_pixels_readonly(pixbuf); // might be threaded here so we need a mutex to stop other thread resetting free_fn pthread_mutex_lock(&mainw->free_fn_mutex); needs_unlock=TRUE; mainw->free_fn=_lives_free_with_check; } lives_object_unref(pixbuf); mainw->do_not_free=NULL; mainw->free_fn=_lives_free_normal; if (needs_unlock) pthread_mutex_unlock(&mainw->free_fn_mutex); } if (mainw->fd_layer!=NULL) weed_layer_free(mainw->fd_layer); mainw->fd_layer=NULL; }
void clean_images_from_virtual(lives_clip_t *sfile, int oldframes) { // remove images on disk where the frame_index points to a frame in // the original clip // only needed if frames were reordered when rendered and the process is // then undone // in future, a smarter function could trace the images back to their // original source frames, and just rename them // should be threadsafe register int i; char *iname=NULL,*com; if (sfile==NULL||sfile->frame_index==NULL) return; for (i=0; i<oldframes; i++) { threaded_dialog_spin(); lives_widget_context_update(); threaded_dialog_spin(); if ((i<sfile->frames&&sfile->frame_index[i]!=-1)||i>=sfile->frames) { iname=lives_strdup_printf("%s/%s/%08d.%s",prefs->tmpdir,sfile->handle,i,get_image_ext_for_type(sfile->img_type)); #ifndef IS_MINGW com=lives_strdup_printf("/bin/rm -f \"%s\"",iname); #else com=lives_strdup_printf("rm.exe -f \"%s\"",iname); #endif lives_system(com,FALSE); lives_free(com); } } }
boolean virtual_to_images(int sfileno, int sframe, int eframe, boolean update_progress, LiVESPixbuf **pbr) { // pull frames from a clip to images // from sframe to eframe inclusive (first frame is 1) // if update_progress, set mainw->msg with number of frames pulled // should be threadsafe apart from progress update // if pbr is non-null, it will be set to point to the pulled pixbuf ( // return FALSE on write error register int i; lives_clip_t *sfile=mainw->files[sfileno]; LiVESPixbuf *pixbuf=NULL; LiVESError *error=NULL; char *oname; int retval; int progress=1; if (sframe<1) sframe=1; for (i=sframe; i<=eframe; i++) { if (i>sfile->frames) break; if (sfile->frame_index[i-1]>=0) { oname=NULL; if (update_progress) { threaded_dialog_spin(); lives_widget_context_update(); } if (pbr!=NULL&&pixbuf!=NULL) lives_object_unref(pixbuf); pixbuf=pull_lives_pixbuf_at_size(sfileno,i,get_image_ext_for_type(sfile->img_type), q_gint64((i-1.)/sfile->fps,sfile->fps),sfile->hsize,sfile->vsize,LIVES_INTERP_BEST); oname=lives_strdup_printf("%s/%s/%08d.%s",prefs->tmpdir,sfile->handle,i,get_image_ext_for_type(sfile->img_type)); do { retval=0; lives_pixbuf_save(pixbuf, oname, sfile->img_type, 100-prefs->ocp, TRUE, &error); if (error!=NULL&&pbr==NULL) { retval=do_write_failed_error_s_with_retry(oname,error->message,NULL); lives_error_free(error); error=NULL; } } while (retval==LIVES_RESPONSE_RETRY); if (oname!=NULL) lives_free(oname); if (pbr==NULL) { if (pixbuf!=NULL) lives_object_unref(pixbuf); pixbuf=NULL; } if (retval==LIVES_RESPONSE_CANCEL) return FALSE; // another thread may have called check_if_non_virtual - TODO : use a mutex if (sfile->frame_index==NULL) break; sfile->frame_index[i-1]=-1; if (update_progress) { // sig_progress... lives_snprintf(mainw->msg,256,"%d",progress++); threaded_dialog_spin(); lives_widget_context_update(); } if (mainw->cancelled!=CANCEL_NONE) { if (!check_if_non_virtual(sfileno,1,sfile->frames)) save_frame_index(sfileno); if (pbr!=NULL) *pbr=pixbuf; return TRUE; } } } if (pbr!=NULL) *pbr=pixbuf; if (!check_if_non_virtual(sfileno,1,sfile->frames)) if (!save_frame_index(sfileno)) return FALSE; return TRUE; }
void load_rfx_preview(lives_rfx_t *rfx) { // load a preview of an rfx (rendered effect) in clip editor LiVESPixbuf *pixbuf; FILE *infofile=NULL; int max_frame=0,tot_frames=0; int vend=cfile->start; int retval; int alarm_handle; int current_file=mainw->current_file; boolean retb; boolean timeout; weed_timecode_t tc; const char *img_ext; if (mainw->framedraw_frame==0) mainw->framedraw_frame=1; lives_set_cursor_style(LIVES_CURSOR_BUSY,NULL); clear_mainw_msg(); mainw->write_failed=FALSE; if (cfile->clip_type==CLIP_TYPE_FILE&&vend<=cfile->end) { // pull some frames for 10 seconds alarm_handle=lives_alarm_set(LIVES_DEFAULT_TIMEOUT); do { lives_widget_context_update(); if (is_virtual_frame(mainw->current_file,vend)) { retb=virtual_to_images(mainw->current_file,vend,vend,FALSE,NULL); if (!retb) return; } vend++; timeout=lives_alarm_get(alarm_handle); } while (vend<=cfile->end&&!timeout&&!mainw->cancelled); lives_alarm_clear(alarm_handle); } if (mainw->cancelled) { lives_set_cursor_style(LIVES_CURSOR_NORMAL,NULL); return; } // get message from back end processor while (!(infofile=fopen(cfile->info_file,"r"))&&!mainw->cancelled) { // wait until we get at least 1 frame lives_widget_context_update(); if (cfile->clip_type==CLIP_TYPE_FILE&&vend<=cfile->end) { // if we have a virtual clip (frames inside a video file) // pull some more frames to images to get us started do { retb=FALSE; if (is_virtual_frame(mainw->current_file,vend)) { retb=virtual_to_images(mainw->current_file,vend,vend,FALSE,NULL); if (!retb) { fclose(infofile); return; } } vend++; } while (vend<=cfile->end&&!retb); } else { // otherwise wait lives_usleep(prefs->sleep_time); } } if (mainw->cancelled) { if (infofile) fclose(infofile); lives_set_cursor_style(LIVES_CURSOR_NORMAL,NULL); return; } do { retval=0; mainw->read_failed=FALSE; lives_fgets(mainw->msg,512,infofile); if (mainw->read_failed) retval=do_read_failed_error_s_with_retry(cfile->info_file,NULL,NULL); } while (retval==LIVES_RESPONSE_RETRY); fclose(infofile); if (strncmp(mainw->msg,"completed",9)) { if (rfx->num_in_channels>0) { max_frame=atoi(mainw->msg); } else { int numtok=get_token_count(mainw->msg,'|'); if (numtok>4) { char **array=lives_strsplit(mainw->msg,"|",numtok); max_frame=atoi(array[0]); cfile->hsize=atoi(array[1]); cfile->vsize=atoi(array[2]); cfile->fps=cfile->pb_fps=strtod(array[3],NULL); if (cfile->fps==0) cfile->fps=cfile->pb_fps=prefs->default_fps; tot_frames=atoi(array[4]); lives_strfreev(array); } } } else { max_frame=cfile->end; } lives_set_cursor_style(LIVES_CURSOR_NORMAL,NULL); if (max_frame>0) { if (rfx->num_in_channels==0) { int maxlen=calc_spin_button_width(1.,(double)tot_frames,0); lives_spin_button_set_range(LIVES_SPIN_BUTTON(mainw->framedraw_spinbutton),1,tot_frames); lives_entry_set_width_chars(LIVES_ENTRY(mainw->framedraw_spinbutton),maxlen); lives_widget_queue_draw(mainw->framedraw_spinbutton); lives_widget_queue_draw(mainw->framedraw_scale); } if (mainw->framedraw_frame>max_frame) { lives_spin_button_set_value(LIVES_SPIN_BUTTON(mainw->framedraw_spinbutton),max_frame); mainw->current_file=current_file; return; } } if (rfx->num_in_channels>0) { img_ext=LIVES_FILE_EXT_PRE; } else { img_ext=get_image_ext_for_type(cfile->img_type); } tc=((mainw->framedraw_frame-1.))/cfile->fps*U_SECL; pixbuf=pull_lives_pixbuf_at_size(mainw->current_file,mainw->framedraw_frame,(char *)img_ext, tc,(double)cfile->hsize, (double)cfile->vsize,LIVES_INTERP_BEST); load_framedraw_image(pixbuf); redraw_framedraw_image(); mainw->current_file=current_file; }