@@ -33,7 +33,6 @@ class based solution which allows state variables associated with the remap
3333
3434_DEFAULTS_REGISTERED = False
3535_REMAP_DICT = OrderedDict () # type: Dict[str, RemapFunction]
36- newRegMap = OrderedDict ()
3736
3837###########
3938# helper functions
@@ -1828,12 +1827,17 @@ def register_remap(
18281827 """
18291828
18301829 if isinstance (remap_function , type ) and issubclass (remap_function , RemapFunction ):
1831- remap_function = remap_function ()
1830+ remap_function = remap_function ( bit_depth = bit_depth )
18321831 if not isinstance (remap_function , RemapFunction ):
18331832 raise TypeError ('remap_function must be an instance of RemapFunction.' )
18341833
1835- remap_name = remap_function .name
1834+
1835+ if remap_function .bit_depth == 16 :
1836+ remap_name = remap_function .name + '_' + str ( remap_function .bit_depth )
1837+ else :
1838+ remap_name = remap_function .name
18361839
1840+
18371841 if remap_name not in _REMAP_DICT :
18381842 _REMAP_DICT [remap_name ] = remap_function
18391843 elif overwrite :
@@ -1848,15 +1852,25 @@ def _register_defaults():
18481852 if _DEFAULTS_REGISTERED :
18491853 return
18501854
1851- # register class as opposed to instance of class that it was
1852- register_remap (NRL , overwrite = False )
1853- register_remap (Linear , overwrite = False )
1854- register_remap (Density , overwrite = False )
1855- register_remap (High_Contrast , overwrite = False )
1856- register_remap (Brighter , overwrite = False )
1857- register_remap (Darker , overwrite = False )
1858- register_remap (Logarithmic , overwrite = False )
1859- register_remap (PEDF , overwrite = False )
1855+ # register instance of class
1856+ register_remap (NRL ( bit_depth = 8 ), overwrite = False )
1857+ register_remap (Density ( bit_depth = 8 ), overwrite = False )
1858+ register_remap (High_Contrast ( bit_depth = 8 ), overwrite = False )
1859+ register_remap (Brighter ( bit_depth = 8 ), overwrite = False )
1860+ register_remap (Darker ( bit_depth = 8 ), overwrite = False )
1861+ register_remap (Linear ( bit_depth = 8 ), overwrite = False )
1862+ register_remap (Logarithmic ( bit_depth = 8 ), overwrite = False )
1863+ register_remap (PEDF ( bit_depth = 8 ), overwrite = False )
1864+
1865+ register_remap (NRL ( bit_depth = 16 ), overwrite = False )
1866+ register_remap (Density ( bit_depth = 16 ), overwrite = False )
1867+ register_remap (High_Contrast ( bit_depth = 16 ), overwrite = False )
1868+ register_remap (Brighter ( bit_depth = 16 ), overwrite = False )
1869+ register_remap (Darker ( bit_depth = 16 ), overwrite = False )
1870+ register_remap (Linear ( bit_depth = 16 ), overwrite = False )
1871+ register_remap (Logarithmic ( bit_depth = 16 ), overwrite = False )
1872+ register_remap (PEDF ( bit_depth = 16 ), overwrite = False )
1873+
18601874
18611875 if plt is not None :
18621876 try :
@@ -1875,32 +1889,6 @@ def _register_defaults():
18751889 register_remap (LUT8bit (NRL (bit_depth = 8 ), 'bone' , use_alpha = False ), overwrite = False )
18761890 except KeyError :
18771891 pass
1878- # joz
1879- newRegMap [ 'nrl' ] = NRL
1880- newRegMap [ 'linear' ] = Linear
1881- newRegMap [ 'density' ] = Density
1882- newRegMap [ 'high_contrast' ] = High_Contrast
1883- newRegMap [ 'brighter' ] = Brighter
1884- newRegMap [ 'darker' ] = Darker
1885- newRegMap [ 'log' ] = Logarithmic
1886- newRegMap [ 'pedf' ] = PEDF
1887- if plt is not None :
1888- try :
1889- newRegMap [ 'viridis' ] = LUT8bit (NRL (bit_depth = 8 ), 'viridis' , use_alpha = False )
1890- except KeyError :
1891- pass
1892- try :
1893- newRegMap [ 'magma' ] = LUT8bit (NRL (bit_depth = 8 ), 'magma' , use_alpha = False )
1894- except KeyError :
1895- pass
1896- try :
1897- newRegMap [ 'rainbow' ] = LUT8bit (NRL (bit_depth = 8 ), 'rainbow' , use_alpha = False )
1898- except KeyError :
1899- pass
1900- try :
1901- newRegMap [ 'bone' ] = LUT8bit (NRL (bit_depth = 8 ), 'bone' , use_alpha = False )
1902- except KeyError :
1903- pass
19041892
19051893 _DEFAULTS_REGISTERED = True
19061894
@@ -1916,7 +1904,7 @@ def get_remap_names() -> List[str]:
19161904
19171905 if not _DEFAULTS_REGISTERED :
19181906 _register_defaults ()
1919- return list (newRegMap .keys ())
1907+ return list ( _REMAP_DICT .keys ())
19201908
19211909
19221910def get_remap_list () -> List [Tuple [str , RemapFunction ]]:
@@ -1940,10 +1928,10 @@ def get_remap_list() -> List[Tuple[str, RemapFunction]]:
19401928
19411929def get_registered_remap (
19421930 remap_name : str ,
1943- bit_depth = 8 ,
1944- default : Optional [ RemapFunction ] = None ) -> RemapFunction :
1931+ default : Optional [ RemapFunction ] = None ,
1932+ bit_depth = 8 ) -> RemapFunction :
19451933 """
1946- Gets a remap Class/constructor/init from it's registered name.
1934+ Gets a remap instance via its registered name.
19471935 # add 16 bit ability by newRegMap is dict of class/constructors
19481936
19491937
@@ -1963,15 +1951,18 @@ def get_registered_remap(
19631951
19641952 if not _DEFAULTS_REGISTERED :
19651953 _register_defaults ()
1954+
1955+ if int ( bit_depth ) not in [ 8 , 16 ]:
1956+ raise KeyError ('Unregistered remap name `{}` with bit_depth `{}`' .format ( remap_name , bit_depth ))
1957+
1958+ if int ( bit_depth ) == 16 :
1959+ rm_name = remap_name + '_' + str ( bit_depth )
1960+ else :
1961+ rm_name = remap_name
1962+
1963+ if rm_name in _REMAP_DICT :
1964+ return _REMAP_DICT [ rm_name ]
19661965
1967- if remap_name in newRegMap :
1968- # Try new regerst map return class/Constructor
1969- myFunc = newRegMap [ remap_name ]
1970- newRemap = myFunc ( remap_name , bit_depth )
1971- return newRemap
1972-
1973- if remap_name in _REMAP_DICT :
1974- return _REMAP_DICT [remap_name ]
19751966 if default is not None :
19761967 return default
19771968 raise KeyError ('Unregistered remap name `{}`' .format (remap_name ))
0 commit comments