source-class-Com.Tecnick.Barcode.Type.Square.QrCode.MaskNum

It appears that you are using AdBlocking software. The cost of running this website is covered by advertisements. If you like it please feel free to a small amount of money to secure the future of this website.
Overview

Classes

Exceptions

  1: <?php
  2: /**
  3:  * MaskNum.php
  4:  *
  5:  * @since       2015-02-21
  6:  * @category    Library
  7:  * @package     Barcode
  8:  * @author      Nicola Asuni <info@tecnick.com>
  9:  * @copyright   2010-2016 Nicola Asuni - Tecnick.com LTD
 10:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 11:  * @link        https://github.com/tecnickcom/tc-lib-barcode
 12:  *
 13:  * This file is part of tc-lib-barcode software library.
 14:  */
 15: 
 16: namespace Com\Tecnick\Barcode\Type\Square\QrCode;
 17: 
 18: use \Com\Tecnick\Barcode\Exception as BarcodeException;
 19: use \Com\Tecnick\Barcode\Type\Square\QrCode\Data;
 20: 
 21: /**
 22:  * Com\Tecnick\Barcode\Type\Square\QrCode\MaskNum
 23:  *
 24:  * @since       2015-02-21
 25:  * @category    Library
 26:  * @package     Barcode
 27:  * @author      Nicola Asuni <info@tecnick.com>
 28:  * @copyright   2010-2016 Nicola Asuni - Tecnick.com LTD
 29:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 30:  * @link        https://github.com/tecnickcom/tc-lib-barcode
 31:  */
 32: abstract class MaskNum
 33: {
 34:     /**
 35:      * Make Mask Number
 36:      *
 37:      * @param int  $maskNo Mask number
 38:      * @param int  $width  Width
 39:      * @param int  $frame  Frame
 40:      * @param int  $mask   Mask
 41:      *
 42:      * @return int mask number
 43:      */
 44:     protected function makeMaskNo($maskNo, $width, $frame, &$mask)
 45:     {
 46:         $bnum = 0;
 47:         $bitMask = $this->generateMaskNo($maskNo, $width, $frame);
 48:         $mask = $frame;
 49:         for ($ypos = 0; $ypos < $width; ++$ypos) {
 50:             for ($xpos = 0; $xpos < $width; ++$xpos) {
 51:                 if ($bitMask[$ypos][$xpos] == 1) {
 52:                     $mask[$ypos][$xpos] = chr(ord($frame[$ypos][$xpos]) ^ ((int)($bitMask[$ypos][$xpos])));
 53:                 }
 54:                 $bnum += (int)(ord($mask[$ypos][$xpos]) & 1);
 55:             }
 56:         }
 57:         return $bnum;
 58:     }
 59: 
 60:     /**
 61:      * Return bit mask
 62:      *
 63:      * @param int   $maskNo Mask number
 64:      * @param int   $width  Width
 65:      * @param array $frame  Frame
 66:      *
 67:      * @return array bit mask
 68:      */
 69:     protected function generateMaskNo($maskNo, $width, $frame)
 70:     {
 71:         $bitMask = array_fill(0, $width, array_fill(0, $width, 0));
 72:         for ($ypos = 0; $ypos < $width; ++$ypos) {
 73:             for ($xpos = 0; $xpos < $width; ++$xpos) {
 74:                 if (ord($frame[$ypos][$xpos]) & 0x80) {
 75:                     $bitMask[$ypos][$xpos] = 0;
 76:                 } else {
 77:                     $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $xpos, $ypos);
 78:                     $bitMask[$ypos][$xpos] = (($maskFunc == 0) ? 1 : 0);
 79:                 }
 80:             }
 81:         }
 82:         return $bitMask;
 83:     }
 84: 
 85:     /**
 86:      * Mask 0
 87:      *
 88:      * @param int $xpos X position
 89:      * @param int $ypos Y position
 90:      *
 91:      * @return int mask
 92:      */
 93:     protected function mask0($xpos, $ypos)
 94:     {
 95:         return (($xpos + $ypos) & 1);
 96:     }
 97: 
 98:     /**
 99:      * Mask 1
100:      *
101:      * @param int $xpos X position
102:      * @param int $ypos Y position
103:      *
104:      * @return int mask
105:      */
106:     protected function mask1($xpos, $ypos)
107:     {
108:         $xpos = null;
109:         return ($ypos & 1);
110:     }
111: 
112:     /**
113:      * Mask 2
114:      *
115:      * @param int $xpos X position
116:      * @param int $ypos Y position
117:      *
118:      * @return int mask
119:      */
120:     protected function mask2($xpos, $ypos)
121:     {
122:         $ypos = null;
123:         return ($xpos % 3);
124:     }
125: 
126:     /**
127:      * Mask 3
128:      *
129:      * @param int $xpos X position
130:      * @param int $ypos Y position
131:      *
132:      * @return int mask
133:      */
134:     protected function mask3($xpos, $ypos)
135:     {
136:         return (($xpos + $ypos) % 3);
137:     }
138: 
139:     /**
140:      * Mask 4
141:      *
142:      * @param int $xpos X position
143:      * @param int $ypos Y position
144:      *
145:      * @return int mask
146:      */
147:     protected function mask4($xpos, $ypos)
148:     {
149:         return ((((int)($ypos / 2)) + ((int)($xpos / 3))) & 1);
150:     }
151: 
152:     /**
153:      * Mask 5
154:      *
155:      * @param int $xpos X position
156:      * @param int $ypos Y position
157:      *
158:      * @return int mask
159:      */
160:     protected function mask5($xpos, $ypos)
161:     {
162:         return ((($xpos * $ypos) & 1) + ($xpos * $ypos) % 3);
163:     }
164: 
165:     /**
166:      * Mask 6
167:      *
168:      * @param int $xpos X position
169:      * @param int $ypos Y position
170:      *
171:      * @return int mask
172:      */
173:     protected function mask6($xpos, $ypos)
174:     {
175:         return (((($xpos * $ypos) & 1) + ($xpos * $ypos) % 3) & 1);
176:     }
177: 
178:     /**
179:      * Mask 7
180:      *
181:      * @param int $xpos X position
182:      * @param int $ypos Y position
183:      *
184:      * @return int mask
185:      */
186:     protected function mask7($xpos, $ypos)
187:     {
188:         return (((($xpos * $ypos) % 3) + (($xpos + $ypos) & 1)) & 1);
189:     }
190: }
191: 
 

© 2004-2017 – Nicola Asuni - Tecnick.com - All rights reserved.
about - disclaimer - privacy