Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-68379

Extra bytes after QImage conversion

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • 5.9.1
    • GUI: Painting
    • None
    • My spec: MS Win 7x64, Qt 5.9.1 mingw

      I have found that if I have load QImage it is always in QImage::Format_RGB32 (even if on disk images are stored with 24 bit depth). But I need Format_RGB888. So I call QImage::convertToFormat. Images are converted but some of them get some extra bytes and look distorted.

      Code to reproduce:

      QImage _qimg;
      _qimg.load("filename.jpg");
      QImage _tmpqimg;
          if(_qimg.format() == QImage::Format_Grayscale8) {
              _tmpqimg = _qimg;
          } else {
              _tmpqimg = std::move(_qimg.convertToFormat(QImage::Format_RGB888));
          }
      
              std::cout << _tmpqimg.depth()  << " bits" << " W:" << _tmpqimg.width() << " H:" << _tmpqimg.height() << std::endl;
              std::cout << "byteCount(): " << _tmpqimg.byteCount() << ";\twidth() x height() x depth()/8: "
                        << _tmpqimg.width() * _tmpqimg.height() * _tmpqimg.depth()/8
                        << ";\tdiff: " << _tmpqimg.byteCount() - _tmpqimg.width() * _tmpqimg.height() * _tmpqimg.depth()/8 << std::endl << std::endl;
      

      I also have found that difference of byteCount() and (width() x height() x depth()/8) is always K times height(), where K could be 0,1,2,3

        1. bad.jpg
          bad.jpg
          61 kB
        2. good.jpg
          good.jpg
          129 kB
        3. screenshot-1.png
          screenshot-1.png
          85 kB
        4. QTBUG-68379.pro
          0.7 kB
        5. main.cpp
          2 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            vgt Eirik Aavitsland
            pi-null-mezon Alex Taranov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes