pointer_to_buffer

Syntax

int pointer_to_buffer(int buffer, int x, int y, int z)

Arguments

buffer
Set buffer=0 for the input buffer, buffer=1 for the first tile buffer, buffer=2 for the second tile buffer and buffer=3 for the output buffer
x
x-coordinate
y
y-coordinate
z
color channel

Return

Returns a pointer to the specified x-, y- and z-coordinates of the specified buffer.

Description

The returned pointer can be used in conjunction with memcpy() or memmove() to copy or move whole pixels or a whole image row very quickly between the buffers or inside one buffer. Later when FM will directly support pointers, this function can be used to read or write image data much quicker. Please notice that the input and output buffers aren't always allocated as one continuous memory block. A new memory block might be allocated for each row. So you have to use pointer_to_buffer() for every new row. Currently works only for 8-bit images.

Example

%ffp

//Drag the slider to scroll the image vertically in the preview!
ctl(0): "Move", Range=(-100,100),val=0,track

ForEveryTile:
{
   setCtlRange(0,-(y_end-y_start),(y_end-y_start));

   for(y = y_start; y < y_end; ++y) 
       memcpy (pointer_to_buffer(3,x_start,y,0) , pointer_to_buffer(0,x_start, egw(y_start,y_end-1, y+ctl(0)) ,0) , (x_end-x_start)*3);

   return true;
}

Also see

memcpy, (memmove)?

Comments

Everyone can add his comments about his experiences with this function here. Tips for using it are welcome, too.