Ejemplo n.º 1
0
 /**
  * Helper function for applyMaskPenaltyRule1.
  *
  * We need this for doing this calculation in both vertical and horizontal
  * orders respectively.
  *
  * @param  ByteMatrix $matrix
  * @param  boolean    $isHorizontal
  * @return integer
  */
 protected static function applyMaskPenaltyRule1Internal(ByteMatrix $matrix, $isHorizontal)
 {
     $penalty = 0;
     $iLimit = $isHorizontal ? $matrix->getHeight() : $matrix->getWidth();
     $jLimit = $isHorizontal ? $matrix->getWidth() : $matrix->getHeight();
     $array = $matrix->getArray();
     for ($i = 0; $i < $iLimit; $i++) {
         $numSameBitCells = 0;
         $prevBit = -1;
         for ($j = 0; $j < $jLimit; $j++) {
             $bit = $isHorizontal ? $array[$i][$j] : $array[$j][$i];
             if ($bit === $prevBit) {
                 $numSameBitCells++;
             } else {
                 if ($numSameBitCells >= 5) {
                     $penalty += self::N1 + ($numSameBitCells - 5);
                 }
                 $numSameBitCells = 1;
                 $prevBit = $bit;
             }
         }
         if ($numSameBitCells >= 5) {
             $penalty += self::N1 + ($numSameBitCells - 5);
         }
     }
     return $penalty;
 }