----------------------------------------------------------------------
(QRinput $input, $mask)
| 161 | |
| 162 | //---------------------------------------------------------------------- |
| 163 | public function encodeMask(QRinput $input, $mask) |
| 164 | { |
| 165 | if($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) { |
| 166 | throw new Exception('wrong version'); |
| 167 | } |
| 168 | if($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) { |
| 169 | throw new Exception('wrong level'); |
| 170 | } |
| 171 | |
| 172 | $raw = new QRrawcode($input); |
| 173 | |
| 174 | QRtools::markTime('after_raw'); |
| 175 | |
| 176 | $version = $raw->version; |
| 177 | $width = QRspec::getWidth($version); |
| 178 | $frame = QRspec::newFrame($version); |
| 179 | |
| 180 | $filler = new FrameFiller($width, $frame); |
| 181 | if(is_null($filler)) { |
| 182 | return NULL; |
| 183 | } |
| 184 | |
| 185 | // inteleaved data and ecc codes |
| 186 | for($i=0; $i<$raw->dataLength + $raw->eccLength; $i++) { |
| 187 | $code = $raw->getCode(); |
| 188 | $bit = 0x80; |
| 189 | for($j=0; $j<8; $j++) { |
| 190 | $addr = $filler->next(); |
| 191 | $filler->setFrameAt($addr, 0x02 | (($bit & $code) != 0)); |
| 192 | $bit = $bit >> 1; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | QRtools::markTime('after_filler'); |
| 197 | |
| 198 | unset($raw); |
| 199 | |
| 200 | // remainder bits |
| 201 | $j = QRspec::getRemainder($version); |
| 202 | for($i=0; $i<$j; $i++) { |
| 203 | $addr = $filler->next(); |
| 204 | $filler->setFrameAt($addr, 0x02); |
| 205 | } |
| 206 | |
| 207 | $frame = $filler->frame; |
| 208 | unset($filler); |
| 209 | |
| 210 | |
| 211 | // masking |
| 212 | $maskObj = new QRmask(); |
| 213 | if($mask < 0) { |
| 214 | |
| 215 | if (QR_FIND_BEST_MASK) { |
| 216 | $masked = $maskObj->mask($width, $frame, $input->getErrorCorrectionLevel()); |
| 217 | } else { |
| 218 | $masked = $maskObj->makeMask($width, $frame, (intval(QR_DEFAULT_MASK) % 8), $input->getErrorCorrectionLevel()); |
| 219 | } |
| 220 | } else { |
no test coverage detected