Update to 2.0.0 tree from current Fremantle build
[opencv] / interfaces / swig / octave / imagedata.i
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 //  By downloading, copying, installing or using the software you agree to this license.
6 //  If you do not agree to this license, do not download, install,
7 //  copy or use the software.
8 //
9 //
10 //                        Intel License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
15 //
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
18 //
19 //   * Redistribution's of source code must retain the above copyright notice,
20 //     this list of conditions and the following disclaimer.
21 //
22 //   * Redistribution's in binary form must reproduce the above copyright notice,
23 //     this list of conditions and the following disclaimer in the documentation
24 //     and/or other materials provided with the distribution.
25 //
26 //   * The name of Intel Corporation may not be used to endorse or promote products
27 //     derived from this software without specific prior written permission.
28 //
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
39 //
40 //M*/
41
42
43 // 2004-03-16, Gabriel Schreiber <schreiber@ient.rwth-aachen.de>
44 //             Mark Asbach       <asbach@ient.rwth-aachen.de>
45 //             Institute of Communications Engineering, RWTH Aachen University
46
47 // 2006-08-29  Roman Stanchak -- converted to use CvMat rather than IplImage
48
49
50 %{
51
52 /// Accessor to convert a Octave string into the imageData.
53 void CvMat_imageData_set(CvMat * self, octave_value object)
54 {
55   /*
56   char* oct_string = OctString_AsString(object);
57         int depth = CV_MAT_DEPTH(self->type);
58         int cn = CV_MAT_CN(self->type);
59
60         if (depth == CV_8U && cn==3){
61                 // RGB case
62                 // The data is reordered beause OpenCV uses BGR instead of RGB
63
64                 for (long line = 0; line < self->rows; ++line)
65                         for (long pixel = 0; pixel < self->cols; ++pixel)
66                         {
67                                 // In OpenCV the beginning of the lines are aligned
68                                 // to 4 Bytes. So use step instead of cols.
69                                 long position = line*self->step + pixel*3;
70                                 long sourcepos = line*self->cols*3 + pixel*3;
71                                 self->data.ptr[position  ] = oct_string[sourcepos+2];
72                                 self->data.ptr[position+1] = oct_string[sourcepos+1];
73                                 self->data.ptr[position+2] = oct_string[sourcepos  ];
74                         }
75         }
76         else if (depth == CV_8U && cn==1)
77         {
78                 // Grayscale 8bit case
79
80                 for (long line = 0; line < self->rows; ++line)
81                 {
82                         // In OpenCV the beginning of the lines are aligned
83                         // to 4 Bytes. So use step instead of cols.
84                         memcpy
85                                 (
86                                  self->data.ptr + line*self->step,
87                                  oct_string + line*self->cols,
88                                  self->step
89                                 );
90                 }
91         }
92         else if ( depth == CV_32F )
93         {
94                 // float (32bit) case
95                 for (long line = 0; line < self->rows; ++line)
96                 {
97                         // here we don not have to care about alignment as the Floats are
98                         // as long as the alignment
99                         memcpy
100                                 (
101                                  self->data.ptr + line*self->step,
102                                  oct_string + line*self->cols*sizeof(float),
103                                  self->step
104                                 );
105                 }
106         }
107         else if ( depth == CV_64F )
108         {
109                 // double (64bit) case
110                 for (long line = 0; line < self->rows; ++line)
111                 {
112                         // here we don not have to care about alignment as the Floats are
113                         // as long as the alignment
114                         memcpy
115                                 (
116                                  self->data.ptr + line*self->step,
117                                  oct_string + line*self->cols*sizeof(double),
118                                  self->step
119                                 );
120                 }
121         }
122         else
123         {
124           // make some noise
125           SendErrorToOctave (SWIG_TypeError, 
126                        "CvMat_imageData_set", 
127                        "cannot convert string data to this image format",
128                        __FILE__, __LINE__, NULL);
129         }
130   */
131 }
132
133 /// Accessor to convert the imageData into a Octave string.
134 octave_value CvMat_imageData_get(CvMat * self) 
135 {
136   /*
137         if (!self->data.ptr)
138         {
139                 OctErr_SetString(OctExc_TypeError, "Data pointer of CvMat is NULL");
140                 return NULL;
141         }                
142         return OctString_FromStringAndSize((const char *)self->data.ptr, self->rows*self->step);
143   */
144   return octave_value();
145 }
146
147 %}
148
149 // add virtual member variable to CvMat
150 %extend CvMat {
151         octave_value imageData;
152 };