QImage: use rvalue overloads more

to reuse internal buffers
This commit is contained in:
Fushan Wen 2023-09-16 18:24:34 +08:00
parent 75e1280073
commit 485e084fa9
No known key found for this signature in database
GPG Key ID: 2E48D1487C91DCAA
11 changed files with 15 additions and 16 deletions

View File

@ -714,9 +714,9 @@ bool QAVIFHandler::write(const QImage &image)
if (save_depth == 8) {
save_depth = 10;
if (tmpcolorimage.hasAlphaChannel()) {
tmpcolorimage = tmpcolorimage.convertToFormat(QImage::Format_RGBA64);
tmpcolorimage.convertTo(QImage::Format_RGBA64);
} else {
tmpcolorimage = tmpcolorimage.convertToFormat(QImage::Format_RGBX64);
tmpcolorimage.convertTo(QImage::Format_RGBX64);
}
}

View File

@ -249,7 +249,7 @@ bool EXRHandler::read(QImage *outImage)
#endif // !EXR_ALLOW_LINEAR_COLORSPACE
#endif // !EXR_USE_LEGACY_CONVERSIONS
*outImage = image;
*outImage = std::move(image);
return true;
} catch (const std::exception &exc) {

View File

@ -283,7 +283,7 @@ bool HDRHandler::read(QImage *outImage)
// By setting the linear color space, programs that support profiles display HDR files as in GIMP and Photoshop.
img.setColorSpace(QColorSpace(QColorSpace::SRgbLinear));
*outImage = img;
*outImage = std::move(img);
return true;
}

View File

@ -383,8 +383,7 @@ static bool readImage8(QImage &img, QDataStream &s, const PCXHEADER &header)
while (flag != 12 && s.status() == QDataStream::Ok) {
s >> flag;
}
}
else {
} else {
device->seek(device->size() - 769);
s >> flag;
}
@ -613,7 +612,7 @@ static bool writeImage24(QImage &img, QDataStream &s, PCXHEADER &header)
QByteArray b_buf(header.width(), 0);
for (int y = 0; y < header.height(); ++y) {
auto p = (QRgb*)img.scanLine(y);
auto p = (QRgb *)img.scanLine(y);
for (int x = 0; x < header.width(); ++x) {
QRgb rgb = *p++;
@ -684,7 +683,7 @@ bool PCXHandler::read(QImage *outImage)
img.setDotsPerMeterX(qRound(header.HDpi / 25.4 * 1000));
img.setDotsPerMeterY(qRound(header.YDpi / 25.4 * 1000));
*outImage = img;
*outImage = std::move(img);
return true;
}

View File

@ -255,7 +255,7 @@ bool SoftimagePICHandler::read(QImage *image)
}
}
*image = img;
*image = std::move(img);
m_state = Ready;
return true;

View File

@ -1326,7 +1326,7 @@ bool PSDHandler::read(QImage *image)
return false;
}
*image = img;
*image = std::move(img);
return true;
}

View File

@ -402,7 +402,7 @@ bool RASHandler::read(QImage *outImage)
return false;
}
*outImage = img;
*outImage = std::move(img);
return true;
}

View File

@ -748,7 +748,7 @@ bool RAWHandler::read(QImage *image)
return false;
}
*image = img;
*image = std::move(img);
return true;
}

View File

@ -678,9 +678,9 @@ bool SGIImage::writeImage(const QImage &image)
}
if (hasAlpha && img.format() != QImage::Format_ARGB32) {
img = img.convertToFormat(QImage::Format_ARGB32);
img.convertTo(QImage::Format_ARGB32);
} else if (!hasAlpha && img.format() != QImage::Format_RGB32) {
img = img.convertToFormat(QImage::Format_RGB32);
img.convertTo(QImage::Format_RGB32);
}
if (img.isNull()) {
// qDebug() << "can't convert image to depth 32";

View File

@ -419,7 +419,7 @@ bool TGAHandler::read(QImage *outImage)
return false;
}
*outImage = img;
*outImage = std::move(img);
return true;
}

View File

@ -103,7 +103,7 @@ int main(int argc, char **argv)
QTextStream(stderr) << "Unknown QImage data format " << parser.value(qimgformat) << '\n';
return 4;
}
img = img.convertToFormat(qformat);
img.convertTo(qformat);
}
qint64 written = output.write(reinterpret_cast<const char *>(img.bits()), img.sizeInBytes());
if (written != img.sizeInBytes()) {