Look into this code of floodfill. Running out of memory.
-
Please see this code here I am trying to fill all the pixels of a particular color with black. The figure is irregular so I can't use any of the known fill functions. The problem here is that the processing stops after some time. Probably runs out of memory(as shown by an error when the same code was run in VB). If anyone knows any fill function for an irregular object, or can debug this code suggest it. Any help woul be appriciated. void dlg::floodfill(int x, int y, int r , int g, int b)// x,y are pixel positions r,g,b are color components, pixels coloured with these have to be found and replaced { CClientDC dc(this); COLORREF rgb,rgb1; rgb=dc.GetPixel(x,y); BYTE r1,g1,b1; r1=GetRValue(rgb); g1=GetGValue(rgb); b1=GetBValue(rgb); if((r1r-20)) if((g1g-20)) if((b1b-20)) { rgb=RGB(0,0,0); rgb1=dc.SetPixel(x,y,rgb); floodfill(x-1,y-1,r,g,b); floodfill(x,y-1,r,g,b); floodfill(x+1,y-1,r,g,b); floodfill(x-1,y,r,g,b); floodfill(x+1,y,r,g,b); floodfill(x-1,y+1,r,g,b); floodfill(x,y+1,r,g,b); floodfill(x+1,y+1,r,g,b); } } Awasthy Any work worth doing is worth doing well.
-
Please see this code here I am trying to fill all the pixels of a particular color with black. The figure is irregular so I can't use any of the known fill functions. The problem here is that the processing stops after some time. Probably runs out of memory(as shown by an error when the same code was run in VB). If anyone knows any fill function for an irregular object, or can debug this code suggest it. Any help woul be appriciated. void dlg::floodfill(int x, int y, int r , int g, int b)// x,y are pixel positions r,g,b are color components, pixels coloured with these have to be found and replaced { CClientDC dc(this); COLORREF rgb,rgb1; rgb=dc.GetPixel(x,y); BYTE r1,g1,b1; r1=GetRValue(rgb); g1=GetGValue(rgb); b1=GetBValue(rgb); if((r1r-20)) if((g1g-20)) if((b1b-20)) { rgb=RGB(0,0,0); rgb1=dc.SetPixel(x,y,rgb); floodfill(x-1,y-1,r,g,b); floodfill(x,y-1,r,g,b); floodfill(x+1,y-1,r,g,b); floodfill(x-1,y,r,g,b); floodfill(x+1,y,r,g,b); floodfill(x-1,y+1,r,g,b); floodfill(x,y+1,r,g,b); floodfill(x+1,y+1,r,g,b); } } Awasthy Any work worth doing is worth doing well.
Infinite (or extremely deep) recursion, perhaps? /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com
-
Please see this code here I am trying to fill all the pixels of a particular color with black. The figure is irregular so I can't use any of the known fill functions. The problem here is that the processing stops after some time. Probably runs out of memory(as shown by an error when the same code was run in VB). If anyone knows any fill function for an irregular object, or can debug this code suggest it. Any help woul be appriciated. void dlg::floodfill(int x, int y, int r , int g, int b)// x,y are pixel positions r,g,b are color components, pixels coloured with these have to be found and replaced { CClientDC dc(this); COLORREF rgb,rgb1; rgb=dc.GetPixel(x,y); BYTE r1,g1,b1; r1=GetRValue(rgb); g1=GetGValue(rgb); b1=GetBValue(rgb); if((r1r-20)) if((g1g-20)) if((b1b-20)) { rgb=RGB(0,0,0); rgb1=dc.SetPixel(x,y,rgb); floodfill(x-1,y-1,r,g,b); floodfill(x,y-1,r,g,b); floodfill(x+1,y-1,r,g,b); floodfill(x-1,y,r,g,b); floodfill(x+1,y,r,g,b); floodfill(x-1,y+1,r,g,b); floodfill(x,y+1,r,g,b); floodfill(x+1,y+1,r,g,b); } } Awasthy Any work worth doing is worth doing well.
-
Please see this code here I am trying to fill all the pixels of a particular color with black. The figure is irregular so I can't use any of the known fill functions. The problem here is that the processing stops after some time. Probably runs out of memory(as shown by an error when the same code was run in VB). If anyone knows any fill function for an irregular object, or can debug this code suggest it. Any help woul be appriciated. void dlg::floodfill(int x, int y, int r , int g, int b)// x,y are pixel positions r,g,b are color components, pixels coloured with these have to be found and replaced { CClientDC dc(this); COLORREF rgb,rgb1; rgb=dc.GetPixel(x,y); BYTE r1,g1,b1; r1=GetRValue(rgb); g1=GetGValue(rgb); b1=GetBValue(rgb); if((r1r-20)) if((g1g-20)) if((b1b-20)) { rgb=RGB(0,0,0); rgb1=dc.SetPixel(x,y,rgb); floodfill(x-1,y-1,r,g,b); floodfill(x,y-1,r,g,b); floodfill(x+1,y-1,r,g,b); floodfill(x-1,y,r,g,b); floodfill(x+1,y,r,g,b); floodfill(x-1,y+1,r,g,b); floodfill(x,y+1,r,g,b); floodfill(x+1,y+1,r,g,b); } } Awasthy Any work worth doing is worth doing well.
For any non-trivial area of the screen, you're likely to run out of stack space. You're also going to end up treating each pixel repeatedly. See this article[^] for a good fill algorithm (judging by the ranking in Google's search results and the CP article rating of 4.71). Stability. What an interesting concept. -- Chris Maunder