MCPcopy
hub / github.com/kciter/qart.js / getLZWRaster

Function getLZWRaster

src/qrcode.js:1885–1939  ·  view source on GitHub ↗
(lzwMinCodeSize)

Source from the content-addressed store, hash-verified

1883 }
1884
1885 var getLZWRaster = function (lzwMinCodeSize) {
1886 var clearCode = 1 << lzwMinCodeSize
1887 var endCode = (1 << lzwMinCodeSize) + 1
1888 var bitLength = lzwMinCodeSize + 1
1889
1890 // Setup LZWTable
1891 var table = lzwTable()
1892
1893 for (var i = 0; i < clearCode; i += 1) {
1894 table.add(String.fromCharCode(i))
1895 }
1896 table.add(String.fromCharCode(clearCode))
1897 table.add(String.fromCharCode(endCode))
1898
1899 var byteOut = byteArrayOutputStream()
1900 var bitOut = bitOutputStream(byteOut)
1901
1902 // clear code
1903 bitOut.write(clearCode, bitLength)
1904
1905 var dataIndex = 0
1906
1907 var s = String.fromCharCode(_data[dataIndex])
1908 dataIndex += 1
1909
1910 while (dataIndex < _data.length) {
1911 var c = String.fromCharCode(_data[dataIndex])
1912 dataIndex += 1
1913
1914 if (table.contains(s + c)) {
1915 s = s + c
1916 } else {
1917 bitOut.write(table.indexOf(s), bitLength)
1918
1919 if (table.size() < 0xfff) {
1920 if (table.size() == (1 << bitLength)) {
1921 bitLength += 1
1922 }
1923
1924 table.add(s + c)
1925 }
1926
1927 s = c
1928 }
1929 }
1930
1931 bitOut.write(table.indexOf(s), bitLength)
1932
1933 // end code
1934 bitOut.write(endCode, bitLength)
1935
1936 bitOut.flush()
1937
1938 return byteOut.toByteArray()
1939 }
1940
1941 var lzwTable = function () {
1942 var _map = {}

Callers 1

gifImageFunction · 0.85

Calls 3

lzwTableFunction · 0.85
byteArrayOutputStreamFunction · 0.85
bitOutputStreamFunction · 0.85

Tested by

no test coverage detected