Damaged JPG/RAW files.

This is one of the questions we often receive. "My jpeg files have the correct size, but I can't open them." "I have recovered my images, but I can't use them." etc... The short answer is "in most cases, damaged jpeg files can't be fixed, sorry". The long answer is a bit more complicated. Read on if interested.

Case 1 - Random File Corruption

Most image files are compressed streams of data. That means that very small changes can have devastating effects

undamaged jpeg This is the original file.
One byte changed Same file with a single byte randomly changed.
one byte added Same file with a single byte randomly inserted.

What would it take to fix that file? First, we'd have to find the incorrect byte. That's not easy, and not always possible. Assume we are extremely lucky and find it: how do we determine what the correct byte was? We could try the 255 (and not 256 since the current value is wrong) other values a byte can take and look at the 255 potentially corrected pictures. Finding out which byte was added is also very difficult. Handling a mix of both is simply mind boggling.

For example, assuming 4 bytes in sequence are randomly corrupted, what would be a reasonable estimate of the complexity of the problem? Something like

extreme luck x 255 x 255 x 255 x 255 or extreme luck x 4.228.250.625

What if 4 bytes random bytes are randomly corrupted? The estimate becomes something like

(extreme luck x 255) x (extreme luck x 255) x (extreme luck x 255) x (extreme luck x 255)

Pretty scary, isn't it? And don't forget that a typical digital camera image consists of several millions of bytes. For the sake of completeness, let us say that there are a few techniques based on relatively complex mathematics that could reduce the problem to a more manageable size, but not enough to guarantee results in practice.

Case 2 - poor recovery, wrong copy from a damaged file system.

to be continued...