Nonlinear electromagnetic self-duality and Legendre transformations