It should be taking place during the transformation. To clarify with example of my problem, I will post the output of the difference from original to images applied with transformations
Code used:
new_rep_recpoltrans
$ sp monalisa +new_rep_recpoltrans 0,0,1 new_rep_recpoltrans. 0,0,0,1 a z
new_rep_recpoltrans:
skip ${1=0},${2=0},${3=0},${4=}
if $1<-1||$1>1 error ($1>=-1&&$1<=1)=0 fi
if $2<-1||$2>1 error ($2>=-1&&$2<=1)=0 fi
repeat $! l[$>]
if $3>0
if abs($1)==1&&abs($2)==1
maxlength={max(w,h)*2}
perimeter={(w+h)*2}
if $1==1 x_coord=round(ww-dix)
else x_coord=round(dix)
fi
if $2==1 y_coord=round(hh-diy)
else y_coord=round(diy)
fi
{$perimeter},{$maxlength},{d},{s},":begin(
if($1==$2
,surface=expr('begin(const hpi=acos(0););hpi-x/w*hpi;',w);
,surface=expr('begin(const hpi=acos(0););(x/w)*hpi;',w);
);
const hpi=acos(0);
const ww=w#0-1;
const hh=h#0-1;
const ihh=h-1;
const cut_ang=atan2(hh,ww);
distanceaway=[ww,hh];
);
surface_angle=surface[x];
surface_angle<cut_ang?side=0:side=1;
mdist=side%2?abs(1/sin(surface_angle)):abs(1/cos(surface_angle));
dix=cos(surface_angle)*distanceaway[side]*mdist*y/ihh;
diy=sin(surface_angle)*distanceaway[side]*mdist*y/ihh;
I(#0,"$x_coord","$y_coord",z);"
else
maxlength={max(w,h)*2}
perimeter={(w+h)*4}
{$perimeter},{$maxlength},{d},{s},":begin(
surface=expr('begin(const dpi=2*pi;);(x/w)*dpi;',w);
const dpi=pi*2;
const ww=w#0-1;
const hh=h#0-1;
const ihh=h-1;
const point_x=(($1*-1)*.5+.5)*ww;
const point_y=($2*.5+.5)*hh;
const inv_point_x=ww-point_x;
const inv_point_y=hh-point_y;
const cut_ang_s0=abs(atan2(inv_point_y,inv_point_x));
const cut_ang_s1=pi-abs(atan2(inv_point_y,point_x));
const cut_ang_s2=pi+abs(atan2(point_y,point_x));
const cut_ang_s3=dpi-abs(atan2(point_y,inv_point_x));
distanceaway=[ww-point_x,hh-point_y,point_x,point_y];
);
surface_angle=surface[x];
surface_angle>cut_ang_s0&&surface_angle<=cut_ang_s1?side=1:
surface_angle>cut_ang_s1&&surface_angle<=cut_ang_s2?side=2:
surface_angle>cut_ang_s2&&surface_angle<=cut_ang_s3?side=3:
side=0;
mdist=abs(side%2?1/sin(surface_angle):1/cos(surface_angle));
dix=point_x+cos(surface_angle)*distanceaway[side]*mdist*y/ihh;
diy=point_y+sin(surface_angle)*distanceaway[side]*mdist*y/ihh;
I(#0,round(ww-dix),round(diy),z);"
fi
else
$=val
orientation=${val{$>+4}}
perimeter={w}
if abs($1)==1&&abs($2)==1
length_1={$perimeter-h}
length_2={$perimeter-$length_1}
else
length_1={$perimeter-h*2}
length_2={$perimeter-$length_1}
fi
if $orientation
width={min($length_1,$length_2)}
height={max($length_1,$length_2)}
else
width={max($length_1,$length_2)}
height={min($length_1,$length_2)}
fi
if abs($1)==1&&abs($2)==1
if $1==1 surface_x=x-nw
else surface_x=x
fi
if $2==1 surface_y=y-nh
else surface_y=y
fi
if [$1,$2]==[-1,-1] calc_ay=(atan2(-ypos,xpos)+hpi)/hpi
elif [$1,$2]==[1,1] calc_ay=y!=nh?atan2(-ypos,xpos)/pi:1
elif [$1,$2]==[-1,1] calc_ay=atan2(-ypos,xpos)/hpi
elif [$1,$2]==[1,-1] calc_ay=ypos?(atan2(-ypos,xpos)+pi)/hpi
else error invalid_inp("$"1,"$"2) fi
{$width/2},{$height/2},{d},{s},"begin(
const ww=w#0-1;
const hh=h#0-1;
const nw=w-1;
const nh=h-1;
const hpi=acos(0);
);
xpos="$surface_x";
ypos="$surface_y";
ay=max(abs(xpos/nw),abs(ypos/nh));
ax="$calc_ay";
I(#0,ax*ww,ay*hh,z,2,1);
"
else
{$width/4},{$height/4},{d},{s},":begin(
const ww=w#0-1;
const hh=h#0-1;
const nw=w-1;
const nh=h-1;
const dpi=2*pi;
const cx=.5+$1*.5;
const cy=.5+$2*.5;
const px=cx*nw;
const py=cy*nh;
const rpx=nw-px;
const rpy=nh-py;
);
xpos=x-px;
ypos=y-py;
ax=1-(atan2(ypos,xpos)+pi)/dpi;
ay_x=x>px?(rpx-(nw-x))/rpx:(px-x)/px;
ay_y=y>py?(rpy-(nh-y))/rpy:(py-y)/py;
ay=max(ay_x,ay_y);
I(#0,ax*ww+(ax*ay),ay*hh,z,2,1);
"
fi
fi
k.
endl done
Difference analysis:
Note how most of the image is black? That is the result I want to see. The minimum difference possible. Now, it seems that there are localized error. Let’s zoom in that area and check what happens.
Before:

After:

They look almost the same. The thing is that only the value is off, not the internal coordinates used for transformation, and even if that were off, it’s pretty minor.
So, that’s why I want cut value using capital I(#n) as input, and to cut values found in each channel. Should be done during transformations.