MCPcopy Create free account
hub / github.com/codemistic/Web-Development / QRbitstream

Class QRbitstream

text-to-qr/lib/phpqrcode/phpqrcode.php:1777–1929  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1775 */
1776
1777 class QRbitstream {
1778
1779 public $data = array();
1780
1781 //----------------------------------------------------------------------
1782 public function size()
1783 {
1784 return count($this->data);
1785 }
1786
1787 //----------------------------------------------------------------------
1788 public function allocate($setLength)
1789 {
1790 $this->data = array_fill(0, $setLength, 0);
1791 return 0;
1792 }
1793
1794 //----------------------------------------------------------------------
1795 public static function newFromNum($bits, $num)
1796 {
1797 $bstream = new QRbitstream();
1798 $bstream->allocate($bits);
1799
1800 $mask = 1 << ($bits - 1);
1801 for($i=0; $i<$bits; $i++) {
1802 if($num & $mask) {
1803 $bstream->data[$i] = 1;
1804 } else {
1805 $bstream->data[$i] = 0;
1806 }
1807 $mask = $mask >> 1;
1808 }
1809
1810 return $bstream;
1811 }
1812
1813 //----------------------------------------------------------------------
1814 public static function newFromBytes($size, $data)
1815 {
1816 $bstream = new QRbitstream();
1817 $bstream->allocate($size * 8);
1818 $p=0;
1819
1820 for($i=0; $i<$size; $i++) {
1821 $mask = 0x80;
1822 for($j=0; $j<8; $j++) {
1823 if($data[$i] & $mask) {
1824 $bstream->data[$p] = 1;
1825 } else {
1826 $bstream->data[$p] = 0;
1827 }
1828 $p++;
1829 $mask = $mask >> 1;
1830 }
1831 }
1832
1833 return $bstream;
1834 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected