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.
- data/History.txt +6 -0
- data/Manifest.txt +65 -0
- data/README.txt +75 -0
- data/Rakefile +49 -0
- data/bin/qrdecode +14 -0
- data/ext/qrtools/Makefile.in +65 -0
- data/ext/qrtools/bitstream.cpp +147 -0
- data/ext/qrtools/bitstream.h +48 -0
- data/ext/qrtools/codedata.cpp +506 -0
- data/ext/qrtools/codedata.h +95 -0
- data/ext/qrtools/container.cpp +288 -0
- data/ext/qrtools/container.h +175 -0
- data/ext/qrtools/decodeqr.h +286 -0
- data/ext/qrtools/ecidecoder.cpp +341 -0
- data/ext/qrtools/ecidecoder.h +110 -0
- data/ext/qrtools/extconf.rb +24 -0
- data/ext/qrtools/formatinfo.cpp +195 -0
- data/ext/qrtools/formatinfo.h +113 -0
- data/ext/qrtools/galois.cpp +593 -0
- data/ext/qrtools/galois.h +134 -0
- data/ext/qrtools/imagereader.cpp +1099 -0
- data/ext/qrtools/imagereader.h +127 -0
- data/ext/qrtools/libdecodeqr.cpp +195 -0
- data/ext/qrtools/libdecodeqr.dep +80 -0
- data/ext/qrtools/libdecodeqr.dsp +160 -0
- data/ext/qrtools/libdecodeqr.dsw +29 -0
- data/ext/qrtools/libdecodeqr.mak +245 -0
- data/ext/qrtools/qrerror.h +40 -0
- data/ext/qrtools/qrtools.c +17 -0
- data/ext/qrtools/qrtools.h +21 -0
- data/ext/qrtools/qrtools_decoder.c +123 -0
- data/ext/qrtools/qrtools_decoder.h +10 -0
- data/ext/qrtools/qrtools_encoder.c +63 -0
- data/ext/qrtools/qrtools_encoder.h +10 -0
- data/ext/qrtools/qrtools_header.c +51 -0
- data/ext/qrtools/qrtools_header.h +10 -0
- data/ext/qrtools/qrtools_image.c +80 -0
- data/ext/qrtools/qrtools_image.h +11 -0
- data/ext/qrtools/qrtools_qrcode.c +36 -0
- data/ext/qrtools/qrtools_qrcode.h +10 -0
- data/ext/qrtools/qrtools_ui_camera.c +58 -0
- data/ext/qrtools/qrtools_ui_camera.h +10 -0
- data/ext/qrtools/qrtools_ui_window.c +40 -0
- data/ext/qrtools/qrtools_ui_window.h +10 -0
- data/ext/qrtools/qrtypes.h +42 -0
- data/ext/qrtools/version.h +42 -0
- data/lib/qrtools.rb +11 -0
- data/lib/qrtools/decoder.rb +17 -0
- data/lib/qrtools/encoder.rb +14 -0
- data/lib/qrtools/image.rb +43 -0
- data/lib/qrtools/qrcode.rb +54 -0
- data/lib/qrtools/ui/camera.rb +28 -0
- data/lib/qrtools/ui/window.rb +16 -0
- data/lib/qrtools/version.rb +3 -0
- data/qrtools.gemspec +38 -0
- data/test/assets/01-1.jpg +0 -0
- data/test/helper.rb +17 -0
- data/test/test_decoder.rb +67 -0
- data/test/test_encoder.rb +35 -0
- data/test/test_header.rb +14 -0
- data/test/test_image.rb +19 -0
- data/test/test_qrcode.rb +78 -0
- data/test/test_qrdecode.rb +0 -0
- data/test/ui/test_camera.rb +43 -0
- data/test/ui/test_window.rb +34 -0
- metadata +138 -0
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/////////////////////////////////////////////////////////////////////////
|
|
2
|
+
//
|
|
3
|
+
// libdecodeqr.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: decodeqr.h 36 2007-02-21 23:22:03Z zophos $
|
|
13
|
+
//
|
|
14
|
+
#ifndef __QR_DECODER__
|
|
15
|
+
#define __QR_DECODER__
|
|
16
|
+
|
|
17
|
+
#include <cv.h>
|
|
18
|
+
#include "qrerror.h"
|
|
19
|
+
#include "qrtypes.h"
|
|
20
|
+
|
|
21
|
+
#define DEFAULT_ADAPTIVE_TH_SIZE 25
|
|
22
|
+
#define DEFAULT_ADAPTIVE_TH_DELTA 10
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
#ifdef __cplusplus
|
|
26
|
+
extern "C" {
|
|
27
|
+
#endif
|
|
28
|
+
|
|
29
|
+
/////////////////////////////////////////////////////////////////////////
|
|
30
|
+
//
|
|
31
|
+
// initializer
|
|
32
|
+
//
|
|
33
|
+
// ARGS: none
|
|
34
|
+
// RETURN:
|
|
35
|
+
// QrDecoderHandle handle
|
|
36
|
+
//
|
|
37
|
+
extern QrDecoderHandle qr_decoder_open();
|
|
38
|
+
|
|
39
|
+
/////////////////////////////////////////////////////////////////////////
|
|
40
|
+
//
|
|
41
|
+
// initializer with source image size
|
|
42
|
+
//
|
|
43
|
+
// ARGS:
|
|
44
|
+
// int width: pixel width of source image
|
|
45
|
+
// int height: pixel height of source image
|
|
46
|
+
// int depth: image depth (bit par pixel; use OpenCV IPL_DEPTH_*)
|
|
47
|
+
// int channel: number of image channel
|
|
48
|
+
//
|
|
49
|
+
// RETURN:
|
|
50
|
+
// QrDecoderHandle handle
|
|
51
|
+
//
|
|
52
|
+
// NOTE:
|
|
53
|
+
// 24-bit full color image has IPL_DEPTH_8U depth and 3 channels.
|
|
54
|
+
//
|
|
55
|
+
extern QrDecoderHandle qr_decoder_open_with_image_size(
|
|
56
|
+
int width,int height,int depth,int channel);
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
/////////////////////////////////////////////////////////////////////////
|
|
60
|
+
//
|
|
61
|
+
// finalizer
|
|
62
|
+
//
|
|
63
|
+
// ARGS:
|
|
64
|
+
// QrDecoderHandle decoder: handler
|
|
65
|
+
//
|
|
66
|
+
// RETURN: none
|
|
67
|
+
//
|
|
68
|
+
extern void qr_decoder_close(QrDecoderHandle decoder);
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
/////////////////////////////////////////////////////////////////////////
|
|
72
|
+
//
|
|
73
|
+
// get status
|
|
74
|
+
//
|
|
75
|
+
// ARGS:
|
|
76
|
+
// QrDecoderHandle decoder: handler
|
|
77
|
+
//
|
|
78
|
+
// RETURN: status code
|
|
79
|
+
//
|
|
80
|
+
extern short qr_decoder_get_status(QrDecoderHandle decoder);
|
|
81
|
+
|
|
82
|
+
/////////////////////////////////////////////////////////////////////////
|
|
83
|
+
//
|
|
84
|
+
// get working status
|
|
85
|
+
//
|
|
86
|
+
// ARGS:
|
|
87
|
+
// QrDecoderHandle decoder: handler
|
|
88
|
+
//
|
|
89
|
+
// RETURN: status code
|
|
90
|
+
//
|
|
91
|
+
extern int qr_decoder_is_busy(QrDecoderHandle decoder);
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
/////////////////////////////////////////////////////////////////////////
|
|
95
|
+
//
|
|
96
|
+
// set source image size
|
|
97
|
+
//
|
|
98
|
+
// ARGS:
|
|
99
|
+
// QrDecoderHandle decoder: handler
|
|
100
|
+
// int width: pixel width of source image
|
|
101
|
+
// int height: pixel height of source image
|
|
102
|
+
// int depth: image depth (bit par pixel; use OpenCV IPL_DEPTH_*)
|
|
103
|
+
// int channel: number of image channel
|
|
104
|
+
//
|
|
105
|
+
// RETURN:
|
|
106
|
+
// QrDecoderHandle handle
|
|
107
|
+
//
|
|
108
|
+
// NOTE:
|
|
109
|
+
// This method provide same function as qr_decoder_open_with_image_size().
|
|
110
|
+
//
|
|
111
|
+
extern QrDecoderHandle qr_decoder_set_image_size(
|
|
112
|
+
QrDecoderHandle decoder,int width,int height,int depth,int channel);
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
/////////////////////////////////////////////////////////////////////////
|
|
116
|
+
//
|
|
117
|
+
// preset gaven image as source image
|
|
118
|
+
//
|
|
119
|
+
// ARGS:
|
|
120
|
+
// QrDecoderHandle decoder: handler
|
|
121
|
+
// IplImage *src: source image
|
|
122
|
+
//
|
|
123
|
+
// RETURN:
|
|
124
|
+
// QrDecoderHandle handle
|
|
125
|
+
//
|
|
126
|
+
extern QrDecoderHandle qr_decoder_set_image_buffer(
|
|
127
|
+
QrDecoderHandle decoder,IplImage *src);
|
|
128
|
+
|
|
129
|
+
/////////////////////////////////////////////////////////////////////////
|
|
130
|
+
//
|
|
131
|
+
// get source image buffer
|
|
132
|
+
//
|
|
133
|
+
// ARGS:
|
|
134
|
+
// QrDecoderHandle decoder: handler
|
|
135
|
+
//
|
|
136
|
+
// RETURN:
|
|
137
|
+
// IplImage *: pointer to buffer source image|NULL
|
|
138
|
+
//
|
|
139
|
+
// NOTE:
|
|
140
|
+
// See OpenCV reference manual to access to IplImage *
|
|
141
|
+
//
|
|
142
|
+
extern IplImage *qr_decoder_get_image_buffer(QrDecoderHandle decoder);
|
|
143
|
+
|
|
144
|
+
extern IplImage *qr_decoder_get_transformed_image_buffer(
|
|
145
|
+
QrDecoderHandle decoder);
|
|
146
|
+
extern IplImage *qr_decoder_get_binarized_image_buffer(
|
|
147
|
+
QrDecoderHandle decoder);
|
|
148
|
+
extern IplImage *qr_decoder_get_tmp_image_buffer(
|
|
149
|
+
QrDecoderHandle decoder);
|
|
150
|
+
|
|
151
|
+
/////////////////////////////////////////////////////////////////////////
|
|
152
|
+
//
|
|
153
|
+
// decode preset source image
|
|
154
|
+
//
|
|
155
|
+
// ARGS:
|
|
156
|
+
// QrDecoderHandle decoder: handler
|
|
157
|
+
// int adaptive_th_size: value of AdaptiveThreshold size
|
|
158
|
+
// int adaptive_th_delta: value of AdaptiveThreshold delta
|
|
159
|
+
//
|
|
160
|
+
// RETURN:
|
|
161
|
+
// short: status code of decoder
|
|
162
|
+
//
|
|
163
|
+
// NOTE:
|
|
164
|
+
// On succeeded, status code has 0x2000.
|
|
165
|
+
// See qrtypes.h for details of status code.
|
|
166
|
+
//
|
|
167
|
+
// In case of adaptive_th_size=0, binarizing methods will be
|
|
168
|
+
// used cvThreshlod() instead of cvAdaptiveThreshold()
|
|
169
|
+
//
|
|
170
|
+
#ifdef __cplusplus
|
|
171
|
+
extern short qr_decoder_decode(QrDecoderHandle decoder,
|
|
172
|
+
int adaptive_th_size=
|
|
173
|
+
DEFAULT_ADAPTIVE_TH_SIZE,
|
|
174
|
+
int adaptive_th_delta=
|
|
175
|
+
DEFAULT_ADAPTIVE_TH_DELTA);
|
|
176
|
+
#else
|
|
177
|
+
extern short qr_decoder_decode(QrDecoderHandle decoder,
|
|
178
|
+
int adaptive_th_size,
|
|
179
|
+
int adaptive_th_delta);
|
|
180
|
+
#endif
|
|
181
|
+
|
|
182
|
+
/////////////////////////////////////////////////////////////////////////
|
|
183
|
+
//
|
|
184
|
+
// decode gaven image
|
|
185
|
+
//
|
|
186
|
+
// ARGS:
|
|
187
|
+
// QrDecoderHandle decoder: handler
|
|
188
|
+
// IplImage *src: image to decode
|
|
189
|
+
// int adaptive_th_size: value of AdaptiveThreshold size
|
|
190
|
+
// int adaptive_th_delta: value of AdaptiveThreshold delta
|
|
191
|
+
//
|
|
192
|
+
// RETURN:
|
|
193
|
+
// short: status code of decoder
|
|
194
|
+
//
|
|
195
|
+
#ifdef __cplusplus
|
|
196
|
+
extern short qr_decoder_decode_image(QrDecoderHandle decoder,
|
|
197
|
+
IplImage *src,
|
|
198
|
+
int adaptive_th_size=
|
|
199
|
+
DEFAULT_ADAPTIVE_TH_SIZE,
|
|
200
|
+
int adaptive_th_delta=
|
|
201
|
+
DEFAULT_ADAPTIVE_TH_DELTA);
|
|
202
|
+
#else
|
|
203
|
+
extern short qr_decoder_decode_image(QrDecoderHandle decoder,
|
|
204
|
+
IplImage *src,
|
|
205
|
+
int adaptive_th_size,
|
|
206
|
+
int adaptive_th_delta);
|
|
207
|
+
#endif
|
|
208
|
+
|
|
209
|
+
/////////////////////////////////////////////////////////////////////////
|
|
210
|
+
//
|
|
211
|
+
// get abstruction of decoded data
|
|
212
|
+
//
|
|
213
|
+
// ARGS:
|
|
214
|
+
// QrDecoderHandle decoder: handler
|
|
215
|
+
// QrCodeHeader *header: pointer to buffer of header
|
|
216
|
+
//
|
|
217
|
+
// RETURN:
|
|
218
|
+
// 1 (on success)||0 (on error)
|
|
219
|
+
//
|
|
220
|
+
extern int qr_decoder_get_header(QrDecoderHandle decoder,
|
|
221
|
+
QrCodeHeader *header);
|
|
222
|
+
|
|
223
|
+
/////////////////////////////////////////////////////////////////////////
|
|
224
|
+
//
|
|
225
|
+
// get decoded text data
|
|
226
|
+
//
|
|
227
|
+
// ARGS:
|
|
228
|
+
// QrDecoderHandle decoder: handler
|
|
229
|
+
// unsigned char *buf: pointer to buffer of header
|
|
230
|
+
// int buf_size: buffer size
|
|
231
|
+
//
|
|
232
|
+
// RETURN:
|
|
233
|
+
// copied data size||0 (on error)
|
|
234
|
+
//
|
|
235
|
+
// NOTE:
|
|
236
|
+
// The data DOES NOT TERMINATE with null.
|
|
237
|
+
// To get actual buffer size, use QrCodeHeader's .byte_size element.
|
|
238
|
+
//
|
|
239
|
+
extern int qr_decoder_get_body(QrDecoderHandle decoder,
|
|
240
|
+
unsigned char *buf,int buf_size);
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
/////////////////////////////////////////////////////////////////////////
|
|
244
|
+
//
|
|
245
|
+
// get vertexes of decoded code region
|
|
246
|
+
//
|
|
247
|
+
// ARGS:
|
|
248
|
+
// QrDecoderHandle decoder: handler
|
|
249
|
+
//
|
|
250
|
+
// RETURN:
|
|
251
|
+
// Pointer to CvPoint[4] which consist vertexes of code region
|
|
252
|
+
//
|
|
253
|
+
extern CvPoint *qr_decoder_get_coderegion_vertexes(QrDecoderHandle decoder);
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
/////////////////////////////////////////////////////////////////////////
|
|
257
|
+
//
|
|
258
|
+
// get Box array of decoded finder patterns
|
|
259
|
+
//
|
|
260
|
+
// ARGS:
|
|
261
|
+
// QrDecoderHandle decoder: handler
|
|
262
|
+
//
|
|
263
|
+
// RETURN:
|
|
264
|
+
// Pointer to CvBox2D[3] which consist boxes of finder pattern
|
|
265
|
+
//
|
|
266
|
+
extern CvBox2D *qr_decoder_get_finderpattern_boxes(QrDecoderHandle decoder);
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
/////////////////////////////////////////////////////////////////////////
|
|
270
|
+
//
|
|
271
|
+
// version information
|
|
272
|
+
//
|
|
273
|
+
extern char *qr_decoder_version();
|
|
274
|
+
extern char *qr_decoder_version_description();
|
|
275
|
+
extern char *qr_decoder_version_product();
|
|
276
|
+
extern int qr_decoder_version_major();
|
|
277
|
+
extern int qr_decoder_version_minor();
|
|
278
|
+
extern int qr_decoder_version_teeny();
|
|
279
|
+
extern char *qr_decoder_version_suffix();
|
|
280
|
+
extern char *qr_decoder_version_revision();
|
|
281
|
+
|
|
282
|
+
#ifdef __cplusplus
|
|
283
|
+
}
|
|
284
|
+
#endif
|
|
285
|
+
|
|
286
|
+
#endif
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
/////////////////////////////////////////////////////////////////////////
|
|
2
|
+
//
|
|
3
|
+
// ecidecoder.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: ecidecoder.cpp 36 2007-02-21 23:22:03Z zophos $
|
|
13
|
+
//
|
|
14
|
+
#include "ecidecoder.h"
|
|
15
|
+
|
|
16
|
+
namespace Qr{
|
|
17
|
+
namespace ECI{
|
|
18
|
+
|
|
19
|
+
//
|
|
20
|
+
// length of charactor count indicator
|
|
21
|
+
// [version][mode]
|
|
22
|
+
//
|
|
23
|
+
const static int CHARACTOR_COUNTS[41][4]={
|
|
24
|
+
//
|
|
25
|
+
// version 0 (not exist, just a dummy)
|
|
26
|
+
//
|
|
27
|
+
{0,0,0,0},
|
|
28
|
+
//
|
|
29
|
+
// version 1-9
|
|
30
|
+
//
|
|
31
|
+
{10,9,8,8},{10,9,8,8},{10,9,8,8},{10,9,8,8},
|
|
32
|
+
{10,9,8,8},{10,9,8,8},{10,9,8,8},{10,9,8,8},{10,9,8,8},
|
|
33
|
+
//
|
|
34
|
+
// version 10-26
|
|
35
|
+
//
|
|
36
|
+
{12,11,16,10},{12,11,16,10},{12,11,16,10},{12,11,16,10},{12,11,16,10},
|
|
37
|
+
{12,11,16,10},{12,11,16,10},{12,11,16,10},{12,11,16,10},{12,11,16,10},
|
|
38
|
+
{12,11,16,10},{12,11,16,10},{12,11,16,10},{12,11,16,10},{12,11,16,10},
|
|
39
|
+
{12,11,16,10},{12,11,16,10},
|
|
40
|
+
//
|
|
41
|
+
// version 27-40
|
|
42
|
+
//
|
|
43
|
+
{14,13,16,12},{14,13,16,12},{14,13,16,12},
|
|
44
|
+
{14,13,16,12},{14,13,16,12},{14,13,16,12},{14,13,16,12},{14,13,16,12},
|
|
45
|
+
{14,13,16,12},{14,13,16,12},{14,13,16,12},{14,13,16,12},{14,13,16,12},
|
|
46
|
+
{14,13,16,12}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
//
|
|
50
|
+
// number to alphabet conversion table
|
|
51
|
+
//
|
|
52
|
+
const static char NUM2ALPABET[45]={
|
|
53
|
+
0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, // 0-9
|
|
54
|
+
0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a, // A-J
|
|
55
|
+
0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,0x54, // K-T
|
|
56
|
+
0x55,0x56,0x57,0x58,0x59,0x5a, // U-Z
|
|
57
|
+
0x20,0x23,0x25,0x2a,0x2b,0x2d,0x2e,0x2f,0x3a
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
Decoder::Decoder()
|
|
61
|
+
{
|
|
62
|
+
this->mode=0;
|
|
63
|
+
this->length=0;
|
|
64
|
+
this->byte_length=0;
|
|
65
|
+
this->eci_mode=20;
|
|
66
|
+
|
|
67
|
+
this->_raw_data=NULL;
|
|
68
|
+
this->_bit_par_block=0;
|
|
69
|
+
this->_char_par_block=0;
|
|
70
|
+
this->_byte_par_char=0;
|
|
71
|
+
|
|
72
|
+
this->_read_length=0;
|
|
73
|
+
this->_written_length=0;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
Decoder::~Decoder()
|
|
77
|
+
{
|
|
78
|
+
if(this->_raw_data)
|
|
79
|
+
delete this->_raw_data;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
unsigned char *Decoder::raw_data()
|
|
83
|
+
{
|
|
84
|
+
return(this->_raw_data);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
int Decoder::decode(int version,BitStream *bitstream)
|
|
88
|
+
{
|
|
89
|
+
this->_read_header(version,bitstream);
|
|
90
|
+
int blocks=this->length/this->_char_par_block+
|
|
91
|
+
(this->length%this->_char_par_block?1:0);
|
|
92
|
+
|
|
93
|
+
for(int i=0;i<blocks;i++){
|
|
94
|
+
if(!this->_read_data(bitstream))
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return(this->length);
|
|
99
|
+
}
|
|
100
|
+
int Decoder::_read_header(int version,BitStream *bitstream)
|
|
101
|
+
{
|
|
102
|
+
int charactor_count=this->_get_charactor_count(version);
|
|
103
|
+
bitstream->read(&(this->length),sizeof(this->length),
|
|
104
|
+
charactor_count);
|
|
105
|
+
this->length=ntohl(this->length);
|
|
106
|
+
this->byte_length=this->length*this->_byte_par_char;
|
|
107
|
+
|
|
108
|
+
int storage_sz=this->byte_length;
|
|
109
|
+
if(this->mode!=4)
|
|
110
|
+
storage_sz++;
|
|
111
|
+
|
|
112
|
+
this->_raw_data=new unsigned char[storage_sz];
|
|
113
|
+
memset(this->_raw_data,0,storage_sz);
|
|
114
|
+
this->_current_pos=this->_raw_data;
|
|
115
|
+
|
|
116
|
+
return(bitstream->position());
|
|
117
|
+
}
|
|
118
|
+
int Decoder::_get_charactor_count(int version)
|
|
119
|
+
{
|
|
120
|
+
return(0);
|
|
121
|
+
}
|
|
122
|
+
int Decoder::_read_data(BitStream *bitstream)
|
|
123
|
+
{
|
|
124
|
+
return(0);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
NumericalDecoder::NumericalDecoder()
|
|
128
|
+
{
|
|
129
|
+
this->mode=1;
|
|
130
|
+
this->_bit_par_block=10;
|
|
131
|
+
this->_char_par_block=3;
|
|
132
|
+
this->_byte_par_char=1;
|
|
133
|
+
}
|
|
134
|
+
int NumericalDecoder::_get_charactor_count(int version)
|
|
135
|
+
{
|
|
136
|
+
return(CHARACTOR_COUNTS[version][0]);
|
|
137
|
+
}
|
|
138
|
+
int NumericalDecoder::_read_data(BitStream *bitstream)
|
|
139
|
+
{
|
|
140
|
+
if(bitstream->is_eod())
|
|
141
|
+
return(0);
|
|
142
|
+
|
|
143
|
+
int read_bits=this->_bit_par_block;
|
|
144
|
+
int write_bytes=this->_char_par_block*this->_byte_par_char;
|
|
145
|
+
switch(this->length-this->_read_length){
|
|
146
|
+
case 0:
|
|
147
|
+
return(0);
|
|
148
|
+
case 1:
|
|
149
|
+
read_bits=4;
|
|
150
|
+
write_bytes=1;
|
|
151
|
+
break;
|
|
152
|
+
case 2:
|
|
153
|
+
read_bits=7;
|
|
154
|
+
write_bytes=2;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
this->_read_buf=0;
|
|
158
|
+
bitstream->read(&(this->_read_buf),sizeof(this->_read_buf),
|
|
159
|
+
read_bits);
|
|
160
|
+
this->_read_buf=ntohs(this->_read_buf);
|
|
161
|
+
this->_read_length+=write_bytes;
|
|
162
|
+
|
|
163
|
+
int remain_bytes=this->byte_length-this->_written_length;
|
|
164
|
+
if(write_bytes>remain_bytes)
|
|
165
|
+
write_bytes=remain_bytes;
|
|
166
|
+
|
|
167
|
+
char format_str[5];
|
|
168
|
+
snprintf(format_str,5,"%%0%dd",write_bytes);
|
|
169
|
+
int ret=snprintf((char *)this->_current_pos,
|
|
170
|
+
write_bytes+1,
|
|
171
|
+
format_str,
|
|
172
|
+
this->_read_buf);
|
|
173
|
+
|
|
174
|
+
if(ret<0)
|
|
175
|
+
ret=0-ret;
|
|
176
|
+
this->_current_pos+=ret;
|
|
177
|
+
this->_written_length+=ret;
|
|
178
|
+
|
|
179
|
+
return(ret);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
AlphabeticalDecoder::AlphabeticalDecoder()
|
|
184
|
+
{
|
|
185
|
+
this->mode=2;
|
|
186
|
+
this->_bit_par_block=11;
|
|
187
|
+
this->_char_par_block=2;
|
|
188
|
+
this->_byte_par_char=1;
|
|
189
|
+
}
|
|
190
|
+
int AlphabeticalDecoder::_get_charactor_count(int version)
|
|
191
|
+
{
|
|
192
|
+
return(CHARACTOR_COUNTS[version][1]);
|
|
193
|
+
}
|
|
194
|
+
int AlphabeticalDecoder::_read_data(BitStream *bitstream)
|
|
195
|
+
{
|
|
196
|
+
if(bitstream->is_eod())
|
|
197
|
+
return(0);
|
|
198
|
+
|
|
199
|
+
int read_bits=this->_bit_par_block;
|
|
200
|
+
int write_bytes=this->_char_par_block*this->_byte_par_char;
|
|
201
|
+
switch(this->length-this->_read_length){
|
|
202
|
+
case 0:
|
|
203
|
+
return(0);
|
|
204
|
+
case 1:
|
|
205
|
+
read_bits=6;
|
|
206
|
+
write_bytes=1;
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
this->_read_buf=0;
|
|
210
|
+
bitstream->read(&(this->_read_buf),sizeof(this->_read_buf),
|
|
211
|
+
read_bits);
|
|
212
|
+
this->_read_buf=ntohs(this->_read_buf);
|
|
213
|
+
this->_read_length+=write_bytes;
|
|
214
|
+
|
|
215
|
+
int remain_bytes=this->byte_length-this->_written_length;
|
|
216
|
+
int ret=0;
|
|
217
|
+
if(read_bits==this->_bit_par_block){
|
|
218
|
+
int x=this->_read_buf/45;
|
|
219
|
+
char c=NUM2ALPABET[x];
|
|
220
|
+
if(remain_bytes>0){
|
|
221
|
+
if(snprintf((char *)this->_current_pos,2,"%c",c)>0){
|
|
222
|
+
ret++;
|
|
223
|
+
this->_current_pos++;
|
|
224
|
+
remain_bytes--;
|
|
225
|
+
this->_written_length++;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if(remain_bytes>0){
|
|
230
|
+
int x=this->_read_buf%45;
|
|
231
|
+
char c=NUM2ALPABET[x];
|
|
232
|
+
if(snprintf((char *)this->_current_pos,2,"%c",c)>0){
|
|
233
|
+
ret++;
|
|
234
|
+
this->_current_pos++;
|
|
235
|
+
remain_bytes--;
|
|
236
|
+
this->_written_length++;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return(ret);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
ByteDecoder::ByteDecoder()
|
|
244
|
+
{
|
|
245
|
+
this->mode=4;
|
|
246
|
+
this->_bit_par_block=8;
|
|
247
|
+
this->_char_par_block=1;
|
|
248
|
+
this->_byte_par_char=1;
|
|
249
|
+
}
|
|
250
|
+
int ByteDecoder::_get_charactor_count(int version)
|
|
251
|
+
{
|
|
252
|
+
return(CHARACTOR_COUNTS[version][2]);
|
|
253
|
+
}
|
|
254
|
+
int ByteDecoder::_read_data(BitStream *bitstream)
|
|
255
|
+
{
|
|
256
|
+
if(bitstream->is_eod())
|
|
257
|
+
return(0);
|
|
258
|
+
|
|
259
|
+
int read_bits=this->_bit_par_block;
|
|
260
|
+
int write_bytes=this->_char_par_block*this->_byte_par_char;
|
|
261
|
+
this->_read_buf=0;
|
|
262
|
+
bitstream->read(&(this->_read_buf),sizeof(this->_read_buf),
|
|
263
|
+
read_bits);
|
|
264
|
+
this->_read_length+=write_bytes;
|
|
265
|
+
|
|
266
|
+
if(this->byte_length-this->_written_length){
|
|
267
|
+
*this->_current_pos=(unsigned char)this->_read_buf;
|
|
268
|
+
this->_current_pos++;
|
|
269
|
+
this->_written_length++;
|
|
270
|
+
return(1);
|
|
271
|
+
}
|
|
272
|
+
else{
|
|
273
|
+
return(0);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
GenericDecoder::GenericDecoder()
|
|
278
|
+
{
|
|
279
|
+
this->mode=7;
|
|
280
|
+
}
|
|
281
|
+
int GenericDecoder::_get_charactor_count(int version)
|
|
282
|
+
{
|
|
283
|
+
return(0);
|
|
284
|
+
}
|
|
285
|
+
int GenericDecoder::_read_data(BitStream *bitstream)
|
|
286
|
+
{
|
|
287
|
+
return(0);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
KanjiDecoder::KanjiDecoder()
|
|
291
|
+
{
|
|
292
|
+
this->mode=8;
|
|
293
|
+
this->_bit_par_block=13;
|
|
294
|
+
this->_char_par_block=1;
|
|
295
|
+
this->_byte_par_char=2;
|
|
296
|
+
}
|
|
297
|
+
int KanjiDecoder::_get_charactor_count(int version)
|
|
298
|
+
{
|
|
299
|
+
return(CHARACTOR_COUNTS[version][3]);
|
|
300
|
+
}
|
|
301
|
+
int KanjiDecoder::_read_data(BitStream *bitstream)
|
|
302
|
+
{
|
|
303
|
+
if(bitstream->is_eod())
|
|
304
|
+
return(0);
|
|
305
|
+
|
|
306
|
+
int read_bits=this->_bit_par_block;
|
|
307
|
+
int write_bytes=this->_char_par_block*this->_byte_par_char;
|
|
308
|
+
if(this->length-this->_read_length<=0)
|
|
309
|
+
return(0);
|
|
310
|
+
|
|
311
|
+
this->_read_buf=0;
|
|
312
|
+
bitstream->read(&(this->_read_buf),sizeof(this->_read_buf),
|
|
313
|
+
read_bits);
|
|
314
|
+
this->_read_buf=ntohs(this->_read_buf);
|
|
315
|
+
this->_read_length++;
|
|
316
|
+
|
|
317
|
+
if(this->byte_length-this->_written_length>=write_bytes){
|
|
318
|
+
int c=this->_read_buf/0xc0;
|
|
319
|
+
c*=0x100;
|
|
320
|
+
c+=this->_read_buf%0xc0;
|
|
321
|
+
if(c>=0x1f00)
|
|
322
|
+
c+=0xc140;
|
|
323
|
+
else
|
|
324
|
+
c+=0x8140;
|
|
325
|
+
|
|
326
|
+
unsigned char c1=(unsigned char)(c/0x100);
|
|
327
|
+
unsigned char c2=(unsigned char)(c%0x100);
|
|
328
|
+
|
|
329
|
+
*this->_current_pos=c1;
|
|
330
|
+
*(this->_current_pos+1)=c2;
|
|
331
|
+
this->_current_pos+=2;
|
|
332
|
+
this->_written_length+=2;
|
|
333
|
+
return(2);
|
|
334
|
+
}
|
|
335
|
+
else
|
|
336
|
+
return(0);
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
|