Next is an algorithm to calculate the histogram for a given YUV420sp image.  The YUV data is given by the hardware camera as an unsigned char*.The algorithms works correctly, but I'm looking to optimize it for speed.void calculateHistogram(const unsigned char* yuv420sp, const int yuvWidth, const int yuvHeight,                         const int canvasHeight, int* histogramBins){    const int BINS = 256;    // Clear the output    memset(histogramBins, 0, BINS * sizeof(int));    // Get the bin values    const unsigned int totalPixels = yuvWidth * yuvHeight;    for (int index = 0; index < totalPixels; index++)    {        histogramBins[yuv420sp[index]]++;    }    // Resolve the maximum count in bins    int maxBinValue = 0;    for (int index = 0; index < BINS; index++)    {        if (histogramBins[index] > maxBinValue)        {            maxBinValue = histogramBins[index];        }    }    maxBinValue = maxBinValue == 0 ? 1 : maxBinValue;    // Normalize to fit into the histogram UI canvas height    for (int index = 0; index < BINS; index++)    {        histogramBins[index] = histogramBins[index] * canvasHeight / maxBinValue;    }}
Optimization for histogram computation algorithm in C
optimization;c;statistics