Fix loading of inline JPEG images

This is a tentative patch to fix loading of inline JPEG images, based on this paragraph: http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#page=223&zoom=auto,0,600.

Fixes #2812.
Fixes #4776.
Fixes [bug 1065245](https://bugzilla.mozilla.org/show_bug.cgi?id=1065245)

Also fixes missing images in (but the text is still incorrect):
#2840.
#4054.
its not there because nobody needs it right now. So I would say its valid to be part of this PR (maybe a second commit). I think that API should be there, and the actual way of getting it merged doesnt matter much :)