/*
:::::::::::::::::::::::::::::::::::::::::::::::
::                                           ::
::          Image descriptor block           ::
::                                           ::
:::::::::::::::::::::::::::::::::::::::::::::::
481741
function read_image_descriptor()
	{
		$this->getbytes(9);
		$head = $this->buffer;
    	$this->local_color_table_flag = ($this->buffer[8] & 0x80) ? true : false;
    	if($this->local_color_table_flag)
    	{
        	$sizecode = $this->buffer[8] & 0x07;
			$size = 2 << $sizecode;
			$this->getbytes(3 * $size);
			for($i = 0; $i < (3 * $size); $i++)
			{
        		$this->local_in[$i] = $this->buffer[$i];
        	}
        	if($this->out_color_table_size == 0)
        	{
        		$this->out_color_table_size = $size;
        		$out_color_table_sizecode = $sizecode;
				for($i = 0; $i < (3 * $size); $i++)
				{
					$this->global_out[$i] = $this->local_in[$i];
				}
        	}
    	}
    	if($this->first)
    	{
			$this->first = false;
			$this->fout .= "\x47\x49\x46\x38\x39\x61"; // <= 'GIF89a'
			if($this->width && $this->height)
			{
				$this->logical_screen_descriptor[0] = $this->width & 0xFF;
				$this->logical_screen_descriptor[1] = ($this->width & 0xFF00) >> 8;
				$this->logical_screen_descriptor[2] = $this->height & 0xFF;
				$this->logical_screen_descriptor[3] = ($this->height & 0xFF00) >> 8;
			}
			$this->logical_screen_descriptor[4] |= 0x80;
			$this->logical_screen_descriptor[5] &= 0xF0;
			$this->logical_screen_descriptor[6] |= $this->out_color_table_sizecode;
			$this->putbytes($this->logical_screen_descriptor, 7);
        	$this->putbytes($this->global_out, ($this->out_color_table_size * 3));
			if($this->use_loop)
			{
				$ns[0] = 0x21;
				$ns[1] = 0xFF;
				$ns[2] = 0x0B;
				$ns[3] = 0x4e;  // N
				$ns[4] = 0x45;  // E
				$ns[5] = 0x54;  // T
				$ns[6] = 0x53;  // S
				$ns[7] = 0x43;  // C
				$ns[8] = 0x41;  // A
				$ns[9] = 0x50;  // P
				$ns[10] = 0x45; // E
				$ns[11] = 0x32; // 2
				$ns[12] = 0x2e; // .
				$ns[13] = 0x30; // 0
				$ns[14] = 0x03;
				$ns[15] = 0x01;
				$ns[16] = $this->loop & 255;
    			$ns[17] = $this->loop >> 8;
				$ns[18] = 0x00;
				$this->putbytes($ns, 19);
			}
    	}
  		if($this->use_global_in)
		{
			$outtable = $this->global_in;
			$outsize = $this->global_color_table_size;
			$outsizecode = $this->global_color_table_sizecode;
		}
		else
		{
			$outtable = $this->global_out;
			$outsize = $this->out_color_table_size;
		}
		if ($this->local_color_table_flag)
		{
			if ($size == $this->out_color_table_size && !$this->arrcmp($this->local_in, $this->global_out, $size))
			{
				$outtable = $global_out;
				$outsize = $this->out_color_table_size;
			}
			else
			{
				$outtable = $this->local_in;
				$outsize = $size;
				$outsizecode = $sizecode;
			}
		}
		$use_trans = false;
		if($this->transparent)
		{
			for ($i = 0; $i < $outsize; $i++)
				if (   $outtable [3 * $i	] == $this->trans1
					&& $outtable [3 * $i + 1] == $this->trans2
					&& $outtable [3 * $i + 2] == $this->trans3
				)
					break;
			if ($i < $outsize)
			{
				$transindex = $i;
				$use_trans = true;
			}
			else
			{
				if($this->debug) print "Transparent color not found!\n<br>";
			}
		}
		if($this->delay || $use_trans)
		{
			$this->buffer[0] = 0x21;
			$this->buffer[1] = 0xf9;
			$this->buffer[2] = 0x04;
			$this->buffer[3] = ($this->disposal << 2) + ($use_trans ? 1 : 0);
			$this->buffer[4] = $this->delay & 0xff;
			$this->buffer[5] = ($this->delay & 0xff00) >> 8;
			$this->buffer[6] = $use_trans ? $transindex : 0;
			$this->buffer[7] = 0x00;
			$this->putbytes($this->buffer,8);
		}
		$this->buffer[0] = 0x2c;
		$this->putbytes($this->buffer,1);
		$head[0] = $this->x & 0xff;
		$head[1] = ($this->x & 0xff00) >> 8;
		$head[2] = $this->y & 0xff;
		$head[3] = ($this->y & 0xff00) >> 8;
		$head[8] &= 0x40;
		if($outtable != $this->global_out)
		{
			$head[8] |= 0x80;
			$head[8] |= $outsizecode;
		}
		$this->putbytes($head,9);
		if($outtable != $this->global_out)
		{
			if($this->debug) print "Using local color table.\n<br>";
			$this->putbytes($outtable, (3 * $outsize));
		}
		$this->getbytes(1);
		$this->putbytes($this->buffer,1);
		for (;;)
		{
			$this->getbytes(1);
			$this->putbytes($this->buffer,1);
			if(($u = $this->buffer[0]) == 0)
			{
				break;
			}
			$this->getbytes($u);
			$this->putbytes($this->buffer, $u);
    	}
	}
1374733
function encodeBlock(block) {
  /** @type {!Array<number>} */
  let adpcmSamples = blockHead_(block[0]);
  for (let i=3; i<block.length; i+=2) {
    /** @type {number} */
    let sample2 = encodeSample_(block[i]);
    /** @type {number} */
    let sample = encodeSample_(block[i + 1]);
    adpcmSamples.push((sample << 4) | sample2);
  }
  while (adpcmSamples.length < 256) {
    adpcmSamples.push(0);
  }
  return adpcmSamples;
}
115924
function(src, dest) {
    var i = 0;
    var len = Math.min(src.length, dest.length);
    while(i < len) {
      dest[i] = src[i];
      i++;
    }
    return dest;
  }
484198
private void process(int[] srcImage, int[] dstImage, int x, int y)
    {
        final int a = getSourcePixel(srcImage, x - 1, y - 1);
        final int b = getSourcePixel(srcImage, x, y - 1);
        final int c = getSourcePixel(srcImage, x + 1, y - 1);
        final int d = getSourcePixel(srcImage, x - 1, y);
        final int e = getSourcePixel(srcImage, x, y);
        final int f = getSourcePixel(srcImage, x + 1, y);
        final int g = getSourcePixel(srcImage, x - 1, y + 1);
        final int h = getSourcePixel(srcImage, x, y + 1);
        final int i = getSourcePixel(srcImage, x + 1, y + 1);
        int e0 = e;
        int e1 = e;
        int e2 = e;
        int e3 = e;
        int e4 = e;
        int e5 = e;
        int e6 = e;
        int e7 = e;
        int e8 = e;

        if (b != h && d != f)
        {
            e0 = computeE0(b, d, e);
            e1 = computeE1(a, b, c, d, e, f);
            e2 = computeE2(b, e, f);
            e3 = computeE3(a, b, d, e, g, h);
            e4 = e;
            e5 = computeE5(b, c, e, f, h, i);
            e6 = computeE6(d, e, h);
            e7 = computeE7(d, e, f, g, h, i);
            e8 = computeE8(e, f, h);
        }

        setDestPixel(dstImage, x * SCALE, y * SCALE, e0);
        setDestPixel(dstImage, x * SCALE + 1, y * SCALE, e1);
        setDestPixel(dstImage, x * SCALE + 2, y * SCALE, e2);
        setDestPixel(dstImage, x * SCALE, y * SCALE + 1, e3);
        setDestPixel(dstImage, x * SCALE + 1, y * SCALE + 1, e4);
        setDestPixel(dstImage, x * SCALE + 2, y * SCALE + 1, e5);
        setDestPixel(dstImage, x * SCALE, y * SCALE + 2, e6);
        setDestPixel(dstImage, x * SCALE + 1, y * SCALE + 2, e7);
        setDestPixel(dstImage, x * SCALE + 2, y * SCALE + 2, e8);
    }
311839
function init_block() {
		var n; // iterates over tree elements

		// Initialize the trees.
		for (n = 0; n < L_CODES;  n++) {
			dyn_ltree[n].fc = 0;
		}
		for (n = 0; n < D_CODES;  n++) {
			dyn_dtree[n].fc = 0;
		}
		for (n = 0; n < BL_CODES; n++) {
			bl_tree[n].fc = 0;
		}

		dyn_ltree[END_BLOCK].fc = 1;
		opt_len = static_len = 0;
		last_lit = last_dist = last_flags = 0;
		flags = 0;
		flag_bit = 1;
	}
783274
function minimizeImage(src, dest, cb) {
    squirrel(
        IMIN_MODULES, IMIN_OPTIONS,
        (err, Imagemin) => {
            const safeCb = (err) => {
                if (err) {
                    logger.error(err);
                }
                cb();
            };

            if (err) {
                safeCb(err);
            } else {
                const imin = new Imagemin()
                    .src(src)
                    .dest(dest)
                    .use(Imagemin.jpegtran({progressive: true}))
                    .use(Imagemin.optipng({optimizationLevel: 3}))
                    .use(Imagemin.gifsicle({interlaced: true}))
                    .use(Imagemin.svgo());

                imin.run(safeCb);
            }
        }
    );
}
818427
function(image) {
        var maskWidth = this._getMaskX(image.width);
        var maskHeight = this._getMaskY(image.height);
        var buf = this._getResizedImageBuffer(image, maskWidth, maskHeight);
        var mask = new Array(maskWidth * maskHeight);
        for (var y = 0; y < maskHeight; y++) {
            for (var x = 0; x < maskWidth; x++) {
                var idx = (y * maskWidth + x);
                var filled = this._checkFilledPixel(buf, idx);
                mask[idx] = filled ? 1 : 0;
            }
        }
        return mask;
    }
1178778
function learn() {
    var i;

    var lengthcount = pixels.length;
    var alphadec = 30 + ((samplefac - 1) / 3);
    var samplepixels = lengthcount / (3 * samplefac);
    var delta = ~~(samplepixels / ncycles);
    var alpha = initalpha;
    var radius = initradius;

    var rad = radius >> radiusbiasshift;

    if (rad <= 1) rad = 0;
    for (i = 0; i < rad; i++)
      radpower[i] = alpha * (((rad * rad - i * i) * radbias) / (rad * rad));

    var step;
    if (lengthcount < minpicturebytes) {
      samplefac = 1;
      step = 3;
    } else if ((lengthcount % prime1) !== 0) {
      step = 3 * prime1;
    } else if ((lengthcount % prime2) !== 0) {
      step = 3 * prime2;
    } else if ((lengthcount % prime3) !== 0)  {
      step = 3 * prime3;
    } else {
      step = 3 * prime4;
    }

    var b, g, r, j;
    var pix = 0; // current pixel

    i = 0;
    while (i < samplepixels) {
      b = (pixels[pix] & 0xff) << netbiasshift;
      g = (pixels[pix + 1] & 0xff) << netbiasshift;
      r = (pixels[pix + 2] & 0xff) << netbiasshift;

      j = contest(b, g, r);

      altersingle(alpha, j, b, g, r);
      if (rad !== 0) alterneigh(rad, j, b, g, r); // alter neighbours

      pix += step;
      if (pix >= lengthcount) pix -= lengthcount;

      i++;

      if (delta === 0) delta = 1;
      if (i % delta === 0) {
        alpha -= alpha / alphadec;
        radius -= radius / radiusdec;
        rad = radius >> radiusbiasshift;

        if (rad <= 1) rad = 0;
        for (j = 0; j < rad; j++)
          radpower[j] = alpha * (((rad * rad - j * j) * radbias) / (rad * rad));
      }
    }
  }
1232611
function (inData, outData, width, height) {
        var c = 1 / 9;
        convolve3x3(inData, outData, width, height,
            [
                [c, c, c],
                [c, c, c],
                [c, c, c]
            ]);
    }
1069400
public static void hessianInner(GrayS32 integral, int skip , int size ,
									GrayF32 intensity)
	{
		final int w = intensity.width;
		final int h = intensity.height;

		float norm = 1.0f/(size*size);

		int blockSmall = size/3;
		int blockLarge = size-blockSmall-1;
		int radiusFeature = size/2;
		int radiusSkinny = blockLarge/2;

		int blockW2 = 2*blockSmall;
		int blockW3 = 3*blockSmall;


		int rowOff1 = blockSmall*integral.stride;
		int rowOff2 = 2*rowOff1;
		int rowOff3 = 3*rowOff1;

		// make sure it starts on the correct pixel
		final int borderOrig = radiusFeature+ 1 + (skip-(radiusFeature+1)%skip);
		final int border = borderOrig/skip;
		final int lostPixel = borderOrig - radiusFeature-1;
		final int endY = h - border;
		final int endX = w - border;

		for( int y = border; y < endY; y++ ) {

			// pixel location in original input image
			int yy = y*skip;

			// index for output
			int indexDst = intensity.startIndex + y*intensity.stride+border;

			// indexes for Dxx
			int indexTop = integral.startIndex + (yy-radiusSkinny-1)*integral.stride+lostPixel;
			int indexBottom = indexTop + (blockLarge)*integral.stride;

			// indexes for Dyy
			int indexL = integral.startIndex + (yy-radiusFeature-1)*integral.stride + (radiusFeature-radiusSkinny)+lostPixel;
			int indexR = indexL + blockLarge;

			// indexes for Dxy
			int indexY1 = integral.startIndex + (yy-blockSmall-1)*integral.stride + (radiusFeature-blockSmall)+lostPixel;
			int indexY2 = indexY1 + blockSmall*integral.stride;
			int indexY3 = indexY2 + integral.stride;
			int indexY4 = indexY3 + blockSmall*integral.stride;

			for( int x = border; x < endX; x++ , indexDst++) {
				float Dxx = integral.data[indexBottom+blockW3] - integral.data[indexTop+blockW3] - integral.data[indexBottom] + integral.data[indexTop];
				Dxx -= 3*(integral.data[indexBottom+blockW2] - integral.data[indexTop+blockW2] - integral.data[indexBottom+blockSmall] + integral.data[indexTop+blockSmall]);

				float Dyy = integral.data[indexR+rowOff3] - integral.data[indexL+rowOff3] - integral.data[indexR] + integral.data[indexL];
				Dyy -= 3*(integral.data[indexR+rowOff2] - integral.data[indexL+rowOff2] - integral.data[indexR+rowOff1] + integral.data[indexL+rowOff1]);

				int x3 = blockSmall+1;
				int x4 = x3+blockSmall;

				float Dxy = integral.data[indexY2+blockSmall] - integral.data[indexY1+blockSmall] - integral.data[indexY2] + integral.data[indexY1];
				Dxy -= integral.data[indexY2+x4] - integral.data[indexY1+x4] - integral.data[indexY2+x3] + integral.data[indexY1+x3];
				Dxy += integral.data[indexY4+x4] - integral.data[indexY3+x4] - integral.data[indexY4+x3] + integral.data[indexY3+x3];
				Dxy -= integral.data[indexY4+blockSmall] - integral.data[indexY3+blockSmall] - integral.data[indexY4] + integral.data[indexY3];

				Dxx *= norm;
				Dxy *= norm;
				Dyy *= norm;

				intensity.data[indexDst] = Dxx*Dyy-0.81f*Dxy*Dxy;

				indexTop += skip;
				indexBottom += skip;
				indexL += skip;
				indexR += skip;
				indexY1 += skip;
				indexY2 += skip;
				indexY3 += skip;
				indexY4 += skip;
			}
		}
	}
309327
private void describeImage(T input, List<Point2D_F64> points, FastQueue<TD> descs )
	{
		detDesc.detect(input);

		for( int i = 0; i < detDesc.getNumberOfFeatures(); i++ ) {
			points.add( detDesc.getLocation(i).copy() );
			descs.grow().setTo(detDesc.getDescription(i));
		}
	}
992882
public static void multPlusTransA(int blockLength ,
                                      DSubmatrixD1 A , DSubmatrixD1 B ,
                                      DSubmatrixD1 C )
    {
        int heightA = Math.min( blockLength , A.row1 - A.row0 );

        for( int i = C.row0+blockLength; i < C.row1; i += blockLength ) {
            int heightC = Math.min( blockLength , C.row1 - i );

            int indexA = A.row0*A.original.numCols + (i-C.row0+A.col0)*heightA;

            for( int j = i; j < C.col1; j += blockLength ) {
                int widthC = Math.min( blockLength , C.col1 - j );

                int indexC = i*C.original.numCols + j*heightC;
                int indexB = B.row0*B.original.numCols + (j-C.col0+B.col0)*heightA;

                blockMultPlusTransA(A.original.data,B.original.data,C.original.data,
                            indexA,indexB,indexC,heightA,heightC,widthC);
            }
        }
    }
1078680
static function imageCopy( $imageObject, $destinationGeometry, $sourceGeometry,
                               $sourceMimeData, $destinationMimeData )
    {
        $destinationWidth = $destinationGeometry['width'];
        $destinationHeight = $destinationGeometry['height'];

        $temporaryImageObject = eZImageGDHandler::imageCreate( $destinationWidth, $destinationHeight, eZImageGDHandler::isImageTrueColor( $imageObject, $sourceMimeData ) );
        ImageCopy( $temporaryImageObject, $imageObject,
                   $destinationGeometry['x'], $destinationGeometry['y'],
                   $sourceGeometry['x'], $sourceGeometry['y'], $sourceGeometry['width'], $sourceGeometry['height'] );
        return $temporaryImageObject;
    }
1286044
function imageBounding(image) {
  var imageObj = element_object(image);
  if (!imageObj) return null;

  if (!imageObj.transform) imageObj.transform = 'matrix(1 0 0 1 0 0)';
  var matrix = helper.matrixStrToArr(imageObj.transform.trim());
  var width = imageObj.width;
  var height = imageObj.height;

  // The matrix variable contains 6 numbers, let's call them
  // a, b, c, d, e, f
  var a = matrix[0];
  var b = matrix[1];
  var c = matrix[2];
  var d = matrix[3];
  var e = matrix[4];
  var f = matrix[5];

  // The original top left point of the image is unknown. The e and f
  // in the matrix is the transformed top left point.
  // Now assume translate is applied to the image first, we have the
  // following points: (e, f), (e+w, f), (e+w, f+h), (e, f+h)
  var points1 = [e, f, e + width, f, e + width, f + height, e, f + height];

  // Then apply trasform matrix (a b c d 0 0) to these points, the
  // formula is newX = a*x + c*y, newY = b*x + d*y
  var points2 = [];
  for (var i = 0; i < points1.length; i += 2) {
    points2[i] = a * points1[i] + c * points1[i + 1];
    points2[i + 1] = b * points1[i] + d * points1[i + 1];
  }

  // Find the delta of the top left point and apply it to all the points
  var dx = points2[0] - points1[0];
  var dy = points2[1] - points1[1];
  var points = [e, f];
  for (var i = 2; i < points1.length; i += 2) {
    points[i] = points2[i] - dx;
    points[i + 1] = points2[i + 1] - dy;
  }

  var left = Number.POSITIVE_INFINITY;
  var right = Number.NEGATIVE_INFINITY;
  var top = Number.POSITIVE_INFINITY;
  var bottom = Number.NEGATIVE_INFINITY;

  for (var i = 0; i < points.length; i += 2) {
    if (points[i] < left) left = points[i];
    if (points[i] > right) right = points[i];
    if (points[i + 1] < top) top = points[i + 1];
    if (points[i + 1] > bottom) bottom = points[i + 1];
  }

  return {
    left: left,
    right: right,
    top: top,
    bottom: bottom,
    width: right - left,
    height: bottom - top
  };
}
457554
function initialiseBlock(&$blk)
	{
		$blk['margin_top'] = 0;
		$blk['margin_left'] = 0;
		$blk['margin_bottom'] = 0;
		$blk['margin_right'] = 0;
		$blk['padding_top'] = 0;
		$blk['padding_left'] = 0;
		$blk['padding_bottom'] = 0;
		$blk['padding_right'] = 0;
		$blk['border_top']['w'] = 0;
		$blk['border_left']['w'] = 0;
		$blk['border_bottom']['w'] = 0;
		$blk['border_right']['w'] = 0;
		$blk['direction'] = 'ltr';
		$blk['hide'] = false;
		$blk['outer_left_margin'] = 0;
		$blk['outer_right_margin'] = 0;
		$blk['cascadeCSS'] = [];
		$blk['block-align'] = false;
		$blk['bgcolor'] = false;
		$blk['page_break_after_avoid'] = false;
		$blk['keep_block_together'] = false;
		$blk['float'] = false;
		$blk['line_height'] = '';
		$blk['margin_collapse'] = false;
	}
823650
function decodeBlock(block) {
  decoderPredicted_ = sign_((block[1] << 8) | block[0]);
  decoderIndex_ = block[2];
  decoderStep_ = STEP_TABLE[decoderIndex_];
  /** @type {!Array<number>} */
  let result = [
      decoderPredicted_,
      sign_((block[3] << 8) | block[2])
    ];
  for (let i=4; i<block.length; i++) {
    /** @type {number} */
    let original_sample = block[i];
    /** @type {number} */
    let second_sample = original_sample >> 4;
    /** @type {number} */
    let first_sample = (second_sample << 4) ^ original_sample;
    result.push(decodeSample_(first_sample));
    result.push(decodeSample_(second_sample));
  }
  return result;
}
448237
function getImagePixels() {
    var w = width;
    var h = height;
    pixels = [];
    var data = image;
    var count = 0;

    for (var i = 0; i < h; i++) {

      for (var j = 0; j < w; j++) {

        var b = (i * w * 4) + j * 4;
        pixels[count++] = data[b];
        pixels[count++] = data[b + 1];
        pixels[count++] = data[b + 2];

      }

    }
  }