Jump to content

B/G screen remover NEEDS coding help!


Bleek II

Recommended Posts

Help, help... I have an issue with my code that I just can't figure out. I made my own code for AA and color fixing edges but I've found that in many cases it doesn't fix the area that it should. Instead it just drifts off target as the user increases the size of the loops used to detect and fix edges. It's harder to notice for the AA because the loops are much smaller but for the color fixing it's a bit issue. It feel like a 1off error some where in the code but I can't find it.

Here is a shot of the issue in action. (note: the code can remove green screen but was set to low sensitivity to make the error easy to see.)

Untitled.gif

#region UICode
int Amount1 = 2; // [1,2] blue/green
int Amount2 = 90; // [0,100] remove power (less is more)
int Amount3 = 3; // [0,6] edge alpha range
int Amount4 = 40; // [0,80] alpha power
int Amount5 = 40; // [0,40] edge color fix range

#endregion

void Render(Surface dst, Surface src, Rectangle rect)
{
   int x1;
   int y1;
   int x2;
   int y2;
   int cl;
   int cl2;
   int dif1;
   int dif2;
   int dif3;
   int dif4;
   byte set=255;
   ColorBgra CP2;
   ColorBgra CP;
   for (int y = rect.Top; y < rect.Bottom; y++)
   {

       for (int x = rect.Left; x < rect.Right; x++)
       {   
           dif2 = 0;
           cl=0;
           CP = src[x,y];
           if(Amount1 == 2)
           {
               dif1 = CP.G - ((CP.R + CP.B)/2);
               if(CP.G > CP.R)dif2++;
               if(CP.G > CP.B)dif2++;
           }
           else
           {
               dif1 = CP.B - ((CP.R + CP.G)/2);
               if(CP.B > CP.R)dif2++;
               if(CP.B > CP.G)dif2++;
           }

           if(dif1 > Amount2 && dif2 == 2)
           {
               set = 0;
           }
           else
           {
               set = 255;
           }
           CP.A = set;
           //!!!!!!!!!!!!!!!!!!!!!!!
           //edge stuff
           //!!!!!!!!!!!!!!!!!!!!!!!!!!!!
           if (set == 255)
           {
           //!!!!!!!!!!!!!!!!!!!!!!!!!
           //edge alpha
           //!!!!!!!!!!!!!!!!!!!!!!!!!!
           x1 = x - Amount3;
           if(x1 < 0)
           {
               x1 = 0;
           }
           x2 = x + Amount3;
           if(x2 > rect.Right)
           {
               x2 = rect.Right;
           }

           y1 = y - Amount3;
           if(y1 < 0)
           {
               y1 = 0;
           }  
           y2 = y + Amount3;
           if(y2 > rect.Bottom)
           {
               y2 = rect.Bottom;
           }                
           while (y1 < y2)
           {
               while ( x1 < x2)
               {
                   CP2 = src[x1,y1];
                   dif4 = 0;
                   if(Amount1 == 2)
                   {
                       dif3 = CP2.G - ((CP2.R + CP2.B)/2);
                       if(CP2.G > CP2.R)dif4++;
                       if(CP2.G > CP2.B)dif4++;
                   }
                   else
                   {
                       dif3 = CP2.B - ((CP2.R + CP2.G)/2);
                       if(CP2.B > CP2.R)dif4++;
                       if(CP2.B > CP2.G)dif4++;
                   }

                   if(dif3 > Amount2 & dif4 == 2)
                   {
                       cl++;
                   }
                       x1++;
               }
               y1++;
           }
               if(cl > 0)
               {
                   cl2 = 255 - (cl*Amount4) -dif1 + (dif2*20);
                   if(dif1<10)cl2 =255;

                   if(cl2 >255)cl2 = 255;
                   if(cl2<0)cl2=0;
                   CP.A = (byte)cl2;
               } 
           //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
           //color fixing    
           //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
           x1 = x - Amount5;
           if(x1 < 0)
           {
               x1 = 0;
           }
           x2 = x + Amount5;
           if(x2 > rect.Right)
           {
               x2 = rect.Right;
           }

           y1 = y - Amount5;
           if(y1 < 0)
           {
               y1 = 0;
           }  
           y2 = y + Amount5;
           if(y2 > rect.Bottom)
           {
               y2 = rect.Bottom;
           }                
           while (y1 < y2)
           {
               while ( x1 < x2)
               {
                   CP2 = src[x1,y1];
                   dif4 = 0;
                   if(Amount1 == 2)
                   {
                       dif3 = CP2.G - ((CP2.R + CP2.B)/2);
                       if(CP2.G > CP2.R)dif4++;
                       if(CP2.G > CP2.B)dif4++;
                   }
                   else
                   {
                       dif3 = CP2.B - ((CP2.R + CP2.G)/2);
                       if(CP2.B > CP2.R)dif4++;
                       if(CP2.B > CP2.G)dif4++;
                   }

                   if(dif3 > Amount2 & dif4 == 2)
                   {
                       cl++;
                   }
                       x1++;
               }
               y1++;
           }
               if(cl > 0)
               {

                   if(dif1>10 && Amount1 == 1)CP.B = (byte)(CP.B - dif1/2);                    

                   if(dif1>15 && Amount1 == 2)
                   {
                       CP.G = (byte)(CP.G - dif1);
                       if(CP.R > dif1/2.4)CP.R = (byte)(CP.R - dif1/2.4);
                   }
               }
           }



           dst[x,y] = CP;
       }
   }
}

Link to comment
Share on other sites

I didn't go through the all code.

But I think rect is at any time a small part of the image and not the full image itself.

I mean you should at some point considere the src instead the rect.

Ex:

...
if(x2 > rect.Right)
{
 x2 = rect.Right;
}
...
if(y2 > rect.Bottom)
{
 y2 = rect.Bottom;
}                
...

Link to comment
Share on other sites

Thanks MadJik! You're always rescuing me from my own programing monsters. I put in src instead of rect but I got this error.

'PaintDotNet.Surface' does not contain a definition for 'Right'

I don't think that part of the code is an issue anyway. I can hard code it for that image using 799 and 599 instead of rect.Right and rect.Bottom and I still get the same issue. Though you may be on the right track because I have no idea what is wrong with it. Thanks MadJik!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...