Designation/usage of some struct with callbck func pointes

Windows specific forum
LiK137
Enthusiast
Enthusiast
Posts: 279
Joined: Wed Jun 23, 2010 5:13 pm

Designation/usage of some struct with callbck func pointes

Post by LiK137 »

I often see strange structures in C(pp).
These structures hold pointers to functions which are needed for callbacks
I do not understand the need and usage of such structures.

One of them I met few month ago which was difficult for me to adapt dll library.
Another one I saw yesterday in "libJpeg-Turbo" turbojpeg.dll

Code: Select all

typedef struct tjtransform
{
  /**
   * Cropping region
   */
  tjregion r;
  /**
   * One of the @ref TJXOP "transform operations"
   */
  int op;
  /**
   * The bitwise OR of one of more of the @ref TJXOPT_CROP "transform options"
   */
  int options;
  /**
   * Arbitrary data that can be accessed within the body of the callback
   * function
   */
  void *data;
  /**
   * A callback function that can be used to modify the DCT coefficients
   * after they are losslessly transformed but before they are transcoded to a
   * new JPEG image.  This allows for custom filters or other transformations
   * to be applied in the frequency domain.
   *
   * @param coeffs pointer to an array of transformed DCT coefficients.  (NOTE:
   * this pointer is not guaranteed to be valid once the callback returns, so
   * applications wishing to hand off the DCT coefficients to another function
   * or library should make a copy of them within the body of the callback.)
   *
   * @param arrayRegion #tjregion structure containing the width and height of
   * the array pointed to by <tt>coeffs</tt> as well as its offset relative to
   * the component plane.  TurboJPEG implementations may choose to split each
   * component plane into multiple DCT coefficient arrays and call the callback
   * function once for each array.
   *
   * @param planeRegion #tjregion structure containing the width and height of
   * the component plane to which <tt>coeffs</tt> belongs
   *
   * @param componentID ID number of the component plane to which
   * <tt>coeffs</tt> belongs (Y, Cb, and Cr have, respectively, ID's of 0, 1,
   * and 2 in typical JPEG images.)
   *
   * @param transformID ID number of the transformed image to which
   * <tt>coeffs</tt> belongs.  This is the same as the index of the transform
   * in the <tt>transforms</tt> array that was passed to #tjTransform().
   *
   * @param transform a pointer to a #tjtransform structure that specifies the
   * parameters and/or cropping region for this transform
   *
   * @return 0 if the callback was successful, or -1 if an error occurred.
   */
  int (*customFilter)(short *coeffs, tjregion arrayRegion,
    tjregion planeRegion, int componentIndex, int transformIndex,
    struct tjtransform *transform);
} tjtransform;

Does anyone know the Usage of below shown customFilter (or similar) in PureBasic so if we prepare absolutely same Purebasic structure based on given

CPP structure:
int (*customFilter)(short *coeffs, tjregion arrayRegion,
tjregion planeRegion, int componentIndex, int transformIndex,
struct tjtransform *transform);