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

QImage::Format_Grayscale8 skip bytes for some image resolutions

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Not Evaluated
    • Resolution: Invalid
    • Affects Version/s: 5.6.3, 5.12.0, 5.12.4
    • Fix Version/s: None
    • Labels:
      None
    • Platform/s:
      macOS

      Description

      QImage can't handle correctly grayscale buffers for some widths/heights. In this case, 2 bytes are skipped at the end of each line, resulting in a tearing like effect:
       (at 450x450)

      The expected result was:
      (at 900x900)

      My test code was:

      #include <QImage>
      
      int main(int argc, char *argv[])
      {
          int w=450, h=450;
          int hW=w*.5;
          QByteArray buff(w*h, Qt::Uninitialized);
          for(int y=0; y<h; ++y)
          {
              std::memset((uchar*)&buff.data()[y*w], 0, hW);
              std::memset((uchar*)&buff.data()[y*w+hW], 255, hW);
          }
          QImage((uchar*) buff.data(), w, h, QImage::Format_Grayscale8).save("result.jpg");
      }
      

        Attachments

        1. result.jpg
          result.jpg
          13 kB
        2. result2.jpg
          result2.jpg
          12 kB
        3. TestQimageSaveGrayscale.zip
          4 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            • Assignee:
              vgt Eirik Aavitsland
              Reporter:
              ahi Adriel Jr.
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Gerrit Reviews

                There are no open Gerrit changes