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

Method mask

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

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

($width, $frame, $level)

Source from the content-addressed store, hash-verified

2755
2756 //----------------------------------------------------------------------
2757 public function mask($width, $frame, $level)
2758 {
2759 $minDemerit = PHP_INT_MAX;
2760 $bestMaskNum = 0;
2761 $bestMask = array();
2762
2763 $checked_masks = array(0,1,2,3,4,5,6,7);
2764
2765 if (QR_FIND_FROM_RANDOM !== false) {
2766
2767 $howManuOut = 8-(QR_FIND_FROM_RANDOM % 9);
2768 for ($i = 0; $i < $howManuOut; $i++) {
2769 $remPos = rand (0, count($checked_masks)-1);
2770 unset($checked_masks[$remPos]);
2771 $checked_masks = array_values($checked_masks);
2772 }
2773
2774 }
2775
2776 $bestMask = $frame;
2777
2778 foreach($checked_masks as $i) {
2779 $mask = array_fill(0, $width, str_repeat("\0", $width));
2780
2781 $demerit = 0;
2782 $blacks = 0;
2783 $blacks = $this->makeMaskNo($i, $width, $frame, $mask);
2784 $blacks += $this->writeFormatInformation($width, $mask, $i, $level);
2785 $blacks = (int)(100 * $blacks / ($width * $width));
2786 $demerit = (int)((int)(abs($blacks - 50) / 5) * N4);
2787 $demerit += $this->evaluateSymbol($width, $mask);
2788
2789 if($demerit < $minDemerit) {
2790 $minDemerit = $demerit;
2791 $bestMask = $mask;
2792 $bestMaskNum = $i;
2793 }
2794 }
2795
2796 return $bestMask;
2797 }
2798
2799 //----------------------------------------------------------------------
2800 }

Callers 1

encodeMaskMethod · 0.45

Calls 4

makeMaskNoMethod · 0.95
evaluateSymbolMethod · 0.95
countFunction · 0.85

Tested by

no test coverage detected