I can only barely comprehend what you are
trying to do or why, but unless the reference image is a
lossless JPEG (I assume not, if it has a DQT), any
decompression/compression cycle will result in generational
loss. Thus, you cannot exactly regenerate a lossy reference
JPEG image unless you have the original uncompressed image that
was used to generate the reference image in the first place.
Once a JPEG image is generated, then some of that original data
is lost. The best you can do is copy the DCT blocks (in the
frequency domain) from one JPEG container to another, which is
what jpegtran does. That avoids a decompression/recompression
cycle and thus avoids generational loss, so the transformed JPEG
image has no additional loss relative to the reference JPEG
image. However, there are limits to what you can do in the
frequency domain. You can reorder the DCT blocks; spatially
transpose, rotate, or flip the blocks; remove or change the
order of some of the component planes (e.g. convert color to
grayscale); negate the coefficients (photo negative);
re-quantize the coefficients (lower the effective JPEG quality);
change the entropy algorithm (e.g. convert baseline to
progressive or arithmetic); add restart markers; crop the image
(by discarding certain blocks); wipe an image region (by greying
out certain blocks); drop another image into the source image
(by replacing certain blocks); or remove metadata.
--
You received this message because you are subscribed to the Google Groups "libjpeg-turbo User Discussion/Support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to libjpeg-turbo-u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/libjpeg-turbo-users/db388722-522d-40f7-b868-185684060ffan%40googlegroups.com.
I think you may have misunderstood my intention. What I hope to achieve is to compress an image using the same compression method as reference.jpg, perfectly simulating it. In my understanding, the hex code of a JPEG includes information such as DQT, SOF, and DHT. I wonder if I can use this information to re-compress an image and generate output.jpg. Theoretically, the hex code between FFD8 and FFDA should be identical in output.jpg and reference.jpg, and the compression data after SOS should also be calculated based on information such as DQT, SOF, and DHT. I hope to use libjpeg-turbo to implement this function. It seems that jpegtran cannot achieve this.
Even if you use the identical compression method, there is no way to perfectly simulate a JPEG reference image unless you can obtain the original pixels that were used to generate the reference image. The term "re-compress" means that you have to decompress first, so you will incur generational loss, as I mentioned below. You can't perfectly duplicate the JPEG image data (the data after the SOS marker) from the metadata and decompressed pixels of a reference JPEG image. You can perfectly duplicate the JPEG image data from the metadata of a reference JPEG image if you have access to the original pixels that were used to generate the reference image, but your messages imply that you don't. That means that what you're trying to do is impossible.
To view this discussion on the web visit https://groups.google.com/d/msgid/libjpeg-turbo-users/384ceb0a-e840-4bb9-b94c-1a613f965231n%40googlegroups.com.
In your original message, you said that "the resulting output.jpg differs in hex code from the reference image", which implied that you expected the entire images to be bitwise-identical. That is an unrealistic expectation. If, however, you meant that you expected the data between the SOI and SOS markers to be the same, then what you're actually trying to do is make the image *headers* bitwise-identical. That is also an unrealistic expectation, unless the camera uses libjpeg-turbo. Different codecs don't always write the headers in the same way. If, however, what you're really trying to do is duplicate the level of JPEG compression that a camera uses, then using jpeg_copy_critical_parameters() (as your code already does) is the way to do that.
That's all the help I can provide.
To view this discussion on the web visit https://groups.google.com/d/msgid/libjpeg-turbo-users/2616ce8b-c747-48e7-8c39-a3ee243b88edn%40googlegroups.com.
Thank you very much for giving me such a clear answer!! Now I understand that I shouldn't continue studying on libjpeg-turbo. At the same time, I would like to ask, if I want to achieve my goal, is there any way to do it? For example, what kind of library should I use or what should I learn?
Thank you again!!