Jump to content

Illnab1024

Members
  • Posts

    1,178
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by Illnab1024

  1. bool [,] surfaceIndex = null;
    int div = 40000;
    int treshold = 200;
    int distanceX = 5;
    int distanceY = 5;
    
    int color_element;
    bool applyFilter = true; // if (false) { tresholding_only(); }
    unsafe void Render(Surface dst, Surface src, Rectangle rect)
    {
       surfaceIndex = new bool[rect.Right,rect.Bottom];
    
     for (int y = rect.Top; y < rect.Bottom; ++y)
     {
         for (int x = rect.Left; x < rect.Right; ++x)
         {
             ColorBgra color = src[x, y];
             // RGB to grayscale
             color_element = (byte)((double)color.R * 0.299 + (double)color.G * 0.587 + (double)color.B * 0.114);
             if (!applyFilter) // tresholding only
             {
                 dst[x, y] = (color_element > treshold)
                     ? ColorBgra.FromBgra(255, 255, 255, 255)
                     : ColorBgra.FromBgra(0, 0, 0, 255);
             }
             else // if applyFilter
             {
                // clear destination image
                dst[x, y] = ColorBgra.FromBgra(255,255,255, 255);
                // store position matrix
                surfaceIndex[x, y] = ((x % distanceX == 0) && (y % distanceY == 0) && (color_element < treshold));
             } // endof if applyFilter
    
         } // foreach(x)
     } // foreach(y)
    
     if (applyFilter) {
    
           // second pass    
    
       for (int y = rect.Top; y < rect.Bottom; ++y)
       {
         for (int x = rect.Left; x < rect.Right; ++x)
         {
               if (surfaceIndex[x,y]) {
                   // draw square 4x4 pixel 
                   for (int i = 0; i < 4; i++) {
                     for (int j = 0; j < 4; j++) {
                       dst[x + i,y + j] = ColorBgra.FromBgra(128, 0, 0, 255);
                     }
                   }
                   // graphics.DrawString()
               }
         } // foreach(x)
       } // foreach(y)
     } // if applyFilter
    }
    

    Laziness rules, BoltBait.

  2. Okay, I got it. You weren't thinking in the right direction :D

    int Amount1=0;   //[0,100]Slider 1 Description
    int Amount2=0;   //[0,100]Slider 2 Description
    int Amount3=0;   //[0,100]Slider 3 Description
    
    void Render(Surface dst, Surface src, Rectangle rect)
    {
       Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
       float width = dst.Bounds.Right - dst.Bounds.Left;
       long CenterX = (long)(((selection.Right - selection.Left) / 2)+selection.Left);
       long CenterY = (long)(((selection.Bottom - selection.Top) / 2)+selection.Top);
       float r, theta, offx, offy, setx, sety;
       for(int y = rect.Top; y < rect.Bottom; y++)
       {
           for (int x = rect.Left; x < rect.Right; x++)
           {
               r = y/2;
               theta = (float)((System.Math.PI*2)*(x/width));
               offx = (float)(r*System.Math.Cos(theta));
               offy = (float)(r*System.Math.Sin(theta));
               setx = (float)(CenterX+offx);
               sety = (float)(CenterY-offy);
               dst[x,y] = src.GetBilinearSample(setx, sety);
           }
       }
    }
    

    It's actually rather simple.

×
×
  • Create New...