0
void SplitColors(unsigned char *rgb, int count, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *y, unsigned char *cb, unsigned char *cr, bool useRGBA)
{
    int multiplier = useRGBA ? 4 : 3;
    for (int i = 0; i < count; i++)
    {
        if (y || cb || cr)
        {
            int yy, ccb, ccr;
            RGB_to_YCbCr(
                rgb[i * multiplier + 0],
                rgb[i * multiplier + 1],
                rgb[i * multiplier + 2],
                yy, ccb, ccr);
            yy = fmax(0, yy);  yy = fmin(255, yy);
            ccb = fmax(0, ccb); ccb = fmin(255, ccb);
            ccr = fmax(0, ccr); ccr = fmin(255, ccr);
            if (y != NULL)
                y[i] = (unsigned char)yy;
            if (cb != NULL)
                cb[i] = (unsigned char)ccb;
            if (cr != NULL)
                cr[i] = (unsigned char)ccr;
        }
        if (r != NULL)
            r[i] = rgb[i * multiplier + 0];
        if (g != NULL)
            g[i] = rgb[i * multiplier + 1];
        if (b != NULL)
            b[i] = rgb[i * multiplier + 2];
    }
}

Don't understand why the fmax and fmin functions aren't working in this one? I've declared the yy etc as int? Also doesn't work if I try to declare them as double...

2 Answers2

0

fmin and fmax were introduced to C++ as part of the C++11 iteration, I don't think Visual C++ supports them yet, at least up to VS2012.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
0

fmax and fmin are C++11, but you could simply use max and min since you're using them on ints anyway.

Also, since you're using the two functions to clamp your integers to the 0..255 range, you could define a function just for that:

int clamp(int val, int min = 0, int max = 255)
{
    return std::min(std::max(val, min), max);
}

And then use it like this:

yy = clamp(yy);
Emil Laine
  • 41,598
  • 9
  • 101
  • 157