[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22189] branches/soc-2009-chingachgook/ source/blender/blenkernel: Merged BKE_get_image_export_path() from soc-2009-kazanbas branch with:

Chingiz Dyussenov chingiz.ds at gmail.com
Mon Aug 3 17:45:43 CEST 2009


Revision: 22189
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22189
Author:   chingachgook
Date:     2009-08-03 17:45:43 +0200 (Mon, 03 Aug 2009)

Log Message:
-----------
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

Modified Paths:
--------------
    branches/soc-2009-chingachgook/source/blender/blenkernel/BKE_image.h
    branches/soc-2009-chingachgook/source/blender/blenkernel/intern/image.c

Modified: branches/soc-2009-chingachgook/source/blender/blenkernel/BKE_image.h
===================================================================
--- branches/soc-2009-chingachgook/source/blender/blenkernel/BKE_image.h	2009-08-03 15:19:51 UTC (rev 22188)
+++ branches/soc-2009-chingachgook/source/blender/blenkernel/BKE_image.h	2009-08-03 15:45:43 UTC (rev 22189)
@@ -40,6 +40,7 @@
 struct Tex;
 struct anim;
 struct Scene;
+struct ListBase;
 
 /* call from library */
 void	free_image(struct Image *me);
@@ -154,6 +155,9 @@
 /* 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

Modified: branches/soc-2009-chingachgook/source/blender/blenkernel/intern/image.c
===================================================================
--- branches/soc-2009-chingachgook/source/blender/blenkernel/intern/image.c	2009-08-03 15:19:51 UTC (rev 22188)
+++ branches/soc-2009-chingachgook/source/blender/blenkernel/intern/image.c	2009-08-03 15:45:43 UTC (rev 22189)
@@ -2123,3 +2123,102 @@
 	}
 }
 
+/*
+  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;
+}





More information about the Bf-blender-cvs mailing list