Results 1 to 16 of 16

Thread: Loading corrupt jpeg images with QImage

  1. #1
    Join Date
    Apr 2009
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default 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

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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?

  3. #3
    Join Date
    Apr 2009
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Loading corrupt jpeg images with QImage

    Quote Originally Posted by talk2amulya View Post
    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:

    Qt Code:
    1. QByteArray data = reply->readAll();
    2. reply->close();
    3.  
    4. // construct QImage from data
    5. QImage img;
    6. bool loaded = img.loadFromData(data);
    To copy to clipboard, switch view to plain text mode 

    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.

  4. #4
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Loading corrupt jpeg images with QImage

    try using QImageReader , it has functions like canRead() and read() which might be helpful to you

  5. The following user says thank you to talk2amulya for this useful post:

    mikeee7 (3rd April 2009)

  6. #5
    Join Date
    Apr 2009
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default 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:

    Qt Code:
    1. bool QImage::load(const QString &fileName, const char* format)
    2. {
    3. if (fileName.isEmpty())
    4. return false;
    5.  
    6. QImage image = QImageReader(fileName, format).read();
    7. if (!image.isNull()) {
    8. operator=(image);
    9. return true;
    10. }
    11. return false;
    12. }
    To copy to clipboard, switch view to plain text mode 

    Any other ideas for detecting images that cause the "Corrupt JPEG data" error message?

    Thanks,
    mikeee7

  7. #6
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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

  8. #7
    Join Date
    Apr 2009
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default 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

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. The following user says thank you to wysota for this useful post:

    mikeee7 (3rd April 2009)

  11. #9
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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?

  12. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #11
    Join Date
    Apr 2009
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Loading corrupt jpeg images with QImage

    Thanks for your help!

    I reported the problem in the Qt tasktracker.

  14. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Loading corrupt jpeg images with QImage

    Did you check if libjpeg is able to report such errors?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #13
    Join Date
    Apr 2009
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default 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
    Qt Code:
    1. static bool read_jpeg_image(QIODevice *device, QImage *outImage, const QByteArray &parameters, QSize scaledSize, int inQuality )
    To copy to clipboard, switch view to plain text mode 

    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.

  16. #14
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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

  17. #15
    Join Date
    Apr 2009
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default 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

  18. #16
    Join Date
    Dec 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

Similar Threads

  1. WekKit won't load JPEG images.
    By andrem in forum Qt Programming
    Replies: 4
    Last Post: 10th December 2008, 01:24
  2. Problem with displaying jpeg and gif images, in QT4
    By node_ex in forum Installation and Deployment
    Replies: 1
    Last Post: 23rd September 2008, 16:29
  3. QImage not loading successively.
    By node_ex in forum Qt Programming
    Replies: 3
    Last Post: 26th July 2008, 14:20
  4. JPEG Images not shown in QiconView using QT3??
    By darpan in forum Qt Programming
    Replies: 1
    Last Post: 4th August 2006, 21:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.