Skip to content

Commit 21b0b3f

Browse files
authored
Fix Qt screenhot crash (#889)
1 parent 126c18e commit 21b0b3f

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

include/utils/ImageData.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ class ImageData : public QSharedData
136136

137137
void toRgb(ImageData<ColorRgb>& image)
138138
{
139-
image.resize(_width, _height);
139+
if (image.width() != _width || image.height() != _height)
140+
image.resize(_width, _height);
141+
140142
const unsigned imageSize = _width * _height;
141143

142144
for (unsigned idx = 0; idx < imageSize; idx++)

libsrc/grabber/qt/QtGrabber.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ int QtGrabber::grabFrame(Image<ColorRgb> & image)
101101
QPixmap originalPixmap = _screen->grabWindow(0, _src_x, _src_y, _src_x_max, _src_y_max);
102102
QPixmap resizedPixmap = originalPixmap.scaled(_width,_height);
103103
QImage imageFrame = resizedPixmap.toImage().convertToFormat( QImage::Format_RGB888);
104+
image.resize(imageFrame.width(), imageFrame.height());
104105

105106
for (int y=0; y<imageFrame.height(); ++y)
106107
for (int x=0; x<imageFrame.width(); ++x)

libsrc/utils/ImageResampler.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ void ImageResampler::processImage(const uint8_t * data, int width, int height, i
6060
// calculate the output size
6161
int outputWidth = (width - _cropLeft - cropRight - (_horizontalDecimation >> 1) + _horizontalDecimation - 1) / _horizontalDecimation;
6262
int outputHeight = (height - _cropTop - cropBottom - (_verticalDecimation >> 1) + _verticalDecimation - 1) / _verticalDecimation;
63-
outputImage.resize(outputWidth, outputHeight);
63+
64+
if (outputImage.width() != outputWidth || outputImage.height() != outputHeight)
65+
outputImage.resize(outputWidth, outputHeight);
6466

6567
for (int yDest = 0, ySource = _cropTop + (_verticalDecimation >> 1); yDest < outputHeight; ySource += _verticalDecimation, ++yDest)
6668
{

0 commit comments

Comments
 (0)