Sign in to follow this  
TechnoRobbo

TR's Halftone Plugin

Recommended Posts

TechnoRobbo's Halftone Plugin

 

This plugin was designed to simulate Halftone printing technique used in newspapers and magazine.

The plug in interprets color depth with a Dot or a Square. The larger the dot the more lights gets taken away from the background. 

 

The color option creates a pseudo CMYK Halftone Effect except the halftone screens aren't rotated.

 

Instructions not necessary - just play around

 

 

Menu: Effects->Stylize

 

HTMenu.PNG?raw=1

 

Purple Mila

PurpleMila.png?raw=1

 

Color Mila

ColorMila.png?raw=1

 

Eye See Dots

eyeCDots.png?raw=1

 

The Code

Hidden Content:

// Submenu: Stylize
// Name: TR's Half Tone
// Title: TR's Half Tone - v1.0
// Author: TechnoRobbo
 
#region UICode
int Amount1 = 4; // [2,16] Cell Size
bool Amount2 = false; // [0,1] Color Dither
byte Amount3 = 0; // [1] Dither Shape|Dots|Boxes
ColorBgra Amount4 = ColorBgra.FromBgr(0,0,0); // Two Tone Color
bool Amount5 = false; // [0,1] Use Background Color
ColorBgra Amount6 = ColorBgra.FromBgr(0,0,0); // Background Color
#endregion
 
void Render(Surface dst, Surface src, Rectangle rect)
{
    Rectangle sel = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
    float CellSize = Amount1;
    bool BW=!Amount2;
    int dither = Amount3;
    ColorBgra custom =Amount4;
    bool useBG=Amount5;
    ColorBgra BGColor = Amount6;
    
    //test variable
    //BW=false;
    dst.CopySurface( src,rect.Location,rect);
    //----------------------------------
    Graphics g = new RenderArgs(dst).Graphics;
    g.Clip =new Region(rect);
    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
    
    //BackGround-------------------------------
    System.Drawing.SolidBrush BBrush = new System.Drawing.SolidBrush(System.Drawing.Color.White);
    if (useBG){BBrush = new System.Drawing.SolidBrush(BGColor);}
    //--------------------------
    
    g.FillRectangle(BBrush , new Rectangle(sel.Top, sel.Left,sel.Width,sel.Height));
    BBrush.Dispose();
    g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
    //===========================================================================================
    
    
    ColorBgra CP;
    System.Drawing.SolidBrush CBrush = new System.Drawing.SolidBrush(custom);
    System.Drawing.SolidBrush NBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
    System.Drawing.SolidBrush RBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Cyan);
    System.Drawing.SolidBrush GBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Magenta);
    System.Drawing.SolidBrush BLBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Yellow);
    System.Drawing.SolidBrush TBrush = NBrush;
    float offset = 0;
    Rectangle Cell;
    
    
    int alt=0;
    for (float y = sel.Top; y < sel.Bottom; y += CellSize)
    {
        int altx=0;
        for (float x = sel.Left; x < sel.Right; x += CellSize)
        
        {
            CP = src.GetBilinearSampleClamped(x,y);
            if (BW){
                float v =(float)(CP.R + CP.G + CP.B)/3/255;
                offset = (1-v) * CellSize ;
                
                Cell = new Rectangle((int)( x + CellSize/2 - (alt % 2 ) * CellSize/2 - offset),
                    (int)(y + CellSize/2  - offset), (int)offset, (int)offset);
                
                TBrush=CBrush;
            }else{
                float halfcell=CellSize/2;
                float[] stagger={0,0,0,0,halfcell,halfcell,halfcell,halfcell,0,0,0,0,halfcell,halfcell,halfcell,halfcell};
                int[] cswitch={0,1,2,3, 2,3,0,1, 3,0,1,2, 2,3,0,1};
                int toggle=(alt % 4) * 4  + (altx % 4);
                
                switch(cswitch[toggle]){
                    
                    case 0:
                        float r =(float)CP.R/255;
                        offset = (1-r) * CellSize;
                        TBrush=RBrush;
                        break;
                    
                    case 1:
                        float gr =(float)CP.G/255;
                        offset = (1-gr) * CellSize ;
                        TBrush=GBrush;  
                        break;
                    
                    case 2:
                        float b =(float)CP.B/255;
                        offset = (1- B) * CellSize ;
                        TBrush=BLBrush;              
                        break;
                    case 3:
                        float k =(float)(CP.R + CP.G + CP.B)/3/255;
                        offset = (1-k) * CellSize ;
                        TBrush=NBrush;                
                        break;
                }
                Cell = new Rectangle((int)( x + CellSize/2 + stagger[toggle] - offset), (int)(y + CellSize/2 - offset), (int)offset, (int)offset);
 
            }
            if (dither==0){
                g.FillEllipse(TBrush,Cell);
            }else{
                g.FillRectangle(TBrush,Cell);
            }           
            altx++;
        }
        alt++;
    }
    NBrush.Dispose();
    RBrush.Dispose();
    GBrush.Dispose();
    BLBrush.Dispose();
    TBrush.Dispose();
    CBrush.Dispose();
}
 

 

TRsHalfTone.zip

Edited by TechnoRobbo
  • Upvote 2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this