In addition to that, I like to be the grammar police some times... One of my grand pet peeves is someone using contractions in speech out of place. You realize that "Pixel's" is the contraction of "Pixel" and "is", yes? ....Well, no one's perfect...but that sort of grammar error kind of irritates me. Maybe I just gave you a helpful grammar lesson that you can take with you in life: Unless it's showing posession (The pixel's color) or is a contraction (The pixel's eating cheese), don't use an apostrophe.
This has been a friendly grammar lesson from Dean.
You can't be serious. Maybe you've been smoking too much of your user name. This is not a grammar board nor an english board. Get over it and keep your comments relative to um...well...C++ programming.
As for the question. I'm assuming you have a COLORREF pointer to the buffer that has the color information in it.
Code:
struct PixelInformation
{
COLORREF Color;
CPoint Position;
PixelInformation *Next;
PixelInformation *Prev;
PixelInformation(void):Color(0),Position(CPoint(0,0)),Next(NULL),Prev(NULL) {}
};
void FindPixelsWithColor(COLORREF ColorToSearchFor,COLORREF *Buffer,int BufferWidth,DWORD BufferSize,PixelInformation &Root)
{
DWORD offset=0;
DWORD color=0;
int x=0,y=0;
DWORD MatchingPixels=0;
DWORD PixelColor=0;
PixelInformation *CurPixel;
for (offset=0;offset<BufferSize;i++)
{
PixelColor=Buffer[offset];
if (PixelColor==ColorToSearchFor)
{
if (MatchingPixels==0)
{
Root.Color=PixelColor;
Root.Position.x=x;
Root.Position.y=y;
Root.Position.Prev=NULL;
Root.Next=NULL;
*CurPixel=Root;
MatchingPixels++;
}
else
{
PixelInformation *pixel=new PixelInformation;
CurPixel->Next=pixel;
pixel->Prev=CurPixel;
pixel->Next=NULL;
pixel->Color=PixelColor;
pixel->Position.x=x;
pixel->Position.y=y;
CurPixel=pixel;
MatchingPixels++;
}
x++;
if (x>BufferWidth)
{
x=0;
y++;
}
}
}
}
If this doesn't compile check the pointer usage. I did not test it so I'm not sure I'm using them correctly. This will assemble a double linked list of pixels that match the given color. Each pixel is linked to the previous and next in the list. I would have to compile it and see what happened in order to get it perfect.
But this should work.