From 37f2293156d9a5b9335fa7f8a67a56cd2b72aa82 Mon Sep 17 00:00:00 2001 From: Gres Date: Sun, 11 Oct 2015 19:51:37 +0300 Subject: [PATCH] Image conversion optimization. --- ImageProcessing.cpp | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/ImageProcessing.cpp b/ImageProcessing.cpp index 8caf0c9..2e25dff 100644 --- a/ImageProcessing.cpp +++ b/ImageProcessing.cpp @@ -37,28 +37,20 @@ qint64 getFreeMemory () { Pix * convertImage (const QImage &image) { PIX *pix; - QImage swapped = image.rgbSwapped (); - int width = swapped.width (); - int height = swapped.height (); - int depth = swapped.depth (); - int wpl = swapped.bytesPerLine () / 4; + int width = image.width (); + int height = image.height (); + int depth = image.depth (); + int bytesPerLine = image.bytesPerLine (); + int wpl = bytesPerLine / 4; pix = pixCreate (width, height, depth); pixSetWpl (pix, wpl); pixSetColormap (pix, NULL); - l_uint32 *outData = pix->data; - - for (int y = 0; y < height; y++) { - l_uint32 *lines = outData + y * wpl; - QByteArray a ((const char *)swapped.scanLine (y), swapped.bytesPerLine ()); - for (int j = 0; j < a.size (); j++) { - *((l_uint8 *)lines + j) = a[j]; - } - } + memmove (pix->data, image.bits (), bytesPerLine * height); const qreal toDPM = 1.0 / 0.0254; - int resolutionX = swapped.dotsPerMeterX () / toDPM; - int resolutionY = swapped.dotsPerMeterY () / toDPM; + int resolutionX = image.dotsPerMeterX () / toDPM; + int resolutionY = image.dotsPerMeterY () / toDPM; if (resolutionX < 300) { resolutionX = 300; @@ -67,8 +59,6 @@ Pix * convertImage (const QImage &image) { resolutionY = 300; } pixSetResolution (pix, resolutionX, resolutionY); - - pixEndianByteSwap (pix); return pix; } @@ -77,7 +67,7 @@ QImage convertImage (Pix &image) { int height = pixGetHeight (&image); int depth = pixGetDepth (&image); int bytesPerLine = pixGetWpl (&image) * 4; - l_uint32 *datas = pixGetData (pixEndianByteSwapNew (&image)); + l_uint32 *datas = pixGetData (&image); QImage::Format format; if (depth == 1) { @@ -125,7 +115,7 @@ QImage convertImage (Pix &image) { return none; } - return result.rgbSwapped (); + return result; } Pix * prepareImage (const QImage &image, int preferredScale) {