Source code for lablib.processors.oiio_repositions
"""Processors providing positional effect arguments for OIIO."""from__future__importannotationsimportinspectimportloggingfromtypingimportAny,Listfrom..operatorsimportrepositionslog=logging.getLogger(__name__)log.setLevel(logging.DEBUG)
[docs]classOIIORepositionProcessor:"""Processor for repositioning images. Hint: You can use this processor without operators only specifying :attr:`dst_width` or :attr:`dst_height`. This way :obj:`OIIORepositionProcessor` will act as a basic reformat. Attributes: operators (List): The list of repositioning operators. src_width (int): The source image width. dst_width (int): The destination image width. src_height (int): The source image height. dst_height (int): The destination image height. fit (str): The fit mode for the image. """operators:List[Any]=[]src_width:int=0dst_width:int=0src_height:int=0dst_height:int=0fit:str=None_wrapper_class_members=dict(inspect.getmembers(repositions,inspect.isclass))def__init__(self,**kwargs)->None:fork,vinkwargs.items():ifhasattr(self,k):setattr(self,k,v)def__repr__(self)->str:exposed_props=["operators","dst_width","dst_height","fit"]props=""forpropinexposed_props:props=props+f"{prop}={getattr(self,prop)}, "returnf"{self.__class__.__name__}({props[:-2]})"
[docs]defget_oiiotool_cmd(self)->List[str]:"""Get the OIIO arguments for repositioning images. Returns: List[str]: The OIIO arguments. """result=[]foropinself.operators:result.extend(op.to_oiio_args())ifany([self.dst_height,self.dst_width]):dest_size=f"{self.dst_width}x{self.dst_height}"# TODO: check with rendererifself.fitin["letterbox","width","height"]:result.extend([f"--fit:fillmode={self.fit}",dest_size])else:result.extend(["--resize",dest_size])log.debug(f"{result= }")returnresult