repairing jpegs
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: repairing jpegs
try searching google for "unix command line jpg reader" and see if you find anything useful
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: repairing jpegs
Have you looked at the first 4 (or whatever) magic bytes? Maybe that's all that is wrong. If so, a simple C program could fix it.
snibgo's IM pages: im.snibgo.com
Re: repairing jpegs
i did. i tried about 3 - 4. nothing really useful. my guess is that all the open source programs that use libjpeg (and probably most of them, if not all of them, do) will have the same behavior. so unless some of those are using some other/proprietary libraries - like adobe and that converter do - then it doesn't matter much which one you use...fmw42 wrote:try searching google for "unix command line jpg reader" and see if you find anything useful
Re: repairing jpegs
that is my next option. will eventually look into that. c is not the problem. the problem is i do not know much about jpeg headers...snibgo wrote:Have you looked at the first 4 (or whatever) magic bytes? Maybe that's all that is wrong. If so, a simple C program could fix it.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: repairing jpegs
By comparing imgfoo.jpg, a valid jpg file, the JPEG spec at http://www.w3.org/Graphics/JPEG/jfif3.pdf, and /usr/share/ImageMagick-6.4.5/config/magic.xml which contains the line:
imgfoofixed.jpg is now readable by IM and Gimp.
it seems imgfoo contains 21 spurious bytes at the start. These can be stripped by a simple C program (or perhaps some shell tool):<magic name="JPEG" offset="0" target="\377\330\377"/>
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
int main (int argc, char *argv [])
{
// Strip the first 21 bytes
FILE * fhin = fopen ("imgfoo.jpg", "rb");
FILE * fhout = fopen ("imgfoofixed.jpg", "wb");
char c;
int i;
for (i = 0; i < 21; i++) {
fread (&c, 1, 1, fhin);
}
while (fread (&c, 1, 1, fhin)) {
fwrite (&c, 1, 1, fhout);
}
fclose (fhout);
fclose (fhin);
return (0);
}
snibgo's IM pages: im.snibgo.com
Re: repairing jpegs
snibgo... i love you man. thanks.... i had a similar script. i just didn't know how many chars to jump... thanks. appreciated.snibgo wrote:imgfoofixed.jpg is now readable by IM and Gimp.
Re: repairing jpegs
one question. how did you know that they are 21? can you explain please...snibgo wrote: it seems imgfoo contains 21 spurious bytes at the start. These can be stripped by a simple C program (or perhaps some shell tool).
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: repairing jpegs
I dumped them using a filter called DumpBin that converts nonprintable characters to hex. Then I counted the characters until I reached FF D8 FF, which is hex for the octal "\377\330\377", which IM expects to be at the start.
You might find other files have a different number of spurious bytes. If so, you could write a program or script to do the counting each time.
You might find other files have a different number of spurious bytes. If so, you could write a program or script to do the counting each time.
snibgo's IM pages: im.snibgo.com
Re: repairing jpegs
i see. understood. again, thank you for the help....