int test_store_restore(TestData* testdata){ MotionDetect md; test_bool(initMotionDetect(&md, &testdata->fi, "test") == VS_OK); test_bool(configureMotionDetect(&md)== VS_OK); LocalMotions lms; int i; for(i=0; i<2; i++){ test_bool(motionDetection(&md, &lms,&testdata->frames[i])== VS_OK); if (i==0) vs_vector_del(&lms); } FILE* f = fopen("lmtest","w"); storeLocalmotions(f,&lms); fclose(f); f = fopen("lmtest","r"); LocalMotions test = restoreLocalmotions(f); fclose(f); storeLocalmotions(stderr,&test); compare_localmotions(&lms,&test); fprintf(stderr,"\n** LM and LMS OKAY\n"); f = fopen("lmstest","w"); md.frameNum=1; prepareFile(&md,f); writeToFile(&md,f,&lms); md.frameNum=2; writeToFile(&md,f,&test); fclose(f); f = fopen("lmstest","r"); test_bool(readFileVersion(f)==1); LocalMotions read1; test_bool(readFromFile(f,&read1)==1); compare_localmotions(&lms,&read1); LocalMotions read2; test_bool(readFromFile(f,&read2)==2); compare_localmotions(&test,&read2); fclose(f); fprintf(stderr,"** Reading file stepwise OKAY\n"); vs_vector_del(&read1); vs_vector_del(&read2); vs_vector_del(&test); vs_vector_del(&lms); f = fopen("lmstest","r"); ManyLocalMotions mlms; test_bool(readLocalMotionsFile(f,&mlms)==VS_OK); test_bool(vs_vector_size(&mlms)==2); fprintf(stderr,"** Entire file routine OKAY\n\n"); for(i=0; i< vs_vector_size(&mlms); i++){ if(MLMGet(&mlms,i)) vs_vector_del(MLMGet(&mlms,i)); } vs_vector_del(&mlms); return 1; }
/* * deshake_configure: Configure this instance of the module. See * tcmodule-data.h for function details. */ static int deshake_configure(TCModuleInstance *self, const char *options, vob_t *vob) { DeshakeData *sd = NULL; TC_MODULE_SELF_CHECK(self, "configure"); char* filenamecopy, *filebasename; sd = self->userdata; /* sd->framesize = sd->vob->im_v_width * MAX_PLANES * sizeof(char) * 2 * sd->vob->im_v_height * 2; */ MotionDetect* md = &(sd->md); TransformData* td = &(sd->td); // init MotionDetect part VSFrameInfo fi; initFrameInfo(&fi, sd->vob->ex_v_width, sd->vob->ex_v_height, transcode2ourPF(sd->vob->im_v_codec)); if(initMotionDetect(md, &fi, MOD_NAME) != VS_OK){ tc_log_error(MOD_NAME, "initialization of Motion Detection failed"); return TC_ERROR; } sd->result = tc_malloc(TC_BUF_LINE); filenamecopy = tc_strdup(sd->vob->video_in_file); filebasename = basename(filenamecopy); if (strlen(filebasename) < TC_BUF_LINE - 4) { tc_snprintf(sd->result, TC_BUF_LINE, "%s.trf", filebasename); } else { tc_log_warn(MOD_NAME, "input name too long, using default `%s'", DEFAULT_TRANS_FILE_NAME); tc_snprintf(sd->result, TC_BUF_LINE, DEFAULT_TRANS_FILE_NAME); } // init trasform part VSFrameInfo fi_dest; initFrameInfo(&fi_dest, sd->vob->ex_v_width, sd->vob->ex_v_height, transcode2ourPF(sd->vob->im_v_codec)); if(initTransformData(td, &fi, &fi_dest, MOD_NAME) != VS_OK){ tc_log_error(MOD_NAME, "initialization of TransformData failed"); return TC_ERROR; } td->verbose=verbose; if (options != NULL) { // for some reason this plugin is called in the old fashion // (not with inspect). Anyway we support both ways of getting help. if(optstr_lookup(options, "help")) { tc_log_info(MOD_NAME,deshake_help); return(TC_IMPORT_ERROR); } optstr_get(options, "result", "%[^:]", sd->result); optstr_get(options, "shakiness", "%d", &md->shakiness); optstr_get(options, "accuracy", "%d", &md->accuracy); optstr_get(options, "stepsize", "%d", &md->stepSize); optstr_get(options, "algo", "%d", &md->algo); optstr_get(options, "mincontrast","%lf",&md->contrastThreshold); md->show = 0; optstr_get(options, "maxshift", "%d", &td->maxShift); optstr_get(options, "maxangle", "%lf", &td->maxAngle); optstr_get(options, "smoothing", "%d", &td->smoothing); optstr_get(options, "crop" , "%d", (int*)&td->crop); optstr_get(options, "zoom" , "%lf",&td->zoom); optstr_get(options, "optzoom" , "%d", &td->optZoom); optstr_get(options, "interpol" , "%d", (int*)(&td->interpolType)); optstr_get(options, "sharpen" , "%lf",&td->sharpen); td->relative=1; td->invert=0; } if(configureMotionDetect(md)!= VS_OK){ tc_log_error(MOD_NAME, "configuration of Motion Detection failed"); return TC_ERROR; } if(configureTransformData(td)!= VS_OK){ tc_log_error(MOD_NAME, "configuration of Tranform failed"); return TC_ERROR; } if (verbose) { tc_log_info(MOD_NAME, "Video Deshake Settings:"); tc_log_info(MOD_NAME, " smoothing = %d", td->smoothing); tc_log_info(MOD_NAME, " shakiness = %d", md->shakiness); tc_log_info(MOD_NAME, " accuracy = %d", md->accuracy); tc_log_info(MOD_NAME, " stepsize = %d", md->stepSize); tc_log_info(MOD_NAME, " algo = %d", md->algo); tc_log_info(MOD_NAME, " mincontrast = %f", md->contrastThreshold); tc_log_info(MOD_NAME, " show = %d", md->show); tc_log_info(MOD_NAME, " result = %s", sd->result); tc_log_info(MOD_NAME, " maxshift = %d", td->maxShift); tc_log_info(MOD_NAME, " maxangle = %f", td->maxAngle); tc_log_info(MOD_NAME, " crop = %s", td->crop ? "Black" : "Keep"); tc_log_info(MOD_NAME, " zoom = %f", td->zoom); tc_log_info(MOD_NAME, " optzoom = %s", td->optZoom ? "On" : "Off"); tc_log_info(MOD_NAME, " interpol = %s", interpolTypes[td->interpolType]); tc_log_info(MOD_NAME, " sharpen = %f", td->sharpen); } sd->avg.initialized=0; sd->f = fopen(sd->result, "w"); if (sd->f == NULL) { tc_log_error(MOD_NAME, "cannot open result file %s!\n", sd->result); return TC_ERROR; } return TC_OK; }