imagecore 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. data/.gitignore +24 -0
  2. data/Gemfile +4 -0
  3. data/Rakefile +2 -0
  4. data/ext/imagecore/analyze_image.cxx +58 -0
  5. data/ext/imagecore/analyze_image.h +6 -0
  6. data/ext/imagecore/extconf.rb +9 -0
  7. data/ext/imagecore/imagecore.cxx +34 -0
  8. data/ext/opencv/core/___.c +3 -0
  9. data/ext/opencv/core/alloc.cpp +697 -0
  10. data/ext/opencv/core/array.cpp +3206 -0
  11. data/ext/opencv/core/datastructs.cpp +4064 -0
  12. data/ext/opencv/core/extconf.rb +22 -0
  13. data/ext/opencv/core/matrix.cpp +3777 -0
  14. data/ext/opencv/core/precomp.hpp +216 -0
  15. data/ext/opencv/core/system.cpp +832 -0
  16. data/ext/opencv/core/tables.cpp +3512 -0
  17. data/ext/opencv/highgui/___.c +3 -0
  18. data/ext/opencv/highgui/bitstrm.cpp +582 -0
  19. data/ext/opencv/highgui/bitstrm.hpp +182 -0
  20. data/ext/opencv/highgui/extconf.rb +28 -0
  21. data/ext/opencv/highgui/grfmt_base.cpp +128 -0
  22. data/ext/opencv/highgui/grfmt_base.hpp +113 -0
  23. data/ext/opencv/highgui/grfmt_bmp.cpp +564 -0
  24. data/ext/opencv/highgui/grfmt_bmp.hpp +99 -0
  25. data/ext/opencv/highgui/grfmt_exr.hpp +113 -0
  26. data/ext/opencv/highgui/grfmt_imageio.hpp +56 -0
  27. data/ext/opencv/highgui/grfmt_jpeg.cpp +622 -0
  28. data/ext/opencv/highgui/grfmt_jpeg.hpp +90 -0
  29. data/ext/opencv/highgui/grfmt_jpeg2000.cpp +529 -0
  30. data/ext/opencv/highgui/grfmt_jpeg2000.hpp +95 -0
  31. data/ext/opencv/highgui/grfmt_png.cpp +406 -0
  32. data/ext/opencv/highgui/grfmt_png.hpp +101 -0
  33. data/ext/opencv/highgui/grfmt_pxm.cpp +513 -0
  34. data/ext/opencv/highgui/grfmt_pxm.hpp +92 -0
  35. data/ext/opencv/highgui/grfmt_sunras.cpp +425 -0
  36. data/ext/opencv/highgui/grfmt_sunras.hpp +105 -0
  37. data/ext/opencv/highgui/grfmt_tiff.cpp +718 -0
  38. data/ext/opencv/highgui/grfmt_tiff.hpp +136 -0
  39. data/ext/opencv/highgui/grfmts.hpp +56 -0
  40. data/ext/opencv/highgui/loadsave.cpp +535 -0
  41. data/ext/opencv/highgui/precomp.hpp +223 -0
  42. data/ext/opencv/highgui/utils.cpp +689 -0
  43. data/ext/opencv/highgui/utils.hpp +128 -0
  44. data/ext/opencv/imgproc/___.c +3 -0
  45. data/ext/opencv/imgproc/_geom.h +72 -0
  46. data/ext/opencv/imgproc/color.cpp +3179 -0
  47. data/ext/opencv/imgproc/contours.cpp +1780 -0
  48. data/ext/opencv/imgproc/extconf.rb +11 -0
  49. data/ext/opencv/imgproc/filter.cpp +3063 -0
  50. data/ext/opencv/imgproc/precomp.hpp +159 -0
  51. data/ext/opencv/imgproc/shapedescr.cpp +1306 -0
  52. data/ext/opencv/imgproc/smooth.cpp +1566 -0
  53. data/ext/opencv/imgproc/tables.cpp +214 -0
  54. data/ext/opencv/imgproc/thresh.cpp +636 -0
  55. data/ext/opencv/imgproc/utils.cpp +242 -0
  56. data/ext/opencv/include/opencv2/core/core.hpp +4344 -0
  57. data/ext/opencv/include/opencv2/core/core_c.h +1885 -0
  58. data/ext/opencv/include/opencv2/core/internal.hpp +710 -0
  59. data/ext/opencv/include/opencv2/core/mat.hpp +2557 -0
  60. data/ext/opencv/include/opencv2/core/operations.hpp +3623 -0
  61. data/ext/opencv/include/opencv2/core/types_c.h +1875 -0
  62. data/ext/opencv/include/opencv2/core/version.hpp +58 -0
  63. data/ext/opencv/include/opencv2/highgui/highgui.hpp +198 -0
  64. data/ext/opencv/include/opencv2/highgui/highgui_c.h +506 -0
  65. data/ext/opencv/include/opencv2/imgproc/imgproc.hpp +1139 -0
  66. data/ext/opencv/include/opencv2/imgproc/imgproc_c.h +783 -0
  67. data/ext/opencv/include/opencv2/imgproc/types_c.h +538 -0
  68. data/imagecore.gemspec +20 -0
  69. data/lib/imagecore.rb +16 -0
  70. data/lib/imagecore/version.rb +3 -0
  71. metadata +119 -0
@@ -0,0 +1,710 @@
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
+ // License Agreement
11
+ // For Open Source Computer Vision Library
12
+ //
13
+ // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14
+ // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15
+ // Third party copyrights are property of their respective owners.
16
+ //
17
+ // Redistribution and use in source and binary forms, with or without modification,
18
+ // are permitted provided that the following conditions are met:
19
+ //
20
+ // * Redistribution's of source code must retain the above copyright notice,
21
+ // this list of conditions and the following disclaimer.
22
+ //
23
+ // * Redistribution's in binary form must reproduce the above copyright notice,
24
+ // this list of conditions and the following disclaimer in the documentation
25
+ // and/or other materials provided with the distribution.
26
+ //
27
+ // * The name of the copyright holders may not be used to endorse or promote products
28
+ // derived from this software without specific prior written permission.
29
+ //
30
+ // This software is provided by the copyright holders and contributors "as is" and
31
+ // any express or implied warranties, including, but not limited to, the implied
32
+ // warranties of merchantability and fitness for a particular purpose are disclaimed.
33
+ // In no event shall the Intel Corporation or contributors be liable for any direct,
34
+ // indirect, incidental, special, exemplary, or consequential damages
35
+ // (including, but not limited to, procurement of substitute goods or services;
36
+ // loss of use, data, or profits; or business interruption) however caused
37
+ // and on any theory of liability, whether in contract, strict liability,
38
+ // or tort (including negligence or otherwise) arising in any way out of
39
+ // the use of this software, even if advised of the possibility of such damage.
40
+ //
41
+ //M*/
42
+
43
+ /* The header is for internal use and it is likely to change.
44
+ It contains some macro definitions that are used in cxcore, cv, cvaux
45
+ and, probably, other libraries. If you need some of this functionality,
46
+ the safe way is to copy it into your code and rename the macros.
47
+ */
48
+ #ifndef __OPENCV_CORE_INTERNAL_HPP__
49
+ #define __OPENCV_CORE_INTERNAL_HPP__
50
+
51
+ #include <vector>
52
+
53
+ #if defined WIN32 || defined _WIN32
54
+ # ifndef WIN32
55
+ # define WIN32
56
+ # endif
57
+ # ifndef _WIN32
58
+ # define _WIN32
59
+ # endif
60
+ #endif
61
+
62
+ #if defined WIN32 || defined WINCE
63
+ #ifndef _WIN32_WINNT // This is needed for the declaration of TryEnterCriticalSection in winbase.h with Visual Studio 2005 (and older?)
64
+ #define _WIN32_WINNT 0x0400 // http://msdn.microsoft.com/en-us/library/ms686857(VS.85).aspx
65
+ #endif
66
+ #include <windows.h>
67
+ #undef small
68
+ #undef min
69
+ #undef max
70
+ #else
71
+ #include <pthread.h>
72
+ #include <sys/mman.h>
73
+ #endif
74
+
75
+ #ifdef __BORLANDC__
76
+ #ifndef WIN32
77
+ #define WIN32
78
+ #endif
79
+ #ifndef _WIN32
80
+ #define _WIN32
81
+ #endif
82
+ #define CV_DLL
83
+ #undef _CV_ALWAYS_PROFILE_
84
+ #define _CV_ALWAYS_NO_PROFILE_
85
+ #endif
86
+
87
+ #ifndef FALSE
88
+ #define FALSE 0
89
+ #endif
90
+ #ifndef TRUE
91
+ #define TRUE 1
92
+ #endif
93
+
94
+ #define __BEGIN__ __CV_BEGIN__
95
+ #define __END__ __CV_END__
96
+ #define EXIT __CV_EXIT__
97
+
98
+ #ifdef HAVE_IPP
99
+ #include "ipp.h"
100
+
101
+ CV_INLINE IppiSize ippiSize(int width, int height)
102
+ {
103
+ IppiSize size = { width, height };
104
+ return size;
105
+ }
106
+ #endif
107
+
108
+ #if defined __SSE2__ || _MSC_VER >= 1300
109
+ #include "emmintrin.h"
110
+ #define CV_SSE 1
111
+ #define CV_SSE2 1
112
+ #if defined __SSE3__ || _MSC_VER >= 1500
113
+ #include "pmmintrin.h"
114
+ #define CV_SSE3 1
115
+ #endif
116
+ #else
117
+ #define CV_SSE 0
118
+ #define CV_SSE2 0
119
+ #define CV_SSE3 0
120
+ #endif
121
+
122
+ #if defined ANDROID && defined __ARM_NEON__
123
+ #include "arm_neon.h"
124
+ #define CV_NEON 1
125
+
126
+ #define CPU_HAS_NEON_FEATURE (true)
127
+ //TODO: make real check using stuff from "cpu-features.h"
128
+ //((bool)android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON)
129
+ #else
130
+ #define CV_NEON 0
131
+ #define CPU_HAS_NEON_FEATURE (false)
132
+ #endif
133
+
134
+ #ifndef IPPI_CALL
135
+ #define IPPI_CALL(func) CV_Assert((func) >= 0)
136
+ #endif
137
+
138
+ #ifdef HAVE_TBB
139
+ #include "tbb/tbb_stddef.h"
140
+ #if TBB_VERSION_MAJOR*100 + TBB_VERSION_MINOR >= 202
141
+ #include "tbb/tbb.h"
142
+ #include "tbb/task.h"
143
+ #undef min
144
+ #undef max
145
+ #else
146
+ #undef HAVE_TBB
147
+ #endif
148
+ #endif
149
+
150
+ #ifdef HAVE_EIGEN
151
+ #include <Eigen/Core>
152
+ #include "opencv2/core/eigen.hpp"
153
+ #endif
154
+
155
+ #ifdef __cplusplus
156
+
157
+ #ifdef HAVE_TBB
158
+ namespace cv
159
+ {
160
+ typedef tbb::blocked_range<int> BlockedRange;
161
+
162
+ template<typename Body> static inline
163
+ void parallel_for( const BlockedRange& range, const Body& body )
164
+ {
165
+ tbb::parallel_for(range, body);
166
+ }
167
+
168
+ template<typename Iterator, typename Body> static inline
169
+ void parallel_do( Iterator first, Iterator last, const Body& body )
170
+ {
171
+ tbb::parallel_do(first, last, body);
172
+ }
173
+
174
+ typedef tbb::split Split;
175
+
176
+ template<typename Body> static inline
177
+ void parallel_reduce( const BlockedRange& range, Body& body )
178
+ {
179
+ tbb::parallel_reduce(range, body);
180
+ }
181
+
182
+ typedef tbb::concurrent_vector<Rect> ConcurrentRectVector;
183
+ typedef tbb::concurrent_vector<double> ConcurrentDoubleVector;
184
+ }
185
+ #else
186
+ namespace cv
187
+ {
188
+ class BlockedRange
189
+ {
190
+ public:
191
+ BlockedRange() : _begin(0), _end(0), _grainsize(0) {}
192
+ BlockedRange(int b, int e, int g=1) : _begin(b), _end(e), _grainsize(g) {}
193
+ int begin() const { return _begin; }
194
+ int end() const { return _end; }
195
+ int grainsize() const { return _grainsize; }
196
+
197
+ protected:
198
+ int _begin, _end, _grainsize;
199
+ };
200
+
201
+
202
+ #ifdef HAVE_THREADING_FRAMEWORK
203
+ #include "threading_framework.hpp"
204
+
205
+ template<typename Body>
206
+ static void parallel_for( const BlockedRange& range, const Body& body )
207
+ {
208
+ tf::parallel_for<Body>(range, body);
209
+ }
210
+
211
+ typedef tf::ConcurrentVector<Rect> ConcurrentRectVector;
212
+ #else
213
+ template<typename Body> static inline
214
+ void parallel_for( const BlockedRange& range, const Body& body )
215
+ {
216
+ body(range);
217
+ }
218
+ typedef std::vector<Rect> ConcurrentRectVector;
219
+ typedef std::vector<double> ConcurrentDoubleVector;
220
+ #endif
221
+
222
+ template<typename Iterator, typename Body> static inline
223
+ void parallel_do( Iterator first, Iterator last, const Body& body )
224
+ {
225
+ for( ; first != last; ++first )
226
+ body(*first);
227
+ }
228
+
229
+ class Split {};
230
+
231
+ template<typename Body> static inline
232
+ void parallel_reduce( const BlockedRange& range, Body& body )
233
+ {
234
+ body(range);
235
+ }
236
+
237
+ }
238
+ #endif
239
+ #endif
240
+
241
+ /* maximal size of vector to run matrix operations on it inline (i.e. w/o ipp calls) */
242
+ #define CV_MAX_INLINE_MAT_OP_SIZE 10
243
+
244
+ /* maximal linear size of matrix to allocate it on stack. */
245
+ #define CV_MAX_LOCAL_MAT_SIZE 32
246
+
247
+ /* maximal size of local memory storage */
248
+ #define CV_MAX_LOCAL_SIZE \
249
+ (CV_MAX_LOCAL_MAT_SIZE*CV_MAX_LOCAL_MAT_SIZE*(int)sizeof(double))
250
+
251
+ /* default image row align (in bytes) */
252
+ #define CV_DEFAULT_IMAGE_ROW_ALIGN 4
253
+
254
+ /* matrices are continuous by default */
255
+ #define CV_DEFAULT_MAT_ROW_ALIGN 1
256
+
257
+ /* maximum size of dynamic memory buffer.
258
+ cvAlloc reports an error if a larger block is requested. */
259
+ #define CV_MAX_ALLOC_SIZE (((size_t)1 << (sizeof(size_t)*8-2)))
260
+
261
+ /* the alignment of all the allocated buffers */
262
+ #define CV_MALLOC_ALIGN 16
263
+
264
+ /* default alignment for dynamic data strucutures, resided in storages. */
265
+ #define CV_STRUCT_ALIGN ((int)sizeof(double))
266
+
267
+ /* default storage block size */
268
+ #define CV_STORAGE_BLOCK_SIZE ((1<<16) - 128)
269
+
270
+ /* default memory block for sparse array elements */
271
+ #define CV_SPARSE_MAT_BLOCK (1<<12)
272
+
273
+ /* initial hash table size */
274
+ #define CV_SPARSE_HASH_SIZE0 (1<<10)
275
+
276
+ /* maximal average node_count/hash_size ratio beyond which hash table is resized */
277
+ #define CV_SPARSE_HASH_RATIO 3
278
+
279
+ /* max length of strings */
280
+ #define CV_MAX_STRLEN 1024
281
+
282
+ #if 0 /*def CV_CHECK_FOR_NANS*/
283
+ #define CV_CHECK_NANS( arr ) cvCheckArray((arr))
284
+ #else
285
+ #define CV_CHECK_NANS( arr )
286
+ #endif
287
+
288
+ /****************************************************************************************\
289
+ * Common declarations *
290
+ \****************************************************************************************/
291
+
292
+ /* get alloca declaration */
293
+ #ifdef __GNUC__
294
+ #undef alloca
295
+ #define alloca __builtin_alloca
296
+ #define CV_HAVE_ALLOCA 1
297
+ #elif defined WIN32 || defined _WIN32 || \
298
+ defined WINCE || defined _MSC_VER || defined __BORLANDC__
299
+ #include <malloc.h>
300
+ #define CV_HAVE_ALLOCA 1
301
+ #elif defined HAVE_ALLOCA_H
302
+ #include <alloca.h>
303
+ #define CV_HAVE_ALLOCA 1
304
+ #elif defined HAVE_ALLOCA
305
+ #include <stdlib.h>
306
+ #define CV_HAVE_ALLOCA 1
307
+ #else
308
+ #undef CV_HAVE_ALLOCA
309
+ #endif
310
+
311
+ #ifdef __GNUC__
312
+ #define CV_DECL_ALIGNED(x) __attribute__ ((aligned (x)))
313
+ #elif defined _MSC_VER
314
+ #define CV_DECL_ALIGNED(x) __declspec(align(x))
315
+ #else
316
+ #define CV_DECL_ALIGNED(x)
317
+ #endif
318
+
319
+ #if CV_HAVE_ALLOCA
320
+ /* ! DO NOT make it an inline function */
321
+ #define cvStackAlloc(size) cvAlignPtr( alloca((size) + CV_MALLOC_ALIGN), CV_MALLOC_ALIGN )
322
+ #endif
323
+
324
+ #ifndef CV_IMPL
325
+ #define CV_IMPL CV_EXTERN_C
326
+ #endif
327
+
328
+ #define CV_DBG_BREAK() { volatile int* crashMe = 0; *crashMe = 0; }
329
+
330
+ /* default step, set in case of continuous data
331
+ to work around checks for valid step in some ipp functions */
332
+ #define CV_STUB_STEP (1 << 30)
333
+
334
+ #define CV_SIZEOF_FLOAT ((int)sizeof(float))
335
+ #define CV_SIZEOF_SHORT ((int)sizeof(short))
336
+
337
+ #define CV_ORIGIN_TL 0
338
+ #define CV_ORIGIN_BL 1
339
+
340
+ /* IEEE754 constants and macros */
341
+ #define CV_POS_INF 0x7f800000
342
+ #define CV_NEG_INF 0x807fffff /* CV_TOGGLE_FLT(0xff800000) */
343
+ #define CV_1F 0x3f800000
344
+ #define CV_TOGGLE_FLT(x) ((x)^((int)(x) < 0 ? 0x7fffffff : 0))
345
+ #define CV_TOGGLE_DBL(x) \
346
+ ((x)^((int64)(x) < 0 ? CV_BIG_INT(0x7fffffffffffffff) : 0))
347
+
348
+ #define CV_NOP(a) (a)
349
+ #define CV_ADD(a, b) ((a) + (b))
350
+ #define CV_SUB(a, b) ((a) - (b))
351
+ #define CV_MUL(a, b) ((a) * (b))
352
+ #define CV_AND(a, b) ((a) & (b))
353
+ #define CV_OR(a, b) ((a) | (b))
354
+ #define CV_XOR(a, b) ((a) ^ (b))
355
+ #define CV_ANDN(a, b) (~(a) & (b))
356
+ #define CV_ORN(a, b) (~(a) | (b))
357
+ #define CV_SQR(a) ((a) * (a))
358
+
359
+ #define CV_LT(a, b) ((a) < (b))
360
+ #define CV_LE(a, b) ((a) <= (b))
361
+ #define CV_EQ(a, b) ((a) == (b))
362
+ #define CV_NE(a, b) ((a) != (b))
363
+ #define CV_GT(a, b) ((a) > (b))
364
+ #define CV_GE(a, b) ((a) >= (b))
365
+
366
+ #define CV_NONZERO(a) ((a) != 0)
367
+ #define CV_NONZERO_FLT(a) (((a)+(a)) != 0)
368
+
369
+ /* general-purpose saturation macros */
370
+ #define CV_CAST_8U(t) (uchar)(!((t) & ~255) ? (t) : (t) > 0 ? 255 : 0)
371
+ #define CV_CAST_8S(t) (schar)(!(((t)+128) & ~255) ? (t) : (t) > 0 ? 127 : -128)
372
+ #define CV_CAST_16U(t) (ushort)(!((t) & ~65535) ? (t) : (t) > 0 ? 65535 : 0)
373
+ #define CV_CAST_16S(t) (short)(!(((t)+32768) & ~65535) ? (t) : (t) > 0 ? 32767 : -32768)
374
+ #define CV_CAST_32S(t) (int)(t)
375
+ #define CV_CAST_64S(t) (int64)(t)
376
+ #define CV_CAST_32F(t) (float)(t)
377
+ #define CV_CAST_64F(t) (double)(t)
378
+
379
+ #define CV_PASTE2(a,b) a##b
380
+ #define CV_PASTE(a,b) CV_PASTE2(a,b)
381
+
382
+ #define CV_EMPTY
383
+ #define CV_MAKE_STR(a) #a
384
+
385
+ #define CV_ZERO_OBJ(x) memset((x), 0, sizeof(*(x)))
386
+
387
+ #define CV_DIM(static_array) ((int)(sizeof(static_array)/sizeof((static_array)[0])))
388
+
389
+ #define cvUnsupportedFormat "Unsupported format"
390
+
391
+ CV_INLINE void* cvAlignPtr( const void* ptr, int align CV_DEFAULT(32) )
392
+ {
393
+ assert( (align & (align-1)) == 0 );
394
+ return (void*)( ((size_t)ptr + align - 1) & ~(size_t)(align-1) );
395
+ }
396
+
397
+ CV_INLINE int cvAlign( int size, int align )
398
+ {
399
+ assert( (align & (align-1)) == 0 && size < INT_MAX );
400
+ return (size + align - 1) & -align;
401
+ }
402
+
403
+ CV_INLINE CvSize cvGetMatSize( const CvMat* mat )
404
+ {
405
+ CvSize size;
406
+ size.width = mat->cols;
407
+ size.height = mat->rows;
408
+ return size;
409
+ }
410
+
411
+ #define CV_DESCALE(x,n) (((x) + (1 << ((n)-1))) >> (n))
412
+ #define CV_FLT_TO_FIX(x,n) cvRound((x)*(1<<(n)))
413
+
414
+ /****************************************************************************************\
415
+
416
+ Generic implementation of QuickSort algorithm.
417
+ ----------------------------------------------
418
+ Using this macro user can declare customized sort function that can be much faster
419
+ than built-in qsort function because of lower overhead on elements
420
+ comparison and exchange. The macro takes less_than (or LT) argument - a macro or function
421
+ that takes 2 arguments returns non-zero if the first argument should be before the second
422
+ one in the sorted sequence and zero otherwise.
423
+
424
+ Example:
425
+
426
+ Suppose that the task is to sort points by ascending of y coordinates and if
427
+ y's are equal x's should ascend.
428
+
429
+ The code is:
430
+ ------------------------------------------------------------------------------
431
+ #define cmp_pts( pt1, pt2 ) \
432
+ ((pt1).y < (pt2).y || ((pt1).y < (pt2).y && (pt1).x < (pt2).x))
433
+
434
+ [static] CV_IMPLEMENT_QSORT( icvSortPoints, CvPoint, cmp_pts )
435
+ ------------------------------------------------------------------------------
436
+
437
+ After that the function "void icvSortPoints( CvPoint* array, size_t total, int aux );"
438
+ is available to user.
439
+
440
+ aux is an additional parameter, which can be used when comparing elements.
441
+ The current implementation was derived from *BSD system qsort():
442
+
443
+ * Copyright (c) 1992, 1993
444
+ * The Regents of the University of California. All rights reserved.
445
+ *
446
+ * Redistribution and use in source and binary forms, with or without
447
+ * modification, are permitted provided that the following conditions
448
+ * are met:
449
+ * 1. Redistributions of source code must retain the above copyright
450
+ * notice, this list of conditions and the following disclaimer.
451
+ * 2. Redistributions in binary form must reproduce the above copyright
452
+ * notice, this list of conditions and the following disclaimer in the
453
+ * documentation and/or other materials provided with the distribution.
454
+ * 3. All advertising materials mentioning features or use of this software
455
+ * must display the following acknowledgement:
456
+ * This product includes software developed by the University of
457
+ * California, Berkeley and its contributors.
458
+ * 4. Neither the name of the University nor the names of its contributors
459
+ * may be used to endorse or promote products derived from this software
460
+ * without specific prior written permission.
461
+ *
462
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
463
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
464
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
465
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
466
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
467
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
468
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
469
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
470
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
471
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
472
+ * SUCH DAMAGE.
473
+
474
+ \****************************************************************************************/
475
+
476
+ #define CV_IMPLEMENT_QSORT_EX( func_name, T, LT, user_data_type ) \
477
+ void func_name( T *array, size_t total, user_data_type aux ) \
478
+ { \
479
+ int isort_thresh = 7; \
480
+ T t; \
481
+ int sp = 0; \
482
+ \
483
+ struct \
484
+ { \
485
+ T *lb; \
486
+ T *ub; \
487
+ } \
488
+ stack[48]; \
489
+ \
490
+ aux = aux; \
491
+ \
492
+ if( total <= 1 ) \
493
+ return; \
494
+ \
495
+ stack[0].lb = array; \
496
+ stack[0].ub = array + (total - 1); \
497
+ \
498
+ while( sp >= 0 ) \
499
+ { \
500
+ T* left = stack[sp].lb; \
501
+ T* right = stack[sp--].ub; \
502
+ \
503
+ for(;;) \
504
+ { \
505
+ int i, n = (int)(right - left) + 1, m; \
506
+ T* ptr; \
507
+ T* ptr2; \
508
+ \
509
+ if( n <= isort_thresh ) \
510
+ { \
511
+ insert_sort: \
512
+ for( ptr = left + 1; ptr <= right; ptr++ ) \
513
+ { \
514
+ for( ptr2 = ptr; ptr2 > left && LT(ptr2[0],ptr2[-1]); ptr2--) \
515
+ CV_SWAP( ptr2[0], ptr2[-1], t ); \
516
+ } \
517
+ break; \
518
+ } \
519
+ else \
520
+ { \
521
+ T* left0; \
522
+ T* left1; \
523
+ T* right0; \
524
+ T* right1; \
525
+ T* pivot; \
526
+ T* a; \
527
+ T* b; \
528
+ T* c; \
529
+ int swap_cnt = 0; \
530
+ \
531
+ left0 = left; \
532
+ right0 = right; \
533
+ pivot = left + (n/2); \
534
+ \
535
+ if( n > 40 ) \
536
+ { \
537
+ int d = n / 8; \
538
+ a = left, b = left + d, c = left + 2*d; \
539
+ left = LT(*a, *b) ? (LT(*b, *c) ? b : (LT(*a, *c) ? c : a)) \
540
+ : (LT(*c, *b) ? b : (LT(*a, *c) ? a : c)); \
541
+ \
542
+ a = pivot - d, b = pivot, c = pivot + d; \
543
+ pivot = LT(*a, *b) ? (LT(*b, *c) ? b : (LT(*a, *c) ? c : a)) \
544
+ : (LT(*c, *b) ? b : (LT(*a, *c) ? a : c)); \
545
+ \
546
+ a = right - 2*d, b = right - d, c = right; \
547
+ right = LT(*a, *b) ? (LT(*b, *c) ? b : (LT(*a, *c) ? c : a)) \
548
+ : (LT(*c, *b) ? b : (LT(*a, *c) ? a : c)); \
549
+ } \
550
+ \
551
+ a = left, b = pivot, c = right; \
552
+ pivot = LT(*a, *b) ? (LT(*b, *c) ? b : (LT(*a, *c) ? c : a)) \
553
+ : (LT(*c, *b) ? b : (LT(*a, *c) ? a : c)); \
554
+ if( pivot != left0 ) \
555
+ { \
556
+ CV_SWAP( *pivot, *left0, t ); \
557
+ pivot = left0; \
558
+ } \
559
+ left = left1 = left0 + 1; \
560
+ right = right1 = right0; \
561
+ \
562
+ for(;;) \
563
+ { \
564
+ while( left <= right && !LT(*pivot, *left) ) \
565
+ { \
566
+ if( !LT(*left, *pivot) ) \
567
+ { \
568
+ if( left > left1 ) \
569
+ CV_SWAP( *left1, *left, t ); \
570
+ swap_cnt = 1; \
571
+ left1++; \
572
+ } \
573
+ left++; \
574
+ } \
575
+ \
576
+ while( left <= right && !LT(*right, *pivot) ) \
577
+ { \
578
+ if( !LT(*pivot, *right) ) \
579
+ { \
580
+ if( right < right1 ) \
581
+ CV_SWAP( *right1, *right, t ); \
582
+ swap_cnt = 1; \
583
+ right1--; \
584
+ } \
585
+ right--; \
586
+ } \
587
+ \
588
+ if( left > right ) \
589
+ break; \
590
+ CV_SWAP( *left, *right, t ); \
591
+ swap_cnt = 1; \
592
+ left++; \
593
+ right--; \
594
+ } \
595
+ \
596
+ if( swap_cnt == 0 ) \
597
+ { \
598
+ left = left0, right = right0; \
599
+ goto insert_sort; \
600
+ } \
601
+ \
602
+ n = MIN( (int)(left1 - left0), (int)(left - left1) ); \
603
+ for( i = 0; i < n; i++ ) \
604
+ CV_SWAP( left0[i], left[i-n], t ); \
605
+ \
606
+ n = MIN( (int)(right0 - right1), (int)(right1 - right) ); \
607
+ for( i = 0; i < n; i++ ) \
608
+ CV_SWAP( left[i], right0[i-n+1], t ); \
609
+ n = (int)(left - left1); \
610
+ m = (int)(right1 - right); \
611
+ if( n > 1 ) \
612
+ { \
613
+ if( m > 1 ) \
614
+ { \
615
+ if( n > m ) \
616
+ { \
617
+ stack[++sp].lb = left0; \
618
+ stack[sp].ub = left0 + n - 1; \
619
+ left = right0 - m + 1, right = right0; \
620
+ } \
621
+ else \
622
+ { \
623
+ stack[++sp].lb = right0 - m + 1; \
624
+ stack[sp].ub = right0; \
625
+ left = left0, right = left0 + n - 1; \
626
+ } \
627
+ } \
628
+ else \
629
+ left = left0, right = left0 + n - 1; \
630
+ } \
631
+ else if( m > 1 ) \
632
+ left = right0 - m + 1, right = right0; \
633
+ else \
634
+ break; \
635
+ } \
636
+ } \
637
+ } \
638
+ }
639
+
640
+ #define CV_IMPLEMENT_QSORT( func_name, T, cmp ) \
641
+ CV_IMPLEMENT_QSORT_EX( func_name, T, cmp, int )
642
+
643
+ /****************************************************************************************\
644
+ * Structures and macros for integration with IPP *
645
+ \****************************************************************************************/
646
+
647
+ /* IPP-compatible return codes */
648
+ typedef enum CvStatus
649
+ {
650
+ CV_BADMEMBLOCK_ERR = -113,
651
+ CV_INPLACE_NOT_SUPPORTED_ERR= -112,
652
+ CV_UNMATCHED_ROI_ERR = -111,
653
+ CV_NOTFOUND_ERR = -110,
654
+ CV_BADCONVERGENCE_ERR = -109,
655
+
656
+ CV_BADDEPTH_ERR = -107,
657
+ CV_BADROI_ERR = -106,
658
+ CV_BADHEADER_ERR = -105,
659
+ CV_UNMATCHED_FORMATS_ERR = -104,
660
+ CV_UNSUPPORTED_COI_ERR = -103,
661
+ CV_UNSUPPORTED_CHANNELS_ERR = -102,
662
+ CV_UNSUPPORTED_DEPTH_ERR = -101,
663
+ CV_UNSUPPORTED_FORMAT_ERR = -100,
664
+
665
+ CV_BADARG_ERR = -49, //ipp comp
666
+ CV_NOTDEFINED_ERR = -48, //ipp comp
667
+
668
+ CV_BADCHANNELS_ERR = -47, //ipp comp
669
+ CV_BADRANGE_ERR = -44, //ipp comp
670
+ CV_BADSTEP_ERR = -29, //ipp comp
671
+
672
+ CV_BADFLAG_ERR = -12,
673
+ CV_DIV_BY_ZERO_ERR = -11, //ipp comp
674
+ CV_BADCOEF_ERR = -10,
675
+
676
+ CV_BADFACTOR_ERR = -7,
677
+ CV_BADPOINT_ERR = -6,
678
+ CV_BADSCALE_ERR = -4,
679
+ CV_OUTOFMEM_ERR = -3,
680
+ CV_NULLPTR_ERR = -2,
681
+ CV_BADSIZE_ERR = -1,
682
+ CV_NO_ERR = 0,
683
+ CV_OK = CV_NO_ERR
684
+ }
685
+ CvStatus;
686
+
687
+ #define CV_NOTHROW throw()
688
+
689
+ typedef struct CvFuncTable
690
+ {
691
+ void* fn_2d[CV_DEPTH_MAX];
692
+ }
693
+ CvFuncTable;
694
+
695
+ typedef struct CvBigFuncTable
696
+ {
697
+ void* fn_2d[CV_DEPTH_MAX*4];
698
+ }
699
+ CvBigFuncTable;
700
+
701
+ #define CV_INIT_FUNC_TAB( tab, FUNCNAME, FLAG ) \
702
+ (tab).fn_2d[CV_8U] = (void*)FUNCNAME##_8u##FLAG; \
703
+ (tab).fn_2d[CV_8S] = 0; \
704
+ (tab).fn_2d[CV_16U] = (void*)FUNCNAME##_16u##FLAG; \
705
+ (tab).fn_2d[CV_16S] = (void*)FUNCNAME##_16s##FLAG; \
706
+ (tab).fn_2d[CV_32S] = (void*)FUNCNAME##_32s##FLAG; \
707
+ (tab).fn_2d[CV_32F] = (void*)FUNCNAME##_32f##FLAG; \
708
+ (tab).fn_2d[CV_64F] = (void*)FUNCNAME##_64f##FLAG
709
+
710
+ #endif