GetRValue returns 255 every time

First to start off I understand this has been asked repeatedly:
http://answers.yahoo.com/question/index?qid=20111015170327AA8vHmY
http://cboard.cprogramming.com/windows-programming/13153-getrvalue.html
http://www.tek-tips.com/viewthread.cfm?qid=1431078
ect...

I also found this website that gives a nice tutorial on it:
http://www.ucancode.net/faq/COLORREF.htm

Here is my code:
Attempt 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
void convertToArray(void) {
	SelectObject(hdcMem, curFrame);
	for (int x = 0; x < 640; x+=traq) {
		for (int y = 0; y < 480; y+=traq) {
			cur[x][y] = GetPixel(hdcMem,x,y);
		}
	}
	int temp = cur[10][10].r;
	SelectObject(hdcMem, lasFrame);
	for (int x = 0; x < 640; x+=traq) {
		for (int y = 0; y < 480; y+=traq) {
			las[x][y] = GetPixel(hdcMem,x,y);
		}
	}
	SelectObject(hdcMem, bakFrame);
	for (int x = traq; x < 640; x+=traq) {
		for (int y = traq; y < 480; y+=traq) {
			DWORD Color;
			DWORD curColor = cur[x][y];
			DWORD lasColor = las[x][y];
			int temp1 = curColor;
			int val1 = (GetRValue(curColor)+GetGValue(curColor)+GetBValue(curColor))/3;
			int val2 = (GetRValue(lasColor)+GetGValue(lasColor)+GetBValue(lasColor))/3;
			if (val1 > val2-20 & val1 < val2+20) {
				Color = RGB(0,255,0);
			} else {
				Color = RGB(255,0,0);
			}
			SetPixel(hdcMem,x,y,Color);
		}
	}
}

Attempt 2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
BYTE* ScreenData = new BYTE[921600];
BITMAPINFO bmi;
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biWidth = 640;
bmi.bmiHeader.biHeight = -480;
bmi.bmiHeader.biCompression = BI_RGB;
    
int traq = 10;
class vec {
public:
	int r,g,b,x;
};
vec cur[640][480];
vec las[640][480];
vec bak[640][480];
//Motion tracking functions
void convertToArray(void) {
	SelectObject(hdcMem, curFrame);
	GetDIBits(hdcMem, curFrame, 0, 480, ScreenData, &bmi, DIB_RGB_COLORS);
	//SelectObject(hdcMem, curFrame);
	for (int x = 0; x < 640; x+=traq) {
		for (int y = 0; y < 480; y+=traq) {
			cur[x][y].r = ScreenData[3*((y*640)+x)+2];
			cur[x][y].g = ScreenData[3*((y*640)+x)+1];
			cur[x][y].b = ScreenData[3*((y*640)+x)];
		}
	}
	int temp = cur[10][10].r;
}


In Attempt 1 the value I get from GetRValue, GetGValue, and GetBValue always return 255. When I was researching the problem I came accross this forum post:
http://www.tek-tips.com/viewthread.cfm?qid=1431078
Which sounded exactly like my problem however I do not understand his message of "I'm an idiot. Turns out I was using a hardcoded value of GetPixel instead of the dynamic parameter.".
I understand that GetRValue returns a BYTE, but even that didn't seem to change from a value of (255 'Y').

In Attempt 2 I get the error:
1>main.cpp(26): error C2143: syntax error : missing ';' before '.'
which is refering to these lines:
1
2
3
4
5
6
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biWidth = 640;
bmi.bmiHeader.biHeight = -480;
bmi.bmiHeader.biCompression = BI_RGB;


Thanks in advance.
Got it to work, I needed to declare
1
2
3
4
5
6
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biWidth = 640;
bmi.bmiHeader.biHeight = -480;
bmi.bmiHeader.biCompression = BI_RGB;

Inside a function, I was doing it globally.
Topic archived. No new replies allowed.