diff --git a/ksanetwain/ktwain_widget.cpp b/ksanetwain/ktwain_widget.cpp --- a/ksanetwain/ktwain_widget.cpp +++ b/ksanetwain/ktwain_widget.cpp @@ -97,21 +97,36 @@ int bytes_per_line, ImageFormat format) { - QImage img = QImage::fromData(data, "BMP"); - return img; + return toQImageSilent(data, + width, + height, + bytes_per_line, + format); +} + +QImage KSaneWidget::toQImageSilent(const QByteArray &data, + int width, + int height, + int bytes_per_line, + ImageFormat format) +{ + return KSaneWidget::toQImageSilent(data, + width, + height, + bytes_per_line, + (int) currentDPI(), + format); } QImage KSaneWidget::toQImageSilent(const QByteArray &data, int width, int height, int bytes_per_line, + int dpi, ImageFormat format) { - return KSaneWidget::toQImage(data, - width, - height, - bytes_per_line, - format); + QImage img = QImage::fromData(data, "BMP"); + return img; } void KSaneWidget::scanFinal() diff --git a/src/ksanewidget.h b/src/ksanewidget.h --- a/src/ksanewidget.h +++ b/src/ksanewidget.h @@ -150,6 +150,26 @@ int bytes_per_line, ImageFormat format); + /** + * This is a static version of toQImageSilent() method that requires dpi as additional + * argument. Non-static version uses currentDPI() for it. + * + * @param data is the byte data containing the image. + * @param width is the width of the image in pixels. + * @param height is the height of the image in pixels. + * @param bytes_per_line is the number of bytes used per line. This might include padding + * and is probably only relevant for 'FormatBlackWhite'. + * @param format is the KSane image format of the data. + * @param dpi is the dpi value of the image. + * @return This function returns the provided image data as a QImage. */ + static + QImage toQImageSilent(const QByteArray &data, + int width, + int height, + int bytes_per_line, + int dpi, + ImageFormat format); + /** This method returns the vendor name of the scanner (Same as make). */ QString vendor() const; /** This method returns the make name of the scanner. */ diff --git a/src/ksanewidget.cpp b/src/ksanewidget.cpp --- a/src/ksanewidget.cpp +++ b/src/ksanewidget.cpp @@ -547,6 +547,16 @@ int height, int bytes_per_line, ImageFormat format) +{ + return KSaneWidget::toQImageSilent(data, width, height, bytes_per_line, currentDPI(), format); +} + +QImage KSaneWidget::toQImageSilent(const QByteArray &data, + int width, + int height, + int bytes_per_line, + int dpi, + ImageFormat format) { QImage img; int j = 0; @@ -619,7 +629,7 @@ qDebug() << "Unsupported conversion"; break; } - float dpm = currentDPI() * (1000.0 / 25.4); + float dpm = dpi * (1000.0 / 25.4); img.setDotsPerMeterX(dpm); img.setDotsPerMeterY(dpm); return img;