Image conversion optimization.

This commit is contained in:
Gres 2015-10-11 19:51:37 +03:00
parent e18f9b2431
commit 37f2293156

View File

@ -37,28 +37,20 @@ qint64 getFreeMemory () {
Pix * convertImage (const QImage &image) { Pix * convertImage (const QImage &image) {
PIX *pix; PIX *pix;
QImage swapped = image.rgbSwapped (); int width = image.width ();
int width = swapped.width (); int height = image.height ();
int height = swapped.height (); int depth = image.depth ();
int depth = swapped.depth (); int bytesPerLine = image.bytesPerLine ();
int wpl = swapped.bytesPerLine () / 4; int wpl = bytesPerLine / 4;
pix = pixCreate (width, height, depth); pix = pixCreate (width, height, depth);
pixSetWpl (pix, wpl); pixSetWpl (pix, wpl);
pixSetColormap (pix, NULL); pixSetColormap (pix, NULL);
l_uint32 *outData = pix->data; memmove (pix->data, image.bits (), bytesPerLine * height);
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];
}
}
const qreal toDPM = 1.0 / 0.0254; const qreal toDPM = 1.0 / 0.0254;
int resolutionX = swapped.dotsPerMeterX () / toDPM; int resolutionX = image.dotsPerMeterX () / toDPM;
int resolutionY = swapped.dotsPerMeterY () / toDPM; int resolutionY = image.dotsPerMeterY () / toDPM;
if (resolutionX < 300) { if (resolutionX < 300) {
resolutionX = 300; resolutionX = 300;
@ -67,8 +59,6 @@ Pix * convertImage (const QImage &image) {
resolutionY = 300; resolutionY = 300;
} }
pixSetResolution (pix, resolutionX, resolutionY); pixSetResolution (pix, resolutionX, resolutionY);
pixEndianByteSwap (pix);
return pix; return pix;
} }
@ -77,7 +67,7 @@ QImage convertImage (Pix &image) {
int height = pixGetHeight (&image); int height = pixGetHeight (&image);
int depth = pixGetDepth (&image); int depth = pixGetDepth (&image);
int bytesPerLine = pixGetWpl (&image) * 4; int bytesPerLine = pixGetWpl (&image) * 4;
l_uint32 *datas = pixGetData (pixEndianByteSwapNew (&image)); l_uint32 *datas = pixGetData (&image);
QImage::Format format; QImage::Format format;
if (depth == 1) { if (depth == 1) {
@ -125,7 +115,7 @@ QImage convertImage (Pix &image) {
return none; return none;
} }
return result.rgbSwapped (); return result;
} }
Pix * prepareImage (const QImage &image, int preferredScale) { Pix * prepareImage (const QImage &image, int preferredScale) {