code: private static int checkEdge(int width, int x, int col, int edge)
      {
          int ix = x + col;
          if (ix < 0)
          {
              if (edge == CLAMP_EDGES)
              {
                  ix = 0;
              }
              else
              {
                  ix = (x + width) % width;
              }
          }
          else if (ix >= width)
          {
              if (edge == CLAMP_EDGES)
              {
                  ix = width - 1;
              }
              else
              {
                  ix = (x + width) % width;
              }
          }
          return ix;
      }
docs: Check the edge value.
  
  @param width The image width.
  @param x The current horizontal pixel.
  @param col The column size.
  @param edge The edge flag.
  @return The edge offset.