I'm implementing the JPEG encoding and writing it in a JFIF container.
The original image (bitmap):
My encoded JPEG:
encoded JPEG with The Gimp (quality 50 and basic settings):
I'm trying to figure out the problem and my guess is it is in the encoded data itself and not in the JFIF header.
The steps (basic overview) that I've done in the encoding:
For the last step (7) I process the Y, Cb and Cr blocks as follow:
So my data is currently stored as Y Cb Cr Y Cb Cr Y Cb Cr Y Cb ... Is this correct?
or should data of Y, Cb and Cr be processed as following:
Y Y Y Y ... Yn Cb Cb Cb .... Cbn Cr Cr Cr Cr .... Crn
My question (as I guess the mistake is in the encoding of the data):
How do you store the encoded data itself?
Trying to figure out why my JPEG encoded output is bigger and not showing correctly. Any help is welcome.
I had a similar issue when I wrote a JPEG encoder from scratch in C. So I use bmptoppm to convert BMP to JPG and use this JPG image as a reference. Open the reference image and the incorrect resultant one (append .hex to the file name, e.g. reference.jpg.hex and myImage.jpg.hex) in your text editor (I use Sublime Text). Firstly, make sure the headers of two JPG files are the same. Then navigate to the encoded data. Find out where the difference is and from which 8 X 8 pixel block the difference derives. Now look into the block and find out which encoding step is incorrect.
My problem was that there was a wrong value in the Huffman table. So when I first tried to encode the image on the left, I got the one on the right. My encoder is only for gray-scale, so I am not sure about the sequence of Y, Cb and Cr.
Hopefully, you can fix the error by following the steps.