Analytical theory of resonance diffraction and transformation of light polarization