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

Method encodeMask

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

----------------------------------------------------------------------

(QRinput $input, $mask)

Source from the content-addressed store, hash-verified

2969
2970 //----------------------------------------------------------------------
2971 public function encodeMask(QRinput $input, $mask)
2972 {
2973 if($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) {
2974 throw new Exception('wrong version');
2975 }
2976 if($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) {
2977 throw new Exception('wrong level');
2978 }
2979
2980 $raw = new QRrawcode($input);
2981
2982 QRtools::markTime('after_raw');
2983
2984 $version = $raw->version;
2985 $width = QRspec::getWidth($version);
2986 $frame = QRspec::newFrame($version);
2987
2988 $filler = new FrameFiller($width, $frame);
2989 if(is_null($filler)) {
2990 return NULL;
2991 }
2992
2993 // inteleaved data and ecc codes
2994 for($i=0; $i<$raw->dataLength + $raw->eccLength; $i++) {
2995 $code = $raw->getCode();
2996 $bit = 0x80;
2997 for($j=0; $j<8; $j++) {
2998 $addr = $filler->next();
2999 $filler->setFrameAt($addr, 0x02 | (($bit & $code) != 0));
3000 $bit = $bit >> 1;
3001 }
3002 }
3003
3004 QRtools::markTime('after_filler');
3005
3006 unset($raw);
3007
3008 // remainder bits
3009 $j = QRspec::getRemainder($version);
3010 for($i=0; $i<$j; $i++) {
3011 $addr = $filler->next();
3012 $filler->setFrameAt($addr, 0x02);
3013 }
3014
3015 $frame = $filler->frame;
3016 unset($filler);
3017
3018
3019 // masking
3020 $maskObj = new QRmask();
3021 if($mask < 0) {
3022
3023 if (QR_FIND_BEST_MASK) {
3024 $masked = $maskObj->mask($width, $frame, $input->getErrorCorrectionLevel());
3025 } else {
3026 $masked = $maskObj->makeMask($width, $frame, (intval(QR_DEFAULT_MASK) % 8), $input->getErrorCorrectionLevel());
3027 }
3028 } else {

Callers 1

encodeInputMethod · 0.95

Calls 11

getVersionMethod · 0.45
markTimeMethod · 0.45
getWidthMethod · 0.45
newFrameMethod · 0.45
getCodeMethod · 0.45
nextMethod · 0.45
setFrameAtMethod · 0.45
getRemainderMethod · 0.45
maskMethod · 0.45
makeMaskMethod · 0.45

Tested by

no test coverage detected