Esempio n. 1
0
bool CaptureManager::SaveTrajectoryImage(wxBitmap &bmp)
{
	if (!Access(0,0, false, true)->contourArray.size())
	{
		wxLogError(_T("No objects in the first frame. Detect/draw boundaries in the first frame and apply tracking first."));
		return false;
	}
	wxRealPoint scale(6,6);
	CvPoint lastLoc;
	bmp.Create(scale.x*size.width,scale.y*size.height);
	wxMemoryDC dc(bmp);
	dc.SetBackground(*wxWHITE_BRUSH);
	dc.Clear();
	for (int c=0; c<Access(0,0,false, true)->contourArray.size(); c++)
	{
		std::vector<CvPoint> traj = GetTrajectory(c);
		lastLoc = traj[0];
		// draw first boundary
		MyCanvas::DrawContour_static(&dc, Access(0,0, false, true)->contourArray[c],wxPoint(0,0),scale);
		// drawing trajectory lines
		dc.SetBrush(*wxTRANSPARENT_BRUSH);
		for (int i=1; i<traj.size(); i++)
		{
			if(traj[i].x<0)
				continue;
			if (i>0)
			{
				dc.SetPen(wxPen(wxColour(Preferences::GetColorContourBorderColor()), Preferences::GetColorContourBorderWidth()));
				dc.DrawLine(scale.x*lastLoc.x,scale.y*lastLoc.y, scale.x*traj[i].x,scale.y*traj[i].y);
			}
			lastLoc = traj[i];
		}
		// drawing trajectory points
		dc.SetBrush(wxBrush(wxColour(Preferences::GetColorContourPointColor())));
		dc.SetPen(wxPen(wxColour(Preferences::GetColorContourPointColor())));
		for (int i=0; i<traj.size(); i++)
		{
			if(traj[i].x<0)
				continue;
			dc.DrawCircle(MyPoint(traj[i])*scale, 2*Preferences::GetColorContourBorderWidth());
		}
		// draw last boundary
		dc.SetBrush(*wxRED_BRUSH);
		dc.SetPen(wxPen(*wxRED));
		if(traj[frameCount-1].x>=0)
		{
			dc.DrawCircle(MyPoint(traj[frameCount-1])*scale, 2*Preferences::GetColorContourBorderWidth());
			MyCanvas::DrawContour_static(&dc, book[(frameCount-1)*offset]->contourArray[c],wxPoint(0,0),scale, true, wxRED);
		}
	}
	return true;
}
Esempio n. 2
0
void BitmapTestCase::setUp()
{
    m_bmp.Create(10, 10);

    wxMemoryDC dc(m_bmp);;
    dc.SetBackground(*wxWHITE);
    dc.Clear();

    dc.SetBrush(*wxBLACK_BRUSH);
    dc.DrawRectangle(4, 4, 2, 2);

    dc.SetPen(*wxRED_PEN);
    dc.DrawLine(0, 0, 10, 10);
    dc.DrawLine(10, 0, 0, 10);
}
Esempio n. 3
0
bool BitmapFromWindow(wxWindow *window, wxBitmap& bitmap)
{
    bool ret;
    wxMemoryDC mdc;
    wxClientDC cdc(window);
    const wxSize& size=window->GetClientSize();

    window->Raise();
    wxTheApp->Yield();

    bitmap.Create(size.x, size.y);
    mdc.SelectObject(bitmap);
    ret=mdc.Blit(0, 0, size.x, size.y, &cdc, 0, 0);
    mdc.SelectObject(wxNullBitmap);

    return ret;
}
Esempio n. 4
0
void SjOscWindow::OnTimer(wxTimerEvent&)
{
	SJ_FORCE_IN_HERE_ONLY_ONCE;

	if( m_oscModule )
	{
		// volume stuff
		long                volume, maxVolume = 1;
		bool                volumeBeat;

		// other objects
		long                i;
		bool                titleChanged, forceOscAnim, forceSpectrAnim;
		wxString            newTitle;

		// get data
		g_mainFrame->m_player.GetVisData(m_bufferStart, m_sampleCount*SJ_WW_CH*SJ_WW_BYTERES, 0);

		// get window client size, correct offscreen DC if needed
		wxSize clientSize = m_oscModule->m_oscWindow->GetClientSize();
		if( clientSize.x != m_offscreenBitmap.GetWidth() || clientSize.y != m_offscreenBitmap.GetHeight() )
		{
			m_offscreenBitmap.Create(clientSize.x, clientSize.y);
			m_offscreenDc.SelectObject(m_offscreenBitmap);
		}

		// calculate the points for the lines, collect volume
		m_oscilloscope->Calc(clientSize, m_bufferStart, volume);
		if( m_oscModule->m_showFlags&SJ_OSC_SHOW_SPECTRUM )
		{
			m_spectrum->Calc(clientSize, m_bufferStart);
		}

		// get data that are shared between the threads
		{
			titleChanged = m_oscModule->m_titleChanged;
			m_oscModule->m_titleChanged = FALSE;
			if( titleChanged )
			{
				newTitle = m_oscModule->m_trackName;
				if( newTitle.IsEmpty() )
				{
					newTitle = SJ_PROGRAM_NAME;
				}
				else if( !m_oscModule->m_leadArtistName.IsEmpty() )
				{
					newTitle.Prepend(m_oscModule->m_leadArtistName + wxT(" - "));
				}
			}

			forceOscAnim = m_oscModule->m_forceOscAnim;
			m_oscModule->m_forceOscAnim = FALSE;

			forceSpectrAnim = m_oscModule->m_forceSpectrAnim;
			m_oscModule->m_forceSpectrAnim = FALSE;
		}

		// calculate volume, volume is theoretically max. 255, normally lesser
		if( titleChanged )              { maxVolume = 1;        }
		if( volume > maxVolume )        { maxVolume = volume;   }

		volumeBeat = (volume > maxVolume/2);

		// erase screen
		m_offscreenDc.SetPen(*wxTRANSPARENT_PEN);
		{
			// blue gradient background
			#define BG_STEPS 88
			int rowH = (clientSize.y/BG_STEPS)+1;
			for( i = 0; i < BG_STEPS; i++ )
			{
				m_bgBrush.SetColour(0, 0, i);
				m_offscreenDc.SetBrush(m_bgBrush);
				m_offscreenDc.DrawRectangle(0, i*rowH, clientSize.x, rowH);
			}
		}

		// draw text (very background)
		{
			m_offscreenDc.SetBackgroundMode(wxTRANSPARENT);
			m_offscreenDc.SetTextForeground(m_textColour);
			m_title->Draw(m_offscreenDc, clientSize, titleChanged, newTitle);
		}

		// draw figures (they lay in backgroud)
		if( m_oscModule->m_showFlags&SJ_OSC_SHOW_FIGURES )
		{
			long bgLight = 100;

			// draw hands (optional)
			m_hands->Draw(m_offscreenDc, clientSize, volume, bgLight, titleChanged);

			// draw rotor (optional)
			m_rotor->Draw(m_offscreenDc, clientSize, m_starfield->IsRunning(), titleChanged, volume, bgLight);

			// draw firework (optional)
			m_firework->Draw(m_offscreenDc, clientSize, titleChanged, m_starfield->IsRunning(), volumeBeat, bgLight);
		}

		// draw starfield (optional)
		m_starfield->Draw(m_offscreenDc, clientSize, false, titleChanged, (m_oscModule->m_showFlags&SJ_OSC_SHOW_STARFIELD)!=0);

		// draw spectrum and/or oscilloscope (for both, the spectrum lays over the oscillosope)
		m_offscreenDc.SetPen(m_fgPen);

		if( m_oscModule->m_showFlags&SJ_OSC_SHOW_OSC )
		{
			m_oscilloscope->Draw(m_offscreenDc, forceOscAnim);
		}

		if( m_oscModule->m_showFlags&SJ_OSC_SHOW_SPECTRUM )
		{
			m_spectrum->Draw(m_offscreenDc, volumeBeat,
						  (m_oscModule->m_showFlags&SJ_OSC_SHOW_FIGURES)? true : false,
						  forceSpectrAnim);
		}

		// draw offscreen bitmap to screen
		wxClientDC dc(this);
		dc.Blit(0, 0, m_offscreenBitmap.GetWidth(), m_offscreenBitmap.GetHeight(), &m_offscreenDc, 0, 0);
	}
}
Esempio n. 5
0
bool CaptureManager::SaveTrackImage(wxBitmap &bmp, int start, int end)
{
    if (end == -1) end = frameCount;
	if (!Access(0,0,false, true)->contourArray.size())
	{
		wxLogError(_T("No objects in the first frame. Detect/draw boundaries in the first frame and apply tracking first."));
		return false;
	}
	wxRealPoint scale(6, 6);
	bmp.Create(scale.x*size.width, scale.y*size.height);
	wxMemoryDC dc(bmp);
	dc.SetBackground(*wxWHITE_BRUSH);
	dc.Clear();

	for (int c=0; c<Access(0, 0, false, true)->contourArray.size(); c++)
	{
        std::vector<CvPoint> traj = GetTrajectory(c);
        std::vector< std::vector<double> > ratios;
        CvPoint lastTraj = traj[start];
        float maxRatio = 0;
        float minRatio = 0;
		for (int i=start+1; i<end && Access(i, 0, false, true)->contourArray.size() > c; i++)
        {
            CvSeq* oseq = Access(i-1, 0, false, true)->contourArray[c];
            CvSeq* seq = Access(i, 0, false, true)->contourArray[c];
            ratios.push_back(std::vector<double>());
            for (int j=0; j<oseq->total; j++)
            {
                CvPoint *lastLoc = (CvPoint*) cvGetSeqElem(oseq, j);
                if(seq->total <= j)
					continue;
                CvPoint *p = (CvPoint*) cvGetSeqElem(seq, j);
                float ptx = p->x - lastLoc->x;
                float pty = p->y - lastLoc->y;
                float trajx = traj[i].x - lastTraj.x;
                float trajy = traj[i].y - lastTraj.y;
                float ratio = (ptx*trajx + pty*trajy)/(trajx*trajx + trajy*trajy);
                if (maxRatio < ratio)
                    maxRatio = ratio;
                if (minRatio > ratio)
                    minRatio = ratio;
                ratios[i-1-start].push_back(ratio);
            }
            lastTraj = traj[i];
        }

		CvSeq* oseq = Access(start, 0, false, true)->contourArray[c];
		MyCanvas::DrawContour_static(&dc, oseq, wxPoint(0,0), scale);
		for (int i=0; i<oseq->total; i++)
		{
			CvPoint *lastLoc = (CvPoint*) cvGetSeqElem(oseq, i);
			dc.SetPen(wxPen(wxColour(Preferences::GetColorContourPointColor())));
			dc.SetBrush(*wxTRANSPARENT_BRUSH);
			for (int j=start+1; j<end; j++)
			{
				if(Access(j,0,false, true)->contourArray.size() <= c || Access(j,0,false, true)->contourArray[c]->total <= i)
					continue;
				CvPoint *p = (CvPoint*) cvGetSeqElem(Access(j, 0, false, true)->contourArray[c], i);
				dc.DrawLine(scale.x*lastLoc->x, scale.y*lastLoc->y, scale.x*p->x, scale.y*p->y);
				lastLoc = p;
			}
			//dc.DrawCircle(MyPoint((CvPoint*)cvGetSeqElem(Access(start, 0, false, true)->contourArray[c],i))*scale, Preferences::GetColorContourBorderWidth());
			for (int j=start+1; j<end; j++)
			{
			    wxColor pointColor(*wxLIGHT_GREY);
                if (ratios[j-1-start][i] > 0)
                    pointColor = wxColor(128 + 127*ratios[j-1-start][i]/maxRatio, 128 - 128*ratios[j-1-start][i]/maxRatio, 128 - 128*ratios[j-1-start][i]/maxRatio);
                else
                    pointColor = wxColor(128 - 128*ratios[j-1-start][i]/minRatio, 128 - 128*ratios[j-1-start][i]/minRatio, 128 + 127*ratios[j-1-start][i]/minRatio);
                dc.SetPen(wxPen(pointColor));
                dc.SetBrush(pointColor);
				if(Access(j, 0, false, true)->contourArray.size() <= c || Access(j, 0, false, true)->contourArray[c]->total <= i)
					continue;
				CvPoint *p = (CvPoint*) cvGetSeqElem(Access(j, 0, false, true)->contourArray[c], i);
				dc.DrawCircle(MyPoint(*p)*scale, Preferences::GetColorContourBorderWidth()*2);
			}
		}
		lastTraj = traj[start];
		dc.SetBrush(*wxTRANSPARENT_BRUSH);
		for (int i=start+1; i<end/*traj.size()*/; i++)
		{
			if(traj[i].x<0)
				continue;
			if (i>0)
			{
				dc.SetPen(wxPen(wxColour(Preferences::GetColorContourBorderColor()), Preferences::GetColorContourBorderWidth()));
				dc.DrawLine(scale.x*lastTraj.x,scale.y*lastTraj.y, scale.x*traj[i].x,scale.y*traj[i].y);
			}
			lastTraj = traj[i];
		}
		if(c < Access(end-1,0,false, true)->contourArray.size())
			MyCanvas::DrawContour_static(&dc, Access(end-1,0,false, true)->contourArray[c], wxPoint(0,0), scale, true, wxRED);
	}
	return true;
}
Esempio n. 6
0
void ScreenshotButton::GetScreenshot(wxBitmap &screenshot) {

   //Create a DC for the main window
   wxClientDC dcScreen(GetParent());

   //Get the size of the screen/DC
   wxCoord screenWidth, screenHeight;

   //Size of the image
   int width, height;
   //The pixel array
   byte* graph;
   //Fill the pixel array
   graf->getPixels(graph, width, height);
   
   dcScreen.GetSize(&screenWidth, &screenHeight);

   //Create a Bitmap that will later on hold the screenshot image
   //Note that the Bitmap must have a size big enough to hold the screenshot
   //-1 means using the current default colour depth
   screenshot.Create(screenWidth, screenHeight,-1);
   //screenshot.Create(width, height,-1);

   //Create a memory DC that will be used for actually taking the screenshot
   wxMemoryDC memDC;
   //Tell the memory DC to use our Bitmap
   //all drawing action on the memory DC will go to the Bitmap now
   memDC.SelectObject(screenshot);
   //Blit (in this case copy) the actual screen on the memory DC
   //and thus the Bitmap
   memDC.Blit( 0, //Copy to this X coordinate
            0, //Copy to this Y coordinate
            screenWidth, //Copy this width
            screenHeight, //Copy this height
            &dcScreen, //From where do we copy?
            0, //What's the X offset in the original DC?
            0  //What's the Y offset in the original DC?
         );
   //Draw the graph on the screenshot


   //Temporary color
   wxColour color = wxColor(255,0,0);
   //Temporary position in pixel array
   int pos;

   //Loop through pixel array
   for(int y=0; y<height; y++) {
	   for(int x=0; x<width; x++) {
		   pos = (x+(height-y)*width)*3;
		   color.Set(graph[pos], graph[pos+1], graph[pos+2]);
		   memDC.SetBrush(color);
		   memDC.SetPen(color);
		   memDC.DrawPoint(x+79, y+59);
	   }
   }

   
   //Select the Bitmap out of the memory DC by selecting a new
   //uninitialized Bitmap
   memDC.SelectObject(wxNullBitmap);

   

   return;
}
Esempio n. 7
0
void SjKaraokeWindow::OnTimer(wxTimerEvent&)
{
	wxASSERT( wxThread::IsMain() );

	/**********************************************************************
	 * PREPARE DRAWING
	 **********************************************************************/

	if( m_karaokeModule == NULL || m_karaokeModule->m_bg == NULL ) return;
	if( m_inPaint ) return;
	m_inPaint = true;

	#ifdef __WXMAC__
	m_pleaseUpdateAll = true; // partly updates do not work well on Mac OS X
	#endif

	// does the size of the window have changed?
	if( m_clientSize != GetClientSize() || m_bgChanged )
	{
		// yes: save the new size
		m_clientSize = GetClientSize();
		m_pleaseUpdateAll = true;

		// (re-)create the offscreen DC
		m_offscreenBitmap.Create(m_clientSize.x, m_clientSize.y);
		m_offscreenDc.SelectObject(m_offscreenBitmap);

		// force reloading of the background image
		m_karaokeModule->m_bg->SetSize(m_clientSize);
		m_bgChanged = false;
	}

	// check what to show
	int karaokeEnded = 1;
	if( m_karaokeMaster.HasKaraoke() )
	{
		long totalMs, elapsedMs, remainingMs;
		g_mainFrame->m_player.GetTime(totalMs, elapsedMs, remainingMs);
		if( elapsedMs >= 0 ) // -1=error, 0=normal position 0:00
		{
			karaokeEnded = m_karaokeMaster.SetPosition(elapsedMs)? 0 : 1;
		}
	}

	if( karaokeEnded != m_karaokeEnded )
	{
		if( karaokeEnded )
		{
			if( m_sjScreen == NULL )
				m_sjScreen = new SjSjScreen(wxT("SILVERJUKE KARAOKE"),
				                            g_mainFrame->IsKioskStarted()? wxT("www.silverjuke.net") : wxT(""), 8000);
		}
		else
		{
			if( m_sjScreen )
			{
				delete m_sjScreen;
				m_sjScreen = NULL;
			}
		}

		m_pleaseUpdateAll = true;
		m_karaokeEnded = karaokeEnded;
	}

	// set the DC to use
	wxClientDC clientDcDontUse(this);
	wxDC* dc;
	if( m_pleaseUpdateAll )
	{
		dc = &m_offscreenDc;
	}
	else
	{
		dc = &clientDcDontUse;
	}

	/**********************************************************************
	 * DRAW!
	 **********************************************************************/

	// redraw background?
	if( m_pleaseUpdateAll )
	{
		m_karaokeModule->m_bg->DrawBackground(*dc);
	}

	// redraw karaoke?
	if( karaokeEnded )
	{
		if(  m_sjScreen
		        && !m_sjScreen->Render(*dc, *(m_karaokeModule->m_bg), m_pleaseUpdateAll)
		        && !m_karaokeMaster.HasKaraoke() )
		{
			delete m_sjScreen;
			m_sjScreen = NULL;
			if( !g_mainFrame->IsKioskStarted() /*no error messages in kiosk mode!*/
			        && !g_mainFrame->IsStopped() )
			{
				m_sjScreen = new SjSjScreen(_("No lyrics found."), wxT(""), 0);
			}
		}
	}
	else
	{
		m_karaokeMaster.Render(*dc, *(m_karaokeModule->m_bg), m_pleaseUpdateAll);
	}

	/**********************************************************************
	 * DRAWING DONE
	 **********************************************************************/

	// BLIT if we are drawing offscreen
	if( m_pleaseUpdateAll )
	{
		clientDcDontUse.Blit(0, 0, m_clientSize.x, m_clientSize.y, &m_offscreenDc, 0, 0);
	}

	// really done!
	m_pleaseUpdateAll = false;
	m_inPaint = false;
}