Last active
January 2, 2016 08:19
-
-
Save adsr303/8275493 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import collections | |
import os | |
import sqlite3 | |
import struct | |
LENSFUN_PARAM_NAMES = """ | |
modify_flags | |
inverse | |
scale | |
crop | |
focal | |
aperture | |
distance | |
target_geom | |
camera | |
lens | |
tca_override | |
tca_r | |
tca_b | |
""" | |
LensOp = collections.namedtuple('LensOp', LENSFUN_PARAM_NAMES) | |
LENSFUN_PARAMS_FMT = 'iifffffi%ds%dsiff' | |
# version 1 comes from ancient times and seems to be forgotten by now | |
ID_SIZES = {2: 52, 3: 128} | |
def make_lensfun_struct(size): | |
fmt = LENSFUN_PARAMS_FMT % (size, size) | |
return struct.Struct(fmt) | |
LENS_OP_STRUCTS = { | |
2: make_lensfun_struct(52), | |
3: make_lensfun_struct(128) | |
} | |
# A list of bitmask flags used for ordering various image corrections. | |
LF_MODIFY = { | |
'TCA': 0x01, | |
'VIGNETTING': 0x02, | |
'CCI': 0x04, | |
'DISTORTION': 0x08, | |
'GEOMETRY': 0x10, | |
'SCALE': 0x20 | |
} | |
#typedef enum dt_iop_lensfun_modflag_t | |
#{ | |
# LENSFUN_MODFLAG_NONE = 0, | |
# LENSFUN_MODFLAG_ALL = DISTORTION | TCA | VIGNETTING, | |
# LENSFUN_MODFLAG_DIST_TCA = DISTORTION | TCA, | |
# LENSFUN_MODFLAG_DIST_VIGN = DISTORTION | VIGNETTING, | |
# LENSFUN_MODFLAG_TCA_VIGN = TCA | VIGNETTING, | |
# LENSFUN_MODFLAG_DIST = DISTORTION, | |
# LENSFUN_MODFLAG_TCA = TCA, | |
# LENSFUN_MODFLAG_VIGN = VIGNETTING, | |
# LENSFUN_MODFLAG_MASK = DISTORTION | TCA | VIGNETTING | |
#} | |
LF_NAMES = {v: k for k, v in LF_MODIFY.items()} | |
def nullstrip(s): | |
"""Return a string truncated at the first null character.""" | |
try: | |
return s[:s.index('\x00')] | |
except ValueError: # No nulls were found, which is okay. | |
return s | |
def print_op(op): | |
print op | |
print nullstrip(op.camera) | |
print nullstrip(op.lens) | |
for k, v in LF_MODIFY.items(): | |
if op.modify_flags | v: | |
print k | |
print op.modify_flags & ~(LF_MODIFY['VIGNETTING']|LF_MODIFY['TCA']) | |
def get_op(): | |
dburl = os.getenv('HOME') + '/.config/darktable/library.db' | |
with sqlite3.connect(dburl) as conn: | |
c = conn.cursor() | |
c.execute("select module, op_params from history where operation='lens'") | |
m, p = c.fetchone() | |
s = LENS_OP_STRUCTS[m] | |
op = LensOp(*s.unpack(p)) | |
print_op(op) | |
if __name__ == '__main__': | |
get_op() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment