Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Painting the array to a window takes too long

Status
Not open for further replies.

Old Nick

Advanced Member level 1
Joined
Sep 14, 2007
Messages
479
Helped
68
Reputation
136
Reaction score
18
Trophy points
1,298
Activity points
4,243
Hi,

I've written some code to display the output from a 64x64 camera array we've designed, the problem I'm having is that painting the array to a window takes too long (around a second or so!)

I'm using a function containing

Code:
hPenArray=CreatePen(PS_SOLID,0,RGB(g_RGB,0,0));
	hPenOld = SelectObject(hdc, hPenArray);
	lb.lbColor=RGB(g_RGB,0,0);
	lb.lbStyle = BS_SOLID;
	hBrush = CreateBrushIndirect(&lb);
	hBrushOld = SelectObject(hdc, hBrush);
	for (y=0;y<64;y++)
	{
		for (x=0;x<64;x++)
		Rectangle(hdc, g_X*150, (g_Y+1)*150, (g_X+1)*150, g_Y*150);
.
.
.

where g_RGB is the voltage output og the individual pixels.
This function is called after every pixel read and the window updated.

the painting is done in
Code:
void Cls_OnPaint(HWND hwnd)
{
        PAINTSTRUCT             ps;
		RECT					rectCl;

        BeginPaint(hwnd, &ps);
		SetMapMode(ps.hdc, MM_HIMETRIC);
		GetClientRect(hwnd, &rectCl);
		SetViewportOrgEx(ps.hdc, 0, rectCl.bottom, NULL);
		SetWindowOrgEx(ps.hdc, -500, -500, NULL);

		TextOut(ps.hdc, 0, 15000, g_pathName, strlen(g_pathName));
		TextOut(ps.hdc, 0, 14000, g_fileName, strlen(g_fileName));
		drawArray (hwnd, ps.hdc);
		drawGraph (hwnd, ps.hdc);

        EndPaint(hwnd, &ps);
}

this code is in Cls_OnCommand

Code:
for (row=0;row<64;row++)
				{
			//		cbDOut(boardNum,PortNumB,row); //send row address to camera
					
					for (col=0;col<64;col++)
					{
			//			UDStat = cbDOut(boardNum, PortNumA, col); //send column address to camera
						captureData(Chan0, &(DataArrayA[row][col]), photoNumber, row, col);
						captureData(Chan0, &(DataArrayB[row][col]), photoNumber, row, col);
						captureData(Chan0, &(DataArrayC[row][col]), photoNumber, row, col);
						captureData(Chan0, &(DataArrayD[row][col]), photoNumber, row, col);
						g_X=col;
						g_Y=row;
						InvalidateRect(hwnd, NULL, FALSE);
						UpdateWindow(hwnd);
					
						
					}

g_RGB is calculated elsewhere.

I've tried writing all the values to an array/buffer, then repainting the window after a complete frame grab (using a loop). Is there another way to display this 64x64 array to the screen which will be faster, or am I just stuck with this? I was hoping for 10 frames per sec, which I'm nowhere near.
I'm not a C expert, and am using prettymuch straight C to write this.
 

Re: Painting Windows

I've managed to rearrange my code, and re-introduce the buffer and I am now getting a reasonable speed of repaint.

However the drawing of the array flickers, I have used the following code to repaint the window,

Code:
InvalidateRect(hwnd, NULL, FALSE);
UpdateWindow(hwnd);

the FALSE, meaning that the background is not repainted which reduces the flicker a lot, but the array still flickers badly:cry:.

Anyone have any ideas how to remedy this? Or is this just unavoidable without using some more advanced graphics libraries?

Cheers,

Nick
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top