I have been reading the guide from:
I eventually reached the point where it states:
Finally, we want to convert the DCT DC value to an RGB value. Assuming that the gain of the DCT transform is 4, we divide the values by 4 to get block1 = -128, block2 = +127.
I have to admit, I do not understand where this magic value '4'
is coming from. With the help of djpeg
and jpegtran
, I was able to craft two different JPEG files:
- white512.jpg (
) is a JPEG where the DC value is +512,
- white338.jpg (
) is a JPEG where the DC value is +338
Using a simple check, we can confirm they both decompress to the same white ppm file:
% djpeg -outfile 338.ppm white338.jpg
% djpeg -outfile 512.ppm white512.jpg
% md5sum 338.ppm 512.ppm
18f695bae266c6a24506936dab1dfc23 338.ppm
18f695bae266c6a24506936dab1dfc23 512.ppm
Could someone please tell me:
- Where is this value
'4'
value coming from ? - How come both the DC value 338 & 512 expand to the same white value (0xFF) ?
For reference, the JPEG files uploaded on imgur
have been edited in my back. In particular the upload process strips the APP0
marker. To get the exact same image as I have on disk, one can apply back the default jpegtran
settings:
% jpegtran -outfile white512.jpg -optimize jTKco.jpg
% jpegtran -outfile white338.jpg -optimize WqThz.jpg
% md5sum white512.jpg white338.jpg
695527adb6b269214e38e45157edb256 white512.jpg
051434f11491bdf1c1be38ad8f69f5be white338.jpg