I'm trying to understand how the Mathematical Parser works with the preview feature in the GIMP plugin. The sample below does a limited Droste-like effect as an example. To try it out, give it an image with an alpha hole somewhere in the middle.
The preview with default settings seems to work OK and when applied, the full image looks like the preview. But if you move the x center or y center up or down a bit, the preview moves the inner images a small amount but when applied to the full image, it moves a whole lot more (more than 0.06 and you can't see the images).
So, what is going wrong? How do the "w" and "h" get adjusted between the preview and the full image? When the preview gets calculated, does it use smaller versions of "w" and "h" to fit the preview size? Is there a bug in my code or somewhere else?
Anyway, here's the code (full attribution for the code is provided in the header:
################################################################
# Simple Droste effect code version 1 for Mathmap 1.2.0
# by
# Lorenzo Marchi ( www.flickr.com/photos/lorenzomarchi )
# some code is used with permission from he Droste effect
# by Josh Sommers ( www.flickr.com/photos/joshsommers )
# and breic ( www.flickr.com/photos/breic )
# Also see the flickr group: www.flickr.com/groups/escherdroste
# Last modified: 23/08/2008
################################################################
#@gimp AA_Droste_simple: droste_simple, droste_simple_preview(1)
#@gimp : CenterX = float(0,-1,1)
#@gimp : CenterY = float(0,-1,1)
#@gimp : Iterations = int(10,1,100)
#@gimp : Scale = float(50,0,100)
#@gimp : Rotate = float(0,-180,180)
droste_simple :
[-1] # Duplicate image
-shared[-1] 0 # Work with just 1 channel to save time
-fill[-1] "
init(centerx="$1";
centery="$2";
iterations="$3";
scale="$4";
rotate="$5";
shiftXX=(centerx/100)*(w/2);
shiftYY=(centery/100)*(h/2);
sc=100/scale;
theta=(pi/180)*rotate;
);
colorSoFarR=0;
colorSoFarG=0;
colorSoFarB=0;
colorSoFarA=0;
alphaRemaining=1;
i=0;
whiledo(i<iterations,
X=(2*x/w)-1;
Y=(2*(h-y)/h)-1;
xx=cos(theta*i)*((X-shiftXX)*sc^i)-sin(theta*i)*((Y-shiftYY)*sc^i)+shiftXX;
yy=sin(theta*i)*((X-shiftXX)*sc^i)+cos(theta*i)*((Y-shiftYY)*sc^i)+shiftYY;
realx=(xx+1)/2*w;
realy=h-((yy+1)/2*h);
ColorOutR=i(#1,realx,realy,0,0)/255;
ColorOutG=i(#1,realx,realy,0,1)/255;
ColorOutB=i(#1,realx,realy,0,2)/255;
ColorOutA=i(#1,realx,realy,0,3)/255;
colorSoFarR=colorSoFarR+(ColorOutR*ColorOutA*alphaRemaining);
colorSoFarG=colorSoFarG+(ColorOutG*ColorOutA*alphaRemaining);
colorSoFarB=colorSoFarB+(ColorOutB*ColorOutA*alphaRemaining);
colorSoFarA=colorSoFarA+(ColorOutA*ColorOutA*alphaRemaining);
alphaRemaining=alphaRemaining*(1-ColorOutA);
i=i+1;
);
i(#0,x,y,0,0)=colorSoFarR*255;
i(#0,x,y,0,1)=colorSoFarG*255;
i(#0,x,y,0,2)=colorSoFarB*255;
i(#0,x,y,0,3)=colorSoFarA*255;
colorSoFarR*255"
-keep[-3] # Only third to last image should be kept
droste_simple_preview :
-droste_simple $1,$2,$3,$4,$5
Souphead.