Jump to content

ownage

Members
  • Posts

    13
  • Joined

  • Last visited

Posts posted by ownage

  1. afterwf0.jpgafterwm6.jpg

     

    Download

     

    Just unzip this file and save the dll file in your /Program Files/Paint.NET/Effects folder.

     

     

    Code Lab Code

    Spoiler
    
    // filter kernel
    
    const int size = 5; // odd number
    
    
    //play around with the matrix for interesting effects.
    
    int[,] conv = new int[size, size]
    {
        {-1,  -1,  -1,  -1, -1},
        {-1,  -1,  -1,  -1, -1},
        {-1,  -1,  30,  -1, -1},
        {-1,  -1,  -1,  -1, -1},
        {-1,  -1,  -5,  -1, -1},
    };
    
    unsafe void Render(Surface dst, Surface src, Rectangle rect)
    {
        int radius = (size-1)/2;
        for(int y = rect.Top; y < rect.Bottom; y++)
        {
            int top = y - radius, bottom = y + radius;
            if (top < 0) top = 0;
            if (bottom >= dst.Height) bottom = dst.Height - 1;
            for (int x = rect.Left; x < rect.Right; x++)
            {
                int left = x - radius, right = x + radius;
                int c = 0, s = 0, r = 0, g = 0, b = 0;
                if (left < 0) left = 0;
                if (right >= dst.Width) right = dst.Width - 1;
                for (int v = top; v <= bottom; v++)
                {
                    ColorBgra *pRow = src.GetRowAddressUnchecked(v);
                    int j = v - y + radius;
    
                    for (int u = left; u <= right; u++)
                    {
                        int i = u - x + radius;
                        int w = conv[i, j];
                        ColorBgra *pRef = pRow + u;
                        r += pRef->R * w;
                        g += pRef->G * w;
                        b += pRef->B * w;
                        s += w;
                        c++;
                    }
                }
                dst[x, y] = ColorBgra.FromBgr(
                    Int32Util.ClampToByte(b),
                    Int32Util.ClampToByte(g),
                    Int32Util.ClampToByte(r));
            }
        }
    }

     

     
     
×
×
  • Create New...