private function ensureCapacity($size)
 {
     if ($size > count($this->bits) * 32) {
         $newBits = $this->makeArray($size);
         $newBits = arraycopy($this->bits, 0, $newBits, 0, count($this->bits));
         $this->bits = $newBits;
     }
 }
 public function getMatrix()
 {
     $width = $this->getWidth();
     $height = $this->getHeight();
     // If the caller asks for the entire underlying image, save the copy and give them the
     // original data. The docs specifically warn that result.length must be ignored.
     if ($width == $this->dataWidth && $height == $this->dataHeight) {
         return $this->luminances;
     }
     $area = $width * $height;
     $matrix = array();
     $inputOffset = $this->top * $this->dataWidth + $this->left;
     // If the width matches the full width of the underlying data, perform a single copy.
     if ($width == $this->dataWidth) {
         $matrix = arraycopy($this->luminances, $inputOffset, $matrix, 0, $area);
         return $matrix;
     }
     // Otherwise copy one cropped row at a time.
     $rgb = $this->luminances;
     for ($y = 0; $y < $height; $y++) {
         $outputOffset = $y * $width;
         $matrix = arraycopy($rgb, $inputOffset, $matrix, $outputOffset, $width);
         $inputOffset += $this->dataWidth;
     }
     return $matrix;
 }
 public function addResultPoints($newPoints)
 {
     $oldPoints = $this->resultPoints;
     if ($oldPoints == null) {
         $this->resultPoints = $newPoints;
     } else {
         if ($newPoints != null && count($newPoints) > 0) {
             $allPoints = fill_array(0, count($oldPoints) + count($newPoints), 0);
             $allPoints = arraycopy($oldPoints, 0, $allPoints, 0, count($oldPoints));
             $allPoints = arraycopy($newPoints, 0, $allPoints, count($oldPoints), count($newPoints));
             $this->resultPoints = $allPoints;
         }
     }
 }
 /**
  * @param $y;  row to set
  * @param $row;  {@link BitArray} to copy from
  */
 public function setRow($y, $row)
 {
     $this->bits = arraycopy($row->getBitArray(), 0, $this->bits, $y * $this->rowSize, $this->rowSize);
 }