-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsaveRawDataToDng.m
More file actions
55 lines (45 loc) · 1.51 KB
/
Copy pathsaveRawDataToDng.m
File metadata and controls
55 lines (45 loc) · 1.51 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
%
%% saveRawDataToDng
%
% Ovewrites the raw CFA data inside an existing uncompressed DNG.
%
% _Parameters_
% * dngFilename - Filename of DNG whose raw data we're overwriting
% * stripOffset - Offset into DNG containing raw data (EXIF "stripOffset" value)
% * imgData - Image data to write, in [Rows Columns] orientation
%
% _Return Values_
% * success - true if successful, false if error
%
function success = saveRawDataToDng(dngFilename, stripOffset, imgData)
SIZE_UINT16 = 2;
success = false; % assume error
% open the DNG
file = fopen(dngFilename, "r+");
if (file == -1)
fprintf('Error: "%s" file open failed\n', dngFilename);
return;
end
% seek to where the raw data starts in the file
if (fseek(file, stripOffset, -1) ~= 0)
fprintf('Error: "%s", seek to offset %d failed\n', dngFilename, stripOffset);
return;
end
% overwrite the raw data, check to make sure we wrote the # bytes we wanted
numElementsWritten = fwrite(file, imgData', 'uint16');
fclose(file);
if (numElementsWritten ~= numel(imgData))
fprintf('Error: "%s", write request = %d bytes, actual bytes written = %d\n', dngFilename, numel(imgData)*SIZE_UINT16, numElementsWritten*SIZE_UINT16);
return;
end
%
% remove DNG raw data checksum to prevent nuisance errors when ACR/LR loads
% this DNG we've modified
%
removeDngChecksum(dngFilename);
%
% TBD: Also consider removing the preview images from the DNG, since they
% no longer match the raw data we've modified
%
success = true;
end