Cairo 16 bit & 32 bit Rendering (SDK)
Hi gang!
I know there are a few developers on here using Cairo with the AE SDK and I have recently jumped into this as well. It is indeed quite powerful and makes life significantly easier.
One thing I can't figure out is how to render in other depths like 16 bit and 32 bit. This is the familiar code for rendering in 8-bit from Cairo:
// Write pixel 8-bit
PF_Pixel* sampleIntegral8(PF_EffectWorld& def, int x, int y) {
return (PF_Pixel*)((char*)def.data +
(y * def.rowbytes) +
(x * sizeof(PF_Pixel)));
}
PF_Err cairoCopy8(void* refcon, A_long threadInd, A_long itemNum,
A_long iterTotal)
{
cairoRefcon* data = (cairoRefcon*)refcon;
int i = itemNum;
PF_Err err = PF_Err_NONE;
uint32_t* rowP;
PF_Pixel8* worldPtr = sampleIntegral8(data->output, 0, i);
rowP = (uint32_t*)(data->data + i * data->stride);
for (int x = 0; x < data->output.width; x++) {
worldPtr->alpha = rowP[x] >> 24;
if (worldPtr->alpha)
{
float rf = A_u_char(rowP[x] >> 16) / (float)worldPtr->alpha;
float gf = A_u_char(rowP[x] >> 😎 / (float)worldPtr->alpha;
float bf = A_u_char(rowP[x] >> 0) / (float)worldPtr->alpha;
worldPtr->red = A_u_char(rf * PF_MAX_CHAN8);
worldPtr->green = A_u_char(gf * PF_MAX_CHAN8);
worldPtr->blue = A_u_char(bf * PF_MAX_CHAN8);
}
worldPtr++;
}
return err;
}
This is what I've done in my *attempt* to adapt it to 16-bit rendering:
PF_Pixel16* sampleIntegral16(PF_EffectWorld& def, int x, int y) {
return (PF_Pixel16*)((char*)def.data +
(y * def.rowbytes) +
(x * sizeof(PF_Pixel16)));
}
PF_Err cairoCopy16(void* refcon, A_long threadInd, A_long itemNum,
A_long iterTotal)
{
cairoRefcon* data = (cairoRefcon*)refcon;
int i = itemNum;
PF_Err err = PF_Err_NONE;
uint32_t* rowP;
PF_Pixel16* worldPtr = sampleIntegral16(data->output, 0, i);
rowP = (uint32_t*)(data->data + i * data->stride);
for (int x = 0; x < data->output.width; x++) {
worldPtr->alpha = rowP[x] >> 24;
if (worldPtr->alpha)
{
float rf = A_u_char(rowP[x] >> 16) / (float)worldPtr->alpha;
float gf = A_u_char(rowP[x] >> 😎 / (float)worldPtr->alpha;
float bf = A_u_char(rowP[x] >> 0) / (float)worldPtr->alpha;
worldPtr->red = A_u_char(rf * PF_MAX_CHAN16);
worldPtr->green = A_u_char(gf * PF_MAX_CHAN16);
worldPtr->blue = A_u_char(bf * PF_MAX_CHAN16);
}
worldPtr++;
}
return err;
}
However, this renders incorrectly. It seems it still exports in the range of 0-255. Perhaps it has something to do with the bit-shifting which may need to be different for 16 / 32 bit and which, admittedly, I don't really understand.
Does anyone have any ideas on how to correctly adapt this to 16-bit and 32-bit?
Thank you as always in advance to everyone. Without this forum, I'd get nowhere.
Regards,
-Richard
