cr2hdr check required requirements

Issue #1976 closed
Christophe Francey created an issue

Is there are a possibility to check if dcraw and exiftool is in the same folder of cr2hdr ?
My knowledge in C is not enough to do that. I found getwd but I can make it functional.
This is useful to embedded the latest version of dcraw and exiftool when we share cr2hdr

Comments (12)

  1. Christophe Francey reporter

    Additionnal information: it's only for Mac and Linux. If it's found, run ./dcraw instead of dcraw or path/to/cr2hdr/dcraw

  2. Alex

    I've used a similar technique for Adobe DNG converter (adobedng-bridge.c).

    For this one, I think the simplest way is to run system("./dcraw") at startup; if it succeeds, use ./dcraw for all other calls, otherwise use plain dcraw.

  3. Christophe Francey reporter

    Thanks a1ex!
    This is my first not functional test:

    diff cr2hdr-tof.c cr2hdr.c 
    675,686d674
    <       
    <       char* start;
    <       int test_dcraw = system("./dcraw");
    <       int test_exiftool = system("./exiftool");
    <       if(test_dcraw != 0 && test_exiftool != 0 )
    <       {
    <           start = "./";
    <       }
    <       else
    <       {
    <           start = "";
    <       }   
    689c677
    <         snprintf(dcraw_cmd, sizeof(dcraw_cmd), "%sdcraw -v -i -t 0 \"%s\"", start, filename);
    ---
    >         snprintf(dcraw_cmd, sizeof(dcraw_cmd), "dcraw -v -i -t 0 \"%s\"", filename);
    727c715
    <         snprintf(dcraw_cmd, sizeof(dcraw_cmd), "%sdcraw -4 -E -c -t 0 \"%s\"", start, filename);
    ---
    >         snprintf(dcraw_cmd, sizeof(dcraw_cmd), "dcraw -4 -E -c -t 0 \"%s\"", filename);
    3585c3573
    < }
    ---
    > }
    

    This is the output

    /Users/tof/Documents/MagicLantern/LR\ plugin/cr2hdr-20bit/cr2hdr /Users/tof/Documents/MagicLantern/LR\ plugin/cr2hdr-20bit/_MG_2824-toto.DNG 
    cr2hdr: a post processing tool for Dual ISO images
    
    Last update: 30a5132 on 2014-05-07 10:34:25 UTC by a1ex:
    cr2hdr: print a message when overwriting the output file
    
    Active options:
    --amaze-edge    : use a temporary demosaic step (AMaZE) followed by edge-directed interpolation (default)
    --cs2x2         : apply 2x2 chroma smoothing in noisy and aliased areas (default)
    --wb=graymax    : set AsShotNeutral by maximizing the number of gray pixels (default)
    
    Input file      : /Users/tof/Documents/MagicLantern/LR plugin/cr2hdr-20bit/_MG_2824-toto.DNG
    sh: exiftool: command not found
    sh: ./dcraw: No such file or directory
    sh: ./exiftool: No such file or directory
    sh: ./dcraw: No such file or directory
    sh: exiftool: command not found
    Camera          : Canon EOS 5D Mark III
    Camera model    : Canon EOS 5D Mark III
    dcraw could not open this file
    

    In the folder where cr2hdr have been launched

    ls -l /Users/tof/Documents/MagicLantern/LR\ plugin/cr2hdr-20bit 
    total 246344
    -rw-r--r--  1 tof  staff  47070946  4 mai 13:41 _MG_2824-toto.DNG
    -rwxrwxrwx  1 tof  staff  31285887  3 mar  2013 _MG_2824.CR2
    -rw-r--r--  1 tof  staff  47070946  7 mai 20:04 _MG_2824.DNG
    -rwxr-xr-x  1 tof  staff    124556 10 mai 09:51 cr2hdr
    -rwxr-xr-x  1 tof  staff    323616  7 mai 20:01 dcraw
    -rwxrwxr-x@ 1 tof  staff    241569  3 mai 13:16 exiftool
    drwxrwxr-x@ 5 tof  staff       170  8 mai 21:07 lib
    

    Do you have an idea?

  4. Christophe Francey reporter

    I've updated the code, I make a mistake with != 0 and I've placed the check in early start main and not in for.
    Its work when you launched cr2hdr from terminal only when you are in the same folder.

    like

    cd /path/to/cr2hdr
    ./cr2hdr img.cr2 # Works
    
    /path/to/cr2hdr/cr2hdr img.cr2 # doesn't work because ./ check into the first / and not from cr2hdr path.
    
    diff cr2hdr.c cr2hdr.c.orig 
    601,614d600
    <   
    <   char* start;
    <   int test_dcraw = system("./dcraw");
    <   int test_exiftool = system("./exiftool");
    <   if(test_dcraw != 0 && test_exiftool != 0 )
    <   {
    <       start = "";
    <       printf("use ''");
    <   }
    <   else
    <   {
    <       start = "./";
    <       printf("use ./");
    <   }
    688c674
    <         } 
    ---
    >         }
    691c677
    <         snprintf(dcraw_cmd, sizeof(dcraw_cmd), "%sdcraw -v -i -t 0 \"%s\"", start, filename);
    ---
    >         snprintf(dcraw_cmd, sizeof(dcraw_cmd), "dcraw -v -i -t 0 \"%s\"", filename);
    729c715
    <         snprintf(dcraw_cmd, sizeof(dcraw_cmd), "%sdcraw -4 -E -c -t 0 \"%s\"", start, filename);
    ---
    >         snprintf(dcraw_cmd, sizeof(dcraw_cmd), "dcraw -4 -E -c -t 0 \"%s\"", filename);
    3587c3573
    < }
    ---
    > }
    

    We need to find a way to resolve the path of cr2hdr exec. Another thing, dcraw and exiftool are launched inside cr2hdr (normal with system()) there are a way to mute it?

  5. Jarno Paananen

    Instead of doing system() call, you could also try access("./dcraw", X_OK); which returns 0 if file exists and is executable.

  6. Alex

    The executable path is in argv[0]; you will have to strip the executable name manually though (by finding the last slash or backslash maybe; not sure which is the best way to do this in a portable way, need to search a bit).

  7. Jarno Paananen

    Posix has dirname(/some/full/path/to/file) which returns directory portion of the input path (and may modify it so passing a copy is adviced).

  8. Christophe Francey reporter

    It works !!!

    diff cr2hdr.c cr2hdr.c.orig 
    41d40
    < #include <libgen.h>
    602,616c601
    <   
    <   char* pathFolder = dirname(strdup(argv[0]));
    <   char start[255];
    <   char dcrawPath[255], exiftoolPath[255];
    <   snprintf(dcrawPath, sizeof(dcrawPath), "%s/dcraw", pathFolder);
    <   snprintf(exiftoolPath, sizeof(exiftoolPath), "%s/exiftool", pathFolder);
    <   int test_dcraw = access(dcrawPath, X_OK);
    <   int test_exiftool = access(exiftoolPath, X_OK);
    <   
    <   if(test_dcraw == 0 && test_exiftool == 0 )
    <   {
    <       snprintf(start, sizeof(start), "\"%s/\"", pathFolder);
    <   }
    < 
    <   printf("dcraw: %s\nexiftool: %s\nstart: %s\n", dcrawPath, exiftoolPath, start);
    ---
    >     
    689c674
    <         } 
    ---
    >         }
    692c677
    <         snprintf(dcraw_cmd, sizeof(dcraw_cmd), "%sdcraw -v -i -t 0 \"%s\"", start, filename);
    ---
    >         snprintf(dcraw_cmd, sizeof(dcraw_cmd), "dcraw -v -i -t 0 \"%s\"", filename);
    730c715
    <         snprintf(dcraw_cmd, sizeof(dcraw_cmd), "%sdcraw -4 -E -c -t 0 \"%s\"", start, filename);
    ---
    >         snprintf(dcraw_cmd, sizeof(dcraw_cmd), "dcraw -4 -E -c -t 0 \"%s\"", filename);
    3588c3573
    < }
    ---
    > }
    
  9. Log in to comment