Will the same JPEG decode to exactly the same pixels in every app?
Asked 10/15/2016
4 views
2 answers
0
If I edit JPEGs non-destructively in software like darktable, the original file is not re-saved each time. But when that same JPEG is viewed in different programs—such as darktable, a web browser, or Photoshop—will it always decode to exactly the same pixel values at 100%? Or can different JPEG decoders/renderers produce slightly different results, especially with more heavily compressed JPEGs?
Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0
Photography Stack Exchange contributor
9y ago
2 Answers
20
Short Answer
No, decoding is not guaranteed to always be the same. However, the differences are guaranteed to be very, very small.
ISO Specifications
The International Organization for Standardization (ISO) specifications for JPEG has the following specifications for decoders (emphasis mine):
A decoder shall
a) with appropriate accuracy, convert to reconstructed image data any compressed image data with parameters within the range supported by the application, and which comply with the interchange format syntax specified in Annex B for the decoding process(es) embodied by the decoder;
b) accept and properly store any table-specification data which comply with the abbreviated format for table specification data syntax specified in Annex B for the decoding process(es) embodied by the decoder;
c) with appropriate accuracy, convert to reconstructed image data any compressed image data which comply with the abbreviated format for compressed image data syntax specified in Annex B for the decoding process(es) embodied by the decoder, provided that the table-specification data required for decoding the compressed image data has previously been installed into the decoder.
Appropriate accuracy is very strict. Any converter following these specifications has to be compared to a reference algorithm. For a single pixel, each component can only differ by one bit from the reference. Furthermore, the (squared) error over each 8x8 pixel block and over the whole image needs to be very low.
But why would it be different?
Unlike bmp or png, a jpeg doesn't store the pixels themselves but a description of the image. To reconstruct the individual pixels a complex mathematical algorithm is used. After every step, the algorithm stores the result in memory. This is where things can go wrong: a value in memory has a certain precision, the machine precision. Because of this the value has to be rounded. While the specifications ensure that a minimal precision is used for, there is no maximum. The rounding may thus be different for each implementation. It can even be depending on the hardware used, as some processors use more bits of precision than demanded. Some early Pentium processors even did it plain wrong.
Tiny oversimplified example: calculating 5 * 0.12 by repeated addition.
Storing intermediate values using one digit of precision, a computer might do this: 0.12 + 0.12 = 0.24, store intermediate result as 0.2 (rounding down). Then calculate 0.2 + 0.12 = 0.32, store as 0.3 (again, rounding down). Continue this pattern and the result will be 0.5 instead of the expected result of 0.6. If a higher precision was used (two digits, for example), the result would have been different.
Originally by user57681. Source · Licensed CC BY-SA 4.0
user57681
9y ago
0
Generated from our catalog & community — verify before relying on it.
No. A JPEG is not guaranteed to decode to bit-for-bit identical pixels in every application.
In practice, different JPEG decoders are allowed small implementation differences, so two programs may render the same JPEG slightly differently. These differences are usually extremely small—often invisible unless you compare screenshots at high magnification.
So for normal viewing, the image will usually look the same. But if you ask whether every app must produce exactly the same pixel values, the answer is no.
Compression level (for example, “98%” vs “50% quality”) affects how much image information was discarded when the JPEG was created. A lower-quality JPEG may show more artifacts, but that does not change the core answer: different decoders can still produce slightly different output from the same file.
Also, if your editor uses sidecar files, that means your edits are non-destructive until export; it does not mean JPEG decoding is identical across all software.
Recommended products
UniqueBot
AI9y ago
Your Answer
Related Questions
Why can two JPEGs look identical but have different file sizes?
Why does my sRGB image look different in photo editors versus web browsers on my Mac?
Why does an image show 96 PPI in file info but 300 PPI in GIMP?
Why do my JPEG colors look different in Photoshop, Picasa, and on Flickr?
How do sRGB, Adobe RGB, and ProPhoto RGB relate, and why might file size differ?