MainWindow::MainWindow()
///
/// Constructor
///
: mCurrentImage( NULL ),
  mPreviousImage( NULL ),
  mNextImage( NULL )
{
    setWindowTitle( tr( "Image Filter Collection" ) );
    
	setMaximumSize( QSize( 1250, 650 ) );
    setMinimumSize( QSize( 200, 200 ) );

    mFilterProcessor = new FilterProcessor();

    connect( mFilterProcessor, SIGNAL( FilterDone(QImage) ), this, SLOT( LoadNewImage(QImage) ) );

    InitImagePane();
    
	InitFileMenu();
	InitEditMenu();
	InitFilterMenu();

	setCentralWidget( mScrollArea );
	setMinimumSize( mScrollArea->minimumSize() );

	mStatusText = new QLabel;
	statusBar()->addWidget(mStatusText);
	connect( mFilterProcessor, SIGNAL( FilterStatus(QString) ), this, SLOT( StatusBarUpdated(QString) ) );
}
void
MainWindow::Open()
///
/// Displays an open file dialog and sets the current image to be the one selected by the user.
///
/// @return
///  Nothing
///
{
	const QString default_dir_key("default_dir");
	QSettings app_settings;

	// Display an open file dialog at the default folder in the application setting
	QString file_name = QFileDialog::getOpenFileName( this, tr("Open File"), app_settings.value(default_dir_key).toString(), "Images (*.png *.bmp *.jpg)" );
    if( file_name != "" )
    {
    	// Save the chosen folder as the default in the application settings
    	QDir current_dir;
        app_settings.setValue(default_dir_key, current_dir.absoluteFilePath(file_name));

        // Load the chosen file as the unprocessed image
        QImage image;
        image.load( file_name );

        // Update the current image to this image
        LoadNewImage( image );

        // Resize window to fit new image
        Resize();
    }
}
示例#3
0
sf::Sprite MOO::Visual::ImageManager::LoadNewImage( const char fileName[] )
{
	return LoadNewImage( std::string( fileName ) );
}
//image verification function (loading + blitting)
int CSTATImageVerify::VerifyImage(CString& lastscreenshot)	
{
	TCHAR buffer[70];
	_stprintf(buffer, _T("User set margin of error (percentage) : %ld"), margin);

	pLogFile->Set(START_VERIFICATION, buffer);

	// make sure we've got at least 1 image left
	if(ImagesRemaining())
	{
		if(LoadRefImage())
			pLogFile->Set(REFIMAGELOAD_OK, refimagearray[lastrefimageloaded++].completefilenamepath);
		else
			return pLogFile->Set(REFIMAGELOAD_FAILURE);

		Sleep(500);

		if(LoadNewImage(lastscreenshot))
			pLogFile->Set(NEWIMAGELOAD_OK);
		else
			return pLogFile->Set(NEWIMAGELOAD_FAILURE);
	}
	else
		return pLogFile->Set(REFIMAGELOAD_FAILURE_LIMIT);	//run out of reference images

	//compare images and decide if difference is greater than margin value set earlier

	// If we have not data we can't draw.
	if (!m_pDib2)
		return pLogFile->Set(VERIFICATION_FAILURE);

	//set width and height of images
	int nWidth = m_pBIH2 -> biWidth;
	int nHeight = m_pBIH2 -> biHeight;

	HDC hdc, hMaskDC, hImageDC;
	HBITMAP hMaskBitmap, hImageBitmap;

	hdc = GetDC(NULL);

	//---------------------

	hMaskDC = CreateCompatibleDC(hdc);
	hImageDC = CreateCompatibleDC(hdc);
	
	hMaskBitmap = CreateCompatibleBitmap(hdc, nWidth, nHeight);
	
	SelectObject(hMaskDC, hMaskBitmap);
	SetTextColor(hMaskDC, RGB(0, 0, 255)); 

	//---------------------

	hImageBitmap = CreateCompatibleBitmap(hdc, nWidth, nHeight);

	// release the object now we're finished with it
	ReleaseDC(NULL, hdc);

	SelectObject(hImageDC, hImageBitmap);
	SetTextColor(hImageDC, RGB(0, 0, 255)); 

	//---------------------

	//set MaskBitmap pixel data to that of the original DIB
	SetDIBits(hMaskDC, hMaskBitmap, 0L, nHeight, m_pDibBits, (BITMAPINFO *)m_pBIH, (DWORD)DIB_RGB_COLORS);
	
	//create a new DIB using second image data
	SetDIBits(hImageDC, hImageBitmap, 0L, nHeight, m_pDibBits2, (BITMAPINFO *)m_pBIH2, (DWORD)DIB_RGB_COLORS);

	//XOR new image with original image (so new pic on top of pic 2)
	BitBlt(hMaskDC, 0, 0, nWidth, nHeight, hImageDC, 0, 0, SRCINVERT);

	//***************************************************

	//now work on percentage difference in images

	//need to use 'new' otherwise you get a stack overflow with anything big like this (1MB+)
	COLORREF (*pixelcoord) [480];
	pixelcoord = new COLORREF [640][480];
	if (!pixelcoord)
		return pLogFile->Set(VERIFICATION_FAILURE);

	int x, y, myheight, mywidth;
	float totalpixelarea;

	x = 0;
	y = 0;
	int difference = 0;
	float finalpercentage = 0;
	totalpixelarea = 0;
	myheight = 0;
	mywidth = 0;

	mywidth = m_pBIH -> biWidth;
	myheight = m_pBIH -> biHeight;

	// convert total to float for later % calculation
	totalpixelarea = (float)(mywidth * myheight);

	//initialisation
	for(y = 0; y < 480; y++)
	{
		//go across picture left to right at each line
		for(x = 0; x < 640; x++)
		{
			//get colorref value from coordinates
			pixelcoord[x][y] = 0;
		}
	}

	//check pixels - start at line 0
	for(y = 0; y < myheight; y++)
	{
		//go across picture left to right at each line
		for(x = 0; x < mywidth; x++)
		{
			//get colorref value from coordinates
			pixelcoord[x][y] = GetPixel(hMaskDC, x, y);

			//if not a  black pixel then increment counter
			if(pixelcoord[x][y] != 0)
			{
				difference++;
			}
		}
	}

	// release resources
	delete [] pixelcoord;
	DeleteDC(hMaskDC);
	DeleteDC(hImageDC);
	DeleteObject(hMaskBitmap);
	DeleteObject(hImageBitmap);

	if (m_pDib)
	{
		delete [] m_pDib;
		m_pDib = NULL;
	}

	if (m_pDib2)
	{
		delete [] m_pDib2;
		m_pDib2 = NULL;
	}

	//now calculate percentage of pic that is not black
	finalpercentage = ((difference / totalpixelarea) * 100);

	// write conversion info to file


	CString cBuffer;
	cBuffer.Format(_T("Margin %ld : Difference %f"), margin, finalpercentage);
	pLogFile->Set(cBuffer);

	if(finalpercentage > margin)
		return pLogFile->Set(VERIFICATION_FAILURE);

	return pLogFile->Set(VERIFICATION_PASS);
}