Skip to content

Instantly share code, notes, and snippets.

@3outeille
Last active September 8, 2022 09:14
Show Gist options
  • Save 3outeille/310cc7f707b3324e7f5c7bfdfa482618 to your computer and use it in GitHub Desktop.
Save 3outeille/310cc7f707b3324e7f5c7bfdfa482618 to your computer and use it in GitHub Desktop.
fg_compute_block_avg
int16_t fg_compute_block_avg(int16_t *dstSampleBlk8, uint32_t widthComp, uint16_t *pNumSamples,
uint8_t ySize, uint8_t xSize, uint8_t bitDepth)
{
uint32_t blockAvg = 0;
uint16_t numSamples = 0;
uint8_t k, l;
for (k = 0; k < ySize; k++)
{
for (l = 0; l < xSize; l++)
{
blockAvg += dstSampleBlk8[(k*widthComp)+l];
numSamples++;
}
}
if (numSamples > 0)
{
blockAvg /= numSamples;
blockAvg >>= (bitDepth - 8); /* to handle high bit depths */
}
*pNumSamples = numSamples;
blockAvg = (int16_t) ov_clip_uintp2(blockAvg, 8 );
return blockAvg;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment