Jump to content

Layer Making Via CodeLab?


Recommended Posts

Hey People,

 

I have question, how would I make the following script copy the rectangle and put it on "named layer"? Basically copying the 6 rectangles and putting them onto a new layer which I need to be automatically created. All 6 rectangles should be copied onto a new layer (all on same layer).
 

void Render(Surface dst, Surface src, Rectangle rect)
{
    //torso
    Rectangle fromRect = Rectangle.FromLTRB(231, 74, 359, 202);
    Rectangle toRect1 = Rectangle.FromLTRB(229, 125, 357, 353);

    //left arm
    Rectangle fromRect2 = Rectangle.FromLTRB(308, 355, 372, 483);
    Rectangle toRect2 = Rectangle.FromLTRB(357, 125, 421, 253);

    //right arm
    Rectangle fromRect3 = Rectangle.FromLTRB(217, 355, 281, 483);
    Rectangle toRect3 = Rectangle.FromLTRB(165, 125, 229, 253);

    //back
    Rectangle fromRect4 = Rectangle.FromLTRB(427, 74, 555, 202);
    Rectangle toRect4 = Rectangle.FromLTRB(229, 305, 357, 433);

    //back left arm
    Rectangle fromRect5 = Rectangle.FromLTRB(85, 355, 149, 483);
    Rectangle toRect5 = Rectangle.FromLTRB(357, 305, 421, 433);

    //back right arm
    Rectangle fromRect6 = Rectangle.FromLTRB(440, 355, 504, 483);
    Rectangle toRect6 = Rectangle.FromLTRB(165, 305, 229, 433);


    ColorBgra CurrentPixel;
    for (int y = rect.Top; y < rect.Bottom; y++)
    {
        if (IsCancelRequested) return;
        for (int x = rect.Left; x < rect.Right; x++)
        {
            CurrentPixel = src[x,y];

            if (toRect1.Contains(x, y))

            {
                int offSetX = x - toRect1.Left + fromRect.Left;
                int offSetY = y - toRect1.Top + fromRect.Top;
                CurrentPixel = src[offSetX, offSetY];
            }
            if (toRect2.Contains(x, y))
            {
                int offSetX = fromRect2.Right - toRect2.Right + x;
                int offSetY = y - toRect2.Top + fromRect2.Top;
                CurrentPixel = src[offSetX, offSetY];
            }
             if (toRect3.Contains(x, y))
            {
                int offSetX = fromRect3.Right - toRect3.Right + x;
                int offSetY = y - toRect3.Top + fromRect3.Top;
                CurrentPixel = src[offSetX, offSetY];
            }
             if (toRect4.Contains(x, y))
            {
                int offSetX = fromRect4.Right - toRect4.Right + x;
                int offSetY = y - toRect4.Top + fromRect4.Top;
                CurrentPixel = src[offSetX, offSetY];
            }
            if (toRect5.Contains(x, y))
            {
                int offSetX = fromRect5.Right - toRect5.Right + x;
                int offSetY = y - toRect5.Top + fromRect5.Top;
                CurrentPixel = src[offSetX, offSetY];
            }
            if (toRect6.Contains(x, y))
            {
                int offSetX = fromRect6.Right - toRect6.Right + x;
                int offSetY = y - toRect6.Top + fromRect6.Top;
                CurrentPixel = src[offSetX, offSetY];
                }
            
            dst[x,y] = CurrentPixel;
        }
    }
}

 

Edited by RefreshedMango
Link to comment
Share on other sites

^ ...so a new layer isn't going to be possible.

 

You could create a new blank layer prior to running your plugin and have it write to that. Would that work for you?

 

Oh and a big WELCOME to the paint.net fourm RefreshedMango :)

Link to comment
Share on other sites

Two options

1) What @Ego Eram Reputo said.

2) ImageMagick/G'MIC-QT (This can work with multiple layer).

 

In addition to what @Ego Eram Reputo said, I think individual colors could be used to get around the needs of multiple layers. If 1 and this workaround isn't viable, then I can help. It doesn't look hard to replicate. In C# and PDN, multiple for loop is the solution for multiple color workaround.

 

Also, this seems like roblox template.

Edited by Reptillian

G'MIC Filter Developer

Link to comment
Share on other sites

EDIT: oh I see - you want to copy bits to another location.

 

Try this on a duplicate of the source layer

void Render(Surface dst, Surface src, Rectangle rect)
{
    //torso
    Rectangle fromRect = Rectangle.FromLTRB(231, 74, 359, 202);
    Rectangle toRect1 = Rectangle.FromLTRB(229, 125, 357, 353);

    //left arm
    Rectangle fromRect2 = Rectangle.FromLTRB(308, 355, 372, 483);
    Rectangle toRect2 = Rectangle.FromLTRB(357, 125, 421, 253);

    //right arm
    Rectangle fromRect3 = Rectangle.FromLTRB(217, 355, 281, 483);
    Rectangle toRect3 = Rectangle.FromLTRB(165, 125, 229, 253);

    //back
    Rectangle fromRect4 = Rectangle.FromLTRB(427, 74, 555, 202);
    Rectangle toRect4 = Rectangle.FromLTRB(229, 305, 357, 433);

    //back left arm
    Rectangle fromRect5 = Rectangle.FromLTRB(85, 355, 149, 483);
    Rectangle toRect5 = Rectangle.FromLTRB(357, 305, 421, 433);

    //back right arm
    Rectangle fromRect6 = Rectangle.FromLTRB(440, 355, 504, 483);
    Rectangle toRect6 = Rectangle.FromLTRB(165, 305, 229, 433);


    ColorBgra CurrentPixel;
    for (int y = rect.Top; y < rect.Bottom; y++)
    {
        if (IsCancelRequested) return;
        for (int x = rect.Left; x < rect.Right; x++)
        {
            CurrentPixel = ColorBgra.Transparent;

            if (toRect1.Contains(x, y))
            {
                int offSetX = x - toRect1.Left + fromRect.Left;
                int offSetY = y - toRect1.Top + fromRect.Top;
                CurrentPixel = src[offSetX, offSetY];
            }
            if (toRect2.Contains(x, y))
            {
                int offSetX = fromRect2.Right - toRect2.Right + x;
                int offSetY = y - toRect2.Top + fromRect2.Top;
                CurrentPixel = src[offSetX, offSetY];
            }
             if (toRect3.Contains(x, y))
            {
                int offSetX = fromRect3.Right - toRect3.Right + x;
                int offSetY = y - toRect3.Top + fromRect3.Top;
                CurrentPixel = src[offSetX, offSetY];
            }
             if (toRect4.Contains(x, y))
            {
                int offSetX = fromRect4.Right - toRect4.Right + x;
                int offSetY = y - toRect4.Top + fromRect4.Top;
                CurrentPixel = src[offSetX, offSetY];
            }
            if (toRect5.Contains(x, y))
            {
                int offSetX = fromRect5.Right - toRect5.Right + x;
                int offSetY = y - toRect5.Top + fromRect5.Top;
                CurrentPixel = src[offSetX, offSetY];
            }
            if (toRect6.Contains(x, y))
            {
                int offSetX = fromRect6.Right - toRect6.Right + x;
                int offSetY = y - toRect6.Top + fromRect6.Top;
                CurrentPixel = src[offSetX, offSetY];
                }
                dst[x,y] = CurrentPixel;
        }
    }
}

 

  • Upvote 1
Link to comment
Share on other sites

Thank you,

 

Thank you for the warm welcome @Ego Eram Reputo and thank you for the help however I have two more questions I'm hoping you could answer.

How would insert an image using code, and what file would I put it in?
How would make the image start from lets say "Top Left Point (0,0)"?
How would I cut out a rectangle so it is transparent (no background)?
How would I make a rectangle with 1 thickness and start from (0,0 top left) to (0,0 bottom right)?

I have looked everywhere and I cant find an answer. I am using c# language and codelab.

Your help will be very much appreciated.

Link to comment
Share on other sites

  • toe_head2001 changed the title to Layer Making Via CodeLab?

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...