Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.5.3
-
None
-
macos sonoma
Description
Hi,
I have an application that needs to save a QImage with a size of 6000 pixels by 4000 pixels into a JPEG file.
Sometimes this image is not properly saved, when I try to read it I get the following message :
qt.gui.imageio.jpeg: Corrupt JPEG data: premature end of data segment
It does not happen all the time.
I make a simple program to show the issue. When running this example, we can see that the issue happens randomly
The main file:
#include <QApplication> #include <QImage> #include <QtDebug> #include <exception> void RunTest() { QString outputFileName = "./output.jpeg"; int const width = 6000; int const height = 4000; { QImage image( width, height, QImage::Format_RGB32 ); image.fill( qRgb( 0, 0, 0 ) ); image.save( outputFileName ); } qDebug() << "Reading file " << outputFileName; QImage check( outputFileName ); if( check.isNull() ) { throw std::exception(); } } void RunTests( int inNumTests ) { for( int i = 0; i < inNumTests; ++i ) { RunTest(); } } int main( int argc, char * argv[] ) { QApplication app( argc, argv ); RunTests( 10 ); return 0; }
The CmakeLists.txt file
cmake_minimum_required( VERSION 3.10 )
project( BugJPEGWithQt653 )
set( CMAKE_PREFIX_PATH "/usr/local/Qt-6.5.3" )
set( CMAKE_CXX_STANDARD 17 )
set( CMAKE_CXX_STANDARD_REQUIRED ON )
find_package( Qt6 COMPONENTS Core Gui Widgets REQUIRED )
add_executable( BugJPEGWithQt653 main.cpp )
target_link_libraries( BugJPEGWithQt653 Qt6::Core Qt6::Widgets Qt6::Gui )