/** * Append Padding Bit to bitstream * * @param array $bstream Bit stream * * @return array bitstream */ protected function appendPaddingBit($bstream) { if (is_null($bstream)) { return null; } $bits = count($bstream); $specObj = new Spec(); $maxwords = $specObj->getDataLength($this->version, $this->level); $maxbits = $maxwords * 8; if ($maxbits == $bits) { return $bstream; } if ($maxbits - $bits < 5) { return $this->appendNum($bstream, $maxbits - $bits, 0); } $bits += 4; $words = (int) (($bits + 7) / 8); $padding = array(); $padding = $this->appendNum($padding, $words * 8 - $bits + 4, 0); $padlen = $maxwords - $words; if ($padlen > 0) { $padbuf = array(); for ($idx = 0; $idx < $padlen; ++$idx) { $padbuf[$idx] = $idx & 1 ? 0x11 : 0xec; } $padding = $this->appendBytes($padding, $padlen, $padbuf); } return $this->appendBitstream($bstream, $padding); }
/** * Write Format Information on the frame and returns the number of black bits * * @param int $width Mask width * @param array $frame Frame * @param int $maskNo Mask number * @param int $level Error Correction level * * @return int blacks */ protected function writeFormatInformation($width, &$frame, $maskNo, $level) { $blacks = 0; $spec = new Spec(); $format = $spec->getFormatInfo($maskNo, $level); for ($idx = 0; $idx < 8; ++$idx) { if ($format & 1) { $blacks += 2; $val = 0x85; } else { $val = 0x84; } $frame[8][$width - 1 - $idx] = chr($val); if ($idx < 6) { $frame[$idx][8] = chr($val); } else { $frame[$idx + 1][8] = chr($val); } $format = $format >> 1; } for ($idx = 0; $idx < 7; ++$idx) { if ($format & 1) { $blacks += 2; $val = 0x85; } else { $val = 0x84; } $frame[$width - 7 + $idx][8] = chr($val); if ($idx == 0) { $frame[8][7] = chr($val); } else { $frame[8][6 - $idx] = chr($val); } $format = $format >> 1; } return $blacks; }