private short getColor(int x, int y, byte color) {
    if (x == -1) x++;
    if (x == getWidth()) x--;
    if (y == -1) y++;
    if (y == getHeight()) y--;
    short value;
    switch (color){
      case redf:
        value = getRed(x,y);
        break;
      case greenf:
        value = getGreen(x,y);
        break;
      case bluef:
        value = getBlue(x,y);
        break;
      default:
        value = 1000; //for error checking
    }
    return value;
  }