Apply maemo2 patch
[opencv] / utils / cvarr_operators.py
1 #!/usr/bin/python
2 BINARY_OPERATORS={
3     '+':'cvAdd',
4     '-':'cvSub', 
5     '/':'cvDiv', 
6     '*':'cvMul',
7     '^':'cvXor',
8     '&':'cvAnd',
9     '|':'cvOr',
10 }
11 SCALAR_OPERATORS={
12     '+':'cvAddS',
13     '-':'cvSubS', 
14     '&':'cvAndS',
15     '|':'cvOrS',
16     '^':'cvXorS',
17 }
18 CMP_OPERATORS={
19     '==':'CV_CMP_EQ',
20     '!=':'CV_CMP_NE',
21     '>=':'CV_CMP_GE',
22     '>':'CV_CMP_GT',
23     '<=':'CV_CMP_LE',
24     '<':'CV_CMP_LT',
25 }
26 ARR={
27     'CvMat':'cvCreateMat(self->rows, self->cols, self->type)',
28     'IplImage':'cvCreateImage(cvGetSize(self), self->depth, self->nChannels)'
29 }
30
31 def scalar_scale_operator(arr, op, arg):
32     print '\t%s * operator %s (double val){' % (arr, op)
33     print '\t\t%s * res = %s;' % (arr, ARR[arr] )
34     print '\t\tcvScale(self, res, %s);' % arg
35     print '\t\treturn res;'
36     print '\t}'
37     print '\t%s * operator %s (double val){' % (arr, op)
38     print '\t\t%s * res = %s;' % (arr, ARR[arr] )
39     print '\t\tcvScale(self, res, %s);' % arg
40     print '\t\treturn res;'
41     print '\t}'
42
43 print "/** This file was automatically generated using util/cvarr_operators.py script */"
44
45 for arr in ARR:
46     print '%%extend %s {' % arr
47     for op in BINARY_OPERATORS:
48         print '\t%%newobject operator %s;' % (op)
49         print '\t%s * operator %s (CvArr * src){' % ( arr, op )
50         print '\t\t%s * res = %s;' % ( arr, ARR[arr] )
51         print '\t\t%s(self, src, res);' % ( BINARY_OPERATORS[op] )
52         print '\t\treturn res;'
53         print '\t}'
54         print '\t%s * operator %s= (CvArr * src){' % ( arr, op )
55         print '\t\t%s(self, src, self);' % ( BINARY_OPERATORS[op] )
56         print '\t\treturn self;'
57         print '\t}'
58     for op in SCALAR_OPERATORS:
59         print '\t%%newobject operator %s;' % (op)
60         print '\t%s * operator %s (CvScalar val){' % ( arr, op )
61         print '\t\t%s * res = %s;' % ( arr, ARR[arr] )
62         print '\t\t%s(self, val, res);' % ( SCALAR_OPERATORS[op] )
63         print '\t\treturn res;'
64         print '\t}'
65         print '\t%s * operator %s= (CvScalar val){' % ( arr, op )
66         print '\t\t%s(self, val, self);' % ( SCALAR_OPERATORS[op] )
67         print '\t\treturn self;'
68         print '\t}'
69     for op in CMP_OPERATORS:
70         print '\t%%newobject operator %s;' % (op)
71         print '\t%s * operator %s (CvArr * src){' % ( arr, op )
72         print '\t\t%s * res = %s;' % ( arr, ARR[arr] )
73         print '\t\tcvCmp(self, src, res, %s);' % ( CMP_OPERATORS[op] )
74         print '\t\treturn res;'
75         print '\t}'
76         print '\t%s * operator %s (double val){' % ( arr, op )
77         print '\t\t%s * res = %s;' % ( arr, ARR[arr] )
78         print '\t\tcvCmpS(self, val, res, %s);' % ( CMP_OPERATORS[op] )
79         print '\t\treturn res;'
80         print '\t}'
81
82     # *,/ scalar operators
83     print '\t%newobject operator /;'
84     print '\t%s * operator / (double val){' % arr
85     print '\t\t%s * res = %s;' % (arr, ARR[arr] )
86     print '\t\tcvScale(self, res, val);'
87     print '\t\treturn res;'
88     print '\t}'
89
90
91     print '} /* extend %s */\n' % arr