Stress analysis of polycrystalline thin films and surface regions by X-ray diffraction