Skip to content

Commit

Permalink
conversion tools: Add commandline argument for Scan, fix DNG noncompl…
Browse files Browse the repository at this point in the history
…iance

The DNG standard requires subfiletype to be 0 for raw data.  Also set this in the TIFF output to prepare for eventual inclusion of previews

Also, the rotation handler needs to know if the file is originating from a Scan or a Pro variant

Fixes issues #2 and #4
  • Loading branch information
Entropy512 committed Apr 26, 2024
1 parent 61c358d commit 9717de2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 11 additions & 1 deletion cnv_jpeg_to_dng.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def init_TurboJPEG():

#Colorspace and transfer function conversion
rawdata = xt.jpeg_to_raw(rgbdata).astype(np.uint16)
unique_cam_model = exifdata['Exif.Image.Make'] + " " + exifdata['Exif.Image.Model']

dng_extratags = []
dng_extratags.append(('ColorMatrix1', '2i', 9, dng_color_matrix))
Expand All @@ -59,20 +60,29 @@ def init_TurboJPEG():
dng_extratags.append(('DNGVersion', 'B', 4, [1,4,0,0])) #DNGVersion
dng_extratags.append(('DNGBackwardVersion', 'B', 4, [1,4,0,0])) #DNGBackwardVersion
dng_extratags.append(('AsShotNeutral', '2I', 3, [1, 1, 1, 1, 1, 1])) #Xphase pre-applies a D50 white balance so AsShotNeutral is 1.0, 1.0, 1.0 """
dng_extratags.append(('UniqueCameraModel', 's', len(unique_cam_model), unique_cam_model))

with TIFF.TiffWriter(dngname) as dng:
dng.write(rawdata,
photometric=34892, #tiffile does not have enums for LinearRaw, use numeric instead
extratags=dng_extratags)
extratags=dng_extratags,
subfiletype=0)

with pyexiv2.Image(tifname) as tif:
tif.modify_exif(exifdata)

if __name__ == "__main__":
ap = argparse.ArgumentParser()
ap.add_argument('-i', '--input', required=True,
help='path to input file')
ap.add_argument('-s', '--scan', help='Assume image came from an Xphase Scan and rotate accordingly', action='store_true')

args = vars(ap.parse_args())
jpeg_file = args['input']

xphase_exif = {'Exif.Image.Make': 'Xphase'}
xphase_exif['Exif.Image.Model'] = 'Scan' if args['scan'] else 'Pro'

filebase = os.path.splitext(jpeg_file)[0]
with open(jpeg_file, 'rb') as jpgfile:
write_dng(jpgfile.read(), {}, filebase)
8 changes: 5 additions & 3 deletions cnv_jpeg_to_tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def init_TurboJPEG():
photometric='rgb',
compression='zlib',
predictor=True,
extratags=[('InterColorProfile', tifffile.DATATYPE.BYTE, len(icc_profile), icc_profile)])
extratags=[('InterColorProfile', tifffile.DATATYPE.BYTE, len(icc_profile), icc_profile)],
subfiletype=0)

with pyexiv2.Image(tifname) as tif:
tif.modify_exif(exifdata)
Expand All @@ -64,14 +65,15 @@ def init_TurboJPEG():
ap = argparse.ArgumentParser()
ap.add_argument('-i', '--input', required=True,
help='path to input file')
ap.add_argument('-s', '--scan', help='Assume image came from an Xphase Scan and rotate accordingly', action='store_true')

args = vars(ap.parse_args())
jpeg_file = args['input']

filebase = os.path.splitext(jpeg_file)[0]

xphase_exif = {'Exif.Image.Make': 'Xphase',
'Exif.Image.Model': 'Xphase'}
xphase_exif = {'Exif.Image.Make': 'Xphase'}
xphase_exif['Exif.Image.Model'] = 'Scan' if args['scan'] else 'Pro'

with open(jpeg_file, 'rb') as jpgfile:
write_tiff(jpgfile.read(), xphase_exif, filebase)

0 comments on commit 9717de2

Please sign in to comment.