[ALMOST DONE] Folders or filenames for bracket sets

Started by engardeknave, October 11, 2012, 11:39:21 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

engardeknave

Would it be possible to make a new folder and switch to it at the end of each bracket set? Doesn't have to be a custom name, just the default naming scheme. (I have the MKII.)

Or maybe it would be better to add something to the file name to indicate that it belongs to a bracket set. Like a number. Like IMG_0001.B01.CR2 or B01_0001.CR2. (This would probably be the better option for most people.)

Just some way to easily pick out which files belong to which set of bracketed photos.

a1ex

What's possible is to change the file prefix (first 4 characters).

Like B01_1234.CR2, B02_1235.CR2, B03_1236.CR2...

engardeknave

Well, to be clear it would be like: B01_1234.CR2, B01_1235.CR2, B01_1236.CR2, B02_1237.CR2, B02_1238.CR2, B02_1239.CR2 (which I'm sure you realize).

So yeah, that idea sounds awesome to me. I don't know what anyone could have against it.

a1ex

Correct - it would be a big help in sorting the files.

The only trouble I see right now would be on 5D3, where this setting is probably persistent (so if you turn off the camera in the middle of taking a bracketed shot, ML has to restore the setting somehow, maybe at next boot). I've only tried to alter it on 60D, where it's not persistent (it reverts to IMG_ after reboot).

a1ex

Here's a patch that does it.

I'm not yet sure it's without side effects, so I won't commit it yet. Tested only on 5D2. It assumes that file prefix is only changed in RAM (not persistent) - true on 60D and 5D2, not tested on others.


diff -r 3aac88fc7992 src/shoot.c
--- a/src/shoot.c Fri Oct 12 09:18:17 2012 +0300
+++ b/src/shoot.c Fri Oct 12 10:46:38 2012 +0300
@@ -56,12 +56,18 @@
         ((!DISPLAY_IS_ON && CURRENT_DIALOG_MAYBE == 0) || (intptr_t)get_current_dialog_handler() == (intptr_t)&ShootOlcApp_handler);
}

+static char file_prefix[8] = "IMG_";
+PROP_HANDLER(PROP_FILE_PREFIX)
+{
+    snprintf(file_prefix, sizeof(file_prefix), "%s", (const char *)buf);
+}
+
#ifndef CONFIG_5D3
-static char dcim_dir_suffix[6];
+static char dcim_dir_suffix[6] = "EOS5D"; // default value for 5Dc, where this property doesn't exist
static char dcim_dir[100];
PROP_HANDLER(PROP_DCIM_DIR_SUFFIX)
{
-    snprintf(dcim_dir_suffix, sizeof(dcim_dir_suffix), (const char *)buf);
+    snprintf(dcim_dir_suffix, sizeof(dcim_dir_suffix), "%s", (const char *)buf);
}
const char* get_dcim_dir()
{
@@ -5399,7 +5405,7 @@
         my_fprintf(f, "enfuse \"$@\" %s --output=%s_%04d.JPG ", focus_stack ? "--exposure-weight=0 --saturation-weight=0 --contrast-weight=1 --hard-mask" : "", focus_stack ? "FST" : "HDR", f0);
         for(int i = 0; i < steps; i++ )
         {
-            my_fprintf(f, "IMG_%04d.JPG ", mod(f0 + i, 10000));
+            my_fprintf(f, " %s%04d.JPG", file_prefix, mod(f0 + i, 10000));
         }
         my_fprintf(f, "\n");
         FIO_CloseFile(f);
@@ -5421,7 +5427,7 @@
         my_fprintf(f, "align_image_stack -m -a %s_AIS_%04d", focus_stack ? "FST" : "HDR", f0);
         for(int i = 0; i < steps; i++ )
         {
-            my_fprintf(f, " IMG_%04d.JPG", mod(f0 + i, 10000));
+            my_fprintf(f, " %s%04d.JPG", file_prefix, mod(f0 + i, 10000));
         }
         my_fprintf(f, "\n");
         my_fprintf(f, "enfuse \"$@\" %s --output=%s_%04d.JPG %s_AIS_%04d*\n", focus_stack ? "--contrast-window-size=9 --exposure-weight=0 --saturation-weight=0 --contrast-weight=1 --hard-mask" : "", focus_stack ? "FST" : "HDR", f0, focus_stack ? "FST" : "HDR", f0);
@@ -5737,7 +5743,7 @@
     if (!skip0) hdr_shutter_release_then_check_for_under_or_over_exposure(0, 1, &under, &over);
     else hdr_check_for_under_or_over_exposure(&under, &over);
     if (!under) UNDER = 0; if (!over) OVER = 0;
-    if (hdr_check_cancel(0)) goto end;
+    if (hdr_check_cancel(0)) return;
     
     int steps = 1;
     switch (hdr_sequence)
@@ -5752,7 +5758,7 @@
                     if (!under) UNDER = 0; if (!over) OVER = 0;
                     if (!ok) OVER = 0; // Canon limit reached, don't continue this sequence
                     steps++;
-                    if (hdr_check_cancel(0)) goto end;
+                    if (hdr_check_cancel(0)) return;
                 }
                 
                 if (UNDER)
@@ -5761,7 +5767,7 @@
                     if (!under) UNDER = 0; if (!over) OVER = 0;
                     if (!ok) UNDER = 0; // Canon limit reached, don't continue this sequence
                     steps++;
-                    if (hdr_check_cancel(0)) goto end;
+                    if (hdr_check_cancel(0)) return;
                 }
             }
             break;
@@ -5776,7 +5782,7 @@
                     if (!under) UNDER = 0; if (!over) OVER = 0;
                     if (!ok) OVER = 0;
                     steps++;
-                    if (hdr_check_cancel(0)) goto end;
+                    if (hdr_check_cancel(0)) return;
                 }
             }
             break;
@@ -5791,7 +5797,7 @@
                     if (!under) UNDER = 0; if (!over) OVER = 0;
                     if (!ok) UNDER = 0;
                     steps++;
-                    if (hdr_check_cancel(0)) goto end;
+                    if (hdr_check_cancel(0)) return;
                 }
             }
             break;
@@ -5799,9 +5805,6 @@
     }

     hdr_create_script(steps, skip0, 0, file_number - steps + 1);
-
-end:
-    restore_af_button_assignment();
}

// skip0: don't take the middle exposure
@@ -5816,16 +5819,11 @@
     //~ NotifyBox(2000, "HDR script created"); msleep(2000);
     int i;
     
-    // make sure it won't autofocus
-    // change it only once per HDR sequence to avoid slowdown
-    assign_af_button_to_star_button();
-    // be careful: don't return without restoring the setting back!
-   
     hdr_check_cancel(1);
     
     // first exposure is always at 0 EV (and might be skipped)
     if (!skip0) hdr_shutter_release(0, 1);
-    if (hdr_check_cancel(0)) goto end;
+    if (hdr_check_cancel(0)) return;
     
     switch (hdr_sequence)
     {
@@ -5834,12 +5832,12 @@
             for( i = 1; i <= steps/2; i ++  )
             {
                 hdr_shutter_release(-step_size * i, 1);
-                if (hdr_check_cancel(0)) goto end;
+                if (hdr_check_cancel(0)) return;

                 if (steps % 2 == 0 && i == steps/2) break;
                 
                 hdr_shutter_release(step_size * i, 1);
-                if (hdr_check_cancel(0)) goto end;
+                if (hdr_check_cancel(0)) return;
             }
             break;
         }
@@ -5849,16 +5847,13 @@
             for( i = 1; i < steps; i ++  )
             {
                 hdr_shutter_release(step_size * i * (hdr_sequence == 2 ? 1 : -1), 1);
-                if (hdr_check_cancel(0)) goto end;
+                if (hdr_check_cancel(0)) return;
             }
             break;
         }
     }

     hdr_create_script(steps, skip0, 0, file_number - steps + 1);
-
-end:
-    restore_af_button_assignment();
}

static void press_rec_button()
@@ -5943,6 +5938,79 @@
     movie_end();
}

+// look in DCIM dir for other files named B00_something, B01_something etc
+int hdr_counter = 0;
+int hdr_update_prefix_counter()
+{
+    struct fio_file file;
+    struct fio_dirent * dirent = 0;
+    int N = 0;
+   
+    dirent = FIO_FindFirstEx( get_dcim_dir(), &file );
+    if( IS_ERROR(dirent) )
+        return 0;
+
+    do {
+        if (file.mode & 0x10) continue; // is a directory
+        int n = strlen(file.name);
+        if (n > 4)
+        {
+            if (file.name[0] == 'B' && file.name[3] == '_' && isdigit(file.name[1]) && isdigit(file.name[2]))
+            {
+                int num = (file.name[1]-'0') * 10 + (file.name[2]-'0');
+                hdr_counter = MAX(num, hdr_counter);
+            }
+            else if (file.name[0] == 'B' && isdigit(file.name[1]) && isdigit(file.name[2]) && isdigit(file.name[3]))
+            {
+                int num = (file.name[1]-'0') * 100 + (file.name[2]-'0') * 10 + (file.name[3]-'0');
+                hdr_counter = MAX(num, hdr_counter);
+            }
+        }
+    } while( FIO_FindNextEx( dirent, &file ) == 0);
+    FIO_CleanupAfterFindNext_maybe(dirent);
+    return 1; // success
+}
+
+static int hdr_file_prefix_dirty = 0;
+static char hdr_old_prefix[8];
+static char hdr_prefix[8] = "B00_";
+
+int hdr_increment_file_prefix()
+{
+    if (hdr_counter < 0) return 0; // you have poured alcohol into the CPU?
+    hdr_counter++;
+    if (hdr_counter >= 1000) return 0; // you took 1000 bracketed shots?!
+   
+    if (hdr_counter < 100) snprintf(hdr_prefix, 8, "B%02d_", hdr_counter);
+    else snprintf(hdr_prefix, 8, "B%03d", hdr_counter);
+
+    while (lens_info.job_state) msleep(100);
+    prop_request_change(PROP_FILE_PREFIX, hdr_prefix, 8);
+    hdr_file_prefix_dirty = 1;
+}
+
+void hdr_change_file_prefix()
+{
+    if (ml_shutdown_requested) return;
+    if (intervalometer_running) return 0; // would overflow probably soon, better leave them unchanged in this case
+    if (hdr_file_prefix_dirty) return; // already changed, restore first
+   
+    snprintf(hdr_old_prefix, sizeof(hdr_old_prefix), "%s", file_prefix);
+
+    if (hdr_update_prefix_counter())
+        hdr_increment_file_prefix();
+}
+
+void hdr_restore_file_prefix()
+{
+    if (hdr_file_prefix_dirty)
+    {
+        while (lens_info.job_state) msleep(100);
+        prop_request_change(PROP_FILE_PREFIX, hdr_old_prefix, 8);
+        hdr_file_prefix_dirty = 0;
+    }
+}
+
// take one picture or a HDR / focus stack sequence
// to be used with the intervalometer
void hdr_shot(int skip0, int wait)
@@ -5950,19 +6018,28 @@
     NotifyBoxHide();
     if (HDR_ENABLED)
     {
-        //~ NotifyBox(1000, "HDR shot (%dx%dEV)...", hdr_steps, hdr_stepsize/8); msleep(1000);
         int drive_mode_bak = 0;
         lens_wait_readytotakepic(64);
+       
+        // this works best with single drive mode
         if (drive_mode != DRIVE_SINGLE)
         {
             drive_mode_bak = drive_mode;
             lens_set_drivemode(DRIVE_SINGLE);
         }

+        // make sure it won't autofocus
+        // change it only once per HDR sequence to avoid slowdown
+        assign_af_button_to_star_button();
+
         hdr_take_pics(hdr_steps, hdr_stepsize, skip0);
-
         lens_wait_readytotakepic(64);
+
+        // restore things back
+        restore_af_button_assignment();
         if (drive_mode_bak) lens_set_drivemode(drive_mode_bak);
+
+        hdr_increment_file_prefix();
     }
     else // regular pic (not HDR)
     {
@@ -6302,6 +6379,13 @@
static void
shoot_task( void* unused )
{
+    // file numbering was left to B00_ from bracketing
+    if (file_prefix[0] == 'B' && isdigit(file_prefix[1]) && isdigit(file_prefix[2]) && (isdigit(file_prefix[3]) || file_prefix[3] == '_'))
+    {
+        NotifyBox(5000, "Images are named %snnnn.JPG\nRestore IMG_ from Canon menu.");
+        msleep(5000);
+    }
+   
     #ifdef AFFRAME_PROP_LEN
     if (!lv)
     {   // center AF frame at startup in photo mode
@@ -6378,11 +6462,14 @@

         // avoid camera shake for HDR shots => force self timer
         static int drive_mode_bk = -1;
-        if (((HDR_ENABLED && hdr_delay) || is_focus_stack_enabled()) && get_halfshutter_pressed() && drive_mode != DRIVE_SELFTIMER_2SEC && drive_mode != DRIVE_SELFTIMER_REMOTE)
+        if (((HDR_ENABLED && hdr_delay) || is_focus_stack_enabled()) && get_halfshutter_pressed())
         {
-            drive_mode_bk = drive_mode;
-            #ifndef CONFIG_5DC
-            lens_set_drivemode(DRIVE_SELFTIMER_2SEC);
+            #ifndef CONFIG_5DC // can't change drive mode when halfshutter is pressed
+            if (drive_mode != DRIVE_SELFTIMER_2SEC && drive_mode != DRIVE_SELFTIMER_REMOTE)
+            {
+                drive_mode_bk = drive_mode;
+                lens_set_drivemode(DRIVE_SELFTIMER_2SEC);
+            }
             #endif
             info_led_on();
         }
@@ -6395,7 +6482,14 @@
             drive_mode_bk = -1;
             info_led_off();
         }
-   
+
+        // change file prefix to B00, B01 etc (change is done only once)
+        if (HDR_ENABLED)
+            hdr_change_file_prefix();
+        else
+            hdr_restore_file_prefix();
+
+
         if (bulb_timer && is_bulb_mode() && !gui_menu_shown())
         {
             // look for a transition of half-shutter during idle state

ilguercio

I guess i want to risk my 50D in the next few hours.
;)
Canon EOS 6D, 60D, 50D.
Sigma 70-200 EX OS HSM, Sigma 70-200 Apo EX HSM, Samyang 14 2.8, Samyang 35 1.4, Samyang 85 1.4.
Proud supporter of Magic Lantern.

engardeknave

Would it help for me to test it? I can only do so with a compiled version on a 5D2 though.

engardeknave

Still would really love to see this feature happen.

1%

I built it into the 6D tree so its working here... also in my 600D tree. Patch 2.0 kills the bug that causes af button to not be re assigned back with silent pics.

engardeknave


Matthias

Quote from: 1% on March 22, 2013, 07:12:30 PM
I built it into the 6D tree so its working here... also in my 600D tree. Patch 2.0 kills the bug that causes af button to not be re assigned back with silent pics.

Hello one percent,

i looked into your bitbucket profile to find "your 600D tree" but canĀ“t figure out which is the right one pertaining to the feature discussed in this thread. Also, there are no 600D Binarys for nobody ;)

Greg

Somewhere seen prop current folder. So maybe we can do 100CANON - 999CANON

1%


engardeknave

I wound up writing a script that reads the post script list of file names to find the bracket sets, if that helps anyone.