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,92 @@
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
+ #ifndef _GRFMT_PxM_H_
44
+ #define _GRFMT_PxM_H_
45
+
46
+ #include "grfmt_base.hpp"
47
+ #include "bitstrm.hpp"
48
+
49
+ namespace cv
50
+ {
51
+
52
+ class PxMDecoder : public BaseImageDecoder
53
+ {
54
+ public:
55
+
56
+ PxMDecoder();
57
+ virtual ~PxMDecoder();
58
+
59
+ bool readData( Mat& img );
60
+ bool readHeader();
61
+ void close();
62
+
63
+ size_t signatureLength() const;
64
+ bool checkSignature( const string& signature ) const;
65
+ ImageDecoder newDecoder() const;
66
+
67
+ protected:
68
+
69
+ RLByteStream m_strm;
70
+ PaletteEntry m_palette[256];
71
+ int m_bpp;
72
+ int m_offset;
73
+ bool m_binary;
74
+ int m_maxval;
75
+ };
76
+
77
+
78
+ class PxMEncoder : public BaseImageEncoder
79
+ {
80
+ public:
81
+ PxMEncoder();
82
+ virtual ~PxMEncoder();
83
+
84
+ bool isFormatSupported( int depth ) const;
85
+ bool write( const Mat& img, const vector<int>& params );
86
+
87
+ ImageEncoder newEncoder() const;
88
+ };
89
+
90
+ }
91
+
92
+ #endif/*_GRFMT_PxM_H_*/
@@ -0,0 +1,425 @@
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
+ #include "precomp.hpp"
44
+ #include "grfmt_sunras.hpp"
45
+
46
+ namespace cv
47
+ {
48
+
49
+ static const char* fmtSignSunRas = "\x59\xA6\x6A\x95";
50
+
51
+ /************************ Sun Raster reader *****************************/
52
+
53
+ SunRasterDecoder::SunRasterDecoder()
54
+ {
55
+ m_offset = -1;
56
+ m_signature = fmtSignSunRas;
57
+ }
58
+
59
+
60
+ SunRasterDecoder::~SunRasterDecoder()
61
+ {
62
+ }
63
+
64
+ ImageDecoder SunRasterDecoder::newDecoder() const
65
+ {
66
+ return new SunRasterDecoder;
67
+ }
68
+
69
+ void SunRasterDecoder::close()
70
+ {
71
+ m_strm.close();
72
+ }
73
+
74
+
75
+ bool SunRasterDecoder::readHeader()
76
+ {
77
+ bool result = false;
78
+
79
+ if( !m_strm.open( m_filename )) return false;
80
+
81
+ try
82
+ {
83
+ m_strm.skip( 4 );
84
+ m_width = m_strm.getDWord();
85
+ m_height = m_strm.getDWord();
86
+ m_bpp = m_strm.getDWord();
87
+ int palSize = 3*(1 << m_bpp);
88
+
89
+ m_strm.skip( 4 );
90
+ m_encoding = (SunRasType)m_strm.getDWord();
91
+ m_maptype = (SunRasMapType)m_strm.getDWord();
92
+ m_maplength = m_strm.getDWord();
93
+
94
+ if( m_width > 0 && m_height > 0 &&
95
+ (m_bpp == 1 || m_bpp == 8 || m_bpp == 24 || m_bpp == 32) &&
96
+ (m_encoding == RAS_OLD || m_encoding == RAS_STANDARD ||
97
+ (m_type == RAS_BYTE_ENCODED && m_bpp == 8) || m_type == RAS_FORMAT_RGB) &&
98
+ ((m_maptype == RMT_NONE && m_maplength == 0) ||
99
+ (m_maptype == RMT_EQUAL_RGB && m_maplength <= palSize && m_bpp <= 8)))
100
+ {
101
+ memset( m_palette, 0, sizeof(m_palette));
102
+
103
+ if( m_maplength != 0 )
104
+ {
105
+ uchar buffer[256*3];
106
+
107
+ if( m_strm.getBytes( buffer, m_maplength ) == m_maplength )
108
+ {
109
+ int i;
110
+ palSize = m_maplength/3;
111
+
112
+ for( i = 0; i < palSize; i++ )
113
+ {
114
+ m_palette[i].b = buffer[i + 2*palSize];
115
+ m_palette[i].g = buffer[i + palSize];
116
+ m_palette[i].r = buffer[i];
117
+ m_palette[i].a = 0;
118
+ }
119
+
120
+ m_type = IsColorPalette( m_palette, m_bpp ) ? CV_8UC3 : CV_8UC1;
121
+ m_offset = m_strm.getPos();
122
+
123
+ assert( m_offset == 32 + m_maplength );
124
+ result = true;
125
+ }
126
+ }
127
+ else
128
+ {
129
+ m_type = m_bpp > 8 ? CV_8UC3 : CV_8UC1;
130
+
131
+ if( CV_MAT_CN(m_type) == 1 )
132
+ FillGrayPalette( m_palette, m_bpp );
133
+
134
+ m_offset = m_strm.getPos();
135
+
136
+ assert( m_offset == 32 + m_maplength );
137
+ result = true;
138
+ }
139
+ }
140
+ }
141
+ catch(...)
142
+ {
143
+ }
144
+
145
+ if( !result )
146
+ {
147
+ m_offset = -1;
148
+ m_width = m_height = -1;
149
+ m_strm.close();
150
+ }
151
+ return result;
152
+ }
153
+
154
+
155
+ bool SunRasterDecoder::readData( Mat& img )
156
+ {
157
+ int color = img.channels() > 1;
158
+ uchar* data = img.data;
159
+ int step = (int)img.step;
160
+ uchar gray_palette[256];
161
+ bool result = false;
162
+ int src_pitch = ((m_width*m_bpp + 7)/8 + 1) & -2;
163
+ int nch = color ? 3 : 1;
164
+ int width3 = m_width*nch;
165
+ int y;
166
+
167
+ if( m_offset < 0 || !m_strm.isOpened())
168
+ return false;
169
+
170
+ AutoBuffer<uchar> _src(src_pitch + 32);
171
+ uchar* src = _src;
172
+ AutoBuffer<uchar> _bgr(m_width*3 + 32);
173
+ uchar* bgr = _bgr;
174
+
175
+ if( !color && m_maptype == RMT_EQUAL_RGB )
176
+ CvtPaletteToGray( m_palette, gray_palette, 1 << m_bpp );
177
+
178
+ try
179
+ {
180
+ m_strm.setPos( m_offset );
181
+
182
+ switch( m_bpp )
183
+ {
184
+ /************************* 1 BPP ************************/
185
+ case 1:
186
+ if( m_type != RAS_BYTE_ENCODED )
187
+ {
188
+ for( y = 0; y < m_height; y++, data += step )
189
+ {
190
+ m_strm.getBytes( src, src_pitch );
191
+ if( color )
192
+ FillColorRow1( data, src, m_width, m_palette );
193
+ else
194
+ FillGrayRow1( data, src, m_width, gray_palette );
195
+ }
196
+ result = true;
197
+ }
198
+ else
199
+ {
200
+ uchar* line_end = src + (m_width*m_bpp + 7)/8;
201
+ uchar* tsrc = src;
202
+ y = 0;
203
+
204
+ for(;;)
205
+ {
206
+ int max_count = (int)(line_end - tsrc);
207
+ int code = 0, len = 0, len1 = 0;
208
+
209
+ do
210
+ {
211
+ code = m_strm.getByte();
212
+ if( code == 0x80 )
213
+ {
214
+ len = m_strm.getByte();
215
+ if( len != 0 ) break;
216
+ }
217
+ tsrc[len1] = (uchar)code;
218
+ }
219
+ while( ++len1 < max_count );
220
+
221
+ tsrc += len1;
222
+
223
+ if( len > 0 ) // encoded mode
224
+ {
225
+ ++len;
226
+ code = m_strm.getByte();
227
+ if( len > line_end - tsrc )
228
+ {
229
+ assert(0);
230
+ goto bad_decoding_1bpp;
231
+ }
232
+
233
+ memset( tsrc, code, len );
234
+ tsrc += len;
235
+ }
236
+
237
+ if( tsrc >= line_end )
238
+ {
239
+ tsrc = src;
240
+ if( color )
241
+ FillColorRow1( data, src, m_width, m_palette );
242
+ else
243
+ FillGrayRow1( data, src, m_width, gray_palette );
244
+ data += step;
245
+ if( ++y >= m_height ) break;
246
+ }
247
+ }
248
+ result = true;
249
+ bad_decoding_1bpp:
250
+ ;
251
+ }
252
+ break;
253
+ /************************* 8 BPP ************************/
254
+ case 8:
255
+ if( m_type != RAS_BYTE_ENCODED )
256
+ {
257
+ for( y = 0; y < m_height; y++, data += step )
258
+ {
259
+ m_strm.getBytes( src, src_pitch );
260
+ if( color )
261
+ FillColorRow8( data, src, m_width, m_palette );
262
+ else
263
+ FillGrayRow8( data, src, m_width, gray_palette );
264
+ }
265
+ result = true;
266
+ }
267
+ else // RLE-encoded
268
+ {
269
+ uchar* line_end = data + width3;
270
+ y = 0;
271
+
272
+ for(;;)
273
+ {
274
+ int max_count = (int)(line_end - data);
275
+ int code = 0, len = 0, len1;
276
+ uchar* tsrc = src;
277
+
278
+ do
279
+ {
280
+ code = m_strm.getByte();
281
+ if( code == 0x80 )
282
+ {
283
+ len = m_strm.getByte();
284
+ if( len != 0 ) break;
285
+ }
286
+ *tsrc++ = (uchar)code;
287
+ }
288
+ while( (max_count -= nch) > 0 );
289
+
290
+ len1 = (int)(tsrc - src);
291
+
292
+ if( len1 > 0 )
293
+ {
294
+ if( color )
295
+ FillColorRow8( data, src, len1, m_palette );
296
+ else
297
+ FillGrayRow8( data, src, len1, gray_palette );
298
+ data += len1*nch;
299
+ }
300
+
301
+ if( len > 0 ) // encoded mode
302
+ {
303
+ len = (len + 1)*nch;
304
+ code = m_strm.getByte();
305
+
306
+ if( color )
307
+ data = FillUniColor( data, line_end, step, width3,
308
+ y, m_height, len,
309
+ m_palette[code] );
310
+ else
311
+ data = FillUniGray( data, line_end, step, width3,
312
+ y, m_height, len,
313
+ gray_palette[code] );
314
+ if( y >= m_height )
315
+ break;
316
+ }
317
+
318
+ if( data == line_end )
319
+ {
320
+ if( m_strm.getByte() != 0 )
321
+ goto bad_decoding_end;
322
+ line_end += step;
323
+ data = line_end - width3;
324
+ if( ++y >= m_height ) break;
325
+ }
326
+ }
327
+
328
+ result = true;
329
+ bad_decoding_end:
330
+ ;
331
+ }
332
+ break;
333
+ /************************* 24 BPP ************************/
334
+ case 24:
335
+ for( y = 0; y < m_height; y++, data += step )
336
+ {
337
+ m_strm.getBytes( color ? data : bgr, src_pitch );
338
+
339
+ if( color )
340
+ {
341
+ if( m_type == RAS_FORMAT_RGB )
342
+ icvCvt_RGB2BGR_8u_C3R( data, 0, data, 0, cvSize(m_width,1) );
343
+ }
344
+ else
345
+ {
346
+ icvCvt_BGR2Gray_8u_C3C1R( bgr, 0, data, 0, cvSize(m_width,1),
347
+ m_type == RAS_FORMAT_RGB ? 2 : 0 );
348
+ }
349
+ }
350
+ result = true;
351
+ break;
352
+ /************************* 32 BPP ************************/
353
+ case 32:
354
+ for( y = 0; y < m_height; y++, data += step )
355
+ {
356
+ /* hack: a0 b0 g0 r0 a1 b1 g1 r1 ... are written to src + 3,
357
+ so when we look at src + 4, we see b0 g0 r0 x b1 g1 g1 x ... */
358
+ m_strm.getBytes( src + 3, src_pitch );
359
+
360
+ if( color )
361
+ icvCvt_BGRA2BGR_8u_C4C3R( src + 4, 0, data, 0, cvSize(m_width,1),
362
+ m_type == RAS_FORMAT_RGB ? 2 : 0 );
363
+ else
364
+ icvCvt_BGRA2Gray_8u_C4C1R( src + 4, 0, data, 0, cvSize(m_width,1),
365
+ m_type == RAS_FORMAT_RGB ? 2 : 0 );
366
+ }
367
+ result = true;
368
+ break;
369
+ default:
370
+ assert(0);
371
+ }
372
+ }
373
+ catch( ... )
374
+ {
375
+ }
376
+
377
+ return result;
378
+ }
379
+
380
+
381
+ //////////////////////////////////////////////////////////////////////////////////////////
382
+
383
+ SunRasterEncoder::SunRasterEncoder()
384
+ {
385
+ m_description = "Sun raster files (*.sr;*.ras)";
386
+ }
387
+
388
+
389
+ ImageEncoder SunRasterEncoder::newEncoder() const
390
+ {
391
+ return new SunRasterEncoder;
392
+ }
393
+
394
+ SunRasterEncoder::~SunRasterEncoder()
395
+ {
396
+ }
397
+
398
+ bool SunRasterEncoder::write( const Mat& img, const vector<int>& )
399
+ {
400
+ bool result = false;
401
+ int y, width = img.cols, height = img.rows, channels = img.channels();
402
+ int fileStep = (width*channels + 1) & -2;
403
+ WMByteStream strm;
404
+
405
+ if( strm.open(m_filename) )
406
+ {
407
+ strm.putBytes( fmtSignSunRas, (int)strlen(fmtSignSunRas) );
408
+ strm.putDWord( width );
409
+ strm.putDWord( height );
410
+ strm.putDWord( channels*8 );
411
+ strm.putDWord( fileStep*height );
412
+ strm.putDWord( RAS_STANDARD );
413
+ strm.putDWord( RMT_NONE );
414
+ strm.putDWord( 0 );
415
+
416
+ for( y = 0; y < height; y++ )
417
+ strm.putBytes( img.data + img.step*y, fileStep );
418
+
419
+ strm.close();
420
+ result = true;
421
+ }
422
+ return result;
423
+ }
424
+
425
+ }