-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvertDirToDng.m
More file actions
103 lines (92 loc) · 4.04 KB
/
convertDirToDng.m
File metadata and controls
103 lines (92 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
%
%% convertDirToDng
%
% Converts a directory of raw images into uncompressed DNGs
%
% _Parameters_
% * sourceDir - Directory containing source DNGs to convert.
% * sourceDirMask - Mask of files to convert (or empty for all files)
% * destDir - Directory to store converted DNGs
%
% _Return Values_
% * success - true if successful, false if not.
% * numDngsCreated - number of files converted
%
function [success, numDngsCreated] = convertDirToDng(sourceDir, sourceDirMask, destDir)
timeStart = tic();
%
% Adobe's DNG converter is heavily optimized for parallel operation, provided
% it's supplied multiple files to convert per invocation. I place an arbitrary
% limit on the number of files per invocation, to keep the size of the command
% line reasonable for situations where there are hundreds of files to process
%
% Note that running the DNG converter's GUI is much faster than invoking
% from the command line, even when we pass it the full list of files on
% the command line :(
%
MAX_FILES_PER_CONVERSION = 32;
success = false; % assume error
numDngsCreated = 0;
% get listing of files in specified source directory
listing = dir(fullfile(sourceDir, sourceDirMask));
numEntriesInListing = numel(listing);
%
% process files in directory
%
firstFileThisConversion = 1;
numFilesConverted = 0;
while (firstFileThisConversion <= numEntriesInListing)
%
% build file list of up to MAX_FILES_PER_CONVERSION files to process on
% this invocation. Note we select any file in the directory, which means
% the directory must only containimage files, otherwise the DNG converter
% will fail when it reaches the non-image file.
%
numFilesThisConversion = 0;
fileListStr = '';
nextFileThisConversion = firstFileThisConversion;
while (nextFileThisConversion <= numEntriesInListing && numFilesThisConversion < MAX_FILES_PER_CONVERSION)
% skip directories and filenames beginning with '.' (hidden files, to prevent .DS_Store and metadata files on OSX)
if (~listing(nextFileThisConversion).isdir && listing(nextFileThisConversion).name(1) ~= '.')
%
% if source mask is not empty then we use all files generated by dir()
% uncondtionally (we assume user/caller used an appropriate file mask).
% if source mask is empty then we select all filenames that have
% extensions indicating they are are files.
%
if (~isempty(sourceDirMask) || isFilenameRawImageFile(listing(nextFileThisConversion).name))
fileListStr = [fileListStr '"' fullfile(listing(nextFileThisConversion).folder, listing(nextFileThisConversion).name) '" '];
numFilesThisConversion = numFilesThisConversion+1;
end
end
nextFileThisConversion = nextFileThisConversion +1;
end
% perform the conversion
if (numFilesThisConversion > 0)
[exitCode, output] = runDngConverter(['-u -d "' destDir '" ' fileListStr]);
if (exitCode ~= 0)
if (~isempty(sourceDirMask))
fprintf(['\n*** Note: DNG conversion will fail if there are any non-raw images '...
'in the directory included in your file mask (' sourceDirMask '), including any hidden files '...
'like .DS_Store on OSX\n']);
end
return;
end
numFilesConverted = numFilesConverted + numFilesThisConversion;
end
% advance outer processing loop index to pick up after the last file we just converted
firstFileThisConversion = nextFileThisConversion;
end
success = true;
numDngsCreated = numFilesConverted;
if (numDngsCreated > 0)
fprintf('Adobe DNG Converter: %d DNGs converted in %.2f seconds\n', numDngsCreated, toc(timeStart));
else
if (isempty(sourceDirMask))
fprintf('\nNo raw image files were found in "%s"\n\n', sourceDir);
else
fprintf('\nNo files matching for your file mask were found in "%s"\n', sourceDir);
fprintf('Make sure the case of your mask (%s) matches the case of the filenames in the directory (case-sensitive)\n\n', sourceDirMask);
end
end
end