Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 8 additions & 8 deletions packages/barcodes/code128.rip
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ charValue =! (c, subset) ->
codewords =! (text, gs1) ->
n = text.length
fail 'Code 128 text is empty' unless n
cost = new Int32Array(3 * (n + 1))
move = new Uint8Array(3 * (n + 1))
cost = Int32Array.new(3 * (n + 1))
move = Uint8Array.new(3 * (n + 1))
i = n - 1
while i >= 0
c = text.charCodeAt i
Expand Down Expand Up @@ -144,7 +144,7 @@ codewords =! (text, gs1) ->

# Module row: 1 dark, 0 light, bars first within each codeword.
modules =! (codes) ->
out = new Uint8Array(11 * codes.length + 2)
out = Uint8Array.new(11 * codes.length + 2)
x = 0
for code in codes
pattern = PATTERNS[code]
Expand Down Expand Up @@ -186,7 +186,7 @@ raster =! (mods, scale, border, height) ->
{ W, H, bars }

pixelRow =! (r) ->
row = new Uint8Array(r.W)
row = Uint8Array.new(r.W)
for k in [0...r.bars.length] by 2
row.fill 1, r.bars[k], r.bars[k] + r.bars[k + 1]
row
Expand Down Expand Up @@ -254,7 +254,7 @@ export encodeCode128 =! (text, output = 'raw', opts = {}) ->

# Widths flattened for the matcher, seven slots per value.
WIDTHS =! do ->
out = new Uint8Array(7 * PATTERNS.length)
out = Uint8Array.new(7 * PATTERNS.length)
for pattern, code in PATTERNS
for k in [0...pattern.length]
out[7 * code + k] = pattern.charCodeAt(k) - 48
Expand Down Expand Up @@ -437,11 +437,11 @@ export readCode128 =! (img, opts = {}) ->
asObject opts, 'opts'
validateImage img, opts.format
{width, height} = img
luma = new Uint8Array(width * height)
luma = Uint8Array.new(width * height)
copyLuma luma, undefined, img, opts.format
side = Math.max(width, height) + 2
runs = new Int32Array(side)
rev = new Int32Array(side)
runs = Int32Array.new(side)
rev = Int32Array.new(side)
codes = []
vertical = false
hit = scanLines luma, width, height, false, runs, rev, codes
Expand Down
9 changes: 5 additions & 4 deletions packages/barcodes/dom.rip
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class QRCanvas
return if @bitmapDrawn
@bitmapDrawn = true
@drawBitmap img
@scanner = new Scanner(decoder)
@scanner = Scanner.new(decoder)
@reader =
clean: =>
@generation++
Expand Down Expand Up @@ -331,7 +331,7 @@ export class QRCanvas
return unless @bitmap
{data, height, width} = img
if @rotate
out = new Uint8ClampedArray(data.length)
out = Uint8ClampedArray.new(data.length)
for y in [0...height]
for x in [0...width]
src = 4 * (y * width + x)
Expand Down Expand Up @@ -821,7 +821,7 @@ invalidState = (msg) -> DOMException.new msg, 'InvalidStateError'

prefixed = (e, prefix) ->
return DOMException.new("#{prefix}: #{e.message}", e.name) if e instanceof DOMException
return new e.constructor("#{prefix}: #{e.message}") if e instanceof Error
return e.constructor.new("#{prefix}: #{e.message}") if e instanceof Error
Error.new "#{prefix}: #{e}"

createCanvas = (width, height) ->
Expand Down Expand Up @@ -878,8 +878,9 @@ toImageData = (image) ->
throw invalidState('Failed to load or decode HTMLImageElement.')
return drawSource(image, image.naturalWidth, image.naturalHeight)
if kind is 'SVGImageElement'
decoding = image.decode?()
try
await image.decode?()
await decoding
catch
throw invalidState('Failed to load or decode SVGImageElement.')
return drawSource(image, image.width.baseVal.value, image.height.baseVal.value)
Expand Down
2 changes: 1 addition & 1 deletion packages/barcodes/gif.rip
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export writeGif =! (W, H, rowFor) ->
N = 126
fullChunks = pixels // N
tail = pixels % N
out = new Uint8Array(408 + fullChunks * (N + 2) + 2 + tail + 4)
out = Uint8Array.new(408 + fullChunks * (N + 2) + 2 + tail + 4)
pos = 0
u16 = (v) ->
out[pos++] = v & 0xff
Expand Down
6 changes: 3 additions & 3 deletions packages/barcodes/image.rip
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ export validateImage =! (img, named, layout, capacity) ->
return RGBA if bytes.length is 4 * px
throw RangeError.new "\"img.data\" expected #{3 * px} or #{4 * px} bytes without opts.format, got #{bytes.length}"

export LITTLE_ENDIAN =! new Uint8Array(new Uint32Array([1]).buffer)[0] is 1
export LITTLE_ENDIAN =! Uint8Array.new(Uint32Array.new([1]).buffer)[0] is 1

# Packed four-byte pixels read as whole words: one load per pixel instead of
# three, unrolled four wide, the same (r + 2g + b) / 4 luma. Alpha and the X
# byte fall out of the mask, and the weights are symmetric in r and b, so
# every RGBA/BGRA/X layout takes this path.
copyWords =! (out, data, byteStart, n) ->
words = new Uint32Array(data.buffer, byteStart, n)
words = Uint32Array.new(data.buffer, byteStart, n)
i = 0
end = n - 3
while i < end
Expand Down Expand Up @@ -106,7 +106,7 @@ export copyLuma =! (out, maxSize, img, named, layout) ->

# RGBA image from a per-pixel dark predicate.
export darkToImage =! (width, height, isDark) ->
data = new Uint8Array(width * height * 4)
data = Uint8Array.new(width * height * 4)
i = 0
for y in [0...height]
for x in [0...width]
Expand Down
88 changes: 44 additions & 44 deletions packages/barcodes/qr.rip
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fail =! (msg) -> throw Error.new msg

# charCode -> Table 5 value; -1 outside the alphabet.
ALNUM_VAL =! do ->
t = new Int8Array(128).fill(-1)
t = Int8Array.new(128).fill(-1)
for i in [0...ALPHANUMERIC.length]
t[ALPHANUMERIC.charCodeAt(i)] = i
t
Expand All @@ -52,7 +52,7 @@ RS_CACHE =! []

rsGenerator =! (n) ->
{exp, log} = GF256
gen = new Uint8Array(n)
gen = Uint8Array.new(n)
gen[n - 1] = 1
root = 1
for i in [0...n]
Expand All @@ -66,7 +66,7 @@ rsCached =! (n) ->
return RS_CACHE[n] if RS_CACHE[n]
{exp, log} = GF256
gen = rsGenerator n
products = new Uint8Array(256 * n)
products = Uint8Array.new(256 * n)
for f in [1...256]
lf = log[f]
base = f * n
Expand All @@ -80,7 +80,7 @@ rsEcc =! (data, rs) ->
{gen, products} = rs
n = gen.length
last = n - 1
res = new Uint8Array(n)
res = Uint8Array.new(n)
for i in [0...data.length]
base = (data[i] ^ res[0]) * n
for j in [0...last]
Expand Down Expand Up @@ -112,7 +112,7 @@ encodeData =! (ver, ecc, text, type, utf8) ->
lengthBits = LENGTH_BITS[type][(ver + 7) // 17]
dataLen = if type is 'byte' then utf8.length else text.length
fail 'Capacity overflow' if dataLen >= 1 << lengthBits
bytes = new Uint8Array(cap.capacity >>> 3)
bytes = Uint8Array.new(cap.capacity >>> 3)
# MSB-first accumulator flushed a byte at a time; pushes are <= 16 bits and
# a flush keeps it below 8, so it never nears 32.
acc = 0
Expand Down Expand Up @@ -163,7 +163,7 @@ encodeData =! (ver, ecc, text, type, utf8) ->
blocks.push block
eccs.push rsEcc(block, rs)
pos += len
res = new Uint8Array(bytes.length + words * numBlocks)
res = Uint8Array.new(bytes.length + words * numBlocks)
out = 0
for i in [0..blockLen]
for b in blocks
Expand All @@ -177,7 +177,7 @@ encodeData =! (ver, ecc, text, type, utf8) ->

mat =! (size) ->
words = (size + 31) >>> 5
{ size, words, v: new Uint32Array(words * size) }
{ size, words, v: Uint32Array.new(words * size) }

matGet =! (m, x, y) -> (m.v[y * m.words + (x >>> 5)] >>> (x & 31)) & 1

Expand All @@ -188,7 +188,7 @@ matSet =! (m, x, y, bit) ->
return

TRANSPOSE_MASKS =! [0x55555555, 0x33333333, 0x0f0f0f0f, 0x00ff00ff, 0x0000ffff]
TRANSPOSE_TMP =! new Uint32Array(32)
TRANSPOSE_TMP =! Uint32Array.new(32)

# 32x32 in-place bit-matrix transpose (butterfly network).
transpose32 =! (a) ->
Expand Down Expand Up @@ -352,7 +352,7 @@ symCache = null
buildSymCache =! (ver) ->
size = 21 + 4 * (ver - 1)
m = mat size
fun = new Uint8Array(size * size)
fun = Uint8Array.new(size * size)
setF = (x, y, bit) ->
matSet m, x, y, bit
fun[y * size + x] = 1
Expand Down Expand Up @@ -395,7 +395,7 @@ buildSymCache =! (ver) ->
planes = []
for i in [0...8]
planes.push mat(size)
posBuf = new Uint16Array(size * size)
posBuf = Uint16Array.new(size * size)
n = 0
xOffset = size - 1
dir = -1
Expand Down Expand Up @@ -576,7 +576,7 @@ renderSvg =! (r, optimize) ->
renderGif =! (r) ->
W = r.W
{m, map} = r
row = new Uint8Array(W)
row = Uint8Array.new(W)
prevMy = -2
writeGif W, W, (y) ->
my = map[y]
Expand Down Expand Up @@ -644,7 +644,7 @@ export encodeQR =! (text, output = 'raw', opts = {}) ->
W = (m.size + 2 * border) * scale
maxOutputSize = if output is 'ascii' or output is 'gif' or output is 'data-url' then MAX_COMPACT_OUTPUT_SIZE else MAX_OUTPUT_SIZE
throw RangeError.new "invalid opts: output is #{W}x#{W} (max #{maxOutputSize}), reduce border/scale" if W > maxOutputSize
map = new Int32Array(W)
map = Int32Array.new(W)
for i in [0...W]
f = i // scale - border
map[i] = if f >= 0 and f < m.size then f else -1
Expand Down Expand Up @@ -705,15 +705,15 @@ BYTE_LENGTH_BITS =! [8, 16, 16]
class Payload
constructor: (capacity) ->
@position = 0
@data = new Uint8Array(0)
@data = Uint8Array.new(0)
@dataLen = 0
@bytes = new Uint8Array(capacity)
@bytes = Uint8Array.new(capacity)
@views = Array.new(capacity + 1)

# A length-n window over the byte arena, created once per length so the
# frame path never allocates after its first use.
view: (n) ->
@views[n] or (@views[n] = new Uint8Array(@bytes.buffer, 0, n))
@views[n] or (@views[n] = Uint8Array.new(@bytes.buffer, 0, n))

read: (bits) ->
start = @position
Expand Down Expand Up @@ -778,7 +778,7 @@ class Payload
length = @read BYTE_LENGTH_BITS[cls]
return FAIL.data if length < 0 or @position + 8 * length > dataLen * 8
if parts
segment = new Uint8Array(length)
segment = Uint8Array.new(length)
for i in [0...length]
segment[i] = @read(8)
parts.push res if res
Expand Down Expand Up @@ -1117,7 +1117,7 @@ resizeRows =! (src, dst, width, dstWidth, from, to) ->
# The same box filter over whole words: one word from each source row holds
# four pixels, summed in two 16-bit lanes to produce two output pixels.
resizeWords =! (src, dst, width, dstWidth, from, to) ->
words = new Uint32Array(src.buffer, src.byteOffset, (width * (to << 1)) >> 2)
words = Uint32Array.new(src.buffer, src.byteOffset, (width * (to << 1)) >> 2)
wordsPerRow = width >> 2
pairs = dstWidth >> 1
for y in [from...to]
Expand Down Expand Up @@ -1312,24 +1312,24 @@ export class QRScanner
@opts = Object.freeze { ...init, effort: @effort, maxSize, timeLimit: @timeLimit }
@width = 0
@height = 0
@luma = new Uint8Array(bytes)
@luma = Uint8Array.new(bytes)
@image = { data: @luma, height: 0, width: 0 }
@input = { data: @luma, height: 0, width: 0 }
@grid = new Uint8Array(177 * 177)
@fun = new Uint8Array(177 * 177)
@alignPos = new Uint8Array(7)
@codewords = new Uint8Array(BYTES[39])
@blockBytes = new Uint8Array(BYTES[39])
@syndromes = new Uint8Array(31)
@sigma = new Uint8Array(31)
@previous = new Uint8Array(31)
@next = new Uint8Array(31)
@candidates = new Uint32Array(16)
@ranks = new Float64Array(16)
@found = new Uint32Array(4 * 16 * 3)
@pick = new Float64Array(8)
@nodes = new Float64Array(7 * 7 * 2)
@located = new Float64Array((7 * 7 - 3) * 4)
@grid = Uint8Array.new(177 * 177)
@fun = Uint8Array.new(177 * 177)
@alignPos = Uint8Array.new(7)
@codewords = Uint8Array.new(BYTES[39])
@blockBytes = Uint8Array.new(BYTES[39])
@syndromes = Uint8Array.new(31)
@sigma = Uint8Array.new(31)
@previous = Uint8Array.new(31)
@next = Uint8Array.new(31)
@candidates = Uint32Array.new(16)
@ranks = Float64Array.new(16)
@found = Uint32Array.new(4 * 16 * 3)
@pick = Float64Array.new(8)
@nodes = Float64Array.new(7 * 7 * 2)
@located = Float64Array.new((7 * 7 - 3) * 4)
@payload = Payload.new BYTES[39]
@inFlight = false
@staged = false
Expand All @@ -1341,11 +1341,11 @@ export class QRScanner
@points = undefined
# `map` holds the active homography; `from` and `to` are scratch, and `to`
# doubles as the fine-plane map until the next build.
@map = new Float64Array(9)
@from = new Float64Array(9)
@to = new Float64Array(9)
@map = Float64Array.new(9)
@from = Float64Array.new(9)
@to = Float64Array.new(9)
@alignPoint = { x: 0.1, y: 0.1 }
@finePlane = { d: new Uint8Array(0), cut: new Int16Array(0), W: 0, H: 0, bw: 0, sh: 0 }
@finePlane = { d: Uint8Array.new(0), cut: Int16Array.new(0), W: 0, H: 0, bw: 0, sh: 0 }
@invertedProjection = false
@decodedSize = 0
layers = []
Expand All @@ -1356,18 +1356,18 @@ export class QRScanner
blockWidth = Math.ceil(width / 8)
blockHeight = Math.ceil(height / 8)
centers = Math.ceil(width / 7) * Math.ceil(height / 7)
luma = if i then new Uint8Array(width * height) else @luma
cuts = new Int16Array(blockWidth * blockHeight)
luma = if i then Uint8Array.new(width * height) else @luma
cuts = Int16Array.new(blockWidth * blockHeight)
layers.push
bitmap: new Uint32Array(Math.ceil(width / 32) * height)
bitmap: Uint32Array.new(Math.ceil(width / 32) * height)
blockHeight: 0
blockWidth: 0
blocks: new Uint8Array(blockWidth * blockHeight)
blocks: Uint8Array.new(blockWidth * blockHeight)
cuts: cuts
height: 0
luma: luma
patternCount: 0
patterns: new Float64Array(centers * 4)
patterns: Float64Array.new(centers * 4)
used: false
width: 0
words: 0
Expand All @@ -1377,10 +1377,10 @@ export class QRScanner
# Native luma offered to downscaled sampling; `r` is the layer index.
context: { opts: @opts, scale: 1 << i, ox: 0, oy: 0, fine: (if i then { luma: @image, r: i } else undefined) }
found: false
inverted: new Uint8Array(centers)
inverted: Uint8Array.new(centers)
setCount: 0
setCursor: 0
sets: new Float64Array(256 * 5)
sets: Float64Array.new(256 * 5)
setsReady: false
# Round-0 pick as an id bag (sum, min, max); retries skip a matching set.
pickSum: -1
Expand Down
6 changes: 3 additions & 3 deletions packages/barcodes/spec.rip
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ export versionBits =! (ver) ->
# GF(2^8) with primitive polynomial 0x11d. EXP is doubled so the product of
# two logs indexes it without a modulo.
export GF256 =! do ->
exp = new Uint8Array(510)
log = new Uint8Array(256)
exp = Uint8Array.new(510)
log = Uint8Array.new(256)
x = 1
for i in [0...255]
exp[i] = exp[i + 255] = x
Expand Down Expand Up @@ -116,7 +116,7 @@ export maskBits =! (x, y) ->
bits

POP16 =! do ->
t = new Uint8Array(1 << 16)
t = Uint8Array.new(1 << 16)
for i in [1...t.length]
t[i] = t[i >>> 1] + (i & 1)
t
Expand Down
Loading