<s> """<STR_LIT>""" <EOL> __version__ = "<STR_LIT>" <EOL> import math <EOL> from utils . abstract_lut_helper import AbstractLUTHelper <EOL> from utils import lut_presets as presets <EOL> from utils . lut_presets import RAISE_MODE , TYPE , PresetException <EOL> from utils . lut_utils import get_bitdepth <EOL> class ThreeDLHelperException ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> SHAPER = '<STR_LIT>' <EOL> MESH = '<STR_LIT>' <EOL> class ThreedlLutHelper ( AbstractLUTHelper ) : <EOL> """<STR_LIT>""" <EOL> @ staticmethod <EOL> def get_default_preset ( ) : <EOL> return { <EOL> presets . TYPE : "<STR_LIT>" , <EOL> presets . EXT : "<STR_LIT>" , <EOL> presets . IN_RANGE : [ <NUM_LIT:0> , <NUM_LIT> ] , <EOL> presets . OUT_RANGE : [ <NUM_LIT:0> , <NUM_LIT> ] , <EOL> presets . CUBE_SIZE : <NUM_LIT> , <EOL> presets . TITLE : "<STR_LIT>" , <EOL> presets . COMMENT : ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( __version__ ) , <EOL> presets . VERSION : "<STR_LIT:1>" , <EOL> SHAPER : True , <EOL> MESH : False <EOL> } <EOL> def _write_1d_2d_lut ( self , process_function , file_path , preset , <EOL> line_function ) : <EOL> message = "<STR_LIT>" <EOL> raise ThreeDLHelperException ( message ) <EOL> def write_3d_lut ( self , process_function , file_path , preset ) : <EOL> for str_range in [ presets . IN_RANGE , presets . OUT_RANGE ] : <EOL> arange = preset [ str_range ] <EOL> presets . check_range_is_int ( arange , <EOL> self . _get_range_message ( str_range , <EOL> arange ) ) <EOL> data = self . _get_3d_data ( process_function , <EOL> preset , <EOL> inverse_loops_order = True ) [ <NUM_LIT:1> ] <EOL> lutfile = open ( file_path , '<STR_LIT>' ) <EOL> cube_size = preset [ presets . CUBE_SIZE ] <EOL> input_range = preset [ presets . IN_RANGE ] <EOL> output_range = preset [ presets . OUT_RANGE ] <EOL> lutfile . write ( "<STR_LIT>" . format ( preset [ presets . TITLE ] ) ) <EOL> if preset [ presets . COMMENT ] : <EOL> lutfile . write ( "<STR_LIT>" . format ( preset [ presets . COMMENT ] ) ) <EOL> lutfile . write ( "<STR_LIT>" . format ( cube_size ) ) <EOL> lutfile . write ( "<STR_LIT>" . format ( input_range ) ) <EOL> lutfile . write ( "<STR_LIT>" . format ( output_range ) ) <EOL> in_bit_depth = get_bitdepth ( input_range [ <NUM_LIT:1> ] ) <EOL> out_bit_depth = get_bitdepth ( output_range [ <NUM_LIT:1> ] ) <EOL> if preset [ MESH ] : <EOL> mesh_input = int ( math . log ( cube_size , <NUM_LIT:2> ) ) <EOL> lutfile . write ( "<STR_LIT>" . format ( mesh_input , <EOL> out_bit_depth ) ) <EOL> if preset [ SHAPER ] : <EOL> shaper = "<STR_LIT>" . format ( self . get_string_shaper_lut ( cube_size , <EOL> in_bit_depth ) ) <EOL> lutfile . write ( shaper ) <EOL> for rgb in data : <EOL> lutfile . write ( self . _get_rgb_value_line ( preset , rgb ) ) <EOL> lutfile . close ( ) <EOL> return self . get_export_message ( file_path ) <EOL> def _get_rgb_value_line ( self , preset , rgb , in_rgb = None , separator = "<STR_LIT:U+0020>" ) : <EOL> return self . _get_pattern ( preset ) . format ( rgb . r , rgb . g , rgb . b ) <EOL> @ staticmethod <EOL> def _get_range_message ( range_name , arange ) : <EOL> """<STR_LIT>""" <EOL> return ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) . format ( range_name , arange ) <EOL> @ staticmethod <EOL> def get_shaper_lut ( cube_size , bit_depth ) : <EOL> """<STR_LIT>""" <EOL> max_value = float ( math . pow ( <NUM_LIT:2> , bit_depth ) - <NUM_LIT:1> ) <EOL> step = max_value / ( cube_size - <NUM_LIT:1> ) <EOL> shaper_lut = [ ] <EOL> for i in range ( <NUM_LIT:0> , cube_size ) : <EOL> shaper_lut . append ( int ( i * step ) ) <EOL> return shaper_lut <EOL> @ staticmethod <EOL> def get_string_shaper_lut ( cube_size , bit_depth ) : <EOL> """<STR_LIT>""" <EOL> shaper_lut = ThreedlLutHelper . get_shaper_lut ( cube_size , bit_depth ) <EOL> return "<STR_LIT:U+0020>" . join ( str ( value ) for value in shaper_lut ) <EOL> def _validate_preset ( self , preset , mode = RAISE_MODE , default_preset = None ) : <EOL> if default_preset is None : <EOL> default_preset = ThreedlLutHelper . get_default_preset ( ) <EOL> if presets . TYPE in preset and not preset [ TYPE ] == '<STR_LIT>' : <EOL> if mode == RAISE_MODE : <EOL> raise PresetException ( ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) . format ( preset [ TYPE ] ) ) <EOL> preset [ presets . TYPE ] = default_preset [ presets . TYPE ] <EOL> preset = AbstractLUTHelper . _validate_preset ( self , preset , mode , <EOL> default_preset ) <EOL> specific_attr = [ SHAPER , MESH ] <EOL> for attr in specific_attr : <EOL> if attr not in preset : <EOL> if mode == RAISE_MODE : <EOL> message = presets . MISSING_ATTR_MESSAGE . format ( attr ) <EOL> raise PresetException ( message ) <EOL> preset [ attr ] = default_preset [ attr ] <EOL> if not isinstance ( preset [ attr ] , bool ) : <EOL> if mode == RAISE_MODE : <EOL> raise PresetException ( "<STR_LIT>" <EOL> ) . format ( attr ) <EOL> return preset <EOL> THREEDL_HELPER = ThreedlLutHelper ( ) </s>
