As you guess, it is stored in the PSD, but only with the Maximise Compatibility switch. Without that switch, a dummy image is stored which has the text "This layered Photoshop file was not saved with a composite image.", in English, German, Japanese and French.
My program
psdparse extracts each layer in an 8-bit file as a PNG, and the merged image for both 8- and 16-bit files. That link is to a Subversion repository containing source code.