Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2008-04-11 19:47:21 +0400
committerCampbell Barton <ideasman42@gmail.com>2008-04-11 19:47:21 +0400
commitf057a38e985fe4db1c57f48864624985a31c9235 (patch)
treec9383d4b2727434e3971096ac8ea4101a84ac89b /source/blender/blenlib/intern/util.c
parenta02937d86ccb30f0cc08ef451634595fb45726c6 (diff)
Changed BLI_convertstringcode to replace any number of hashes with the frame number.
somefile_##.png -> somefile_01.png somefile_########-image.png -> somefile_00000001-image.png Before, A hash at the end of the string would be replaced by a number with 4 characters. This is still default if no #'s are in the string, so nothing has changed. To use this function from the python api use scene.render.getFrameFilename()
Diffstat (limited to 'source/blender/blenlib/intern/util.c')
-rw-r--r--source/blender/blenlib/intern/util.c56
1 files changed, 50 insertions, 6 deletions
diff --git a/source/blender/blenlib/intern/util.c b/source/blender/blenlib/intern/util.c
index 6d8dd3d9b50..46bb1eb0104 100644
--- a/source/blender/blenlib/intern/util.c
+++ b/source/blender/blenlib/intern/util.c
@@ -41,6 +41,7 @@
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
+#include <math.h> /* for log10 */
#include "MEM_guardedalloc.h"
@@ -1027,7 +1028,8 @@ void BLI_makestringcode(const char *relfile, char *file)
int BLI_convertstringcode(char *path, const char *basepath, int framenum)
{
- int len, wasrelative;
+ int wasrelative;
+ int ch_sta, ch_end;
char tmp[FILE_MAX];
char base[FILE_MAX];
char vol[3] = {'\0', '\0', '\0'};
@@ -1082,12 +1084,54 @@ int BLI_convertstringcode(char *path, const char *basepath, int framenum)
MEM_freeN(filepart);
}
-
- len= strlen(tmp);
- if(len && tmp[len-1]=='#') {
- sprintf(tmp+len-1, "%04d", framenum);
+
+
+ /* Insert current frame: file### -> file001 */
+ ch_end = 0;
+ for (ch_sta = 0; tmp[ch_sta] != '\0'; ch_sta++) {
+ if (tmp[ch_sta] == '#') {
+ ch_end = ch_sta+1;
+ while (tmp[ch_end] == '#') {
+ ch_end++;
+ }
+ break;
+ }
}
-
+ if (ch_end) { /* warning, ch_end is the last # +1 */
+ /* Add the frame number? */
+ short numlen, hashlen;
+ char format[16]; /* 6 is realistically the maxframe (300000), so 8 should be enough, but 16 to be safe. */
+
+ numlen = 1 + (int)log10((double)framenum); /* this is the number of chars in the number */
+ hashlen = ch_end - ch_sta;
+
+ sprintf(format, "%d", framenum);
+
+ if (numlen==hashlen) { /* simple case */
+ memcpy(tmp+ch_sta, format, numlen);
+ } else if (numlen < hashlen) {
+ memcpy(tmp+ch_sta + (hashlen-numlen), format, numlen); /*dont copy the string terminator */
+ memset(tmp+ch_sta, '0', hashlen-numlen);
+ } else {
+ /* number is longer then number of #'s */
+ if (tmp[ch_end] == '\0') { /* hashes are last, no need to move any string*/
+ /* bad juju - not testing string length here :/ */
+ memcpy(tmp+ch_sta, format, numlen+1); /* add 1 to get the string terminator \0 */
+ } else {
+ /* we need to move the end characters */
+ int i = strlen(tmp); /* +1 to copy the string terminator */
+ int j = i + (numlen-hashlen); /* from/to */
+ while (i >= ch_end) {
+ tmp[j] = tmp[i];
+ i--;
+ j--;
+ }
+ memcpy(tmp + ch_sta, format, numlen);
+ }
+ }
+ }
+ /* done with file### stuff */
+
strcpy(path, tmp);
#ifdef WIN32
/* skip first two chars, which in case of