Next: 4.3 Adding new types Up: 4. Function dispatch and Previous: 4.1 Simple plugin example Contents

# 4.2 A more complicated example

This section lists the source for `im_extract()`'s function description. Almost all functions in the VIPS library have descriptors -- if you are not sure how to write a description, it's usually easiest to copy one from a similar function in the library.

    /* Args to im_extract.
     */
    static im_arg_desc extract_args[] = {
        IM_INPUT_IMAGE( "input" ),
        IM_OUTPUT_IMAGE( "output" ),
        IM_INPUT_INT( "left" ),
        IM_INPUT_INT( "top" ),
        IM_INPUT_INT( "width" ),
        IM_INPUT_INT( "height" ),
        IM_INPUT_INT( "channel" )
    };

    /* Call im_extract via arg vector.
     */
    static int
    extract_vec( im_object *argv )
    {
        IMAGE_BOX box;

        box.xstart = *((int *) argv[2]);
        box.ystart = *((int *) argv[3]);
        box.xsize = *((int *) argv[4]);
        box.ysize = *((int *) argv[5]);
        box.chsel = *((int *) argv[6]);

        return( im_extract(
            argv[0], argv[1], &box ) );
    }

    /* Description of im_extract.
     */
    static im_function extract_desc = {
        "im_extract",          /* Name */
        "extract area/band",   /* Descrip. */
        IM_FN_PIO | IM_FN_TRANSFORM,
        extract_vec,           /* Dispatch */
        NUMBER( extract_args ),/* # of arg */
        extract_args           /* Arg list */
    };