iget
Syntax
- int iget(double x, double y, int z, int buffer, int mode)
Arguments
- x, y
- The x and y coordinates in the image. They have to be float or double values, otherwise no interpolation is done.
- z
- The z coordinates or color channel
- buffer
- Set 0 for the input buffer, 1 for the first tile buffer, 2 for the second tile buffer and 3 for the output buffer.
- mode
- Interpolation method: 0 for nearest neighbor (no interpolation), 1 for bisquare, 2 for bicosine, 3 for bilinear and 4 for bicubic.
Return
- Returns an interpolated color value from the coordinates (x,y,z).
- Considering the mathematical properties of the interpolation functions, the returned color value may sometimes be greater than 255 or smaller than 0. You may want to limit it between 0 and 255, if you're using the value as an argument to functions that don't automatically limit it (e.g., the RGB function).
Description
- This function makes it easy to create real smooth effects. It lets you choose between 5 different interpolation methods. This function does some value caching, so it works quite fast. Currently it only works for 8 bit images.
Example
%ffp
//Demonstrates image resizing
ctl(0): "Resize",Range=(0,800),Val=200
ctl(10): combobox(vscroll),action=preview, color=#FFFFFF,fontcolor=#0000ff,
pos=(325,40),size=(70,200),
text="Nearest Neighbor\nBisquare\nBicosine\nBilinear\nBicubic",val=0
ctl(100):STATICTEXT, pos=(325,70),"", fontcolor=black
ForEveryTile:
{
float p1,q1,fracx,fracy,CalcD,dx,dy;
int Xnew,Ynew,p,q,Calc;
int m,n;
const int startclock = clock();
int endclock;
//New image dimensions
Xnew=X*ctl(0)/100;
Ynew=Y*ctl(0)/100;
for (y=y_start; y<y_end; y++){ // rows
updateProgress(y,y_end);
for (x=x_start; x<x_end; x++){ // columns
p1=(float)x*X/Xnew;
q1=(float)y*Y/Ynew;
for (z=0; z<zmax; z++){ // channels
if (y<Ynew && x<Xnew){
Calc = iget(p1,q1,z,0,ctl(10));
} else{
//Set the rest of the image to black
Calc=0;
}
pset(x, y, z, Calc);
}
}}
//Display calculation time
endclock = clock() - startclock;
setCtlTextv(100, "Calculation Time: %d ms", endclock);
return true;
}
Also see
- src, tget, t2get, pget
Comments
- It's worth remembering that this function returns int and not double, and requires the x and y parameters to be of type double. If you try using iget and find that your image is all black, it could be because you got your ints and doubles mixed up somewhere.
- While iget correctly handles the 16-bit case when reading from the input or output image buffers, it currently always accesses the 4 t-bufs as though they were 8-bit.