It is often said that if you open a jpeg file and edit it, and save
it, the entire image will be degraded.
Having, once upon a time, ported the IJG JPEG source code to an
embedded processor, I doubted that this was true. I reasoned that if
you edit one section of an image (say using a rubber stamp tool) that
only that section of the image would need to be recalculated.
So tonight with some time on my hands I did a little experiment. I
opened a tiff file, cropped a 128x128 pixel section, and saved it as
0.jpg.
I then copied 0.jpg to 1.jpg, opened 1.jpg, and used the pencil tool
to put a single black pixel near the center of the lower right
quadrant. I then saved and closed 1.jpg.
I then copied 1.jpg to 2.jpg. Opened 2.jpg, and drew another single
black pixel near the center of the lower right quadrant, and saved it.
And so on and so forth for 3.jpg.
Each in turn for 0, 1, 2, and 3.jpg, I opened them up, cropped to the
upper left quadrant (64x64 pixels), and saved each result as a .bmp
file.
So, if my theory was correct, every .bmp, 0.bmp to 3.bmp, should be
identical with a command fc command.
However they were not.
So, based on this experiment, I conclude one of the following is true:
1. The largest MCU used by photoshop 5.5 exceeds 64x64 pixels.
2. Photoshop 5.5 programmers weren't clever enough to keep a score
card of edited MCUs and only calculate the DCT for those MCUs.
I fear option 2 is true, and the adage that opening, editing, and
resaving jpegs corrupts the entire image. Clearly, I think this is
unnecessary.
If they used a simple score card method and only calculated the DCT
of the MCUs that changed, unedited MCUs would be unaffected even
after repeated .jpg saves.
Does any image editing software package (perhaps a later version of
Photoshop) use a scorecard? Or is there some other factor I am not
considering in this edited MCU scorecard idea?
Note: Image degradation results if you don't use a scorecard for
edited MCUs because for a given MCU, say MCUx, MCUx!=DCT(IDCT(MCUx))
primarily or entirely due to round off errors (I should spend more
time to make a more precise statement).
However, if an MCU hasn't been touched, and you keep track of this,
you can just use the original DCT(MCUx) as stored in the .jpg file
when you opened it. Using this scorecard idea, it is absolutely
possible, at least with everything in my mind, to keep unedited MCUs
*exactly* the same through multiple file saves of JPEGs.
This seems pretty obvious to me. If not, I release this idea to the
public domain.
Unless there is some obvious reason this wouldn't work.
It has been awhile since I looked at JPEG compression source code, so
please be polite if you need to correct some of the assertions I've
made.