@moralcode/qrcode-brightscript 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.
- package/LICENSE.txt +21 -0
- package/README.md +33 -0
- package/package.json +17 -0
- package/src/components/qrCode/qrCode.brs +201 -0
- package/src/components/qrCode/qrCode.draw.brs +126 -0
- package/src/components/qrCode/qrCode.help.brs +148 -0
- package/src/components/qrCode/qrCode.high.brs +20 -0
- package/src/components/qrCode/qrCode.low.brs +68 -0
- package/src/components/qrCode/qrCode.mask.brs +198 -0
- package/src/components/qrCode/qrCode.mid.brs +76 -0
- package/src/components/qrCode/qrCode.utils.brs +110 -0
- package/src/components/qrCode/qrCode.xml +25 -0
- package/src/components/qrCode/qrEcc.brs +23 -0
- package/src/components/qrCode/qrEcc.xml +10 -0
- package/src/components/qrCode/qrMode.brs +37 -0
- package/src/components/qrCode/qrMode.xml +11 -0
- package/src/components/qrCode/qrSegment.brs +226 -0
- package/src/images/focus_fhd.jpg +0 -0
- package/src/images/focus_hd.jpg +0 -0
- package/src/images/focus_sd.jpg +0 -0
- package/src/images/splash_fhd.jpg +0 -0
- package/src/images/splash_hd.jpg +0 -0
- package/src/images/splash_sd.jpg +0 -0
- package/src/manifest +17 -0
- package/src/source/main.brs +23 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
'**************************************************************************************
|
|
2
|
+
' QR Code generator library (Brightscript)
|
|
3
|
+
' Copyright (c) Kevin Hoos.
|
|
4
|
+
'**************************************************************************************
|
|
5
|
+
' Ported from:
|
|
6
|
+
' Copyright (c) Project Nayuki. (MIT License)
|
|
7
|
+
' https:'www.nayuki.io/page/qr-code-generator-library
|
|
8
|
+
'
|
|
9
|
+
' Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
10
|
+
' this software and associated documentation files (the "Software"), to deal in
|
|
11
|
+
' the Software without restriction, including without limitation the rights to
|
|
12
|
+
' use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
13
|
+
' the Software, and to permit persons to whom the Software is furnished to do so,
|
|
14
|
+
' subject to the following conditions:
|
|
15
|
+
' - The above copyright notice and this permission notice shall be included in
|
|
16
|
+
' all copies or substantial portions of the Software.
|
|
17
|
+
' - The Software is provided "as is", without warranty of any kind, express or
|
|
18
|
+
' implied, including but not limited to the warranties of merchantability,
|
|
19
|
+
' fitness for a particular purpose and noninfringement. In no event shall the
|
|
20
|
+
' authors or copyright holders be liable for any claim, damages or other
|
|
21
|
+
' liability, whether in an action of contract, tort or otherwise, arising from,
|
|
22
|
+
' out of or in connection with the Software or the use or other dealings in the
|
|
23
|
+
' Software.
|
|
24
|
+
'**************************************************************************************
|
|
25
|
+
|
|
26
|
+
'---- Data segment class ----
|
|
27
|
+
|
|
28
|
+
' A segment of character/binary/control data in a QR Code symbol.
|
|
29
|
+
' Instances of this class are immutable.
|
|
30
|
+
' The mid-level way to create a segment is to take the payload data
|
|
31
|
+
' and call a static factory function such as QrSegment.makeNumeric().
|
|
32
|
+
' The low-level way to create a segment is to custom-make the bit buffer
|
|
33
|
+
' and call the QrSegment() constructor with appropriate values.
|
|
34
|
+
' This segment class imposes no length restrictions, but QR Codes have restrictions.
|
|
35
|
+
' Even in the most favorable conditions, a QR Code can only hold 7089 characters of data.
|
|
36
|
+
' Any segment longer than this is meaningless for the purpose of generating QR Codes.
|
|
37
|
+
function QrSegment() as object
|
|
38
|
+
this = {}
|
|
39
|
+
|
|
40
|
+
this.makeBytes = _qrSegment_makeBytes
|
|
41
|
+
this.makeNumeric = _qrSegment_makeNumeric
|
|
42
|
+
this.makeAlphanumeric = _qrSegment_makeAlphanumeric
|
|
43
|
+
this.makeSegments = _qrSegment_makeSegments
|
|
44
|
+
this.makeEci = _qrSegment_makeEci
|
|
45
|
+
this.isNumeric = _qrSegment_isNumeric
|
|
46
|
+
this.isAlphanumeric = _qrSegment_isAlphanumeric
|
|
47
|
+
this.constructor = _qrSegment_constructor
|
|
48
|
+
|
|
49
|
+
'-- Methods --
|
|
50
|
+
|
|
51
|
+
' Returns a new copy of the data bits of this segment.
|
|
52
|
+
this.getData = function()
|
|
53
|
+
return slice(m.bitData) ' Make defensive copy
|
|
54
|
+
end function
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
' (Package-private) Calculates and returns the number of bits needed to encode the given segments at
|
|
58
|
+
' the given version. The result is infinity if a segment has too many characters to fit its length field.
|
|
59
|
+
this.getTotalBits = function(segs as object, version as integer) as integer
|
|
60
|
+
result = 0
|
|
61
|
+
for each seg in segs
|
|
62
|
+
ccbits = seg.mode.callFunc("numCharCountBits", version)
|
|
63
|
+
if (seg.numChars >= (1 << ccbits)) then
|
|
64
|
+
return infinity() ' The segment's length doesn't fit the field's bit width
|
|
65
|
+
end if
|
|
66
|
+
result += 4 + ccbits + seg.bitData.count()
|
|
67
|
+
next
|
|
68
|
+
return result
|
|
69
|
+
end function
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
' Returns a new array of bytes representing the given string encoded in UTF-8.
|
|
73
|
+
this.toUtf8ByteArray = function(str as string) as object
|
|
74
|
+
str = str.escape()
|
|
75
|
+
result = []
|
|
76
|
+
for i = 0 to str.len() - 1
|
|
77
|
+
if (str.mid(i, 1) <> "%") then
|
|
78
|
+
result.push(asc(str.mid(i, 1)))
|
|
79
|
+
else
|
|
80
|
+
result.push(val(str.mid(i + 1, 2), 16))
|
|
81
|
+
i += 2
|
|
82
|
+
end if
|
|
83
|
+
next
|
|
84
|
+
return result
|
|
85
|
+
end function
|
|
86
|
+
|
|
87
|
+
'-- Constants --'
|
|
88
|
+
|
|
89
|
+
' Describes precisely all strings that are encodable in numeric mode.
|
|
90
|
+
this.NUMERIC_REGEX = CreateObject("roRegex", "^[0-9]*$", "")
|
|
91
|
+
|
|
92
|
+
' Describes precisely all strings that are encodable in alphanumeric mode.
|
|
93
|
+
this.ALPHANUMERIC_REGEX = CreateObject("roRegex", "^[A-Z0-9 $%*+.\/:-]*$", "")
|
|
94
|
+
|
|
95
|
+
' The set of all legal characters in alphanumeric mode,
|
|
96
|
+
' where each character value maps to the index in the string.
|
|
97
|
+
this.ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:"
|
|
98
|
+
|
|
99
|
+
return this
|
|
100
|
+
end function
|
|
101
|
+
|
|
102
|
+
'-- Static factory functions (mid level) --
|
|
103
|
+
|
|
104
|
+
' Returns a segment representing the given binary data encoded in
|
|
105
|
+
' byte mode. All input byte arrays are acceptable. Any text string
|
|
106
|
+
' can be converted to UTF-8 bytes and encoded as a byte mode segment.
|
|
107
|
+
function _qrSegment_makeBytes(data as object) as object
|
|
108
|
+
bb = []
|
|
109
|
+
for each b in data
|
|
110
|
+
appendBits(b, 8, bb)
|
|
111
|
+
next
|
|
112
|
+
return m.constructor("BYTE", data.count(), bb)
|
|
113
|
+
end function
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
' Returns a segment representing the given string of decimal digits encoded in numeric mode.
|
|
117
|
+
function _qrSegment_makeNumeric(digits as string) as object
|
|
118
|
+
if (not m.isNumeric(digits)) then
|
|
119
|
+
throw("String contains non-numeric characters")
|
|
120
|
+
end if
|
|
121
|
+
bb = []
|
|
122
|
+
for i = 0 to digits.len() - 1 ' Consume up to 3 digits per iteration
|
|
123
|
+
n = min(digits.len() - i, 3)
|
|
124
|
+
appendBits(val(digits.mid(i, n), 10), n * 3 + 1, bb)
|
|
125
|
+
i += n
|
|
126
|
+
next
|
|
127
|
+
return m.constructor("NUMERIC", digits.len(), bb)
|
|
128
|
+
end function
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
' Returns a segment representing the given text string encoded in alphanumeric mode.
|
|
132
|
+
' The characters allowed are: 0 to 9, A to Z (uppercase only), space,
|
|
133
|
+
' dollar, percent, asterisk, plus, hyphen, period, slash, colon.
|
|
134
|
+
function _qrSegment_makeAlphanumeric(text as string) as object
|
|
135
|
+
if (not m.isAlphanumeric(text)) then
|
|
136
|
+
throw("String contains unencodable characters in alphanumeric mode")
|
|
137
|
+
end if
|
|
138
|
+
bb = []
|
|
139
|
+
for i = 0 to text.len() - 2 step 2 ' Process groups of 2
|
|
140
|
+
temp = m.ALPHANUMERIC_CHARSET.instr(text.mid(i, 1)) * 45
|
|
141
|
+
temp += m.ALPHANUMERIC_CHARSET.instr(text.mid(i + 1, 1))
|
|
142
|
+
appendBits(temp, 11, bb)
|
|
143
|
+
next
|
|
144
|
+
if (i < text.len()) then ' 1 character remaining
|
|
145
|
+
appendBits(m.ALPHANUMERIC_CHARSET.instr(text.mid(i, 1)), 6, bb)
|
|
146
|
+
end if
|
|
147
|
+
return m.constructor("ALPHANUMERIC", text.len(), bb)
|
|
148
|
+
end function
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
' Returns a new mutable list of zero or more segments to represent the given Unicode text string.
|
|
152
|
+
' The result may use various segment modes and switch modes to optimize the length of the bit stream.
|
|
153
|
+
function _qrSegment_makeSegments(text as string) as object
|
|
154
|
+
' Select the most efficient segment encoding automatically
|
|
155
|
+
if (text = "") then
|
|
156
|
+
return []
|
|
157
|
+
else if (m.isNumeric(text)) then
|
|
158
|
+
return [m.makeNumeric(text)]
|
|
159
|
+
else if (m.isAlphanumeric(text)) then
|
|
160
|
+
return [m.makeAlphanumeric(text)]
|
|
161
|
+
else
|
|
162
|
+
return [m.makeBytes(m.toUtf8ByteArray(text))]
|
|
163
|
+
end if
|
|
164
|
+
end function
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
' Returns a segment representing an Extended Channel Interpretation
|
|
168
|
+
' (ECI) designator with the given assignment value.
|
|
169
|
+
function _qrSegment_makeEci(assignVal as integer) as object
|
|
170
|
+
bb = []
|
|
171
|
+
if (assignVal < 0) then
|
|
172
|
+
throw("ECI assignment value out of range")
|
|
173
|
+
else if (assignVal < (1 << 7)) then
|
|
174
|
+
appendBits(assignVal, 8, bb)
|
|
175
|
+
else if (assignVal < (1 << 14)) then
|
|
176
|
+
appendBits(2, 2, bb) '0b10
|
|
177
|
+
appendBits(assignVal, 14, bb)
|
|
178
|
+
else if (assignVal < 1000000) then
|
|
179
|
+
appendBits(6, 3, bb) '0b110
|
|
180
|
+
appendBits(assignVal, 21, bb)
|
|
181
|
+
else
|
|
182
|
+
throw("ECI assignment value out of range")
|
|
183
|
+
end if
|
|
184
|
+
return m.constructor("ECI", 0, bb)
|
|
185
|
+
end function
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
' Tests whether the given string can be encoded as a segment in numeric mode.
|
|
189
|
+
' A string is encodable iff each character is in the range 0 to 9.
|
|
190
|
+
function _qrSegment_isNumeric(text as string) as boolean
|
|
191
|
+
return m.NUMERIC_REGEX.isMatch(text)
|
|
192
|
+
end function
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
' Tests whether the given string can be encoded as a segment in alphanumeric mode.
|
|
196
|
+
' A string is encodable iff each character is in the following set: 0 to 9, A to Z
|
|
197
|
+
' (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.
|
|
198
|
+
function _qrSegment_isAlphanumeric(text as string) as boolean
|
|
199
|
+
return m.ALPHANUMERIC_REGEX.isMatch(text)
|
|
200
|
+
end function
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
'-- Constructor (low level) and fields --
|
|
204
|
+
|
|
205
|
+
' Creates a new QR Code segment with the given attributes and data.
|
|
206
|
+
' The character count (numChars) must agree with the mode and the bit buffer length,
|
|
207
|
+
' but the constraint isn't checked. The given bit buffer is cloned and stored.
|
|
208
|
+
function _qrSegment_constructor(mode as string, numChars = 0 as integer, bitData = [] as object) as object
|
|
209
|
+
' The mode indicator of this segment.
|
|
210
|
+
m.mode = CreateObject("roSGNode", "QRMode")
|
|
211
|
+
m.mode.mode = mode
|
|
212
|
+
|
|
213
|
+
' The length of this segment's unencoded data. Measured in characters for
|
|
214
|
+
' numeric/alphanumeric/kanji mode, bytes for byte mode, and 0 for ECI mode.
|
|
215
|
+
' Always zero or positive. Not the same as the data's bit length.
|
|
216
|
+
m.numChars = numChars
|
|
217
|
+
|
|
218
|
+
' The data bits of this segment. Accessed through getData().
|
|
219
|
+
m.bitData = bitData
|
|
220
|
+
|
|
221
|
+
if (numChars < 0)
|
|
222
|
+
throw("Invalid argument")
|
|
223
|
+
end if
|
|
224
|
+
m.bitData = slice(bitData) ' Make defensive copy
|
|
225
|
+
return m
|
|
226
|
+
end function
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/src/manifest
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
title=QR Code Generator
|
|
2
|
+
major_version=1
|
|
3
|
+
minor_version=0
|
|
4
|
+
build_version=00001
|
|
5
|
+
|
|
6
|
+
mm_icon_focus_fhd=pkg:/images/focus_fhd.jpg
|
|
7
|
+
mm_icon_focus_hd=pkg:/images/focus_hd.jpg
|
|
8
|
+
mm_icon_focus_sd=pkg:/images/focus_sd.png
|
|
9
|
+
|
|
10
|
+
splash_screen_fhd=pkg:/images/splash_fhd.jpg
|
|
11
|
+
splash_screen_hd=pkg:/images/splash_hd.jpg
|
|
12
|
+
splash_screen_sd=pkg:/images/splash_sd.jpg
|
|
13
|
+
|
|
14
|
+
splash_color=#662D91
|
|
15
|
+
splash_min_time=1000
|
|
16
|
+
|
|
17
|
+
ui_resolutions = "fhd"
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'********** Copyright 2016 Roku Corp. All Rights Reserved. **********
|
|
2
|
+
|
|
3
|
+
sub Main()
|
|
4
|
+
showChannelSGScreen()
|
|
5
|
+
end sub
|
|
6
|
+
|
|
7
|
+
sub showChannelSGScreen()
|
|
8
|
+
screen = CreateObject("roSGScreen")
|
|
9
|
+
m.port = CreateObject("roMessagePort")
|
|
10
|
+
screen.setMessagePort(m.port)
|
|
11
|
+
screen.CreateScene("SampleScene")
|
|
12
|
+
screen.show()
|
|
13
|
+
|
|
14
|
+
while(true)
|
|
15
|
+
msg = wait(0, m.port)
|
|
16
|
+
msgType = type(msg)
|
|
17
|
+
|
|
18
|
+
if msgType = "roSGScreenEvent"
|
|
19
|
+
if msg.isScreenClosed() then return
|
|
20
|
+
end if
|
|
21
|
+
end while
|
|
22
|
+
|
|
23
|
+
end sub
|