People who know other languages and their language (Please feel free to mention more languages. If you want to be added, feel free to request me to add you here.):
@David_Tschumperle - C++
@Reptorian - C# (PDN Plugins), and C++
@grosgood - Python, C, C++, Java (Not so literate in it)
The purpose of this thread is to have gmic developers aid in helping convert scripts from other languages. Another purpose is to add translation of some functions into the gmic language. Python diag() was solved in another thread.
There are many filters that are on gmic which the original filter was developed on other languages. Iām not too sure on where to go from here, so I will just mention a brief example.
For example, I will mention TRās Pixel Sharpener:
It is a plugin that is created for Paint.NET
.
Code to TR's Pixel Sharpener
// Submenu: Photo
// Name: TR's Pixel Sharpener
// Title: TR's Pixel Sharpener - v2.0
// Author: TechnoRobbo
// URL: http://www.technorobbo]http://www.technorobbo
#region UICode
double Amount1 = 0.75; // [0,1] Sharpen Amount
int Amount2 = 1; // [1,5] Blur Width
byte Amount3 = 0; // Blur Type|Photo|Horizontal Motion|Vertical Motion
#endregion
void Render(Surface dst, Surface src, Rectangle rect)
{
Rectangle sel = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
Surface proxy = src.Clone();
double blur = (Amount2 - 1)* 2 + 3;
double qblur= blur * blur;
double eblur = Math.Floor(blur /2);
double sblur = Math.Floor(blur /-2);
ColorBgra CP;
double Coeff =Amount1;
double mult = qblur * Coeff + eblur / Amount2 ;
for (int y = rect.Top; y < rect.Bottom; y++)
{
for (int x = rect.Left; x < rect.Right; x++)
{
CP = src[x,y];
int[] sum = {(int)((double)CP.R * mult ),(int)((double)CP.G * mult ),(int)((double)CP.B * mult) };
for (int i = (int)sblur; i<=eblur; i++){
for (int j = (int)sblur; j<=eblur; j++){
if (i!=0 & j!=0)
{
float nx = x + j;
float ny = y + i;
if (Amount3==2) nx = x;
if (Amount3==1) ny = y;
CP = src.GetBilinearSampleClamped(nx,ny);
sum[0] -= (int)((double)CP.R * Coeff);
sum[1] -=(int)((double)CP.G * Coeff);
sum[2] -= (int)((double)CP.B * Coeff);
}
}
}
CP.R = Int32Util.ClampToByte(sum[0]);
CP.G = Int32Util.ClampToByte(sum[1]);
CP.B = Int32Util.ClampToByte(sum[2]);
dst[x,y] = CP;
}
}
}
Translation:
G'MIC version (Extended after translation)
#@cli rep_trps: eq. to 'rep_tr_pixel_sharpener'. : (+)
rep_trps: rep_tr_pixel_sharpener $*
#@cli rep_tr_pixel_sharpener: sharpen,_internal_blur>=0,_type= { 0=Photo | 1= Horizontal | 2= Vertical | 3= One-Axis Angle | 4= Two-Axis Angle | 5= Two-Axis Disconnected},-360<=_sharpening_angle_a<=360,-360<=_sharpening_angle_b<=360
#@cli : Extended version of the original TR's Pixel Sharpener for Paint.NET. Some code were changed to make more sense or is more practical. Negative values are enabled for first variable in the G'MIC version. The original code this was based on was created by TechnoRobbo. Source code - https://forums.getpaint.net/topic/26783-trs-pixel-sharpener-plugin-v20-dec-21-2014/
#@cli : (eq. to 'rep_trps').\n
#@cli : Default values: '_internal_blur=0','_blur_type=0','_sharpening_angle=0'\n
#@cli : Author: Reptorian.
rep_tr_pixel_sharpener:
skip ${2=0},${3=0},${4=0},${5=0}
f "begin(
const ang=pi*($4/180);
const ang2=pi*($5/180);
const cos_ang=cos(ang);
const sin_ang=sin(ang);
const cos_ang2=cos(ang2);
const sin_ang2=sin(ang2);
rot_x(a,b)=a*cos_ang-b*sin_ang;
rot_y(a,b)=a*sin_ang+b*cos_ang;
rot_y_alt(a,b)=a*sin_ang2+b*cos_ang2;
const blur=(round(abs($2)+1)-1)*2+3;
const qblur=sqr(blur);
const eblur=floor(blur/2);
const sblur=floor(blur/-2);
const coeff=$1/100;
const mult=qblur*coeff+eblur/round(abs($2)+1);
const choice=abs($3)<=2?abs($3):0;
$3==5?(
fnx()=x+rot_x(j,k);
fny()=y+rot_y_alt(j,k);
):
$3==4?(
fnx()=x+rot_x(j,k);
fny()=y+rot_y(j,k);
):
$3==3?(
fnx()=x+rot_x(j,0);
fny()=y+rot_y(j,0);
):
$3==2?(
fnx()=x;
fny()=y+k;
):
$3==1?(
fnx()=x+j;
fny()=y;
):(
fnx()=x+j;
fny()=y+k;
);
);
sum=i*mult;
for(k=int(sblur),k<=eblur,k++,
for(j=int(sblur),j<=eblur,j++,
if(k!=0&j!=0,
nx=fnx();
ny=fny();
nfcalc=i(nx,ny,z,c,0,1);
sum-=nfcalc*coeff;
);
);
);
sum;"
You see the difference between the two version? There is no for(x,y) within the gāmic translation because gāmic has the option to generate images using implicit loops. There is also macro functions declared within the gmic version. src[x,y] can be seen as the equilavent of I(#0) or i#0 because within the C# PDN plugin, that means the pixel located at indice of x,y.
Itās hard to explain how to convert it, but I think the examples should do well to demonstrate their similarity.