Skip to main content
Inspiring
January 15, 2017
Question

Color callback for RGB to HS

  • January 15, 2017
  • 1 reply
  • 1005 views

Hi. I'm using the CB suites to try and convert RGB to HLS but I'm sure I'm doing something wrong, as my result looks different to the channel combiner conversion. Here's my code inside an iterateFloat:

It seems wasteful to acquire the suite every pixel, but I tried passing it via the refcon and it had an exception error, probably my fault. Thanks in advance for any info.

This topic has been closed for replies.

1 reply

Inspiring
January 16, 2017

You're right in that you shouldn't acquire the suite within an iterate function - this will slow your plugin down a lot! I'm not sure why you're getting an error when using it in the refcon though.

In your header:

// Define struct for refcon, including a pointer to callback suite

struct MyRefconStruct {

     PF_ColorCallbacksFloatSuite1 *ccfsP;

     // Other refcon stuff

}

In your render function:

MyRefconStruct my_refcon = {};

// Acquire pointer to suite

AEFX_AcquireSuite(..., (void**)&my_refcon.ccfsP)

// Do iterate

// Release suite

AEFX_ReleaseSuite(...);

You could just provide your own RGB to HLS function as a static function (so no suites to acquire). This example would do the trick:

CodeGuru Forums

But you'd need to omit the conversion to r_percent, etc., as it looks like you're already working in float (0-1).

The reason your results look different is that PF_HLS_Pixel is an array of Fixed Point numbers rather than floating point. You'll need to use the FIX_2_FLOAT(X) macro to convert them, so:

out->red = FIX_2_FLOAT(hls[0]);

//etc.

Inspiring
January 19, 2017

Thank you so much for your detailed response.

Even after running the HLS values through FIX_2_FLOAT I'm still receiving odd values. The hue channel ranges values from 0 to 100, so I assume that needs to be divided 100 fold but no idea why. The saturation values are all 1.000 so something went wrong there. I did a comparison between channel combiner, color callbacks, the codeguru code and smarty pants here:

I'll keep experimenting to try and get color callbacks to work for me!

Inspiring
January 19, 2017

Also I just noticed that smartyPants uses color callbacks for converting between RGB and HLS in 8bpc only, for 16 and 32bpc it uses custom functions which I copied and used in my smartyPants version.