code: private int getSourcePixel(int[] srcImage, int x, int y)
      {
          int x1 = Math.max(0, x);
          x1 = Math.min(width - 1, x1);
          int y1 = Math.max(0, y);
          y1 = Math.min(height - 1, y1);
  
          return srcImage[x1 + y1 * width];
      }
docs: Get pixel source.
  
  @param srcImage The image source.
  @param x The location x.
  @param y The location y.
  @return The pixel value found.