Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brightscript port of QRCode Generator #110

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions brightscript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.env
*.zip
*.keys
node_modules/
builds/
50 changes: 50 additions & 0 deletions brightscript/components/QRCode/QRBitBuffer/QRBitBuffer.brs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
sub init()
m.buffer = []
m.numberOfBits = 0
end sub

' @private
function getBufferIndex(bitIndex as integer) as integer
return int(bitIndex / 8)
end function

' @public
function getBuffer() as object
return m.buffer
end function

' @public
function getBit(index as integer) as integer
if ((m.buffer[getBufferIndex(index)] >> (7 - index MOD 8)) and 1) = 1
return 1
else
return 0
end if
end function

' @public
function getLengthInBits() as integer
return m.numberOfBits
end function

' @public
sub put(num as integer, length as integer)
for i = 0 to length - 1 step 1
pushBit(((num >> (length - i - 1)) and 1) = 1)
end for
end sub

' @public
sub pushBit(isSet as boolean)
bufIndex = getBufferIndex(m.numberOfBits)

if m.buffer.count() <= bufIndex
m.buffer.push(0)
end if

if isSet = true
m.buffer[bufIndex] = m.buffer[bufIndex] or (&H80 >> (m.numberOfBits MOD 8))
end if

m.numberOfBits += 1
end sub
12 changes: 12 additions & 0 deletions brightscript/components/QRCode/QRBitBuffer/QRBitBuffer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<component name="QRBitBuffer" extends="Node">
<script type="text/brightscript" uri="QRBitBuffer.brs" />

<interface>
<function name="getBuffer" /><!-- @return ByteArray -->
<function name="getBit" /><!-- @param index integer, @return integer 1 or 0 -->
<function name="getLengthInBits" /><!-- @return size in bits -->
<function name="put" /><!-- @param num integer, length integer -->
<function name="pushBit" /><!-- @param bit boolean -->
</interface>
</component>
Loading