<s> from __future__ import division <EOL> import numba as nb <EOL> import numpy as np <EOL> __all__ = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:source>' ) <EOL> @ nb . jit ( '<STR_LIT>' , nopython = True , nogil = True , cache = True ) <EOL> def extract_scaled ( x ) : <EOL> """<STR_LIT>""" <EOL> r = np . float64 ( ( x & <NUM_LIT:255> ) / <NUM_LIT:255> ) <EOL> g = np . float64 ( ( ( x >> <NUM_LIT:8> ) & <NUM_LIT:255> ) / <NUM_LIT:255> ) <EOL> b = np . float64 ( ( ( x >> <NUM_LIT:16> ) & <NUM_LIT:255> ) / <NUM_LIT:255> ) <EOL> a = np . float64 ( ( ( x >> <NUM_LIT> ) & <NUM_LIT:255> ) / <NUM_LIT:255> ) <EOL> return r , g , b , a <EOL> @ nb . jit ( '<STR_LIT>' , nopython = True , <EOL> nogil = True , cache = True ) <EOL> def combine_scaled ( r , g , b , a ) : <EOL> """<STR_LIT>""" <EOL> r2 = np . uint32 ( r * <NUM_LIT:255> ) <EOL> g2 = np . uint32 ( g * <NUM_LIT:255> ) <EOL> b2 = np . uint32 ( b * <NUM_LIT:255> ) <EOL> a2 = np . uint32 ( a * <NUM_LIT:255> ) <EOL> return np . uint32 ( ( a2 << <NUM_LIT> ) | ( b2 << <NUM_LIT:16> ) | ( g2 << <NUM_LIT:8> ) | r2 ) <EOL> extract_scaled . disable_compile ( ) <EOL> combine_scaled . disable_compile ( ) <EOL> composite_op_lookup = { } <EOL> def operator ( f ) : <EOL> """<STR_LIT>""" <EOL> f2 = nb . vectorize ( f ) <EOL> f2 . _compile_for_argtys ( ( nb . types . uint32 , nb . types . uint32 ) ) <EOL> f2 . _frozen = True <EOL> composite_op_lookup [ f . __name__ ] = f2 <EOL> return f2 <EOL> @ operator <EOL> def source ( src , dst ) : <EOL> if src & <NUM_LIT> : <EOL> return src <EOL> else : <EOL> return dst <EOL> @ operator <EOL> def over ( src , dst ) : <EOL> sr , sg , sb , sa = extract_scaled ( src ) <EOL> dr , dg , db , da = extract_scaled ( dst ) <EOL> factor = <NUM_LIT:1> - sa <EOL> a = sa + da * factor <EOL> if a == <NUM_LIT:0> : <EOL> return np . uint32 ( <NUM_LIT:0> ) <EOL> r = ( sr * sa + dr * da * factor ) / a <EOL> g = ( sg * sa + dg * da * factor ) / a <EOL> b = ( sb * sa + db * da * factor ) / a <EOL> return combine_scaled ( r , g , b , a ) <EOL> @ operator <EOL> def add ( src , dst ) : <EOL> sr , sg , sb , sa = extract_scaled ( src ) <EOL> dr , dg , db , da = extract_scaled ( dst ) <EOL> a = min ( <NUM_LIT:1> , sa + da ) <EOL> if a == <NUM_LIT:0> : <EOL> return np . uint32 ( <NUM_LIT:0> ) <EOL> r = ( sr * sa + dr * da ) / a <EOL> g = ( sg * sa + dg * da ) / a <EOL> b = ( sb * sa + db * da ) / a <EOL> return combine_scaled ( r , g , b , a ) <EOL> @ operator <EOL> def saturate ( src , dst ) : <EOL> sr , sg , sb , sa = extract_scaled ( src ) <EOL> dr , dg , db , da = extract_scaled ( dst ) <EOL> a = min ( <NUM_LIT:1> , sa + da ) <EOL> if a == <NUM_LIT:0> : <EOL> return np . uint32 ( <NUM_LIT:0> ) <EOL> factor = min ( sa , <NUM_LIT:1> - da ) <EOL> r = ( factor * sr + dr * da ) / a <EOL> g = ( factor * sg + dg * da ) / a <EOL> b = ( factor * sb + db * da ) / a <EOL> return combine_scaled ( r , g , b , a ) </s>
