4
4
5
5
from typing import Sequence , Callable
6
6
7
- from .nodes import NamespaceNode , FunctionNode , OptionalTypeNode , ClassProperty , PrimitiveTypeNode
7
+ from .nodes import (NamespaceNode , FunctionNode , OptionalTypeNode ,
8
+ ClassProperty , PrimitiveTypeNode )
8
9
from .ast_utils import find_function_node , SymbolName
9
10
10
11
11
12
def apply_manual_api_refinement (root : NamespaceNode ) -> None :
13
+ export_matrix_type_constants (root )
12
14
# Export OpenCV exception class
13
15
builtin_exception = root .add_class ("Exception" )
14
16
builtin_exception .is_exported = False
@@ -17,6 +19,33 @@ def apply_manual_api_refinement(root: NamespaceNode) -> None:
17
19
refine_symbol (root , symbol_name )
18
20
19
21
22
+ def export_matrix_type_constants (root : NamespaceNode ) -> None :
23
+ MAX_PREDEFINED_CHANNELS = 4
24
+
25
+ depth_names = ("CV_8U" , "CV_8S" , "CV_16U" , "CV_16S" , "CV_32S" ,
26
+ "CV_32F" , "CV_64F" , "CV_16F" )
27
+ for depth_value , depth_name in enumerate (depth_names ):
28
+ # Export depth constants
29
+ root .add_constant (depth_name , str (depth_value ))
30
+ # Export predefined types
31
+ for c in range (MAX_PREDEFINED_CHANNELS ):
32
+ root .add_constant (f"{ depth_name } C{ c + 1 } " ,
33
+ f"{ depth_value + 8 * c } " )
34
+ # Export type creation function
35
+ root .add_function (
36
+ f"{ depth_name } C" ,
37
+ (FunctionNode .Arg ("channels" , PrimitiveTypeNode .int_ ()), ),
38
+ FunctionNode .RetType (PrimitiveTypeNode .int_ ())
39
+ )
40
+ # Export CV_MAKETYPE
41
+ root .add_function (
42
+ "CV_MAKETYPE" ,
43
+ (FunctionNode .Arg ("depth" , PrimitiveTypeNode .int_ ()),
44
+ FunctionNode .Arg ("channels" , PrimitiveTypeNode .int_ ())),
45
+ FunctionNode .RetType (PrimitiveTypeNode .int_ ())
46
+ )
47
+
48
+
20
49
def make_optional_arg (arg_name : str ) -> Callable [[NamespaceNode , SymbolName ], None ]:
21
50
def _make_optional_arg (root_node : NamespaceNode ,
22
51
function_symbol_name : SymbolName ) -> None :
0 commit comments