accommodate inspector change
[carveJwlIkooP6JGAAIwe30JlM.git] / skaterift_blender / sr_so.py
1 print( "sr_so" )
2
3 # VG Messages
4 # -------------------------------------------------------------------
5
6 # control characters
7 k_vg_msg_end = 0
8 k_vg_msg_frame = 1
9 k_vg_msg_endframe = 2
10 k_vg_msg_kv = 10
11 k_vg_msg_kvstring = 11
12 k_vg_msg_kvbin = 12
13
14 # variable sized types
15 k_vg_msg_float = 0x40
16 k_vg_msg_unsigned = 0x80
17 k_vg_msg_signed = 0xC0
18
19 # masks
20 k_vg_msg_array_count_bits = 0x3C
21 k_vg_msg_type_size_bits = 0x03
22 k_vg_msg_type_base_bits = 0xC0
23 k_vg_msg_type_bits = k_vg_msg_type_base_bits|k_vg_msg_type_size_bits
24
25 # sizes
26 k_vg_msg_8b = 0x00
27 k_vg_msg_16b = 0x01
28 k_vg_msg_32b = 0x02
29 k_vg_msg_64b = 0x03
30
31 # common types
32 k_vg_msg_u8 = k_vg_msg_unsigned|k_vg_msg_8b
33 k_vg_msg_u16 = k_vg_msg_unsigned|k_vg_msg_16b
34 k_vg_msg_u32 = k_vg_msg_unsigned|k_vg_msg_32b
35 k_vg_msg_u64 = k_vg_msg_unsigned|k_vg_msg_64b
36 k_vg_msg_i8 = k_vg_msg_signed |k_vg_msg_8b
37 k_vg_msg_i16 = k_vg_msg_signed |k_vg_msg_16b
38 k_vg_msg_i32 = k_vg_msg_signed |k_vg_msg_32b
39 k_vg_msg_i64 = k_vg_msg_signed |k_vg_msg_64b
40 k_vg_msg_f32 = k_vg_msg_float |k_vg_msg_32b
41 k_vg_msg_f64 = k_vg_msg_float |k_vg_msg_64b
42 k_vg_msg_v2f = k_vg_msg_float |k_vg_msg_32b | (1<<2)
43 k_vg_msg_v3f = k_vg_msg_float |k_vg_msg_32b | (2<<2)
44 k_vg_msg_v4f = k_vg_msg_float |k_vg_msg_32b | (3<<2)
45
46 class vg_msg_cursor(Structure):
47 #{
48 _fields_ = [("co",c_uint32),
49 ("depth",c_uint32)]
50 #}
51
52 class vg_msg(Structure):
53 #{
54 _fields_ = [("max",c_uint32),
55 ("buf",POINTER(c_uint8)),
56 ("cur",vg_msg_cursor),
57 ("error",c_int32)]
58 #}
59
60 class vg_msg_cmd(Structure):
61 #{
62 _fields_ = [("code",c_uint8),
63 ("key",POINTER(c_char)),
64 ("key_djb2",c_uint32),
65 ("value",c_void_p),
66 ("value_djb2",c_uint32),
67 ("len",c_uint32)]
68 #}
69
70 sr_lib = None
71
72 def sr_lib_init():
73 #{
74 global sr_lib
75 if sr_lib: return
76
77 ext = '.dll' if os.name=='nt' else '.so'
78 path = F'{os.path.dirname(__file__)}/skaterift{ext}'
79 print( F'Loading so: {path}' )
80 sr_lib = cdll.LoadLibrary( path )
81 sr_lib.qoi_encode_rgbaf32.argtypes = \
82 [ np.ctypeslib.ndpointer(dtype=np.float32,\
83 ndim=1,\
84 flags='C_CONTIGUOUS'), \
85 c_uint32, c_uint32, POINTER(c_int32) ]
86 sr_lib.qoi_encode_rgbaf32.restype = POINTER(c_uint8)
87 sr_lib.qoi_free.argtypes = [ POINTER(c_uint8) ]
88
89 sr_lib.vg_msg_wbuf.argtypes = [ POINTER(vg_msg), POINTER(c_uint8), c_uint32 ]
90 sr_lib.vg_msg_rbuf.argtypes = [ POINTER(vg_msg), POINTER(c_uint8), c_uint32 ]
91 sr_lib.vg_msg_wstr.argtypes = [ POINTER(vg_msg), POINTER(c_char) ]
92 sr_lib.vg_msg_rstr.argtypes = [ POINTER(vg_msg), POINTER(c_uint32) ]
93 sr_lib.vg_msg_rstr.restype = POINTER(c_char)
94 sr_lib.vg_msg_frame.argtypes = [ POINTER(vg_msg), POINTER(c_char) ]
95 sr_lib.vg_msg_end_frame.argtypes = [ POINTER(vg_msg) ]
96 sr_lib.vg_msg_wkvstr.argtypes = [ POINTER(vg_msg), POINTER(c_char), POINTER(c_char) ]
97 sr_lib.vg_msg_wkvbin.argtypes = [ POINTER(vg_msg), POINTER(c_char), POINTER(c_uint8), c_uint32 ]
98 sr_lib.vg_msg_wkvnum.argtypes = [ POINTER(vg_msg), POINTER(c_char), c_uint8, c_uint8, c_void_p ]
99
100 sr_lib.vg_msg_cmd_array_count.argtypes = [ c_uint8 ]
101 sr_lib.vg_msg_cmd_array_count.restype = c_uint32
102 sr_lib.vg_msg_cmd_type_size.argtypes = [ c_uint8 ]
103 sr_lib.vg_msg_cmd_type_size.restype = c_uint32
104 sr_lib.vg_msg_cmd_bytecount.argtypes = [ c_uint8 ]
105 sr_lib.vg_msg_cmd_bytecount.restype = c_uint32
106 sr_lib.vg_msg_count_bits.argtypes = [ c_uint32 ]
107 sr_lib.vg_msg_count_bits.restype = c_uint8
108
109 sr_lib.vg_msg_init.argtypes = [ POINTER(vg_msg), POINTER(c_uint8), c_uint32 ]
110 sr_lib.vg_msg_next.argtypes = [ POINTER(vg_msg), POINTER(vg_msg_cmd) ]
111 sr_lib.vg_msg_next.restype = c_int32
112 sr_lib.vg_msg_skip_frame.argtypes = [ POINTER(vg_msg) ]
113 sr_lib.vg_msg_skip_frame.restype = c_int32
114 sr_lib.vg_msg_seekframe.argtypes = [ POINTER(vg_msg), POINTER(c_char) ]
115 sr_lib.vg_msg_seekframe.restype = c_int32
116 sr_lib.vg_msg_cast_to_u64.argtypes = [ POINTER(c_char), c_uint8, c_uint8 ]
117 sr_lib.vg_msg_cast_to_u64.restype = c_uint64
118 sr_lib.vg_msg_cast_to_i64.argtypes = [ POINTER(c_char), c_uint8, c_uint8 ]
119 sr_lib.vg_msg_cast_to_i64.restype = c_int64
120 sr_lib.vg_msg_cast_to_f64.argtypes = [ POINTER(c_char), c_uint8, c_uint8 ]
121 sr_lib.vg_msg_cast_to_f64.restype = c_double
122 sr_lib.vg_msg_cast.argtypes = [ POINTER(c_char), c_uint8, c_void_p, c_uint8 ]
123 sr_lib.vg_msg_getkvcmd.argtypes = [ POINTER(vg_msg), POINTER(c_char), POINTER(vg_msg_cmd) ]
124 sr_lib.vg_msg_getkvcmd.restype = c_int32
125 sr_lib.vg_msg_getkvintg.argtypes = [ POINTER(vg_msg), POINTER(c_char), c_uint8, c_void_p, c_void_p ]
126 sr_lib.vg_msg_getkvintg.restype = c_int32
127 sr_lib.vg_msg_getkvstr.argtypes = [ POINTER(vg_msg), POINTER(c_char) ]
128 sr_lib.vg_msg_getkvstr.restype = POINTER(c_char)
129 sr_lib.vg_msg_getkvvecf.argtypes = [ POINTER(vg_msg), POINTER(c_char), c_uint8, c_void_p, c_void_p ]
130 sr_lib.vg_msg_getkvvecf.restype = c_int32
131 sr_lib.vg_msg_print.argtypes = [ POINTER(vg_msg), c_uint32 ]
132 #}
133
134 def qoi_encode( img ):
135 #{
136 print(F"{' ':<30}",end='\r')
137 print(F"[QOI] Encoding {img.name}.qoi[{img.size[0]},{img.size[1]}]",end='\r')
138 print(F"")
139
140 crab = np.asarray(img.pixels, dtype=np.float32)
141 length = c_int()
142 comped = sr_lib.qoi_encode_rgbaf32( crab, img.size[0], img.size[1], byref(length) )
143
144 data = bytearray(comped[:length.value])
145 bytearray_align_to( data, 16, b'\x00' )
146 sr_lib.qoi_free( comped )
147 return data
148 #}