Older Newer
Wed, 11 Jan 2012 19:04:15 . . . . SyneRyder [Added some extra debugging tips in the comments]

Changes by last author:

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


::The z coordinates or color channel


::Set 0 for the input buffer, 1 for the first tile buffer, 2 for the second tile buffer and 3 for the output buffer.


::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 ==



//Demonstrates image resizing

ctl(0): "Resize",Range=(0,800),Val=200

ctl(10): combobox(vscroll),action=preview, color=#FFFFFF,fontcolor=#0000ff,


text="Nearest Neighbor\nBisquare\nBicosine\nBilinear\nBicubic",val=0

ctl(100):STATICTEXT, pos=(325,70),"", fontcolor=black



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



for (y=y_start; y<y_end; y++){ // rows


for (x=x_start; x<x_end; x++){ // columns



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



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.