#include "qimagethread.h" #include "globals.h" #include "pixel.h" #include <qfile.h> #include <qimage.h> QImageThread::QImageThread() { d_p = 0x0; file = 0x0; width = height = 0; pix = 0x0; } void QImageThread::run() { if ( !d_p || !file || !pix ) return; *d_p = this->load_pixels( pix, file, width, height ); } void QImageThread::Load( float* d, Pixel** p, char*f, int w, int h ) { d_p = d; pix = p; file = f; width = w; height = h; } //returns "diff amount" as a sum of diffs over entire image float QImageThread::load_pixels( Pixel** p, char* file, int width, int height ) { if ( !file ) return load_random( p, width, height ); QFile handle( file ); handle.open( IO_ReadOnly ); int size = handle.size(); QByteArray bytes( size ); int i = 0; for ( int c = handle.getch() ; !handle.atEnd() ; c = handle.getch() ) { bytes[i++] = c; if ( ! ( i % 4096 ) ) msleep( 1 ); } handle.close(); bytes[i] = 0; QImage image; image.loadFromData( bytes ); if ( image.isNull() ) return load_random( p, width, height ); msleep( 10 ); if ( settings.autoscale && ( image.width() != width || image.height() != height ) ) { QImage::ScaleMode sm; switch( settings.autoscale ) { case 'L': sm = QImage::ScaleMin; break; case 'M': sm = QImage::ScaleMax; default: case 'S': sm = QImage::ScaleFree; } image = image.smoothScale( width, height, sm ); } msleep( 10 ); float d_t = 0.0; int sx = ( width - image.width() ) / 2; int sy = ( height - image.height() ) / 2; int ix, iy; int py = height; for ( int y = 0 ; y < height ; y++ ) { iy = y - sy; if ( iy < 0 ) iy = 0; else if ( iy >= image.height() ) iy = image.height() - 1; py--; msleep( 1 ); for ( int x = 0 ; x < width ; x++ ) { ix = x - sx; if ( ix < 0 ) ix = 0; else if ( ix >= image.width() ) ix = image.width() - 1; p[x][py].b_r = qRed ( image.pixel( ix, iy ) ) / 255.0 ; p[x][py].b_g = qGreen( image.pixel( ix, iy ) ) / 255.0 ; p[x][py].b_b = qBlue ( image.pixel( ix, iy ) ) / 255.0 ; compute_diff( & p[x][py] ); d_t += p[x][py].d_r + p[x][py].d_g + p[x][py].d_b; } } return d_t; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#4 | 5098 | Sam Stafford |
Rollback the multithreaded image loading functionality. It didn't really boost performance like I'd hoped it would - the CPU would still swamp for a second while decoding the image, and there was no way around that. |
||
#3 | 4791 | Sam Stafford |
Fix random color mode (the default if no valid image files are found). It was severely broken by the change that introduced threads. |
||
#2 | 4706 | Sam Stafford |
When padding an image that doesn't match the world dimensions, use the edges of the image instead of black. |
||
#1 | 4642 | Sam Stafford |
Load images in a seperate thread to cut down on framerate lag. Also moved to Qt 3.3.3. |