Is libweb.lib-1.3.0 buggy?
-
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: MSVCleft: jpeg, right: webp
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);
-
@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:
$ ./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?
-
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?
-
@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?
-
@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:
$ ./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?
-