Merged BKE_get_image_export_path() from soc-2009-kazanbas branch with:

svn merge -r 19844:22173 https://svn.blender.org/svnroot/bf-blender/branches/soc-2009-kazanbas/source/blender/blenkernel/BKE_image.h source/blender/blenkernel/BKE_image.h
svn merge -r 19844:22173 https://svn.blender.org/svnroot/bf-blender/branches/soc-2009-kazanbas/source/blender/blenkernel/intern/image.c source/blender/blenkernel/intern/image.c
This commit is contained in:
Chingiz Dyussenov
2009-08-03 15:45:43 +00:00
parent 87e68418a2
commit 217b865fbd
2 changed files with 103 additions and 0 deletions

View File

@@ -40,6 +40,7 @@ struct ImBuf;
struct Tex;
struct anim;
struct Scene;
struct ListBase;
/* call from library */
void free_image(struct Image *me);
@@ -154,6 +155,9 @@ struct Image *BKE_image_copy(struct Image *ima);
/* merge source into dest, and free source */
void BKE_image_merge(struct Image *dest, struct Image *source);
/* copy image file to a directory rebuilding subdirectory structure */
int BKE_get_image_export_path(struct Image *im, const char *dest_dir, char *abs, int abs_size, char *rel, int rel_size);
#ifdef __cplusplus
}
#endif

View File

@@ -2123,3 +2123,102 @@ void BKE_image_user_calc_imanr(ImageUser *iuser, int cfra, int fieldnr)
}
}
/*
Produce image export path.
Fails returning 0 if image filename is empty or if destination path
matches image path (i.e. both are the same file).
Trailing slash in dest_dir is optional.
Logic:
- if an image is "below" current .blend file directory, rebuild the
same dir structure in dest_dir
For example //textures/foo/bar.png becomes
[dest_dir]/textures/foo/bar.png.
- if an image is not "below" current .blend file directory,
disregard it's path and copy it in the same directory where 3D file
goes.
For example //../foo/bar.png becomes [dest_dir]/bar.png.
This logic will help ensure that all image paths are relative and
that a user gets his images in one place. It'll also provide
consistent behaviour across exporters.
*/
int BKE_get_image_export_path(struct Image *im, const char *dest_dir, char *abs, int abs_size, char *rel, int rel_size)
{
char path[FILE_MAX];
char dir[FILE_MAX];
char base[FILE_MAX];
char blend_dir[FILE_MAX]; /* directory, where current .blend file resides */
char dest_path[FILE_MAX];
char rel_dir[FILE_MAX];
int len;
if (abs)
abs[0]= 0;
if (rel)
rel[0]= 0;
BLI_split_dirfile_basic(G.sce, blend_dir, NULL);
if (!strlen(im->name)) {
if (G.f & G_DEBUG) printf("Invalid image type.\n");
return 0;
}
BLI_strncpy(path, im->name, sizeof(path));
/* expand "//" in filename and get absolute path */
BLI_convertstringcode(path, G.sce);
/* get the directory part */
BLI_split_dirfile_basic(path, dir, base);
len= strlen(blend_dir);
rel_dir[0] = 0;
/* if image is "below" current .blend file directory */
if (!strncmp(path, blend_dir, len)) {
/* if image is _in_ current .blend file directory */
if (!strcmp(dir, blend_dir)) {
BLI_join_dirfile(dest_path, dest_dir, base);
}
/* "below" */
else {
/* rel = image_path_dir - blend_dir */
BLI_strncpy(rel_dir, dir + len, sizeof(rel_dir));
BLI_join_dirfile(dest_path, dest_dir, rel_dir);
BLI_join_dirfile(dest_path, dest_path, base);
}
}
/* image is out of current directory */
else {
BLI_join_dirfile(dest_path, dest_dir, base);
}
/* only return 1 if paths differ */
if (!strcmp(path, dest_path)) {
if (G.f & G_DEBUG) printf("%s and %s are the same file\n", path, dest_path);
return 0;
}
if (abs)
BLI_strncpy(abs, dest_path, abs_size);
if (rel) {
strncat(rel, rel_dir, rel_size);
strncat(rel, base, rel_size);
}
return 1;
}