/*
Gets the color of the pixel at the given coordinates.

@param {int} x The x coordinate of the pixel
@param {int} y The y coordinate of the pixel
@return {Array(byte)} The color of the pixel, or null if coordinates are not in image bounds.
344441
function readPixel(png, x, y) {
  if(x < 0 || y <0 || x > png.width || y > png.height)
    return null;

  var idx = (png.width * y + x) << 2;
  var background = [png.data[idx], png.data[idx+1], png.data[idx+2], png.data[idx+3]];
  return background;
}
1177024
function(x, y) {
        var renderer = this.renderer;

        var ratio = this.downSampleRatio;
        x = Math.ceil(ratio * x);
        y = Math.ceil(ratio * (this.height - y));

        this._frameBuffer.bind(renderer);
        var pixel = new Uint8Array(4);
        var _gl = renderer.gl;
        // TODO out of bounds ?
        // preserveDrawingBuffer ?
        _gl.readPixels(x, y, 1, 1, _gl.RGBA, _gl.UNSIGNED_BYTE, pixel);
        this._frameBuffer.unbind(renderer);
        // Skip interpolated pixel because of anti alias
        if (pixel[3] === 255) {
            var id = unpackID(pixel[0], pixel[1], pixel[2]);
            if (id) {
                var el = this._lookupTable[id - this.lookupOffset];
                return el;
            }
        }
    }
995235
function _getColorByXY(coord, imgSize, imgCols) {
    var colPos = _getColorPositionByXY(coord, imgSize);
    return [imgCols[colPos], imgCols[colPos+1], imgCols[colPos+2], imgCols[colPos+3]];
}
1325043
function getColor(color)
{
    if (!Array.isArray(color))
    {
        return getSingleColor(color);
    }
    else
    {
        for (let i = 0; i < color.length; ++i)
        {
            color[i] = getSingleColor(color[i]);
        }

        return color;
    }
}
58812
function getPointByClient(clientX, clientY) {
    var el = this.get('el');
    var pixelRatio = this.get('pixelRatio') || 1;
    var bbox = el.getBoundingClientRect();
    return {
      x: (clientX - bbox.left) * pixelRatio,
      y: (clientY - bbox.top) * pixelRatio
    };
  }
705584
function _getNeighborPixels(coord, imgSize, imgCols) {
    var res = [], pos;

    if (coord.x > 0 && coord.y > 0) { // tlPx
        pos = {
            x: coord.x - 1,
            y: coord.y - 1
        };
        res.push({
            coord: pos,
            color: _getColorByXY(pos, imgSize, imgCols)
        });
    }

    if (coord.y > 0) { // tPx
        pos = {
            x: coord.x,
            y: coord.y - 1
        };
        res.push({
            coord: pos,
            color: _getColorByXY(pos, imgSize, imgCols)
        });
    }

    if (coord.x < imgSize.w && coord.y > 0) { // trPx
        pos = {
            x: coord.x + 1,
            y: coord.y - 1
        };
        res.push({
            coord: pos,
            color: _getColorByXY(pos, imgSize, imgCols)
        });
    }

    if (coord.x < imgSize.w) { // rPx
        pos = {
            x: coord.x + 1,
            y: coord.y
        };
        res.push({
            coord: pos,
            color: _getColorByXY(pos, imgSize, imgCols)
        });
    }

    if (coord.x < imgSize.w && coord.y < imgSize.h) { // brPx
        pos = {
            x: coord.x + 1,
            y: coord.y + 1
        };
        res.push({
            coord: pos,
            color: _getColorByXY(pos, imgSize, imgCols)
        });
    }

    if (coord.y < imgSize.h) { // bPx
        pos = {
            x: coord.x,
            y: coord.y + 1
        };
        res.push({
            coord: pos,
            color: _getColorByXY(pos, imgSize, imgCols)
        });
    }

    if (coord.x > 0 && coord.y < imgSize.h) { // blPx
        pos = {
            x: coord.x - 1,
            y: coord.y + 1
        };
        res.push({
            coord: pos,
            color: _getColorByXY(pos, imgSize, imgCols)
        });
    }

    if (coord.x > 0) { // lPx
        pos = {
            x: coord.x - 1,
            y: coord.y
        };
        res.push({
            coord: pos,
            color: _getColorByXY(pos, imgSize, imgCols)
        });
    }

    return res;
}
4165
public function pixelIndex(Int $x, Int $y) : Int
    {
        return imagecolorat($this->canvas, $x, $y);
    }
349984
function rgb2hcl(pixel) {
  const red = rgb2xyz(pixel[0]);
  const green = rgb2xyz(pixel[1]);
  const blue = rgb2xyz(pixel[2]);

  const x = xyz2lab(
    (0.4124564 * red + 0.3575761 * green + 0.1804375 * blue) / Xn);
  const y = xyz2lab(
    (0.2126729 * red + 0.7151522 * green + 0.0721750 * blue) / Yn);
  const z = xyz2lab(
    (0.0193339 * red + 0.1191920 * green + 0.9503041 * blue) / Zn);

  const l = 116 * y - 16;
  const a = 500 * (x - y);
  const b = 200 * (y - z);

  const c = Math.sqrt(a * a + b * b);
  let h = Math.atan2(b, a);
  if (h < 0) {
    h += twoPi;
  }

  pixel[0] = h;
  pixel[1] = c;
  pixel[2] = l;

  return pixel;
}
248473
def color_point(x, y, fill)
      f = copy
      f.pixel_color(x, y, fill)
      f
    end
999541
func GetPixelColor(x, y int) string {
	cx := C.size_t(x)
	cy := C.size_t(y)

	color := C.get_pixel_color(cx, cy)
	gcolor := C.GoString(color)
	C.free(unsafe.Pointer(color))

	return gcolor
}
529276
function (x, y) {
		var polygons = this.polygons;
		for (var i = 0, n = polygons.length; i < n; i++)
			if (this.polygonContainsPoint(polygons[i], x, y)) return this.boundingBoxes[i];
		return null;
	}
508731
public Shape<?> findShapeAtPoint(final int x, final int y)
    {
        if (isVisible())
        {
            final SelectionLayer selection = getSelectionLayer();

            if (null != selection)
            {
                final ImageDataPixelColor rgba = selection.getContext().getImageDataPixelColor(x, y);// x,y is adjusted to canvas coordinates in event dispatch

                if (null != rgba)
                {
                    if (rgba.getA() != 255)
                    {
                        return null;
                    }
                    final Shape<?> shape = m_shape_color_map.get(rgba.toBrowserRGB());

                    if ((null != shape) && (shape.isVisible()))
                    {
                        return shape;
                    }
                }
            }
        }
        return null;
    }
169542
public static boolean getF(GrayU8 image, int x, int y) {
		if (image.isInBounds(x, y)) {
			return image.get(x, y) != 0;
		} else {
			return false;
		}
	}
1166594
function(x, y) {
		var offset = (x + y * this.width) * 4;
	
		return [
			this.data[offset + 0],
			this.data[offset + 1],
			this.data[offset + 2],
			this.data[offset + 3]
		];
	}
20835
function( side ) {
			var position = this.options[side].position;
			return typeof position.left !== 'undefined' ?
				this.getPixels(position.left, 'x') :
				this.getXFromRight(this.getPixels(position.right, 'x'));
		}
1115321
public static boolean isBlack(BufferedImage image, int x, int y, int luminanceCutOff) {
        int pixelRGBValue;
        int r;
        int g;
        int b;
        double luminance = 0.0;

        // return white on areas outside of image boundaries
        if (x < 0 || y < 0 || x > image.getWidth() || y > image.getHeight()) {
            return false;
        }

        try {
            pixelRGBValue = image.getRGB(x, y);
            r = (pixelRGBValue >> 16) & 0xff;
            g = (pixelRGBValue >> 8) & 0xff;
            b = (pixelRGBValue) & 0xff;
            luminance = (r * 0.299) + (g * 0.587) + (b * 0.114);
        } catch (Exception e) {
            logger.warn("", e);
        }

        return luminance < luminanceCutOff;
    }
601584
public void onMapSelected(float x, float y) {

        if (x > 255) {
            x = 255;
        }
        if (x < 0) {
            x = 0;
        }
        if (y > 255) {
            y = 255;
        }
        if (y < 0) {
            y = 0;
        }
        switch (m_colorMode) {
            case CmsSliderBar.HUE:
                m_saturation = percentOf(x, 100);
                m_brightness = 100 - percentOf(y, 100);
                m_tbSaturation.setText(Integer.toString(m_saturation));
                m_tbBrightness.setText(Integer.toString(m_brightness));
                onChange(m_tbHue);
                break;
            case CmsSliderBar.SATURATIN:
                m_hue = percentOf(x, 360);
                m_brightness = 100 - percentOf(y, 100);
                m_tbHue.setText(Integer.toString(m_hue));
                m_tbBrightness.setText(Integer.toString(m_brightness));
                onChange(m_tbSaturation);
                break;
            case CmsSliderBar.BRIGHTNESS:
                m_hue = percentOf(x, 360);
                m_saturation = 100 - percentOf(y, 100);
                m_tbHue.setText(Integer.toString(m_hue));
                m_tbSaturation.setText(Integer.toString(m_saturation));
                onChange(m_tbBrightness);
                break;
            case CmsSliderBar.RED:
                m_blue = (int)x;
                m_green = 255 - (int)y;
                m_tbBlue.setText(Integer.toString(m_blue));
                m_tbGreen.setText(Integer.toString(m_green));
                onChange(m_tbRed);
                break;
            case CmsSliderBar.GREEN:
                m_blue = (int)x;
                m_red = 255 - (int)y;
                m_tbBlue.setText(Integer.toString(m_blue));
                m_tbRed.setText(Integer.toString(m_red));
                onChange(m_tbGreen);
                break;
            case CmsSliderBar.BLUE:
                m_red = (int)x;
                m_green = 255 - (int)y;
                m_tbRed.setText(Integer.toString(m_red));
                m_tbGreen.setText(Integer.toString(m_green));
                onChange(m_tbBlue);
                break;
            default:
                break;
        }
    }