public function _IMagickLuminanceSource($image, $width, $height)
 {
     parent::__construct($width, $height);
     $this->dataWidth = $width;
     $this->dataHeight = $height;
     $this->left = 0;
     $this->top = 0;
     $this->image = $image;
     // In order to measure pure decoding speed, we convert the entire image to a greyscale array
     // up front, which is the same as the Y channel of the YUVLuminanceSource in the real app.
     $this->luminances = array();
     $image->setImageColorspace(\Imagick::COLORSPACE_GRAY);
     // $image->newPseudoImage(0, 0, "magick:rose");
     $pixels = $image->exportImagePixels(1, 1, $width, $height, "RGB", \Imagick::COLORSPACE_RGB);
     $array = array();
     $rgb = array();
     for ($i = 0; $i < count($pixels); $i += 3) {
         $r = $pixels[$i] & 0xff;
         $g = $pixels[$i + 1] & 0xff;
         $b = $pixels[$i + 2] & 0xff;
         if ($r == $g && $g == $b) {
             // Image is already greyscale, so pick any channel.
             $this->luminances[] = $r;
             //(($r + 128) % 256) - 128;
         } else {
             // Calculate luminance cheaply, favoring green.
             $this->luminances[] = ($r + 2 * $g + $b) / 4;
             //(((($r + 2 * $g + $b) / 4) + 128) % 256) - 128;
         }
     }
 }
 public function GDLuminanceSource($gdImage, $width, $height)
 {
     parent::__construct($width, $height);
     $this->dataWidth = $width;
     $this->dataHeight = $height;
     $this->left = 0;
     $this->top = 0;
     $this->{$gdImage} = $gdImage;
     // In order to measure pure decoding speed, we convert the entire image to a greyscale array
     // up front, which is the same as the Y channel of the YUVLuminanceSource in the real app.
     $this->luminances = array();
     //$this->luminances = $this->grayScaleToBitmap($this->grayscale());
     $array = array();
     $rgb = array();
     for ($j = 0; $j < $height; $j++) {
         for ($i = 0; $i < $width; $i++) {
             $argb = imagecolorat($this->{$gdImage}, $i, $j);
             $pixel = imagecolorsforindex($this->{$gdImage}, $argb);
             $r = $pixel['red'];
             $g = $pixel['green'];
             $b = $pixel['blue'];
             if ($r == $g && $g == $b) {
                 // Image is already greyscale, so pick any channel.
                 $this->luminances[] = $r;
                 //(($r + 128) % 256) - 128;
             } else {
                 // Calculate luminance cheaply, favoring green.
                 $this->luminances[] = ($r + 2 * $g + $b) / 4;
                 //(((($r + 2 * $g + $b) / 4) + 128) % 256) - 128;
             }
         }
     }
     /*
     
     for ($y = 0; $y < $height; $y++) {
         $offset = $y * $width;
         for ($x = 0; $x < $width; $x++) {
             $pixel = $pixels[$offset + $x];
             $r = ($pixel >> 16) & 0xff;
             $g = ($pixel >> 8) & 0xff;
             $b = $pixel & 0xff;
             if ($r == $g && $g == $b) {
     // Image is already greyscale, so pick any channel.
     
                 $this->luminances[intval($offset + $x)] = (($r+128) % 256) - 128;
             } else {
     // Calculate luminance cheaply, favoring green.
                 $this->luminances[intval($offset + $x)] =  (((($r + 2 * $g + $b) / 4)+128)%256) - 128;
             }
     
     
     
         }
     */
     //}
     //   $this->luminances = $this->grayScaleToBitmap($this->luminances);
 }
 public function __construct($yuvData, $dataWidth, $dataHeight, $left, $top, $width, $height, $reverseHorizontal)
 {
     parent::__construct($width, $height);
     if ($left + $width > $dataWidth || $top + $height > $dataHeight) {
         throw new IllegalArgumentException("Crop rectangle does not fit within image data.");
     }
     $this->yuvData = $yuvData;
     $this->dataWidth = $dataWidth;
     $this->dataHeight = $dataHeight;
     $this->left = $left;
     $this->top = $top;
     if ($reverseHorizontal) {
         $this->reverseHorizontal($width, $height);
     }
 }
 public function RGBLuminanceSource_($width, $height, $pixels)
 {
     parent::__construct($width, $height);
     $this->dataWidth = $width;
     $this->dataHeight = $height;
     $this->left = 0;
     $this->top = 0;
     $this->pixels = $pixels;
     // In order to measure pure decoding speed, we convert the entire image to a greyscale array
     // up front, which is the same as the Y channel of the YUVLuminanceSource in the real app.
     $this->luminances = array();
     //$this->luminances = $this->grayScaleToBitmap($this->grayscale());
     foreach ($pixels as $key => $pixel) {
         $r = $pixel['red'];
         $g = $pixel['green'];
         $b = $pixel['blue'];
         /* if (($pixel & 0xFF000000) == 0) {
                         $pixel = 0xFFFFFFFF; // = white
                     }
         
                     // .229R + 0.587G + 0.114B (YUV/YIQ for PAL and NTSC)
         
                     $this->luminances[$key] =
                         (306 * (($pixel >> 16) & 0xFF) +
                             601 * (($pixel >> 8) & 0xFF) +
                             117 * ($pixel & 0xFF) +
                             0x200) >> 10;
         
                    */
         //$r = ($pixel >> 16) & 0xff;
         //$g = ($pixel >> 8) & 0xff;
         //$b = $pixel & 0xff;
         if ($r == $g && $g == $b) {
             // Image is already greyscale, so pick any channel.
             $this->luminances[$key] = $r;
             //(($r + 128) % 256) - 128;
         } else {
             // Calculate luminance cheaply, favoring green.
             $this->luminances[$key] = ($r + 2 * $g + $b) / 4;
             //(((($r + 2 * $g + $b) / 4) + 128) % 256) - 128;
         }
     }
     /*
     
     for ($y = 0; $y < $height; $y++) {
         $offset = $y * $width;
         for ($x = 0; $x < $width; $x++) {
             $pixel = $pixels[$offset + $x];
             $r = ($pixel >> 16) & 0xff;
             $g = ($pixel >> 8) & 0xff;
             $b = $pixel & 0xff;
             if ($r == $g && $g == $b) {
     // Image is already greyscale, so pick any channel.
     
                 $this->luminances[intval($offset + $x)] = (($r+128) % 256) - 128;
             } else {
     // Calculate luminance cheaply, favoring green.
                 $this->luminances[intval($offset + $x)] =  (((($r + 2 * $g + $b) / 4)+128)%256) - 128;
             }
     
     
     
         }
     */
     //}
     //   $this->luminances = $this->grayScaleToBitmap($this->luminances);
 }