Jump to content

tkddude2

Newbies
  • Posts

    5
  • Joined

  • Last visited

Posts posted by tkddude2

  1. I am making a plugin on CodeLab, and I have been having quite a bit of trouble. I want to make a script that takes an input of something like "[10,10;20,20;0.5,0.25,0.9;1][50,60;10,10;0,0,0;1]" and creates a picture out of it. Heres how its suppose to work. 

    [posX, posY; sizeX, sizeY, R,B,G; ZIndex] (the ZIndex is not being used yet, because other problems are in the way first, but eventually I would like to have it so that tables with high ZIndex's overwrite the colors of tables with lower ZIndexs)

    I want it to paint all of the pixels in the area define by the size and position the RBG given. I have been having trouble debugging this because paint.net keeps on crashing whenever an error exists in the code(because it auto compiles every few seconds). It is VERY annoying. I have tested the string parsing on other programs and am confident that it works, but it still keeps on crashing. Eventually, I want to get rid of the line     String Amount1 = "[10,10;20,20;0.5,0.25,0.9;1][50,60;10,10;0,0,0;1]";   and allow an input from the User Interface Designer. Can anyone out there finish the script for me or point me toward a better plugin creator for Paint.net?

     

     

    Here is the code I have so far (and yes the UI code isnt in yet)

     

    // Name:
    // Submenu:
    // Author:
    // Title:
    // Version:
    // Desc:
    // Keywords:
    // URL:
    // Help:


    private byte Clamp2Byte(int iValue)
    {
        if (iValue<0) return 0;
        if (iValue>255) return 255;
        return (byte)iValue;
    }

    void Render(Surface dst, Surface src, Rectangle rect) 

        String Amount1 = "[10,10;20,20;0.5,0.25,0.9;1][50,60;10,10;0,0,0;1]";   
        int length = Amount1.Length;
        ColorBgra CurrentPixel; 
        double R, G, B;
        
         //--------------------------------------------------------------------------------------------------------------------   
        for (int y = rect.Top; y < rect.Bottom; y++)        //Replicate background before making changes
        {
            if (IsCancelRequested) return;
            for (int x = rect.Left; x < rect.Right; x++)
            {
                CurrentPixel = src[x,y];
                dst[x,y] = CurrentPixel;
            }
        }       
        
        //--------------------------------------------------------------------------------------------------------------------    
      
        while (length > 10) 
        {
            
           int startPos = Amount1.IndexOf("[");
           int endPos = Amount1.IndexOf("]");
           String newString = Amount1.Substring(startPos, endPos - startPos + 1);  //[-293,-280;585,559;1,1,1;1]
           Amount1 = Amount1.Substring(endPos, Amount1.Length - endPos);
           length = Amount1.Length;
           
           int posX = Int32.Parse(newString.Substring(1, newString.IndexOf(",") - 1)); //-293      
                newString = newString.Substring(newString.IndexOf(","), newString.Length - newString.IndexOf(",")); //,-280;585,559;1,1,1;1]            
           //Console.WriteLine(posX);
           //Console.WriteLine(newString);            
           int posY = Int32.Parse(newString.Substring(1, newString.IndexOf(";") - 1)); //-280
                newString = newString.Substring(newString.IndexOf(";"), newString.Length - newString.IndexOf(";")); //;585,559;1,1,1;1]             
           int sizeX = Int32.Parse(newString.Substring(1, newString.IndexOf(",") - 1)); //585
                newString = newString.Substring(newString.IndexOf(","), newString.Length - newString.IndexOf(",")); //,559;1,1,1;1]              
           int sizeY = Int32.Parse(newString.Substring(1, newString.IndexOf(";") - 1)); //559
                newString = newString.Substring(newString.IndexOf(";"), newString.Length - newString.IndexOf(";")); //;1,1,1;1] 
           R = Int32.Parse(newString.Substring(1, newString.IndexOf(",") - 1));         //1
                newString = newString.Substring(newString.IndexOf(","), newString.Length - newString.IndexOf(",")); //,1,1;1]
           G = Int32.Parse(newString.Substring(1, newString.IndexOf(",", 1) - 1));      //1 the extra one is to start the search after the first comma
                 newString = newString.Substring(newString.IndexOf(",", 1), newString.Length - newString.IndexOf(",", 1)); //,1;1]  
           B = Int32.Parse(newString.Substring(1, newString.IndexOf(";") - 1));         //1
                  newString = newString.Substring(newString.IndexOf(";"), newString.Length - newString.IndexOf(";")); //;1]            
           int ZIndex = Int32.Parse(newString.Substring(1, newString.IndexOf("]") - 1)); //1
           newString = "";           
     
     
            MessageBox.Show(
                 "R = " + R.ToString() + "; " +
                 "G = " + G.ToString() + "; " +
                 "B = " + B.ToString()
            );
           
           double A = 1;
           
           for(int y = posY; y < posY + sizeY; y++) 
            { 
                for (int x = posX; x < posX + sizeX; x++) 
                {
                 CurrentPixel = src[x,y]; 
                 int r = (int)Math.Round(R * 255);
                 int g = (int)Math.Round(G * 255);
                 int b = (int)Math.Round(B * 255);
                 int a = (int)Math.Round(A * 255); //opacity              
                 //
                 //// Reassemble the color from R, G, and B
                 //CurrentPixel = ColorBgra.FromBgra(Clamp2Byte(b),Clamp2Byte(g),Clamp2Byte(r),Clamp2Byte(a));
                 //dst[x,y] = CurrentPixel; 
                 //
                    ////MessageBox.Show(
                         ////"R = " + R.ToString() + "; " +
                         ////"G = " + G.ToString() + "; " +
                         ////"B = " + B.ToString() + "; " +
                         ////"X = " + x.ToString() + "; " +    
                         ////"Y = " + y.ToString()              
                    ////);
                 //
                }
            }
        }
    }

×
×
  • Create New...