Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Look into this code of floodfill. Running out of memory.

Look into this code of floodfill. Running out of memory.

Scheduled Pinned Locked Moved C / C++ / MFC
helpdebuggingperformance
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    awasthy
    wrote on last edited by
    #1

    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.

    R S M 3 Replies Last reply
    0
    • A awasthy

      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.

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      Infinite (or extremely deep) recursion, perhaps? /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

      1 Reply Last reply
      0
      • A awasthy

        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.

        S Offline
        S Offline
        squidev
        wrote on last edited by
        #3

        Try not to create the CClientDC object at each recursive call, but once, then call this: void dlg::floodfill(CDC* pDC, int x, int y, int r , int g, int b) Hope this helps :)

        1 Reply Last reply
        0
        • A awasthy

          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.

          M Offline
          M Offline
          Mike Dimmick
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups