fmax和fmin期望一个标识符Visual Studio c ++

时间:2015-03-23 09:06:59

标签: c++ identifier

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];
    }
}

不明白为什么fmax和fmin函数在这个函数中不起作用?我已经将yy等声明为int?如果我尝试将它们声明为double,也行不通......

2 个答案:

答案 0 :(得分:0)

作为C ++ 11迭代的一部分,

fminfmax被引入C ++,我认为Visual C ++还不支持它们,至少在VS2012之前。

答案 1 :(得分:0)

fmaxfmin是C ++ 11,但您可以简单地使用maxmin,因为您无论如何都在int上使用它们

此外,由于您使用这两个函数将整数钳位到0..255范围,因此您可以为此定义一个函数:

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

然后像这样使用它:

yy = clamp(yy);