Loading corrupt jpeg images with QImage
Hi,
I am using QImage to scale and save images downloaded from the net using QNetworkAccessManager.
99.9% of the images can be saved correctly but for a very small fraction of images I get the following error/warning messages printed on the console:
Corrupt JPEG data: premature end of data segment
or
Corrupt JPEG data: 164 extraneous bytes before marker 0xd9
I would be interested in catching those errors and discarding the corresponding images. I wonder if anyone knows a way to do this? QImage::loadFromData() returns true even for images that produce those error messages.
Thanks,
mikeee7
Re: Loading corrupt jpeg images with QImage
probably you arent able to read the images properly from net..are you relying on the finished signal from QNetworkAccessManager?
Re: Loading corrupt jpeg images with QImage
Quote:
Originally Posted by
talk2amulya
probably you arent able to read the images properly from net..are you relying on the finished signal from
QNetworkAccessManager?
Yes, I am relying on the finished signal from QNetworkAccessManager.
Basically, I have the following code:
Code:
reply->close();
// construct QImage from data
bool loaded = img.loadFromData(data);
My problem is that "img.loadFromData(data)" returns true in any case, even if the mentioned error messages get printed onto the console. I would be interested in finding a way to catch those error messages such that I would be able to discard the corresponding images.
Re: Loading corrupt jpeg images with QImage
try using QImageReader , it has functions like canRead() and read() which might be helpful to you
Re: Loading corrupt jpeg images with QImage
Hi,
thanks for your help!
I've tried QImageReader as suggested but the functions canRead() and read() cannot detect the corrupt jpeg data either.
Looking at the QImage source code, one can see that QImage internally of course relies on QImageReader and thus only fails when QImageReader fails:
Code:
{
if (fileName.isEmpty())
return false;
if (!image.isNull()) {
operator=(image);
return true;
}
return false;
}
Any other ideas for detecting images that cause the "Corrupt JPEG data" error message?
Thanks,
mikeee7
Re: Loading corrupt jpeg images with QImage
hmm..thats really odd..anyways, u can maybe try using error() and errorString() of QImageReader, if error is there, u can discard corresponding images
Re: Loading corrupt jpeg images with QImage
Hi,
I tried QImageReader::error() but it does not seem to cover the "Corrupt JPEG data" error.
I found a thread covering the same problem but there is no real solution:
http://www.qtcentre.org/forum/f-qt-p...es-19703.html/
It would be nice to have some additional error enums included into the QImageReader API that allow users to detect the "Corrupt JPEG data" error...
I wonder if anyone has other ideas to detect those errors except writing the data into a logfile and analyzing the logfile afterwards?
Thanks,
mikeee7
Re: Loading corrupt jpeg images with QImage
The corruption message comes from libjpeg which is responsible for decoding the image. It succeeds to do it regardless of data corruption thus QImageReader returns true. I don't think there is anything you can do about it, unfortunately. Unless of course libjpeg can report such problems - then it'd be just a matter of slightly modifying the jpeg imageio plugin.
Re: Loading corrupt jpeg images with QImage
so wysota, do you think this should be taken up to the trolls? i mean it makes sense that if an image is corrupted, it should be reported..or is it like they know the issue and they r just playing ostrich on it?
Re: Loading corrupt jpeg images with QImage
You can report it of course it would be worth to check first if libjpeg has any means of notifying about such corruption. If not, Trolls won't be able to do anything about it other than patching libjpeg which is doubtful they would do.
Re: Loading corrupt jpeg images with QImage
Thanks for your help!
I reported the problem in the Qt tasktracker.
Re: Loading corrupt jpeg images with QImage
Did you check if libjpeg is able to report such errors?
Re: Loading corrupt jpeg images with QImage
libjpeg provides very detailed status codes, see http://libjpeg.cvs.sourceforge.net/v....h?view=markup. However, qjpeghandler.cpp does not seem to check them. The corresponding function is
Also, it seems that the interface provided by QImageIOHandler would need to be extended to be able to forward additional "status messages" since currently the read() and canRead() methods only return boolean values.
Re: Loading corrupt jpeg images with QImage
i always wanted to find a proper bug in Qt..it always seemed so perfect and foolproof..and here we are..good work miky :)
Re: Loading corrupt jpeg images with QImage
The problem discussed can now be found in the tasktracker:
http://www.qtsoftware.com/developer/...ntry&id=251514
Re: Loading corrupt jpeg images with QImage
I'm facing the same issue, and no solutions has been reported on the Bug Tracker.
How did you solve it? Have you found a way to detect the corrupted images?
Thanks