Skip to main content
Inspiring
October 30, 2016
Answered

Question about Gamma Table example and structs

  • October 30, 2016
  • 1 reply
  • 440 views

Hello. In the Gamma Table example there is this code:

typedef struct {

  PF_Fixed gamma_val;

  A_u_char lut[256];

} Gamma_Table;

typedef struct {

unsigned char  *lut;

} GammaInfo;

How come a struct is used to create a pointer to lut inside Gamma_Table? If there is only one data type is this pointless or does it have a reason? Thanks.

This topic has been closed for replies.
Correct answer Christian Lett

The first struct (Gamma_Table) is used as the effect's sequence data. It contains the gamma lookup table (lut), and the gamma value. In Render, the value of gamma_val is compared against the parameter, and if they differ, the lut is re-generated.


The second struct (GammaInfo) is used as the refcon, which is passed to the iterate function to process the pixels. In this case the lut is just a pointer, which is assigned the address of the sequence data lut.

The reason for having separate structs is to keep the sequence and render data separate. In this case the only data passed to the iterate function is the lut, but in reality you may have other data that's required for rendering. You'd store that in the second struct.

Hope that makes sense!

1 reply

Christian LettCorrect answer
Inspiring
November 3, 2016

The first struct (Gamma_Table) is used as the effect's sequence data. It contains the gamma lookup table (lut), and the gamma value. In Render, the value of gamma_val is compared against the parameter, and if they differ, the lut is re-generated.


The second struct (GammaInfo) is used as the refcon, which is passed to the iterate function to process the pixels. In this case the lut is just a pointer, which is assigned the address of the sequence data lut.

The reason for having separate structs is to keep the sequence and render data separate. In this case the only data passed to the iterate function is the lut, but in reality you may have other data that's required for rendering. You'd store that in the second struct.

Hope that makes sense!

Inspiring
November 17, 2016

Thanks Christian. I was initially confused because structs are for storing variables of different types, and in this example the second struct only contains one item. But your explanation makes sense.