The gravitational potential energy can be thermalised and radiated efficiently as a blackbody if this energy is released in material where the radiation is emitted and absorbed many times before escaping, so that the photons come into equilibrium with the electrons (optically thick). The luminosity is then L=A sigma T4.

Conversely, if the energy is released in material where there are rarely any interactions before escape (optically thin) then the emission of radiation is not so efficient. The material is then heated to much higher temperatures before the cooling is able to balance the rate of energy release. There are many emission mechanisms which can be important for optically thin material, including

All of these also have inverse processes, resulting in absorption. The most important of these for X-ray spectral formation is photo-electric absorption (bound-free).