Compact objects

Why can gas spiraling toward a black hole produce intense X-rays before crossing the event horizon?