data_matrix 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/.rubocop.yml +6 -0
- data/.travis.yml +5 -0
- data/Gemfile +5 -0
- data/README.md +36 -0
- data/Rakefile +13 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/data_matrix.gemspec +42 -0
- data/ext/data_matrix/data_matrix.c +206 -0
- data/ext/data_matrix/data_matrix.h +21 -0
- data/ext/data_matrix/extconf.rb +4 -0
- data/ext/data_matrix/iec16022ecc200.c +847 -0
- data/ext/data_matrix/iec16022ecc200.h +36 -0
- data/ext/data_matrix/reedsol.c +122 -0
- data/ext/data_matrix/reedsol.h +10 -0
- data/lib/data_matrix.rb +8 -0
- data/lib/data_matrix/encoder.rb +19 -0
- data/lib/data_matrix/version.rb +4 -0
- data/lib/semacode.rb +3 -0
- metadata +144 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
// IEC16022 bar code generation library
|
2
|
+
// Adrian Kennard, Andrews & Arnold Ltd
|
3
|
+
// with help from Cliff Hones on the RS coding
|
4
|
+
//
|
5
|
+
// Revision 1.3 2004/09/09 07:45:09 cvs
|
6
|
+
// Added change history to source files
|
7
|
+
// Added "info" type to IEC16022
|
8
|
+
// Added exact size checking shortcodes on encoding generation for iec16022
|
9
|
+
//
|
10
|
+
|
11
|
+
// Main encoding function
|
12
|
+
// Returns the grid (malloced) containing the matrix. L corner at 0,0.
|
13
|
+
// Takes suggested size in *Wptr, *Hptr, or 0,0. Fills in actual size.
|
14
|
+
// Takes barcodelen and barcode to be encoded
|
15
|
+
// Note, if *encodingptr is null, then fills with auto picked (malloced) encoding
|
16
|
+
// If lenp not null, then the length of encoded data before any final unlatch or pad is stored
|
17
|
+
// If maxp not null, then the max storage of this size code is stored
|
18
|
+
// If eccp not null, then the number of ecc bytes used in this size is stored
|
19
|
+
// Returns 0 on error (writes to stderr with details).
|
20
|
+
|
21
|
+
#ifndef IEC16022ECC200_H
|
22
|
+
#define IEC16022ECC200_H 1
|
23
|
+
|
24
|
+
#define IEC16022ECC200_MAXBARCODE 3116
|
25
|
+
#define IEC16022ECC200_ERROR_STRING_TOO_SHORT -1
|
26
|
+
#define IEC16022ECC200_ERROR_CANNOT_ENCODE_CHARACTER_X12 -2
|
27
|
+
#define IEC16022ECC200_ERROR_UNEXPECTED_FAILURE -3
|
28
|
+
#define IEC16022ECC200_ERROR_UNKNOWN_ENCODING -4
|
29
|
+
#define IEC16022ECC200_ERROR_DID_NOT_FIT -5
|
30
|
+
#define IEC16022ECC200_BARCODE_TOO_LONG -6
|
31
|
+
|
32
|
+
unsigned char* iec16022ecc200(int *Wptr, int *Hptr, char **encodingptr, const int barcodelen, const unsigned char *barcode,
|
33
|
+
int *lenp,int *maxp,int *eccp);
|
34
|
+
void iec16022init(int *Wptr, int *Hptr, const char *barcode);
|
35
|
+
|
36
|
+
#endif
|
@@ -0,0 +1,122 @@
|
|
1
|
+
// reedsol.c
|
2
|
+
//
|
3
|
+
// This is a simple Reed-Solomon encoder
|
4
|
+
// (C) Cliff Hones 2004
|
5
|
+
//
|
6
|
+
// It is not written with high efficiency in mind, so is probably
|
7
|
+
// not suitable for real-time encoding. The aim was to keep it
|
8
|
+
// simple, general and clear.
|
9
|
+
//
|
10
|
+
// <Some notes on the theory and implementation need to be added here>
|
11
|
+
|
12
|
+
// Usage:
|
13
|
+
// First call rs_init_gf(poly) to set up the Galois Field parameters.
|
14
|
+
// Then call rs_init_code(size, index) to set the encoding size
|
15
|
+
// Then call rs_encode(datasize, data, out) to encode the data.
|
16
|
+
//
|
17
|
+
// These can be called repeatedly as required - but note that
|
18
|
+
// rs_init_code must be called following any rs_init_gf call.
|
19
|
+
//
|
20
|
+
// If the parameters are fixed, some of the statics below can be
|
21
|
+
// replaced with constants in the obvious way, and additionally
|
22
|
+
// malloc/free can be avoided by using static arrays of a suitable
|
23
|
+
// size.
|
24
|
+
|
25
|
+
#include <stdlib.h> // only needed for malloc/free
|
26
|
+
|
27
|
+
static int gfpoly;
|
28
|
+
static int symsize; // in bits
|
29
|
+
static int logmod; // 2**symsize - 1
|
30
|
+
static int rlen;
|
31
|
+
|
32
|
+
static int *log = NULL, *alog = NULL, *rspoly = NULL;
|
33
|
+
|
34
|
+
// rs_init_gf(poly) initialises the parameters for the Galois Field.
|
35
|
+
// The symbol size is determined from the highest bit set in poly
|
36
|
+
// This implementation will support sizes up to 30 bits (though that
|
37
|
+
// will result in very large log/antilog tables) - bit sizes of
|
38
|
+
// 8 or 4 are typical
|
39
|
+
//
|
40
|
+
// The poly is the bit pattern representing the GF characteristic
|
41
|
+
// polynomial. e.g. for ECC200 (8-bit symbols) the polynomial is
|
42
|
+
// a**8 + a**5 + a**3 + a**2 + 1, which translates to 0x12d.
|
43
|
+
|
44
|
+
void rs_init_gf (int poly) {
|
45
|
+
int m, b, p, v;
|
46
|
+
// Return storage from previous setup
|
47
|
+
if (log) {
|
48
|
+
free(log);
|
49
|
+
free(alog);
|
50
|
+
free(rspoly);
|
51
|
+
rspoly = NULL;
|
52
|
+
}
|
53
|
+
// Find the top bit, and hence the symbol size
|
54
|
+
for (b = 1, m = 0; b <= poly; b <<= 1)
|
55
|
+
m++;
|
56
|
+
b >>= 1;
|
57
|
+
m--;
|
58
|
+
gfpoly = poly;
|
59
|
+
symsize = m;
|
60
|
+
// Calculate the log/alog tables
|
61
|
+
logmod = (1 << m) - 1;
|
62
|
+
log = (int *) malloc (sizeof (int) * (logmod + 1));
|
63
|
+
alog = (int *) malloc (sizeof (int) * logmod);
|
64
|
+
|
65
|
+
for (p = 1, v = 0; v < logmod; v++) {
|
66
|
+
alog[v] = p;
|
67
|
+
log[p] = v;
|
68
|
+
p <<= 1;
|
69
|
+
if (p & b)
|
70
|
+
p ^= poly;
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
// rs_init_code(nsym, index) initialises the Reed-Solomon encoder
|
75
|
+
// nsym is the number of symbols to be generated (to be appended
|
76
|
+
// to the input data). index is usually 1 - it is the index of
|
77
|
+
// the constant in the first term (i) of the RS generator polynomial:
|
78
|
+
// (x + 2**i)*(x + 2**(i+1))*... [nsym terms]
|
79
|
+
// For ECC200, index is 1.
|
80
|
+
|
81
|
+
void rs_init_code (int nsym, int index) {
|
82
|
+
int i, k;
|
83
|
+
if (rspoly)
|
84
|
+
free(rspoly);
|
85
|
+
rspoly = (int *) malloc(sizeof(int) * (nsym + 1));
|
86
|
+
rlen = nsym;
|
87
|
+
|
88
|
+
rspoly[0] = 1;
|
89
|
+
for (i = 1; i <= nsym; i++) {
|
90
|
+
rspoly[i] = 1;
|
91
|
+
for (k = i - 1; k > 0; k--) {
|
92
|
+
if (rspoly[k])
|
93
|
+
rspoly[k] = alog[(log[rspoly[k]] + index) % logmod];
|
94
|
+
rspoly[k] ^= rspoly[k - 1];
|
95
|
+
}
|
96
|
+
rspoly[0] = alog[(log[rspoly[0]] + index) % logmod];
|
97
|
+
index++;
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
101
|
+
// Note that the following uses byte arrays, so is only suitable for
|
102
|
+
// symbol sizes up to 8 bits. Just change the data type of data and res
|
103
|
+
// to unsigned int * for larger symbols.
|
104
|
+
|
105
|
+
void rs_encode (int len, unsigned char *data, unsigned char *res) {
|
106
|
+
int i, k, m;
|
107
|
+
for (i = 0; i < rlen; i++)
|
108
|
+
res[i] = 0;
|
109
|
+
for (i = 0; i < len; i++) {
|
110
|
+
m = res[rlen - 1] ^ data[i];
|
111
|
+
for (k = rlen - 1; k > 0; k--) {
|
112
|
+
if (m && rspoly[k])
|
113
|
+
res[k] = res[k - 1] ^ alog[(log[m] + log[rspoly[k]]) % logmod];
|
114
|
+
else
|
115
|
+
res[k] = res[k - 1];
|
116
|
+
}
|
117
|
+
if (m && rspoly[0])
|
118
|
+
res[0] = alog[(log[m] + log[rspoly[0]]) % logmod];
|
119
|
+
else
|
120
|
+
res[0] = 0;
|
121
|
+
}
|
122
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
#ifndef REEDSOL_H
|
2
|
+
#define REEDSOL_H 1
|
3
|
+
/* don't compile in the main function from reedsol.c */
|
4
|
+
#define LIB
|
5
|
+
|
6
|
+
void rs_init_gf(int poly);
|
7
|
+
void rs_init_code(int nsym, int index);
|
8
|
+
void rs_encode(int len, unsigned char *data, unsigned char *res);
|
9
|
+
|
10
|
+
#endif
|
data/lib/data_matrix.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Encoder ext ruby method aliases
|
3
|
+
module DataMatrix
|
4
|
+
# encoder class ruby extensions
|
5
|
+
class Encoder
|
6
|
+
alias to_str to_s
|
7
|
+
alias to_a data
|
8
|
+
|
9
|
+
def initialize(value)
|
10
|
+
raise ArgumentError, 'Value must be convertible to string' unless value.respond_to?(:to_s)
|
11
|
+
encode_string(value.to_s)
|
12
|
+
end
|
13
|
+
|
14
|
+
def length
|
15
|
+
height * width
|
16
|
+
end
|
17
|
+
alias size length
|
18
|
+
end
|
19
|
+
end
|
data/lib/semacode.rb
ADDED
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: data_matrix
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mikhail Bortnyk
|
8
|
+
- Guido Sohne
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2017-03-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.14'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.14'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rake-compiler
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '3.0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rubocop
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
description: |2
|
85
|
+
This Ruby extension implements a DataMatrix encoder for Ruby. It is typically
|
86
|
+
used to create semacodes, which are barcodes, that contain URLs. This encoder
|
87
|
+
does not create image files or visual representations of the semacode. This is
|
88
|
+
because it can be used for more than creating images, such as rendering
|
89
|
+
semacodes to HTML, SVG, PDF or even stored in a database or file for later
|
90
|
+
use.
|
91
|
+
email:
|
92
|
+
- vessimir@gmail.com
|
93
|
+
- guido@sohne.net
|
94
|
+
executables: []
|
95
|
+
extensions:
|
96
|
+
- ext/data_matrix/extconf.rb
|
97
|
+
extra_rdoc_files: []
|
98
|
+
files:
|
99
|
+
- ".gitignore"
|
100
|
+
- ".rspec"
|
101
|
+
- ".rubocop.yml"
|
102
|
+
- ".travis.yml"
|
103
|
+
- Gemfile
|
104
|
+
- README.md
|
105
|
+
- Rakefile
|
106
|
+
- bin/console
|
107
|
+
- bin/setup
|
108
|
+
- data_matrix.gemspec
|
109
|
+
- ext/data_matrix/data_matrix.c
|
110
|
+
- ext/data_matrix/data_matrix.h
|
111
|
+
- ext/data_matrix/extconf.rb
|
112
|
+
- ext/data_matrix/iec16022ecc200.c
|
113
|
+
- ext/data_matrix/iec16022ecc200.h
|
114
|
+
- ext/data_matrix/reedsol.c
|
115
|
+
- ext/data_matrix/reedsol.h
|
116
|
+
- lib/data_matrix.rb
|
117
|
+
- lib/data_matrix/encoder.rb
|
118
|
+
- lib/data_matrix/version.rb
|
119
|
+
- lib/semacode.rb
|
120
|
+
homepage: https://github.com/vessi/data_matrix
|
121
|
+
licenses: []
|
122
|
+
metadata:
|
123
|
+
allowed_push_host: https://rubygems.org
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.6.10
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: Create semacodes (2D barcodes) using Ruby.
|
144
|
+
test_files: []
|