/* checks if image was already loaded, then returns same image * otherwise creates new. * does not load ibuf itself * pass on optional frame for #name images */ MovieClip *BKE_movieclip_file_add(const char *name) { MovieClip *clip; MovieClipUser user = {0}; int file, len, width, height; const char *libname; char str[FILE_MAX], strtest[FILE_MAX]; BLI_strncpy(str, name, sizeof(str)); BLI_path_abs(str, G.main->name); /* exists? */ file = BLI_open(str, O_BINARY | O_RDONLY, 0); if (file == -1) return NULL; close(file); /* ** first search an identical clip ** */ for (clip = G.main->movieclip.first; clip; clip = clip->id.next) { BLI_strncpy(strtest, clip->name, sizeof(clip->name)); BLI_path_abs(strtest, G.main->name); if (strcmp(strtest, str) == 0) { BLI_strncpy(clip->name, name, sizeof(clip->name)); /* for stringcode */ clip->id.us++; /* officially should not, it doesn't link here! */ return clip; } } /* ** add new movieclip ** */ /* create a short library name */ len = strlen(name); while (len > 0 && name[len - 1] != '/' && name[len - 1] != '\\') len--; libname = name + len; clip = movieclip_alloc(libname); BLI_strncpy(clip->name, name, sizeof(clip->name)); if (BLI_testextensie_array(name, imb_ext_movie)) clip->source = MCLIP_SRC_MOVIE; else clip->source = MCLIP_SRC_SEQUENCE; user.framenr = 1; BKE_movieclip_get_size(clip, &user, &width, &height); if (width && height) { clip->tracking.camera.principal[0] = ((float)width) / 2.0f; clip->tracking.camera.principal[1] = ((float)height) / 2.0f; clip->tracking.camera.focal = 24.0f * width / clip->tracking.camera.sensor_width; } movieclip_calc_length(clip); return clip; }
/* checks if image was already loaded, then returns same image * otherwise creates new. * does not load ibuf itself * pass on optional frame for #name images */ MovieClip *BKE_movieclip_file_add(Main *bmain, const char *name) { MovieClip *clip; int file, len; const char *libname; char str[FILE_MAX], strtest[FILE_MAX]; BLI_strncpy(str, name, sizeof(str)); BLI_path_abs(str, bmain->name); /* exists? */ file = BLI_open(str, O_BINARY | O_RDONLY, 0); if (file == -1) return NULL; close(file); /* ** first search an identical clip ** */ for (clip = bmain->movieclip.first; clip; clip = clip->id.next) { BLI_strncpy(strtest, clip->name, sizeof(clip->name)); BLI_path_abs(strtest, G.main->name); if (strcmp(strtest, str) == 0) { BLI_strncpy(clip->name, name, sizeof(clip->name)); /* for stringcode */ clip->id.us++; /* officially should not, it doesn't link here! */ return clip; } } /* ** add new movieclip ** */ /* create a short library name */ len = strlen(name); while (len > 0 && name[len - 1] != '/' && name[len - 1] != '\\') len--; libname = name + len; clip = movieclip_alloc(bmain, libname); BLI_strncpy(clip->name, name, sizeof(clip->name)); detect_clip_source(clip); movieclip_load_get_szie(clip); if (clip->lastsize[0]) { int width = clip->lastsize[0]; clip->tracking.camera.focal = 24.0f * width / clip->tracking.camera.sensor_width; } movieclip_calc_length(clip); return clip; }