qrtools 1.0.0

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 (66) hide show
  1. data/History.txt +6 -0
  2. data/Manifest.txt +65 -0
  3. data/README.txt +75 -0
  4. data/Rakefile +49 -0
  5. data/bin/qrdecode +14 -0
  6. data/ext/qrtools/Makefile.in +65 -0
  7. data/ext/qrtools/bitstream.cpp +147 -0
  8. data/ext/qrtools/bitstream.h +48 -0
  9. data/ext/qrtools/codedata.cpp +506 -0
  10. data/ext/qrtools/codedata.h +95 -0
  11. data/ext/qrtools/container.cpp +288 -0
  12. data/ext/qrtools/container.h +175 -0
  13. data/ext/qrtools/decodeqr.h +286 -0
  14. data/ext/qrtools/ecidecoder.cpp +341 -0
  15. data/ext/qrtools/ecidecoder.h +110 -0
  16. data/ext/qrtools/extconf.rb +24 -0
  17. data/ext/qrtools/formatinfo.cpp +195 -0
  18. data/ext/qrtools/formatinfo.h +113 -0
  19. data/ext/qrtools/galois.cpp +593 -0
  20. data/ext/qrtools/galois.h +134 -0
  21. data/ext/qrtools/imagereader.cpp +1099 -0
  22. data/ext/qrtools/imagereader.h +127 -0
  23. data/ext/qrtools/libdecodeqr.cpp +195 -0
  24. data/ext/qrtools/libdecodeqr.dep +80 -0
  25. data/ext/qrtools/libdecodeqr.dsp +160 -0
  26. data/ext/qrtools/libdecodeqr.dsw +29 -0
  27. data/ext/qrtools/libdecodeqr.mak +245 -0
  28. data/ext/qrtools/qrerror.h +40 -0
  29. data/ext/qrtools/qrtools.c +17 -0
  30. data/ext/qrtools/qrtools.h +21 -0
  31. data/ext/qrtools/qrtools_decoder.c +123 -0
  32. data/ext/qrtools/qrtools_decoder.h +10 -0
  33. data/ext/qrtools/qrtools_encoder.c +63 -0
  34. data/ext/qrtools/qrtools_encoder.h +10 -0
  35. data/ext/qrtools/qrtools_header.c +51 -0
  36. data/ext/qrtools/qrtools_header.h +10 -0
  37. data/ext/qrtools/qrtools_image.c +80 -0
  38. data/ext/qrtools/qrtools_image.h +11 -0
  39. data/ext/qrtools/qrtools_qrcode.c +36 -0
  40. data/ext/qrtools/qrtools_qrcode.h +10 -0
  41. data/ext/qrtools/qrtools_ui_camera.c +58 -0
  42. data/ext/qrtools/qrtools_ui_camera.h +10 -0
  43. data/ext/qrtools/qrtools_ui_window.c +40 -0
  44. data/ext/qrtools/qrtools_ui_window.h +10 -0
  45. data/ext/qrtools/qrtypes.h +42 -0
  46. data/ext/qrtools/version.h +42 -0
  47. data/lib/qrtools.rb +11 -0
  48. data/lib/qrtools/decoder.rb +17 -0
  49. data/lib/qrtools/encoder.rb +14 -0
  50. data/lib/qrtools/image.rb +43 -0
  51. data/lib/qrtools/qrcode.rb +54 -0
  52. data/lib/qrtools/ui/camera.rb +28 -0
  53. data/lib/qrtools/ui/window.rb +16 -0
  54. data/lib/qrtools/version.rb +3 -0
  55. data/qrtools.gemspec +38 -0
  56. data/test/assets/01-1.jpg +0 -0
  57. data/test/helper.rb +17 -0
  58. data/test/test_decoder.rb +67 -0
  59. data/test/test_encoder.rb +35 -0
  60. data/test/test_header.rb +14 -0
  61. data/test/test_image.rb +19 -0
  62. data/test/test_qrcode.rb +78 -0
  63. data/test/test_qrdecode.rb +0 -0
  64. data/test/ui/test_camera.rb +43 -0
  65. data/test/ui/test_window.rb +34 -0
  66. metadata +138 -0
@@ -0,0 +1,29 @@
1
+ Microsoft Developer Studio Workspace File, Format Version 6.00
2
+ # �x��: ����ܰ���߰� ̧�� ��ҏW�܂��͍폜���Ȃ��ł�������!
3
+
4
+ ###############################################################################
5
+
6
+ Project: "libdecodeqr"=".\libdecodeqr.dsp" - Package Owner=<4>
7
+
8
+ Package=<5>
9
+ {{{
10
+ }}}
11
+
12
+ Package=<4>
13
+ {{{
14
+ }}}
15
+
16
+ ###############################################################################
17
+
18
+ Global:
19
+
20
+ Package=<5>
21
+ {{{
22
+ }}}
23
+
24
+ Package=<3>
25
+ {{{
26
+ }}}
27
+
28
+ ###############################################################################
29
+
@@ -0,0 +1,245 @@
1
+ # Microsoft Developer Studio Generated NMAKE File, Based on libdecodeqr.dsp
2
+ !IF "$(CFG)" == ""
3
+ CFG=libdecodeqr - Win32 Debug
4
+ !MESSAGE Missing target. Using defualt "libdecodeqr - Win32 Debug".
5
+ !ENDIF
6
+
7
+ !IF "$(CFG)" != "libdecodeqr - Win32 Release" && "$(CFG)" != "libdecodeqr - Win32 Debug"
8
+ !MESSAGE Mode "$(CFG)" is not valid.
9
+ !MESSAGE
10
+ !MESSAGE Valid modes are:
11
+ !MESSAGE
12
+ !MESSAGE "libdecodeqr - Win32 Release" (for "Win32 (x86) Static Library")
13
+ !MESSAGE "libdecodeqr - Win32 Debug" (for "Win32 (x86) Static Library")
14
+ !MESSAGE
15
+ !MESSAGE eg:
16
+ !MESSAGE
17
+ !MESSAGE NMAKE /f "libdecodeqr.mak" CFG="libdecodeqr - Win32 Debug"
18
+ !ERROR Invalid target are gaven.
19
+ !ENDIF
20
+
21
+ !IF "$(OS)" == "Windows_NT"
22
+ NULL=
23
+ !ELSE
24
+ NULL=nul
25
+ !ENDIF
26
+
27
+ !IF "$(CFG)" == "libdecodeqr - Win32 Release"
28
+
29
+ OUTDIR=.\Release
30
+ INTDIR=.\Release
31
+ # Begin Custom Macros
32
+ OutDir=.\Release
33
+ # End Custom Macros
34
+
35
+ ALL : "$(OUTDIR)\libdecodeqr.lib"
36
+
37
+
38
+ CLEAN :
39
+ -@erase "$(INTDIR)\bitstream.obj"
40
+ -@erase "$(INTDIR)\codedata.obj"
41
+ -@erase "$(INTDIR)\container.obj"
42
+ -@erase "$(INTDIR)\ecidecoder.obj"
43
+ -@erase "$(INTDIR)\formatinfo.obj"
44
+ -@erase "$(INTDIR)\galois.obj"
45
+ -@erase "$(INTDIR)\imagereader.obj"
46
+ -@erase "$(INTDIR)\libdecodeqr.obj"
47
+ -@erase "$(INTDIR)\vc60.idb"
48
+ -@erase "$(OUTDIR)\libdecodeqr.lib"
49
+
50
+ "$(OUTDIR)" :
51
+ if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
52
+
53
+ CPP=cl.exe
54
+ CPP_PROJ=/nologo /ML /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Fp"$(INTDIR)\libdecodeqr.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
55
+
56
+ .c{$(INTDIR)}.obj::
57
+ $(CPP) @<<
58
+ $(CPP_PROJ) $<
59
+ <<
60
+
61
+ .cpp{$(INTDIR)}.obj::
62
+ $(CPP) @<<
63
+ $(CPP_PROJ) $<
64
+ <<
65
+
66
+ .cxx{$(INTDIR)}.obj::
67
+ $(CPP) @<<
68
+ $(CPP_PROJ) $<
69
+ <<
70
+
71
+ .c{$(INTDIR)}.sbr::
72
+ $(CPP) @<<
73
+ $(CPP_PROJ) $<
74
+ <<
75
+
76
+ .cpp{$(INTDIR)}.sbr::
77
+ $(CPP) @<<
78
+ $(CPP_PROJ) $<
79
+ <<
80
+
81
+ .cxx{$(INTDIR)}.sbr::
82
+ $(CPP) @<<
83
+ $(CPP_PROJ) $<
84
+ <<
85
+
86
+ RSC=rc.exe
87
+ BSC32=bscmake.exe
88
+ BSC32_FLAGS=/nologo /o"$(OUTDIR)\libdecodeqr.bsc"
89
+ BSC32_SBRS= \
90
+
91
+ LIB32=link.exe -lib
92
+ LIB32_FLAGS=/nologo /out:"$(OUTDIR)\libdecodeqr.lib"
93
+ LIB32_OBJS= \
94
+ "$(INTDIR)\bitstream.obj" \
95
+ "$(INTDIR)\codedata.obj" \
96
+ "$(INTDIR)\container.obj" \
97
+ "$(INTDIR)\ecidecoder.obj" \
98
+ "$(INTDIR)\formatinfo.obj" \
99
+ "$(INTDIR)\galois.obj" \
100
+ "$(INTDIR)\imagereader.obj" \
101
+ "$(INTDIR)\libdecodeqr.obj"
102
+
103
+ "$(OUTDIR)\libdecodeqr.lib" : "$(OUTDIR)" $(DEF_FILE) $(LIB32_OBJS)
104
+ $(LIB32) @<<
105
+ $(LIB32_FLAGS) $(DEF_FLAGS) $(LIB32_OBJS)
106
+ <<
107
+
108
+ !ELSEIF "$(CFG)" == "libdecodeqr - Win32 Debug"
109
+
110
+ OUTDIR=.\Debug
111
+ INTDIR=.\Debug
112
+ # Begin Custom Macros
113
+ OutDir=.\Debug
114
+ # End Custom Macros
115
+
116
+ ALL : "$(OUTDIR)\libdecodeqr.lib"
117
+
118
+
119
+ CLEAN :
120
+ -@erase "$(INTDIR)\bitstream.obj"
121
+ -@erase "$(INTDIR)\codedata.obj"
122
+ -@erase "$(INTDIR)\container.obj"
123
+ -@erase "$(INTDIR)\ecidecoder.obj"
124
+ -@erase "$(INTDIR)\formatinfo.obj"
125
+ -@erase "$(INTDIR)\galois.obj"
126
+ -@erase "$(INTDIR)\imagereader.obj"
127
+ -@erase "$(INTDIR)\libdecodeqr.obj"
128
+ -@erase "$(INTDIR)\vc60.idb"
129
+ -@erase "$(INTDIR)\vc60.pdb"
130
+ -@erase "$(OUTDIR)\libdecodeqr.lib"
131
+
132
+ "$(OUTDIR)" :
133
+ if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
134
+
135
+ CPP=cl.exe
136
+ CPP_PROJ=/nologo /MLd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /Fp"$(INTDIR)\libdecodeqr.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /GZ /c
137
+
138
+ .c{$(INTDIR)}.obj::
139
+ $(CPP) @<<
140
+ $(CPP_PROJ) $<
141
+ <<
142
+
143
+ .cpp{$(INTDIR)}.obj::
144
+ $(CPP) @<<
145
+ $(CPP_PROJ) $<
146
+ <<
147
+
148
+ .cxx{$(INTDIR)}.obj::
149
+ $(CPP) @<<
150
+ $(CPP_PROJ) $<
151
+ <<
152
+
153
+ .c{$(INTDIR)}.sbr::
154
+ $(CPP) @<<
155
+ $(CPP_PROJ) $<
156
+ <<
157
+
158
+ .cpp{$(INTDIR)}.sbr::
159
+ $(CPP) @<<
160
+ $(CPP_PROJ) $<
161
+ <<
162
+
163
+ .cxx{$(INTDIR)}.sbr::
164
+ $(CPP) @<<
165
+ $(CPP_PROJ) $<
166
+ <<
167
+
168
+ RSC=rc.exe
169
+ BSC32=bscmake.exe
170
+ BSC32_FLAGS=/nologo /o"$(OUTDIR)\libdecodeqr.bsc"
171
+ BSC32_SBRS= \
172
+
173
+ LIB32=link.exe -lib
174
+ LIB32_FLAGS=/nologo /out:"$(OUTDIR)\libdecodeqr.lib"
175
+ LIB32_OBJS= \
176
+ "$(INTDIR)\bitstream.obj" \
177
+ "$(INTDIR)\codedata.obj" \
178
+ "$(INTDIR)\container.obj" \
179
+ "$(INTDIR)\ecidecoder.obj" \
180
+ "$(INTDIR)\formatinfo.obj" \
181
+ "$(INTDIR)\galois.obj" \
182
+ "$(INTDIR)\imagereader.obj" \
183
+ "$(INTDIR)\libdecodeqr.obj"
184
+
185
+ "$(OUTDIR)\libdecodeqr.lib" : "$(OUTDIR)" $(DEF_FILE) $(LIB32_OBJS)
186
+ $(LIB32) @<<
187
+ $(LIB32_FLAGS) $(DEF_FLAGS) $(LIB32_OBJS)
188
+ <<
189
+
190
+ !ENDIF
191
+
192
+
193
+ !IF "$(NO_EXTERNAL_DEPS)" != "1"
194
+ !IF EXISTS("libdecodeqr.dep")
195
+ !INCLUDE "libdecodeqr.dep"
196
+ !ELSE
197
+ !MESSAGE Warning: cannot find "libdecodeqr.dep"
198
+ !ENDIF
199
+ !ENDIF
200
+
201
+
202
+ !IF "$(CFG)" == "libdecodeqr - Win32 Release" || "$(CFG)" == "libdecodeqr - Win32 Debug"
203
+ SOURCE=.\bitstream.cpp
204
+
205
+ "$(INTDIR)\bitstream.obj" : $(SOURCE) "$(INTDIR)"
206
+
207
+
208
+ SOURCE=.\codedata.cpp
209
+
210
+ "$(INTDIR)\codedata.obj" : $(SOURCE) "$(INTDIR)"
211
+
212
+
213
+ SOURCE=.\container.cpp
214
+
215
+ "$(INTDIR)\container.obj" : $(SOURCE) "$(INTDIR)"
216
+
217
+
218
+ SOURCE=.\ecidecoder.cpp
219
+
220
+ "$(INTDIR)\ecidecoder.obj" : $(SOURCE) "$(INTDIR)"
221
+
222
+
223
+ SOURCE=.\formatinfo.cpp
224
+
225
+ "$(INTDIR)\formatinfo.obj" : $(SOURCE) "$(INTDIR)"
226
+
227
+
228
+ SOURCE=.\galois.cpp
229
+
230
+ "$(INTDIR)\galois.obj" : $(SOURCE) "$(INTDIR)"
231
+
232
+
233
+ SOURCE=.\imagereader.cpp
234
+
235
+ "$(INTDIR)\imagereader.obj" : $(SOURCE) "$(INTDIR)"
236
+
237
+
238
+ SOURCE=.\libdecodeqr.cpp
239
+
240
+ "$(INTDIR)\libdecodeqr.obj" : $(SOURCE) "$(INTDIR)"
241
+
242
+
243
+
244
+ !ENDIF
245
+
@@ -0,0 +1,40 @@
1
+ /////////////////////////////////////////////////////////////////////////
2
+ //
3
+ // qrerror.h --a part of libdecodeqr
4
+ //
5
+ // Copyright(C) 2007 NISHI Takao <zophos@koka-in.org>
6
+ // JMA (Japan Medical Association)
7
+ // NaCl (Network Applied Communication Laboratory Ltd.)
8
+ //
9
+ // This is free software with ABSOLUTELY NO WARRANTY.
10
+ // You can redistribute and/or modify it under the terms of LGPL.
11
+ //
12
+ // $Id: qrerror.h 36 2007-02-21 23:22:03Z zophos $
13
+ //
14
+ #ifndef __QR_ERROR_CODE__
15
+ #define __QR_ERROR_CODE__
16
+
17
+ #define QR_IMAGEREADER_WORKING 0x1000
18
+ #define QR_IMAGEREADER_DECODED 0x2000
19
+
20
+ #define QR_VERSIONINFO_ERROR 0x0f00
21
+ #define QR_VERSIONINFO_INVALID 0x0100
22
+ #define QR_VERSIONINFO_MISMATCH 0x0200
23
+ #define QR_VERSIONINFO_UNRECOVERABLE 0x0800
24
+
25
+ #define QR_FORMATINFO_ERROR 0x00f0
26
+ #define QR_FORMATINFO_INVALID_LEVEL 0x0010
27
+ #define QR_FORMATINFO_UNRECOVERABLE 0x0080
28
+
29
+ #define QR_CODEDATA_ERROR 0x000f
30
+ #define QR_CODEDATA_NOT_SUPPORT_ECI 0x0001
31
+ #define QR_CODEDATA_LENGTH_MISMATCH 0x0002
32
+ #define QR_CODEDATA_UNRECOVERABLE 0x0008
33
+
34
+ #define QR_IMAGEREADER_ERROR 0x4000
35
+ #define QR_IMAGEREADER_NOT_INVALID_SRC_IMAGE 0x0100
36
+ #define QR_IMAGEREADER_NOT_FOUND_FINDER_PATTERN 0x0200
37
+ #define QR_IMAGEREADER_NOT_FOUND_CODE_AREA 0x0400
38
+ #define QR_IMAGEREADER_NOT_DETERMINABLE_CODE_AREA 0x0800
39
+
40
+ #endif
@@ -0,0 +1,17 @@
1
+ #include <qrtools.h>
2
+
3
+ VALUE mQRTools;
4
+
5
+ void Init_qrtools()
6
+ {
7
+ VALUE qrtools = rb_define_module("QRTools");
8
+ mQRTools = qrtools;
9
+
10
+ init_qrtools_image();
11
+ init_qrtools_decoder();
12
+ init_qrtools_header();
13
+ init_qrtools_ui_camera();
14
+ init_qrtools_ui_window();
15
+ init_qrtools_encoder();
16
+ init_qrtools_qrcode();
17
+ }
@@ -0,0 +1,21 @@
1
+ #ifndef QRTOOLS_QRTOOLS
2
+ #define QRTOOLS_QRTOOLS
3
+
4
+ #include <stdlib.h>
5
+ #include <stdio.h>
6
+ #include <ruby.h>
7
+ #include <decodeqr.h>
8
+ #include <qrencode.h>
9
+ #include <highgui.h>
10
+
11
+ #include <qrtools_image.h>
12
+ #include <qrtools_decoder.h>
13
+ #include <qrtools_header.h>
14
+ #include <qrtools_ui_camera.h>
15
+ #include <qrtools_ui_window.h>
16
+ #include <qrtools_encoder.h>
17
+ #include <qrtools_qrcode.h>
18
+
19
+ extern VALUE mQRTools;
20
+
21
+ #endif
@@ -0,0 +1,123 @@
1
+ #include <qrtools_decoder.h>
2
+
3
+ static VALUE new(VALUE klass, VALUE image)
4
+ {
5
+ QrDecoderHandle decoder = qr_decoder_open();
6
+
7
+ IplImage * src;
8
+ Data_Get_Struct(image, IplImage, src);
9
+ qr_decoder_set_image_buffer(decoder, src);
10
+
11
+ VALUE self = Data_Wrap_Struct(klass, NULL, qr_decoder_close, decoder);
12
+ return self;
13
+ }
14
+
15
+ static VALUE native_decode(VALUE self, VALUE size, VALUE delta)
16
+ {
17
+ QrDecoderHandle decoder;
18
+
19
+ Data_Get_Struct(self, struct QrDecoderHandle, decoder);
20
+ short stat = qr_decoder_decode(decoder, NUM2INT(size), NUM2INT(delta));
21
+
22
+ if((stat & QR_IMAGEREADER_DECODED) == QR_IMAGEREADER_DECODED)
23
+ return Qtrue;
24
+
25
+ return Qfalse;
26
+ }
27
+
28
+ static VALUE header(VALUE self)
29
+ {
30
+ QrCodeHeader * header = calloc(1, sizeof(QrCodeHeader));
31
+ QrDecoderHandle decoder;
32
+
33
+ Data_Get_Struct(self, struct QrDecoderHandle, decoder);
34
+
35
+ qr_decoder_get_header(decoder, header);
36
+
37
+ if(header)
38
+ return Data_Wrap_Struct(cQRToolsHeader, NULL, free, header);
39
+
40
+ free(header);
41
+ return Qnil;
42
+ }
43
+
44
+ static VALUE body(VALUE self)
45
+ {
46
+ QrDecoderHandle decoder;
47
+ QrCodeHeader * head;
48
+
49
+ VALUE _header = rb_funcall(self, rb_intern("header"), 0);
50
+ if(Qnil == _header) return Qnil;
51
+
52
+ Data_Get_Struct(self, struct QrDecoderHandle, decoder);
53
+ Data_Get_Struct(_header, QrCodeHeader, head);
54
+
55
+ char *buf = calloc(head->byte_size + 1, sizeof(char));
56
+ VALUE b = Qnil;
57
+
58
+ if(qr_decoder_get_body(decoder, (unsigned char *)buf, head->byte_size + 1))
59
+ b = rb_str_new(buf, head->byte_size);
60
+
61
+ free(buf);
62
+ return b;
63
+ }
64
+
65
+ static VALUE set_image(VALUE self, VALUE image)
66
+ {
67
+ QrDecoderHandle decoder;
68
+ Data_Get_Struct(self, struct QrDecoderHandle, decoder);
69
+
70
+ IplImage * src;
71
+ Data_Get_Struct(image, IplImage, src);
72
+ qr_decoder_set_image_buffer(decoder, src);
73
+
74
+ return self;
75
+ }
76
+
77
+ static VALUE binarized_image(VALUE self)
78
+ {
79
+ QrDecoderHandle decoder;
80
+ Data_Get_Struct(self, struct QrDecoderHandle, decoder);
81
+
82
+ IplImage * bin = cvCloneImage(qr_decoder_get_binarized_image_buffer(decoder));
83
+
84
+ return QRTools_Wrap_Image(bin);
85
+ }
86
+
87
+ static VALUE coderegion_vertexes(VALUE self)
88
+ {
89
+ QrDecoderHandle decoder;
90
+ Data_Get_Struct(self, struct QrDecoderHandle, decoder);
91
+
92
+ CvPoint *vertexes = qr_decoder_get_coderegion_vertexes(decoder);
93
+ VALUE cPoint = rb_const_get(cQRToolsImage, rb_intern("Point"));
94
+
95
+ VALUE list = rb_ary_new();
96
+ int i = 0;
97
+ for(i = 0; i < 4; i++) {
98
+ CvPoint p = vertexes[i];
99
+ VALUE point = rb_funcall(cPoint, rb_intern("new"), 2, INT2NUM(p.x), INT2NUM(p.y));
100
+ rb_ary_push(list, point);
101
+ }
102
+
103
+ return list;
104
+ }
105
+
106
+ VALUE cQRToolsDecoder;
107
+ void init_qrtools_decoder()
108
+ {
109
+ VALUE qrtools = rb_define_module("QRTools");
110
+ VALUE klass = rb_define_class_under(qrtools, "Decoder", rb_cObject);
111
+
112
+ cQRToolsDecoder = klass;
113
+
114
+ rb_define_singleton_method(klass, "new", new, 1);
115
+
116
+ rb_define_private_method(klass, "native_decode", native_decode, 2);
117
+
118
+ rb_define_method(klass, "header", header, 0);
119
+ rb_define_method(klass, "body", body, 0);
120
+ rb_define_method(klass, "image=", set_image, 1);
121
+ rb_define_method(klass, "binarized_image", binarized_image, 0);
122
+ rb_define_method(klass, "coderegion_vertexes", coderegion_vertexes, 0);
123
+ }