PDA

View Full Version : Use QImageReader to test image files



jvillain
23rd March 2009, 02:02
I had a hard drive loaded with images go south on me leaving about 20% of them corrupted. I was looking for a way to check for the ones that are corrupted using QImage or QImage Reader. If I do some thing like


#include <QImageReader>

QString test;
QImageReader image;
QIODevice *device;

//Some function to get a bunch of file names here, loop through them and place them one at a time into test.


image.setDevice(device);
image.setFileName(test);
image.read();

qDebug()<<image.error()<<image.errorString()<<test;

I get output like the following in the application output.

0 "Unknown error" "/mnt/media/pics/image1.jpg"
0 "Unknown error" "/mnt/media/pics/image2.jpg"
0 "Unknown error" "/mnt/media/pics/image3.jpg"
0 "Unknown error" "/mnt/media/pics/image4.jpg"
Corrupt JPEG data: bad Huffman code
0 "Unknown error" "/mnt/media/pics/image5.jpg"
Corrupt JPEG data: premature end of data segment
0 "Unknown error" "/mnt/media/pics/image6.jpg"
0 "Unknown error" "/mnt/media/pics/image7.jpg"
0 "Unknown error" "/mnt/media/pics/image8.jpg"

So reading the the error code and error string are not telling me when the images are corrupted but some thing, some where, is detecting the corrupt images and dumping it to the out put but I have no idea what. Can any one tell me how to gain access those Corrupt JPEG messages, Tell me what is putting it into the output or suggest how I could read the output from my application from within the application so I could catch when these messages are being written to the output.

In case it helps the files after the Corrupt JPEG messages are the ones that are hosed.

Thanks in advance.

Hiker Hauk
23rd March 2009, 10:05
I can't answer your question but I have a solution.

Those messages might not even be output by the Qt library but the low level library it uses.

Why not redirect the output of your program to a log file then analyze the log later with another program.

your_image_tester > log.txt

log_analyzer log.txt