Analysis of photorefractive optical damage in lithium niobate: application to planar waveguides.