void CUniCaptureThread::run() {
	emit setIsRunning( true );
	init();

	delayTime = 10;	// initial delay time
	frameCounter = 0;
	frameTimer.start();
	
	while( !*stopThread ) {
		if ( *readyToProcess == true ) {			
			// Check resolution changes
			QRect screenGeometry = scr->geometry();

			int nScreenWidth  = screenGeometry.width();
			int nScreenHeight = screenGeometry.height();

			if ( nScreenWidth != ScreenWidth || nScreenHeight != ScreenHeight )	{
				ScreenWidth = nScreenWidth;
				ScreenHeight = nScreenHeight;

				cleanupBuffers();
				initBuffers();
			}  

			// Creating and filling regions data
			CRegions * regions = new CRegions( settings->getHorizontalSegmentWidth( ScreenWidth ), settings->getHorizontalHeight( ScreenHeight ),
				settings->getVerticalWidth( ScreenWidth ), settings->getVerticalSegmentHeight( ScreenHeight ) );
			
			// Horizontals
			// Top
			for ( unsigned short x = 0; x < settings->LEDnumH; x++ ) {
				QImage im = scr->grabWindow( desktopID, x * regions->hWidth, 0, regions->hWidth, regions->hHeight ).toImage();
				unsigned char * bufH_tmp = new unsigned char[ bufHSize ];
				memcpy( bufH_tmp, im.bits(), bufHSize );

				regions->regionHTop.push_back( bufH_tmp );
			}
			
			// Bottom
			for ( unsigned short x = 0; x < settings->LEDnumH; x++ ) {
				QImage im = scr->grabWindow( desktopID, x * regions->hWidth, ScreenHeight - regions->hHeight, regions->hWidth, regions->hHeight ).toImage();
				unsigned char * bufH_tmp = new unsigned char[ bufHSize ];
				memcpy( bufH_tmp, im.bits(), bufHSize );

				regions->regionHBottom.push_back( bufH_tmp );			
			}

			// Verticals
			// Left
			for ( int x = 0; x < settings->LEDnumV; x++ ) {
				QImage im = scr->grabWindow( desktopID, 0, x * regions->vHeight, regions->vWidth, regions->vHeight ).toImage();
				unsigned char * bufV_tmp = new unsigned char[ bufVSize ];
				memcpy( bufV_tmp, im.bits(), bufVSize );

				regions->regionVLeft.push_back( bufV_tmp );
			}
			
			// Right
			for ( int x = 0; x < settings->LEDnumV; x++ ) {
				QImage im = scr->grabWindow( desktopID, ScreenWidth - regions->vWidth, x * regions->vHeight, regions->vWidth, regions->vHeight ).toImage();
				unsigned char * bufV_tmp = new unsigned char[ bufVSize ];
				memcpy( bufV_tmp, im.bits(), bufVSize );

				regions->regionVRight.push_back( bufV_tmp );			
			}

			*readyToProcess = false;
			emit onImageCaptured( regions );
			++frameCounter;
			updateDelayTime();
		}		
		usleep( delayTime );
	}

	cleanup();
	emit setIsRunning( false );
	//*stopThread = true;
}
Exemple #2
0
void CDXSimpleThread::run() {
	emit setIsRunning( true );
	init();

	delayTime = 10;	// initial delay time
	frameCounter = 0;
	frameTimer.start();

	while( !*stopThread ) {
		if ( *readyToProcess == true ) {
			// Check resolution		
			D3DDISPLAYMODE ddm;
			if( FAILED( g_pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &ddm ) ) ) {
				throw( "Unable to get adapter display mode" );
				//break;
			}
			if ( ddm.Height != ScreenHeight || ddm.Width != ScreenWidth ) {
				cleanup();
				init();
			}
		
			// Capture screen
			g_pd3dDevice->GetFrontBufferData( 0, pSurface );
			D3DLOCKED_RECT lockedRect;
			pSurface->LockRect( &lockedRect, NULL, D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_NOSYSLOCK | D3DLOCK_READONLY );
	
			for( int i=0 ; i < ScreenHeight ; i++ )	{
				memcpy( buf + i * ScreenWidth * BITS_PER_PIXEL / 8, (BYTE*)lockedRect.pBits + i* lockedRect.Pitch, ScreenWidth * BITS_PER_PIXEL / 8 );
			}
			pSurface->UnlockRect();

			CRegions * regions = new CRegions( settings->getHorizontalSegmentWidth( ScreenWidth ), settings->getHorizontalHeight( ScreenHeight ),
				settings->getVerticalWidth( ScreenWidth ), settings->getVerticalSegmentHeight( ScreenHeight ) )	;
			
			// Horizontal
			// Top
			for( int i = 0; i < settings->LEDnumH; i++ ) {
				unsigned char * buf_tmp = new unsigned char[ regions->hWidth * regions->hHeight * BITS_PER_PIXEL / 8 ];
				for( int x = 0; x < regions->hHeight; x++ )
					memcpy( buf_tmp + x * regions->hWidth * BITS_PER_PIXEL / 8, buf + ( x * ScreenWidth + i * regions->hWidth ) * BITS_PER_PIXEL / 8, regions->hWidth * BITS_PER_PIXEL / 8 );

				regions->regionHTop.push_back( buf_tmp );
			}

			// Bottom
			for( int i = 0; i < settings->LEDnumH; i++ ) {
				unsigned char * buf_tmp = new unsigned char[ regions->hWidth * regions->hHeight * BITS_PER_PIXEL / 8 ];
				for( int x = 0; x < regions->hHeight; x++ )
					memcpy( buf_tmp + x * regions->hWidth * BITS_PER_PIXEL / 8, buf + ( ( ScreenHeight - regions->hHeight ) * ScreenWidth + x * ScreenWidth + i * regions->hWidth ) * BITS_PER_PIXEL / 8, regions->hWidth * BITS_PER_PIXEL / 8 );
				
				regions->regionHBottom.push_back( buf_tmp );
			}

			// Verticals
			// Left
			for ( int i = 0; i < settings->LEDnumV; i++ ) {
				unsigned char * buf_tmp = new unsigned char[ regions->vWidth * regions->vHeight * BITS_PER_PIXEL / 8 ];
				for( int x = 0; x < regions->vHeight; x++ )
					memcpy( buf_tmp + x * regions->vWidth * BITS_PER_PIXEL / 8, buf + ( i * regions->vHeight * ScreenWidth + x * ScreenWidth ) * BITS_PER_PIXEL / 8, regions->vWidth * BITS_PER_PIXEL / 8 );
				
				regions->regionVLeft.push_back( buf_tmp );
			}

			// Right
			for ( int i = 0; i < settings->LEDnumV; i++ ) {
				unsigned char * buf_tmp = new unsigned char[ regions->vWidth * regions->vHeight * BITS_PER_PIXEL / 8 ];
				for( int x = 0; x < regions->vHeight; x++ )
					memcpy( buf_tmp + x * regions->vWidth * BITS_PER_PIXEL / 8, buf + ( i * regions->vHeight *  ScreenWidth + ( ScreenWidth - regions->vWidth ) + x * ScreenWidth ) * BITS_PER_PIXEL / 8, regions->vWidth * BITS_PER_PIXEL / 8 );
				
				regions->regionVRight.push_back( buf_tmp );
			}

			*readyToProcess = false;
			emit onImageCaptured( regions );			
			++frameCounter;
			updateDelayTime();
		}
		usleep( delayTime );
	}
	cleanup();
	emit setIsRunning( false );
	//*stopThread = true;
}
Exemple #3
0
void CGDISimpleThread::run() {
	emit setIsRunning( true );
	init();

	delayTime = 10;	// initial delay time
	frameCounter = 0;
	frameTimer.start();
	
	while( !*stopThread ) {
		if ( *readyToProcess == true ) {
			// Check for resolution changes
			int nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
			int nScreenHeight = GetSystemMetrics(SM_CYSCREEN);

			if ( nScreenWidth != ScreenWidth || nScreenHeight != ScreenHeight )	{
				ScreenWidth = nScreenWidth;
				ScreenHeight = nScreenHeight;

				cleanupBuffers();
				initBuffers();
			}  

			// Creating and filling regions data
			CRegions * regions = new CRegions( settings->getHorizontalSegmentWidth( ScreenWidth ), settings->getHorizontalHeight( ScreenHeight ),
				settings->getVerticalWidth( ScreenWidth ), settings->getVerticalSegmentHeight( ScreenHeight ) );

			// Horizontals
			SelectObject( hCaptureDC, hCaptureBitmapH );
			// Top
			for ( unsigned short x = 0; x < settings->LEDnumH; x++ ) {
				BitBlt( hCaptureDC, 0, 0, regions->hWidth, regions->hHeight, hDesktopDC, x * regions->hWidth, 0, SRCCOPY|CAPTUREBLT );
				GetBitmapBits( hCaptureBitmapH, bufHSize, bufH );

				unsigned char * bufH_tmp = new unsigned char[ bufHSize ];
				memcpy( bufH_tmp, bufH, bufHSize );

				regions->regionHTop.push_back( bufH_tmp );
			}
			
			// Bottom
			for ( unsigned short x = 0; x < settings->LEDnumH; x++ ) {
				BitBlt( hCaptureDC, 0, 0, regions->hWidth, regions->hHeight, hDesktopDC, x * regions->hWidth, ScreenHeight - regions->hHeight, SRCCOPY|CAPTUREBLT );
				GetBitmapBits( hCaptureBitmapH, bufHSize, bufH );

				unsigned char * bufH_tmp = new unsigned char[ bufHSize ];
				memcpy( bufH_tmp, bufH, bufHSize );

				regions->regionHBottom.push_back( bufH_tmp );			
			}

			// Verticals
			SelectObject(hCaptureDC,hCaptureBitmapV);
			// Left
			for ( int x = 0; x < settings->LEDnumV; x++ ) {
				BitBlt( hCaptureDC, 0, 0, regions->vWidth, regions->vHeight, hDesktopDC, 0, x * regions->vHeight, SRCCOPY|CAPTUREBLT );
				GetBitmapBits( hCaptureBitmapV, bufVSize, bufV );

				unsigned char * bufV_tmp = new unsigned char[ bufVSize ];
				memcpy( bufV_tmp, bufV, bufVSize );

				regions->regionVLeft.push_back( bufV_tmp );
			}
			
			// Right
			for ( int x = 0; x < settings->LEDnumV; x++ ) {
				BitBlt( hCaptureDC, 0, 0, regions->vWidth, regions->vHeight, hDesktopDC, ScreenWidth - regions->vWidth, x * regions->vHeight, SRCCOPY|CAPTUREBLT );
				GetBitmapBits( hCaptureBitmapV, bufVSize, bufV );

				unsigned char * bufV_tmp = new unsigned char[ bufVSize ];
				memcpy( bufV_tmp, bufV, bufVSize );

				regions->regionVRight.push_back( bufV_tmp );			
			}

			*readyToProcess = false;
			emit onImageCaptured( regions );
			++frameCounter;
			updateDelayTime();
		}		
		usleep( delayTime );
	}
	cleanup();
	emit setIsRunning( false );
	//*stopThread = true;
}