quirc 0.0.2 → 0.1.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.
- checksums.yaml +5 -5
- data/LICENSE +1 -1
- data/ext/quirc/embed/lib/decode.c +11 -5
- data/ext/quirc/embed/lib/identify.c +5 -7
- data/ext/quirc/embed/lib/quirc.c +63 -14
- data/ext/quirc/embed/lib/quirc.h +1 -1
- data/ext/quirc/embed/lib/quirc_internal.h +1 -0
- data/lib/quirc/version.rb +1 -1
- data/test/helper.rb +4 -2
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b098fadcd265ce357ef81036d89dd0a2c260f6fbf050389243fd2853efdcf2d6
|
4
|
+
data.tar.gz: 8aeecc5d6ae1067f73df6352d8a27fbd5e6a3103d12a0cfde7aaa06bbc78d96c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 043eb2848bc2e10383a3815af8b867caf4bf90c923567942ad09664bbd0e0279cb7ca1bc7615cc859d2786b901559e4071dc20b7d2bbaa6b4815ce1244a1f1f9
|
7
|
+
data.tar.gz: 1912a957c0c56ffb6ad5714a0cdc13ac95c4c3cebefad94f00361afa614c53491954ce19f119ff5f33117b79d3645c45711213f89b7037a3e0de0f9078540237
|
data/LICENSE
CHANGED
@@ -117,7 +117,7 @@ static const uint8_t gf256_log[256] = {
|
|
117
117
|
0x74, 0xd6, 0xf4, 0xea, 0xa8, 0x50, 0x58, 0xaf
|
118
118
|
};
|
119
119
|
|
120
|
-
const
|
120
|
+
static const struct galois_field gf256 = {
|
121
121
|
.p = 255,
|
122
122
|
.log = gf256_log,
|
123
123
|
.exp = gf256_exp
|
@@ -790,12 +790,18 @@ static quirc_decode_error_t decode_kanji(struct quirc_data *data,
|
|
790
790
|
|
791
791
|
for (i = 0; i < count; i++) {
|
792
792
|
int d = take_bits(ds, 13);
|
793
|
+
int msB = d / 0xc0;
|
794
|
+
int lsB = d % 0xc0;
|
795
|
+
int intermediate = (msB << 8) | lsB;
|
793
796
|
uint16_t sjw;
|
794
797
|
|
795
|
-
if (
|
796
|
-
|
797
|
-
|
798
|
-
|
798
|
+
if (intermediate + 0x8140 <= 0x9ffc) {
|
799
|
+
/* bytes are in the range 0x8140 to 0x9FFC */
|
800
|
+
sjw = intermediate + 0x8140;
|
801
|
+
} else {
|
802
|
+
/* bytes are in the range 0xE040 to 0xEBBF */
|
803
|
+
sjw = intermediate + 0xc140;
|
804
|
+
}
|
799
805
|
|
800
806
|
data->payload[data->payload_len++] = sjw >> 8;
|
801
807
|
data->payload[data->payload_len++] = sjw & 0xff;
|
@@ -196,9 +196,7 @@ static void threshold(struct quirc *q)
|
|
196
196
|
threshold_s = THRESHOLD_S_MIN;
|
197
197
|
|
198
198
|
for (y = 0; y < q->h; y++) {
|
199
|
-
|
200
|
-
|
201
|
-
memset(row_average, 0, sizeof(row_average));
|
199
|
+
memset(q->row_average, 0, q->w * sizeof(int));
|
202
200
|
|
203
201
|
for (x = 0; x < q->w; x++) {
|
204
202
|
int w, u;
|
@@ -216,12 +214,12 @@ static void threshold(struct quirc *q)
|
|
216
214
|
avg_u = (avg_u * (threshold_s - 1)) /
|
217
215
|
threshold_s + row[u];
|
218
216
|
|
219
|
-
row_average[w] += avg_w;
|
220
|
-
row_average[u] += avg_u;
|
217
|
+
q->row_average[w] += avg_w;
|
218
|
+
q->row_average[u] += avg_u;
|
221
219
|
}
|
222
220
|
|
223
221
|
for (x = 0; x < q->w; x++) {
|
224
|
-
if (row[x] < row_average[x] *
|
222
|
+
if (row[x] < q->row_average[x] *
|
225
223
|
(100 - THRESHOLD_T) / (200 * threshold_s))
|
226
224
|
row[x] = QUIRC_PIXEL_BLACK;
|
227
225
|
else
|
@@ -427,7 +425,7 @@ static void finder_scan(struct quirc *q, int y)
|
|
427
425
|
{
|
428
426
|
quirc_pixel_t *row = q->pixels + y * q->w;
|
429
427
|
int x;
|
430
|
-
int last_color;
|
428
|
+
int last_color = 0;
|
431
429
|
int run_length = 0;
|
432
430
|
int run_count = 0;
|
433
431
|
int pb[5];
|
data/ext/quirc/embed/lib/quirc.c
CHANGED
@@ -36,34 +36,83 @@ struct quirc *quirc_new(void)
|
|
36
36
|
|
37
37
|
void quirc_destroy(struct quirc *q)
|
38
38
|
{
|
39
|
-
|
40
|
-
|
39
|
+
free(q->image);
|
40
|
+
/* q->pixels may alias q->image when their type representation is of the
|
41
|
+
same size, so we need to be careful here to avoid a double free */
|
41
42
|
if (sizeof(*q->image) != sizeof(*q->pixels))
|
42
43
|
free(q->pixels);
|
43
|
-
|
44
|
+
free(q->row_average);
|
44
45
|
free(q);
|
45
46
|
}
|
46
47
|
|
47
48
|
int quirc_resize(struct quirc *q, int w, int h)
|
48
49
|
{
|
49
|
-
uint8_t
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
uint8_t *image = NULL;
|
51
|
+
quirc_pixel_t *pixels = NULL;
|
52
|
+
int *row_average = NULL;
|
53
|
+
|
54
|
+
/*
|
55
|
+
* XXX: w and h should be size_t (or at least unsigned) as negatives
|
56
|
+
* values would not make much sense. The downside is that it would break
|
57
|
+
* both the API and ABI. Thus, at the moment, let's just do a sanity
|
58
|
+
* check.
|
59
|
+
*/
|
60
|
+
if (w < 0 || h < 0)
|
61
|
+
goto fail;
|
62
|
+
|
63
|
+
/*
|
64
|
+
* alloc a new buffer for q->image. We avoid realloc(3) because we want
|
65
|
+
* on failure to be leave `q` in a consistant, unmodified state.
|
66
|
+
*/
|
67
|
+
image = calloc(w, h);
|
68
|
+
if (!image)
|
69
|
+
goto fail;
|
70
|
+
|
71
|
+
/* compute the "old" (i.e. currently allocated) and the "new"
|
72
|
+
(i.e. requested) image dimensions */
|
73
|
+
size_t olddim = q->w * q->h;
|
74
|
+
size_t newdim = w * h;
|
75
|
+
size_t min = (olddim < newdim ? olddim : newdim);
|
76
|
+
|
77
|
+
/*
|
78
|
+
* copy the data into the new buffer, avoiding (a) to read beyond the
|
79
|
+
* old buffer when the new size is greater and (b) to write beyond the
|
80
|
+
* new buffer when the new size is smaller, hence the min computation.
|
81
|
+
*/
|
82
|
+
(void)memcpy(image, q->image, min);
|
83
|
+
|
84
|
+
/* alloc a new buffer for q->pixels if needed */
|
54
85
|
if (sizeof(*q->image) != sizeof(*q->pixels)) {
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
return -1;
|
59
|
-
q->pixels = new_pixels;
|
86
|
+
pixels = calloc(newdim, sizeof(quirc_pixel_t));
|
87
|
+
if (!pixels)
|
88
|
+
goto fail;
|
60
89
|
}
|
61
90
|
|
62
|
-
q->
|
91
|
+
/* alloc a new buffer for q->row_average */
|
92
|
+
row_average = calloc(w, sizeof(int));
|
93
|
+
if (!row_average)
|
94
|
+
goto fail;
|
95
|
+
|
96
|
+
/* alloc succeeded, update `q` with the new size and buffers */
|
63
97
|
q->w = w;
|
64
98
|
q->h = h;
|
99
|
+
free(q->image);
|
100
|
+
q->image = image;
|
101
|
+
if (sizeof(*q->image) != sizeof(*q->pixels)) {
|
102
|
+
free(q->pixels);
|
103
|
+
q->pixels = pixels;
|
104
|
+
}
|
105
|
+
free(q->row_average);
|
106
|
+
q->row_average = row_average;
|
65
107
|
|
66
108
|
return 0;
|
109
|
+
/* NOTREACHED */
|
110
|
+
fail:
|
111
|
+
free(image);
|
112
|
+
free(pixels);
|
113
|
+
free(row_average);
|
114
|
+
|
115
|
+
return -1;
|
67
116
|
}
|
68
117
|
|
69
118
|
int quirc_count(const struct quirc *q)
|
data/ext/quirc/embed/lib/quirc.h
CHANGED
@@ -121,7 +121,7 @@ struct quirc_code {
|
|
121
121
|
* is a bitmask giving the actual values of cells. If the cell
|
122
122
|
* at (x, y) is black, then the following bit is set:
|
123
123
|
*
|
124
|
-
* cell_bitmap[i
|
124
|
+
* cell_bitmap[i >> 3] & (1 << (i & 7))
|
125
125
|
*
|
126
126
|
* where i = (y * size) + x.
|
127
127
|
*/
|
data/lib/quirc/version.rb
CHANGED
data/test/helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quirc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacob Middag
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: oily_png
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
@@ -39,33 +39,33 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rake-compiler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0
|
47
|
+
version: '1.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0
|
54
|
+
version: '1.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rubocop
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0.58'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0.58'
|
69
69
|
description: Ruby bindings for C library quirc that extracts and decode QR images
|
70
70
|
email: jacob@gaddim.nl
|
71
71
|
executables: []
|
@@ -93,7 +93,7 @@ files:
|
|
93
93
|
- test/fixtures/hello-120-utf8-q.png
|
94
94
|
- test/helper.rb
|
95
95
|
- test/test_decode.rb
|
96
|
-
homepage: https://github.com/middagj/quirc
|
96
|
+
homepage: https://github.com/middagj/quirc-ruby
|
97
97
|
licenses:
|
98
98
|
- MIT
|
99
99
|
metadata: {}
|
@@ -105,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
105
|
requirements:
|
106
106
|
- - ">="
|
107
107
|
- !ruby/object:Gem::Version
|
108
|
-
version: '2.
|
108
|
+
version: '2.2'
|
109
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
110
|
requirements:
|
111
111
|
- - ">="
|
@@ -113,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
113
|
version: '0'
|
114
114
|
requirements: []
|
115
115
|
rubyforge_project:
|
116
|
-
rubygems_version: 2.6
|
116
|
+
rubygems_version: 2.7.6
|
117
117
|
signing_key:
|
118
118
|
specification_version: 4
|
119
119
|
summary: QR decoder based on quirc
|