Jump to content

new version of 'Contour' plugin


Red ochre

Recommended Posts

Hello all, I've attached the dll of the re-written contour plugin. The code should be below.

/* =================================================== */
/* 	*/
/* Contour.cs 	*/
/* (c) 2011 John Robbins (Red Ochre) 	*/
/* 	*/
/* Description: creates contours based on an images luminosity 	*/
/* 	*/
/* ========================================== ======== */

// Name: Contour
// Author: Red Ochre (John Robbins)
// Submenu: Stylize
// URL: http://www.getpaint.net/redirect/plugins.html
// Title: Contour - 2011 Red Ochre


#region UICode
int Amount1 = 25;	//[0,100]smoothness (blur radius)
int Amount2 = 5;	//[1,50]number of contours n
double Amount3 = 0.5;	//[0.01,1.00]contour/gap ratio
ColorBgra Amount4 = ColorBgra.FromBgr(250,250,25);	//contour colour
byte Amount5 = 0;	//contour properties|rainbow|background|transparent|solid colour|shaded across contour|shaded along contour|shade both ways|both ways from source(speckled)
ColorBgra Amount6 = ColorBgra.FromBgr(25,25,250);	//gap colour
byte Amount7 = 7;	//gap properties|background|transparent|solid colour|shaded across gap|shaded along gap|shade both ways|both ways from source(speckled)|rainbow
#endregion

void Render(Surface dst, Surface src, Rectangle rect)
{
// Call the Gaussian Blur effect
GaussianBlurEffect blurEffect = new GaussianBlurEffect();
PropertyCollection bProps = blurEffect.CreatePropertyCollection();
PropertyBasedEffectConfigToken bParameters = new PropertyBasedEffectConfigToken(bProps);
bParameters.SetPropertyValue(GaussianBlurEffect.PropertyNames.Radius, Amount1);
blurEffect.SetRenderInfo(bParameters, new RenderArgs(dst), new RenderArgs(src));
blurEffect.Render(new Rectangle[1] {rect},0,1);
ColorBgra CurrentPixel;

int B, G, R, A, tc, tg;
double rad = Math.PI * 2;

for(int y = rect.Top; y < rect.Bottom; y++) 
	{ for (int x = rect.Left; x < rect.Right; x++) 
	{ CurrentPixel = dst[x,y]; 
	B = (int)CurrentPixel.B;
	G = (int)CurrentPixel.G;
	R = (int)CurrentPixel.R;
	A = (int)CurrentPixel.A;
	int n = Amount2;	// n = number of contours from slider
	int bothw = 765/n;	// cw + gw	(cw = contour width, gw = gap width)
	int cw = (int)(bothw * Amount3);	// contour width as ratio of 'bothw'
	int gw = bothw - cw;	// gap width is the remainder
	int tv = B + G + R;	// tone value from current (blurred)
	int ts = (int)src[x,y].B + (int)src[x,y].G + (int)src[x,y].R;	// ts = source (unblurred) tone value

	if(Amount5 == 7){tc = ts;}	// change tone value to unblurred for speckled option
	else {tc = tv;}
	if(Amount7 == 6){tg = ts;}
	else {tg = tv;}

	for (int z = 0; z < n + 1; z++)	// contour and gap loop
	{ int thresh0 = bothw * z;	// thresholds ... gap starts
	int thresh1 = thresh0 + cw;	// thresholds ... gap ends, contour starts
	int thresh2 = thresh0 + bothw; // thresholds ... contour ends, gap starts 
	double rat = (double)tc / 765;	// long ways shading factor
	double midcont = ((thresh2 - thresh1) / 2) + thresh1 ;	// contour mid point 
	double midgap = ((thresh1 - thresh0) / 2) + thresh0 ; // gap mid point
	double c1, c2;	//crossways shading multipliers
	double f = 2.0;	// factor to lighten the bothways shading mode
	int gB = Amount6.B; int gG = Amount6.G; int gR = Amount6.R; int gA = Amount6.A;	// gap colours
	int cB = Amount4.B; int cG = Amount4.G; int cR = Amount4.R; int cA = Amount4.A; // contour colours

	// Gap
	if (tv >= thresh0 && tv < thresh1) 
	{switch(Amount7)
	{case 0:	// background
	B = (int)src[x,y].B;G = (int)src[x,y].G;R = (int)src[x,y].R;A = (int)src[x,y].A;
	break;
	case 1:	// transparent
	A = 0;
	break;
	case 2:	// solid colour
	B = gB; G = gG; R = gR; A = gA;
	break;
	case 3:	// shade across
	if(tv < midgap)
	{c1 = (tv - thresh0) / (midgap - thresh0);
	B = (int)(gB * c1); G = (int)(gG * c1); R = (int)(gR * c1); A = gA;}
	if(tv == midgap){B = gB; G = gG; R = gR; A = gA;}
	if(tv > midgap)
	{c2 = (thresh1 - tv) / (thresh1 - midgap);
	B = (int)(gB * c2); G = (int)(gG * c2); R = (int)(gR * c2); A = gA;}
	break;
	case 4:	// shade along
	B = (int)(gB * rat); G = (int)(gG * rat); R = (int)(gR * rat); A = gA;
	break;
	case 5:	// both ways
	if(tv < midgap)
	{c1 = (tv - thresh0) / (midgap - thresh0);
	B = (int)(gB * c1 * rat * f); G = (int)(gG * c1 * rat * f); R = (int)(gR * c1 * rat * f); A = gA;}
	if(tv == midgap){B = (int)(gB * rat * f); G = (int)(gG * rat * f); R = (int)(gR * rat * f); A = gA;}
	if(tv > midgap)
	{c2 = (thresh1 - tv) / (thresh1 - midgap);
	B = (int)(gB * c2 * rat * f); G = (int)(gG * c2 * rat * f); R = (int)(gR * c2 * rat * f); A = gA;}
	break;
	case 6:	// both from source
	if(tg < midgap)
	{c1 = (tg - thresh0) / (midgap - thresh0);
	B = (int)(gB * c1 * rat * f); G = (int)(gG * c1 * rat * f); R = (int)(gR * c1 * rat * f); A = gA;}
	if(tg == midgap){B = (int)(gB * rat * f); G = (int)(gG * rat * f); R = (int)(gR * rat * f); A = gA;}
	if(tg > midgap)
	{c2 = (thresh1 - tg) / (thresh1 - midgap);
	B = (int)(gB * c2 * rat * f); G = (int)(gG * c2 * rat * f); R = (int)(gR * c2 * rat * f); A = gA;}
	break;
	case 7:	// rainbow 
	if(tv <= midgap)
	{c1 = (tv - thresh0) / (midgap - thresh0);
	double b1 = Math.Sin(c1 * rad * 4 / 3);
	double g1 = Math.Sin(c1 * rad * 5 / 3);
	double r1 = Math.Sin(c1 * rad * 6 / 3);

	B = (int)((gB * c1) + (128 * b1));
	G = (int)((gG * c1) + (128 * g1));
	R = (int)((gR * c1) + (128 * r1)); A = gA;}

	if(tv > midgap)
	{c2 = (thresh1 - tv) / (thresh1 - midgap);
	double b2 = Math.Sin(c2 * rad * 4 / 3);
	double g2 = Math.Sin(c2 * rad * 5 / 3);
	double r2 = Math.Sin(c2 * rad * 6 / 3);

	B = (int)((gB * c2) + (128 * b2));
	G = (int)((gG * c2) + (128 * g2));
	R = (int)((gR * c2) + (128 * r2)); A = gA;}

	break;
	}
	}

	// Contour
	if (tv >= thresh1 && tv < thresh2)
	{switch(Amount5)
	{case 0:	//rainbow
	if(tv <= midcont)
	{c1 = (tv - thresh1) / (midcont - thresh1);
	double b1 = Math.Sin(c1 * rad * 4 / 3);
	double g1 = Math.Sin(c1 * rad * 5 / 3);
	double r1 = Math.Sin(c1 * rad * 6 / 3);

	B = (int)((cB * c1) + (128 * b1));
	G = (int)((cG * c1) + (128 * g1));
	R = (int)((cR * c1) + (128 * r1)); A = cA;}

	if(tv > midcont)
	{c2 = (thresh2 - tv) / (thresh2 - midcont);
	double b2 = Math.Sin(c2 * rad * 4 / 3);
	double g2 = Math.Sin(c2 * rad * 5 / 3);
	double r2 = Math.Sin(c2 * rad * 6 / 3);

	B = (int)((cB * c2) + (128 * b2));
	G = (int)((cG * c2) + (128 * g2));
	R = (int)((cR * c2) + (128 * r2)); A = cA;}
	break;
	case 1:	// background
	B = (int)src[x,y].B;G = (int)src[x,y].G;R = (int)src[x,y].R;A = (int)src[x,y].A;
	break;
	case 2:	// transparent
	A = 0;
	break;
	case 3:	// solid colour
	B = cB; G = cG; R = cR; A = cA;
	break;
	case 4:	// shade across
	if(tv < midcont)
	{c1 = (tv - thresh1) / (midcont - thresh1);
	B = (int)(cB * c1); G = (int)(cG * c1); R = (int)(cR * c1); A = cA;}
	if(tv == midcont){B = cB; G = cG; R = cR; A = cA;}
	if(tv > midcont)
	{c2 = (thresh2 - tv) / (thresh2 - midcont);
	B = (int)(cB * c2); G = (int)(cG * c2); R = (int)(cR * c2); A = cA;}
	break;
	case 5:	// shade along
	B = (int)(cB * rat); G = (int)(cG * rat); R = (int)(cR * rat); A = cA;
	break;
	case 6:	// both ways f = factor to lighten
	if(tv < midcont)
	{c1 = (tv - thresh1) / (midcont - thresh1);
	B = (int)(cB * c1 * rat * f); G = (int)(cG * c1 * rat * f); R = (int)(cR * c1 * rat * f); A = cA;}
	if(tv == midcont){B = (int)(cB * rat * f); G = (int)(cG * rat * f); R = (int)(cR * rat * f); A = cA;}
	if(tv > midcont)
	{c2 = (thresh2 - tv) / (thresh2 - midcont);
	B = (int)(cB * c2 * rat * f); G = (int)(cG * c2 * rat * f); R = (int)(cR * c2 * rat * f); A = cA;}
	break;
	case 7:	//both from source f = factor to lighten
	if(tc < midcont)
	{c1 = (tc - thresh1) / (midcont - thresh1);
	B = (int)(cB * c1 * rat * f); G = (int)(cG * c1 * rat * f); R = (int)(cR * c1 * rat * f); A = cA;}
	if(tc == midcont){B = (int)(cB * rat * f); G = (int)(cG * rat * f); R = (int)(cR * rat * f); A = cA;}
	if(tc > midcont)
	{c2 = (thresh2 - tc) / (thresh2 - midcont);
	B = (int)(cB * c2 * rat * f); G = (int)(cG * c2 * rat * f); R = (int)(cR * c2 * rat * f); A = cA;}
	break;
	}
	}
	// re assemble
	CurrentPixel = ColorBgra.FromBgra( Int32Util.ClampToByte(, Int32Util.ClampToByte(G), Int32Util.ClampToByte(R), Int32Util.ClampToByte(A));
	dst[x,y] = CurrentPixel;
	}
	} 
} 
}



Now in my plugin pack Red ochre plugin pack

Edited by Red ochre

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

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