I would suggest starting here with the JPEG (JFIF) specification.
You'll have to uncompress and determine what makes up those RGB values. Not having specific knowledge in this domain I can't help you much more than this - I don't know if a package already exists for this or anything more.