public static function applyMaskPenaltyRule2(ByteMatrix $matrix) : int
    {
        $penalty = 0;
        $array = $matrix->getArray();
        $width = $matrix->getWidth();
        $height = $matrix->getHeight();

        for ($y = 0; $y < $height - 1; ++$y) {
            for ($x = 0; $x < $width - 1; ++$x) {
                $value = $array[$y][$x];

                if ($value === $array[$y][$x + 1]
                    && $value === $array[$y + 1][$x]
                    && $value === $array[$y + 1][$x + 1]
                ) {
                    ++$penalty;
                }
            }
        }

        return self::N2 * $penalty;
    }
public static function applyMaskPenaltyRule2(ByteMatrix $matrix) : int
    {
        $penalty = 0;
        $array = $matrix->getArray();
        $width = $matrix->getWidth();
        $height = $matrix->getHeight();

        for ($y = 0; $y < $height - 1; ++$y) {
            for ($x = 0; $x < $width - 1; ++$x) {
                $value = $array[$y][$x];

                if ($value === $array[$y][$x + 1]
                    && $value === $array[$y + 1][$x]
                    && $value === $array[$y + 1][$x + 1]
                ) {
                    ++$penalty;
                }
            }
        }

        return self::N2 * $penalty;
    }
public static function applyMaskPenaltyRule2 ( ByteMatrix $ matrix ) : int { $ penalty = 0 ; $ array = $ matrix -> getArray ( ) ; $ width = $ matrix -> getWidth ( ) ; $ height = $ matrix -> getHeight ( ) ; for ( $ y = 0 ; $ y < $ height - 1 ; ++ $ y ) { for ( $ x = 0 ; $ x < $ width - 1 ; ++ $ x ) { $ value = $ array [ $ y ] [ $ x ] ; if ( $ value === $ array [ $ y ] [ $ x + 1 ] && $ value === $ array [ $ y + 1 ] [ $ x ] && $ value === $ array [ $ y + 1 ] [ $ x + 1 ] ) { ++ $ penalty ; } } } return self :: N2 * $ penalty ; }
Applies mask penalty rule 2 and returns the penalty.

Finds 2x2 blocks with the same color and gives penalty to them. This is
actually equivalent to the spec's rule, which is to find MxN blocks and
give a penalty proportional to (M-1)x(N-1), because this is the number of
2x2 blocks inside such a block.
Applies mask penalty rule 2 and returns the penalty .