Jump to content
How to Install Plugins ×

TR's Halftone Plugin


TechnoRobbo

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
  • Like 1
  • Upvote 2

Go out there and be amazing. Have Fun, TR
TRsSig.png?raw=1
Some Pretty Pictures Some Cool Plugins

Link to comment
Share on other sites

:MoveLayerUp: Happy to know I am not alone in thinking it moves  :evillaugh: Thank you Welshblue. :smile:

HFuQlot.png

 

 

 

Link to comment
Share on other sites

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