Skip to content

Instantly share code, notes, and snippets.

@3outeille
Created September 6, 2022 18:07
Show Gist options
  • Save 3outeille/653cf99656e7bca9ffe09a83fb5fc973 to your computer and use it in GitHub Desktop.
Save 3outeille/653cf99656e7bca9ffe09a83fb5fc973 to your computer and use it in GitHub Desktop.
fg_blend_stripe
static inline uint32_t ov_clip_uintp2(int32_t val, uint32_t a)
{
if (val > 0) {
int32_t mask = (1 << a) - 1;
int32_t overflow = !!(val & (~mask));
return ((-overflow) & mask) | (val & mask);
} else {
return 0;
}
#if 0
return OVMIN(OVMAX(0, val), (1 << a) - 1);
#endif
}
void fg_blend_stripe(int16_t *dstSampleOffsetY, int16_t *srcSampleOffsetY, int32_t *grainStripe, uint32_t widthComp, uint32_t blockHeight, uint8_t bitDepth)
{
uint32_t k, l;
int32_t grainSample;
for (l = 0; l < blockHeight; l++) /* y direction */
{
for (k = 0; k < widthComp; k++) /* x direction */
{
grainSample = grainStripe[k + (l*widthComp)];
grainSample <<= (bitDepth - 8);
dstSampleOffsetY[k + (l*widthComp)] = (int16_t) ov_clip_uintp2(grainSample + srcSampleOffsetY[k + (l*widthComp)], bitDepth);
}
}
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment