qrtools 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,6 @@
1
+ === 1.0.0 / 2009-02-11
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,65 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/qrdecode
6
+ ext/qrtools/Makefile.in
7
+ ext/qrtools/bitstream.cpp
8
+ ext/qrtools/bitstream.h
9
+ ext/qrtools/codedata.cpp
10
+ ext/qrtools/codedata.h
11
+ ext/qrtools/container.cpp
12
+ ext/qrtools/container.h
13
+ ext/qrtools/decodeqr.h
14
+ ext/qrtools/ecidecoder.cpp
15
+ ext/qrtools/ecidecoder.h
16
+ ext/qrtools/extconf.rb
17
+ ext/qrtools/formatinfo.cpp
18
+ ext/qrtools/formatinfo.h
19
+ ext/qrtools/galois.cpp
20
+ ext/qrtools/galois.h
21
+ ext/qrtools/imagereader.cpp
22
+ ext/qrtools/imagereader.h
23
+ ext/qrtools/libdecodeqr.cpp
24
+ ext/qrtools/libdecodeqr.dep
25
+ ext/qrtools/libdecodeqr.dsp
26
+ ext/qrtools/libdecodeqr.dsw
27
+ ext/qrtools/libdecodeqr.mak
28
+ ext/qrtools/qrerror.h
29
+ ext/qrtools/qrtools.c
30
+ ext/qrtools/qrtools.h
31
+ ext/qrtools/qrtools_decoder.c
32
+ ext/qrtools/qrtools_decoder.h
33
+ ext/qrtools/qrtools_encoder.c
34
+ ext/qrtools/qrtools_encoder.h
35
+ ext/qrtools/qrtools_header.c
36
+ ext/qrtools/qrtools_header.h
37
+ ext/qrtools/qrtools_image.c
38
+ ext/qrtools/qrtools_image.h
39
+ ext/qrtools/qrtools_qrcode.c
40
+ ext/qrtools/qrtools_qrcode.h
41
+ ext/qrtools/qrtools_ui_camera.c
42
+ ext/qrtools/qrtools_ui_camera.h
43
+ ext/qrtools/qrtools_ui_window.c
44
+ ext/qrtools/qrtools_ui_window.h
45
+ ext/qrtools/qrtypes.h
46
+ ext/qrtools/version.h
47
+ lib/qrtools.rb
48
+ lib/qrtools/decoder.rb
49
+ lib/qrtools/encoder.rb
50
+ lib/qrtools/image.rb
51
+ lib/qrtools/qrcode.rb
52
+ lib/qrtools/ui/camera.rb
53
+ lib/qrtools/ui/window.rb
54
+ lib/qrtools/version.rb
55
+ qrtools.gemspec
56
+ test/assets/01-1.jpg
57
+ test/helper.rb
58
+ test/test_decoder.rb
59
+ test/test_encoder.rb
60
+ test/test_header.rb
61
+ test/test_image.rb
62
+ test/test_qrcode.rb
63
+ test/test_qrdecode.rb
64
+ test/ui/test_camera.rb
65
+ test/ui/test_window.rb
@@ -0,0 +1,75 @@
1
+ = QRTools
2
+
3
+ * http://qrtools.rubyforge.org/
4
+
5
+ == DESCRIPTION:
6
+
7
+ QRTools is a library for decoding QR Codes. It relies on
8
+ libdecodeqr for decoding.
9
+
10
+ == FEATURES/PROBLEMS:
11
+
12
+ * Running the tests will take a picture of you.
13
+ * Currently awesome.
14
+
15
+ == SYNOPSIS:
16
+
17
+ ###
18
+ # Encode a QR code
19
+ require 'qrtools'
20
+ require 'tempfile'
21
+
22
+ filename = File.join(Dir::tmpdir, 'test.png')
23
+ File.open(filename, 'wb') { |fh|
24
+ fh.write QRTools::QRCode.encode('http://tenderlovemaking.com/').to_png
25
+ }
26
+
27
+ ###
28
+ # Decode A QR code from a file
29
+ img = QRTools::Image.load(filename)
30
+ decoder = QRTools::QRCode.decode(img)
31
+ puts decoder.body
32
+
33
+ ###
34
+ # Decode a photo from the webcam
35
+ QRTools::UI::Camera.new(0) do |camera|
36
+ puts QRTools::QRCode.decode(camera.capture).body
37
+ end
38
+
39
+ == REQUIREMENTS:
40
+
41
+ * opencv
42
+
43
+ == INSTALL:
44
+
45
+ On OS X:
46
+
47
+ * port install opencv qrencode
48
+ * gem install qrtools
49
+
50
+ == LICENSE:
51
+
52
+ (The MIT License)
53
+
54
+ Copyright (c) 2009:
55
+
56
+ * {Aaron Patterson}[http://tenderlovemaking.com]
57
+
58
+ Permission is hereby granted, free of charge, to any person obtaining
59
+ a copy of this software and associated documentation files (the
60
+ 'Software'), to deal in the Software without restriction, including
61
+ without limitation the rights to use, copy, modify, merge, publish,
62
+ distribute, sublicense, and/or sell copies of the Software, and to
63
+ permit persons to whom the Software is furnished to do so, subject to
64
+ the following conditions:
65
+
66
+ The above copyright notice and this permission notice shall be
67
+ included in all copies or substantial portions of the Software.
68
+
69
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
70
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
71
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
72
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
73
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
74
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
75
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,49 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ kind = Config::CONFIG['DLEXT']
7
+ windows = RUBY_PLATFORM =~ /mswin/i ? true : false
8
+
9
+ EXT = "ext/qrtools/qrtools.#{kind}"
10
+
11
+ require './lib/qrtools/version'
12
+
13
+ HOE = Hoe.new('qrtools', QRTools::VERSION) do |p|
14
+ p.developer('Aaron Patterson', 'aaronp@rubyforge.org')
15
+ p.clean_globs = [
16
+ 'ext/qrtools/Makefile',
17
+ 'ext/qrtools/*.{o,so,bundle,a,log,dll}',
18
+ 'ext/qrtools/conftest.dSYM',
19
+ ]
20
+ p.spec_extras = { :extensions => ["ext/qrtools/extconf.rb"] }
21
+ end
22
+
23
+ task 'ext/qrtools/Makefile' do
24
+ Dir.chdir('ext/qrtools') do
25
+ ruby "extconf.rb #{ENV['EXTOPTS']}"
26
+ end
27
+ end
28
+
29
+ task EXT => 'ext/qrtools/Makefile' do
30
+ Dir.chdir('ext/qrtools') do
31
+ sh 'make'
32
+ end
33
+ end
34
+ task :build => [EXT]
35
+
36
+ Rake::Task['test'].prerequisites << :build
37
+
38
+ namespace :gem do
39
+ namespace :dev do
40
+ task :spec do
41
+ File.open("#{HOE.name}.gemspec", 'w') do |f|
42
+ HOE.spec.version = "#{HOE.version}.#{Time.now.strftime("%Y%m%d%H%M%S")}"
43
+ f.write(HOE.spec.to_ruby)
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ # vim: syntax=Ruby
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby -w
2
+
3
+ require 'rubygems'
4
+ require 'qrtools'
5
+
6
+ img = QRTools::Image.load(ARGV[0])
7
+ 25.step(3, -2) { |i|
8
+ 10.step(0, -1) { |j|
9
+ body = QRTools::Decoder.decode(img, i, j).body
10
+ next unless body
11
+ puts body
12
+ exit
13
+ }
14
+ }
@@ -0,0 +1,65 @@
1
+ #
2
+ # Makefile.in -- a part of libdecodeqr
3
+ #
4
+ # Copyright(C) 2007 NISHI Takao <zophos@koka-in.org>
5
+ # JMA (Japan Medical Association)
6
+ # NaCl (Network Applied Communication Laboratory Ltd.)
7
+ #
8
+ # This is free software with ABSOLUTELY NO WARRANTY.
9
+ # You can redistribute and/or modify it under the terms of LGPL.
10
+ #
11
+ # $Id: Makefile 20 2006-11-20 03:26:52Z zophos $
12
+ #
13
+ prefix = @prefix@
14
+ exec_prefix = @exec_prefix@
15
+ libdir = @libdir@
16
+ includedir = @includedir@
17
+
18
+ MAJOR=@MAJOR@
19
+ MINOR=@MINOR@
20
+ TEENY=@TEENY@
21
+
22
+ BASENAME=libdecodeqr
23
+ LIBNAME_A=$(BASENAME).a
24
+ SONAME=$(BASENAME).so.$(MAJOR)
25
+ LIBNAME_SO=$(BASENAME).so.$(MAJOR).$(MINOR).$(TEENY)
26
+
27
+ CXX=@CXX@
28
+ CPPFLAGS=@CPPFLAGS@ @CXXFLAGS@ -fPIC -c
29
+
30
+ AR=@AR@
31
+ ARFLAGS=rcs
32
+
33
+ LD=@LD@
34
+ LDFLAGS=@LDFLAGS@ -shared -soname $(SONAME)
35
+ LIBCV=@LIBCV@
36
+ LIBS=$(LIBCV)
37
+
38
+ INSTALL=@INSTALL@
39
+ LDCONFIG=/sbin/ldconfig
40
+ LN=@LN@
41
+
42
+ .SUFFIXES: .cpp .o
43
+ .cpp.o:
44
+ $(CXX) $(CPPFLAGS) $<
45
+
46
+ sources:=$(wildcard *.cpp)
47
+ objs:=$(patsubst %.cpp,%.o,$(wildcard *.cpp))
48
+ dsts:=$(LIBNAME_A) $(LIBNAME_SO) decodeqr.h
49
+
50
+ all: $(dsts)
51
+
52
+ $(LIBNAME_A): $(objs)
53
+ $(AR) $(ARFLAGS) $@ $(objs)
54
+
55
+ $(LIBNAME_SO): $(objs)
56
+ $(LD) -o $@ $(objs) $(LDFLAGS) $(LIBS)
57
+
58
+ install: $(dsts)
59
+ $(INSTALL) -m 0755 $(LIBNAME_A) $(LIBNAME_SO) $(libdir)
60
+ $(LDCONFIG) -n $(libdir)
61
+ $(LN) -sf $(libdir)/$(LIBNAME_SO) $(libdir)/$(BASENAME).so
62
+ $(INSTALL) -m 0644 decodeqr.h qrerror.h qrtypes.h $(includedir)
63
+
64
+ clean:
65
+ -rm *.a *.o *.so.*
@@ -0,0 +1,147 @@
1
+ /////////////////////////////////////////////////////////////////////////
2
+ //
3
+ // bitstream.cpp --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: bitstream.cpp 36 2007-02-21 23:22:03Z zophos $
13
+ //
14
+ #include "bitstream.h"
15
+
16
+ namespace Qr{
17
+ BitStream::BitStream()
18
+ {
19
+ this->data=NULL;
20
+ this->byte_size=0;
21
+ this->bit_size=0;
22
+ this->_pos=0;
23
+ }
24
+ BitStream::BitStream(void *src,int size)
25
+ {
26
+ this->byte_size=size;
27
+ this->bit_size=size<<3;
28
+ this->data=new unsigned char[size];
29
+ memcpy(this->data,src,size);
30
+ this->_pos=0;
31
+ }
32
+ BitStream::~BitStream()
33
+ {
34
+ if(this->data)
35
+ delete this->data;
36
+ }
37
+
38
+ bool BitStream::is_eod()
39
+ {
40
+ return(this->_pos>=this->bit_size);
41
+ }
42
+ int BitStream::position()
43
+ {
44
+ return(this->_pos);
45
+ }
46
+ int BitStream::seek(int pos)
47
+ {
48
+ this->_pos+=pos;
49
+ if(this->_pos<0)
50
+ this->_pos=0;
51
+ if(this->_pos>this->bit_size)
52
+ this->_pos=this->bit_size;
53
+
54
+ return(this->_pos);
55
+ }
56
+ void BitStream::rewind()
57
+ {
58
+ this->_pos=0;
59
+ }
60
+
61
+ unsigned char *BitStream::read(int read_bits)
62
+ {
63
+ int byte_size=(read_bits>>3)+(read_bits&0x07?1:0);
64
+ unsigned char *buf=new unsigned char[byte_size];
65
+ memset(buf,0,byte_size);
66
+
67
+ this->read(buf,byte_size,read_bits);
68
+
69
+ return(buf);
70
+ }
71
+ int BitStream::read(void *dst,int buf_size,int read_bits)
72
+ {
73
+ memset(dst,0,buf_size);
74
+
75
+ if(read_bits>(buf_size<<3))
76
+ read_bits=buf_size<<3;
77
+
78
+ int end_bit=this->_pos+read_bits-1;
79
+ if(end_bit>=this->bit_size){
80
+ end_bit=this->bit_size-1;
81
+ read_bits=this->bit_size-this->_pos;
82
+ }
83
+ int remain_bits=(end_bit+1)&0x07;
84
+ int offset=this->_pos>>3;
85
+ int read_bytes=(read_bits>>3)+(read_bits&0x07?1:0);
86
+
87
+ if(read_bytes<buf_size){
88
+ int diff=buf_size-read_bytes;
89
+ unsigned char *tmp=(unsigned char *)dst;
90
+ tmp+=diff;
91
+ dst=tmp;
92
+ }
93
+
94
+ if(remain_bits){
95
+ unsigned char *src=data+offset;
96
+ unsigned char *tmp=(unsigned char *)dst;
97
+
98
+ int i=0;
99
+ if(read_bytes==(end_bit>>3)-offset+1){
100
+ tmp++;
101
+ i++;
102
+ }
103
+ for(;i<read_bytes;i++,src++,tmp++){
104
+ *tmp=*src<<remain_bits;
105
+ }
106
+ remain_bits=8-remain_bits;
107
+ src=data+(end_bit>>3);
108
+ tmp--;
109
+ for(i=0;i<read_bytes;i++,src--,tmp--){
110
+ *tmp|=*src>>remain_bits;
111
+ }
112
+ }
113
+ else{
114
+ memcpy(dst,this->data+offset,read_bytes);
115
+ }
116
+
117
+ unsigned char mask=0xff;
118
+ switch(8-(read_bits&0x07)){
119
+ case 1:
120
+ mask=0x7f;
121
+ break;
122
+ case 2:
123
+ mask=0x3f;
124
+ break;
125
+ case 3:
126
+ mask=0x1f;
127
+ break;
128
+ case 4:
129
+ mask=0x0f;
130
+ break;
131
+ case 5:
132
+ mask=0x07;
133
+ break;
134
+ case 6:
135
+ mask=0x03;
136
+ break;
137
+ case 7:
138
+ mask=0x01;
139
+ break;
140
+ }
141
+ *((unsigned char *)dst)&=mask;
142
+ this->_pos+=read_bits;
143
+
144
+ return(read_bits);
145
+ }
146
+
147
+ }
@@ -0,0 +1,48 @@
1
+ /////////////////////////////////////////////////////////////////////////
2
+ //
3
+ // bitstream.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: bitstream.h 36 2007-02-21 23:22:03Z zophos $
13
+ //
14
+ #ifndef __QR_BITSTREAM__
15
+ #define __QR_BITSTREAM__
16
+
17
+ #include <memory.h>
18
+
19
+ #ifndef NULL
20
+ #define NULL 0
21
+ #endif
22
+
23
+ namespace Qr{
24
+ class BitStream{
25
+ public:
26
+ unsigned char *data;
27
+ int byte_size;
28
+ int bit_size;
29
+
30
+ private:
31
+ int _pos;
32
+
33
+ public:
34
+ BitStream();
35
+ BitStream(void *src,int size);
36
+ ~BitStream();
37
+
38
+ bool is_eod();
39
+ int position();
40
+ int seek(int pos);
41
+ void rewind();
42
+
43
+ unsigned char *read(int read_bits);
44
+ int read(void *dst,int buf_size,int bitsize);
45
+ };
46
+ };
47
+
48
+ #endif