Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is libweb.lib-1.3.0 buggy?
Forum Updated to NodeBB v4.3 + New Features

Is libweb.lib-1.3.0 buggy?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 352 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MyNameIsQt
    wrote on last edited by MyNameIsQt
    #1

    Save the image as webp using webp.lib. But some images succeed and certain images fail. Also, the color is converted. Specially, Blue and Red.
    Isn't this a bug in webp.lib? Or is there any way to fix this?

    Lib: libwebp-1.3.0-windows-x64
    Compiler: MSVC

    left: jpeg, right: webp
    캡처sasdff.JPG

    if (!WebPPictureImportRGBA(&pic, src, src_stride)) { << here
            WebPPictureFree(&pic);
            return false;
        }
    

    :-1: error: Debugger encountered an exception: Exception at 0x7ff6bffa3e90, code: 0xc0000005: read access violation at: 0x20731fd4000, flags=0x0 (first chance)

    QImageReader reader(m_strBkgndImagePath);
        std::unique_ptr<QImage> unique_img(new QImage(reader.read()));
    
        int width = unique_img->size().width();
        int height = unique_img->size().height();
    
        WebPConfig config;
        WebPConfigPreset(&config, WEBP_PRESET_DEFAULT, 80/*quality*/);
        config.lossless = 0; // Use lossy compression
        config.alpha_quality = 100; // Maximum alpha quality
        config.use_sharp_yuv = 1; // Use RGB color space
    
        // Set up memory writer
        WebPMemoryWriter writer;
        WebPMemoryWriterInit(&writer);
        WebPPicture pic;
        WebPPictureInit(&pic);
    
        // Set up picture
        pic.use_argb = 1;
        pic.width = width;
        pic.height = height;
        pic.colorspace = WEBP_YUV420;
        pic.writer = WebPMemoryWrite;
        pic.custom_ptr = &writer;
    
        // Copy image data to picture
        const uint8_t* src = reinterpret_cast<const uint8_t*>(unique_img->constBits());
        const int src_stride = width * 4;
        if (!WebPPictureImportRGBA(&pic, src, src_stride)) {  // here
            WebPPictureFree(&pic);
            return false;
        }
    
        if (!WebPEncode(&config, &pic)) {
            WebPPictureFree(&pic);
            return false;
        }
    
        // Write the compressed image data to file
        QFileInfo fileInfo(m_strBkgndImagePath);
        QString webpFileName = fileInfo.path() + QDir::separator() + fileInfo.baseName() + ".webp";
    
        FILE* file = fopen(webpFileName.toStdString().c_str(), "wb");
        if (!file) {
            WebPPictureFree(&pic);
            return false;
        }
        const size_t output_size = writer.size;
        if (output_size > 0) {
            const size_t bytes_written = fwrite(writer.mem, 1, output_size, file);
            if (bytes_written != output_size) {
                fclose(file);
                WebPPictureFree(&pic);
                return false;
            }
            m_bkgndHeader.ImageSize = (unsigned int)output_size;
        }
        fclose(file);
        WebPPictureFree(&pic);
    
    
    C 1 Reply Last reply
    0
    • M MyNameIsQt

      @ChrisW67
      The following code doesn't produce anything.

      QImageReader reader(m_strBkgndImagePath);
          std::unique_ptr<QImage> unique_img(new QImage(reader.read()));
      
          if(unique_img->isNull()){
              return false;
          }
          // Convert QImage to QPixmap
          QPixmap pixmap = QPixmap::fromImage(*unique_img);
      
          // Save as WebP file
          QFileInfo fileInfo(m_strBkgndImagePath);
          QString webpFileName = fileInfo.path() + QDir::separator() + fileInfo.baseName() + ".webp";
      
          cout << webpFileName.toStdString() << endl;
          QImageWriter writer(webpFileName, "webp");
          writer.write(pixmap.toImage());
      

      However, if I do the following,

          QImageWriter writer(webpFileName, "png");
      

      a webp file is created, not a png file. I can't understand this. Doesn't the writer function encode the passed file extension? Why is webp created when png is inserted? Why is the file not created even though I set it to webp?

      C Offline
      C Offline
      ChrisW67
      wrote on last edited by ChrisW67
      #4

      @MyNameIsQt Why convert to QPixmap?

      #include <QCoreApplication>
      #include <QImage>
      
      int main(int argc, char **argv) {
              QCoreApplication app(argc, argv);
      
              QImage input("input.png");
              input.save("output.webp");
              return 0;
      }
      

      This input:
      input.png

      $ ./test 
      $ identify input.png output.webp 
      input.png PNG 100x100 100x100+0+0 16-bit sRGB 4699B 0.000u 0:00.000
      output.webp WEBP 100x100 100x100+0+0 8-bit sRGB 1080B 0.000u 0:00.000
      $ file input.png output.webp 
      input.png:   PNG image data, 100 x 100, 16-bit/color RGBA, non-interlaced
      output.webp: RIFF (little-endian) data, Web/P image
      

      Have you installed the Qt Image Formats add-on module?
      967048cc-764f-4f51-af34-9ff461d96ff6-image.png

      M 1 Reply Last reply
      2
      • M MyNameIsQt

        Save the image as webp using webp.lib. But some images succeed and certain images fail. Also, the color is converted. Specially, Blue and Red.
        Isn't this a bug in webp.lib? Or is there any way to fix this?

        Lib: libwebp-1.3.0-windows-x64
        Compiler: MSVC

        left: jpeg, right: webp
        캡처sasdff.JPG

        if (!WebPPictureImportRGBA(&pic, src, src_stride)) { << here
                WebPPictureFree(&pic);
                return false;
            }
        

        :-1: error: Debugger encountered an exception: Exception at 0x7ff6bffa3e90, code: 0xc0000005: read access violation at: 0x20731fd4000, flags=0x0 (first chance)

        QImageReader reader(m_strBkgndImagePath);
            std::unique_ptr<QImage> unique_img(new QImage(reader.read()));
        
            int width = unique_img->size().width();
            int height = unique_img->size().height();
        
            WebPConfig config;
            WebPConfigPreset(&config, WEBP_PRESET_DEFAULT, 80/*quality*/);
            config.lossless = 0; // Use lossy compression
            config.alpha_quality = 100; // Maximum alpha quality
            config.use_sharp_yuv = 1; // Use RGB color space
        
            // Set up memory writer
            WebPMemoryWriter writer;
            WebPMemoryWriterInit(&writer);
            WebPPicture pic;
            WebPPictureInit(&pic);
        
            // Set up picture
            pic.use_argb = 1;
            pic.width = width;
            pic.height = height;
            pic.colorspace = WEBP_YUV420;
            pic.writer = WebPMemoryWrite;
            pic.custom_ptr = &writer;
        
            // Copy image data to picture
            const uint8_t* src = reinterpret_cast<const uint8_t*>(unique_img->constBits());
            const int src_stride = width * 4;
            if (!WebPPictureImportRGBA(&pic, src, src_stride)) {  // here
                WebPPictureFree(&pic);
                return false;
            }
        
            if (!WebPEncode(&config, &pic)) {
                WebPPictureFree(&pic);
                return false;
            }
        
            // Write the compressed image data to file
            QFileInfo fileInfo(m_strBkgndImagePath);
            QString webpFileName = fileInfo.path() + QDir::separator() + fileInfo.baseName() + ".webp";
        
            FILE* file = fopen(webpFileName.toStdString().c_str(), "wb");
            if (!file) {
                WebPPictureFree(&pic);
                return false;
            }
            const size_t output_size = writer.size;
            if (output_size > 0) {
                const size_t bytes_written = fwrite(writer.mem, 1, output_size, file);
                if (bytes_written != output_size) {
                    fclose(file);
                    WebPPictureFree(&pic);
                    return false;
                }
                m_bkgndHeader.ImageSize = (unsigned int)output_size;
            }
            fclose(file);
            WebPPictureFree(&pic);
        
        
        C Offline
        C Offline
        ChrisW67
        wrote on last edited by ChrisW67
        #2

        Is libweb.lib-1.3.0 buggy?

        Probably not (assuming you mean libwebp from Chromium).

        The colour change is likely explained the first time you posted about this problem.

        The exception behaviour is likely an invalid pointer.

        Is there a reason you cannot use the read/write WEBP support in the Qt6 image plugin set?

        M 1 Reply Last reply
        0
        • C ChrisW67

          Is libweb.lib-1.3.0 buggy?

          Probably not (assuming you mean libwebp from Chromium).

          The colour change is likely explained the first time you posted about this problem.

          The exception behaviour is likely an invalid pointer.

          Is there a reason you cannot use the read/write WEBP support in the Qt6 image plugin set?

          M Offline
          M Offline
          MyNameIsQt
          wrote on last edited by
          #3

          @ChrisW67
          The following code doesn't produce anything.

          QImageReader reader(m_strBkgndImagePath);
              std::unique_ptr<QImage> unique_img(new QImage(reader.read()));
          
              if(unique_img->isNull()){
                  return false;
              }
              // Convert QImage to QPixmap
              QPixmap pixmap = QPixmap::fromImage(*unique_img);
          
              // Save as WebP file
              QFileInfo fileInfo(m_strBkgndImagePath);
              QString webpFileName = fileInfo.path() + QDir::separator() + fileInfo.baseName() + ".webp";
          
              cout << webpFileName.toStdString() << endl;
              QImageWriter writer(webpFileName, "webp");
              writer.write(pixmap.toImage());
          

          However, if I do the following,

              QImageWriter writer(webpFileName, "png");
          

          a webp file is created, not a png file. I can't understand this. Doesn't the writer function encode the passed file extension? Why is webp created when png is inserted? Why is the file not created even though I set it to webp?

          C 1 Reply Last reply
          0
          • M MyNameIsQt

            @ChrisW67
            The following code doesn't produce anything.

            QImageReader reader(m_strBkgndImagePath);
                std::unique_ptr<QImage> unique_img(new QImage(reader.read()));
            
                if(unique_img->isNull()){
                    return false;
                }
                // Convert QImage to QPixmap
                QPixmap pixmap = QPixmap::fromImage(*unique_img);
            
                // Save as WebP file
                QFileInfo fileInfo(m_strBkgndImagePath);
                QString webpFileName = fileInfo.path() + QDir::separator() + fileInfo.baseName() + ".webp";
            
                cout << webpFileName.toStdString() << endl;
                QImageWriter writer(webpFileName, "webp");
                writer.write(pixmap.toImage());
            

            However, if I do the following,

                QImageWriter writer(webpFileName, "png");
            

            a webp file is created, not a png file. I can't understand this. Doesn't the writer function encode the passed file extension? Why is webp created when png is inserted? Why is the file not created even though I set it to webp?

            C Offline
            C Offline
            ChrisW67
            wrote on last edited by ChrisW67
            #4

            @MyNameIsQt Why convert to QPixmap?

            #include <QCoreApplication>
            #include <QImage>
            
            int main(int argc, char **argv) {
                    QCoreApplication app(argc, argv);
            
                    QImage input("input.png");
                    input.save("output.webp");
                    return 0;
            }
            

            This input:
            input.png

            $ ./test 
            $ identify input.png output.webp 
            input.png PNG 100x100 100x100+0+0 16-bit sRGB 4699B 0.000u 0:00.000
            output.webp WEBP 100x100 100x100+0+0 8-bit sRGB 1080B 0.000u 0:00.000
            $ file input.png output.webp 
            input.png:   PNG image data, 100 x 100, 16-bit/color RGBA, non-interlaced
            output.webp: RIFF (little-endian) data, Web/P image
            

            Have you installed the Qt Image Formats add-on module?
            967048cc-764f-4f51-af34-9ff461d96ff6-image.png

            M 1 Reply Last reply
            2
            • C ChrisW67

              @MyNameIsQt Why convert to QPixmap?

              #include <QCoreApplication>
              #include <QImage>
              
              int main(int argc, char **argv) {
                      QCoreApplication app(argc, argv);
              
                      QImage input("input.png");
                      input.save("output.webp");
                      return 0;
              }
              

              This input:
              input.png

              $ ./test 
              $ identify input.png output.webp 
              input.png PNG 100x100 100x100+0+0 16-bit sRGB 4699B 0.000u 0:00.000
              output.webp WEBP 100x100 100x100+0+0 8-bit sRGB 1080B 0.000u 0:00.000
              $ file input.png output.webp 
              input.png:   PNG image data, 100 x 100, 16-bit/color RGBA, non-interlaced
              output.webp: RIFF (little-endian) data, Web/P image
              

              Have you installed the Qt Image Formats add-on module?
              967048cc-764f-4f51-af34-9ff461d96ff6-image.png

              M Offline
              M Offline
              MyNameIsQt
              wrote on last edited by
              #5

              @ChrisW67 I didn't know. thank you

              1 Reply Last reply
              0
              • M MyNameIsQt has marked this topic as solved on

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved