Exemple #1
0
        public static XMVector SrgbToRgb(XMVector srgb)
        {
            XMVector cutoff    = XMVector.FromFloat(0.04045f, 0.04045f, 0.04045f, 1.0f);
            XMVector invLinear = XMVector.FromFloat(1.0f / 12.92f, 1.0f / 12.92f, 1.0f / 12.92f, 1.0f);
            XMVector scale     = XMVector.FromFloat(1.0f / 1.055f, 1.0f / 1.055f, 1.0f / 1.055f, 1.0f);
            XMVector bias      = XMVector.FromFloat(0.055f, 0.055f, 0.055f, 0.0f);
            XMVector gamma     = XMVector.FromFloat(2.4f, 2.4f, 2.4f, 1.0f);

            XMVector v  = srgb.Saturate();
            XMVector v0 = XMVector.Multiply(v, invLinear);
            XMVector v1 = XMVector.Pow(XMVector.Multiply(XMVector.Add(v, bias), scale), gamma);

            XMVector select = XMVector.Greater(v, cutoff);

            v = XMVector.Select(v0, v1, select);
            return(XMVector.Select(srgb, v, XMGlobalConstants.Select1110));
        }
Exemple #2
0
        public static XMVector RgbToSrgb(XMVector rgb)
        {
            XMVector cutoff   = XMVector.FromFloat(0.0031308f, 0.0031308f, 0.0031308f, 1.0f);
            XMVector linear   = XMVector.FromFloat(12.92f, 12.92f, 12.92f, 1.0f);
            XMVector scale    = XMVector.FromFloat(1.055f, 1.055f, 1.055f, 1.0f);
            XMVector bias     = XMVector.FromFloat(0.055f, 0.055f, 0.055f, 0.0f);
            XMVector invGamma = XMVector.FromFloat(1.0f / 2.4f, 1.0f / 2.4f, 1.0f / 2.4f, 1.0f);

            XMVector v  = rgb.Saturate();
            XMVector v0 = XMVector.Multiply(v, linear);
            XMVector v1 = XMVector.Subtract(XMVector.Multiply(scale, XMVector.Pow(v, invGamma)), bias);

            XMVector select = XMVector.Less(v, cutoff);

            v = XMVector.Select(v1, v0, select);
            return(XMVector.Select(rgb, v, XMGlobalConstants.Select1110));
        }
Exemple #3
0
        public static XMVector SrgbToXyz(XMVector srgb)
        {
            XMVector scale0 = XMVector.FromFloat(0.4124f, 0.2126f, 0.0193f, 0.0f);
            XMVector scale1 = XMVector.FromFloat(0.3576f, 0.7152f, 0.1192f, 0.0f);
            XMVector scale2 = XMVector.FromFloat(0.1805f, 0.0722f, 0.9505f, 0.0f);
            XMVector cutoff = XMVector.FromFloat(0.04045f, 0.04045f, 0.04045f, 0.0f);
            XMVector exp    = XMVector.FromFloat(2.4f, 2.4f, 2.4f, 1.0f);

            XMVector sel = XMVector.Greater(srgb, cutoff);

            // lclr = clr / 12.92
            XMVector smallC = XMVector.Divide(srgb, XMGlobalConstants.MsrgbScale);

            // lclr = pow( (clr + a) / (1+a), 2.4 )
            XMVector largeC = XMVector.Pow(XMVector.Divide(XMVector.Add(srgb, XMGlobalConstants.MsrgbA), XMGlobalConstants.MsrgbA1), exp);

            XMVector lclr = XMVector.Select(smallC, largeC, sel);

            XMMatrix m   = new XMMatrix(scale0, scale1, scale2, XMGlobalConstants.Zero);
            XMVector clr = XMVector3.Transform(lclr, m);

            return(XMVector.Select(srgb, clr, XMGlobalConstants.Select1110));
        }
Exemple #4
0
        public static XMVector XyzToSrgb(XMVector xyz)
        {
            XMVector scale0 = XMVector.FromFloat(3.2406f, -0.9689f, 0.0557f, 0.0f);
            XMVector scale1 = XMVector.FromFloat(-1.5372f, 1.8758f, -0.2040f, 0.0f);
            XMVector scale2 = XMVector.FromFloat(-0.4986f, 0.0415f, 1.0570f, 0.0f);
            XMVector cutoff = XMVector.FromFloat(0.0031308f, 0.0031308f, 0.0031308f, 0.0f);
            XMVector exp    = XMVector.FromFloat(1.0f / 2.4f, 1.0f / 2.4f, 1.0f / 2.4f, 1.0f);

            XMMatrix m    = new XMMatrix(scale0, scale1, scale2, XMGlobalConstants.Zero);
            XMVector lclr = XMVector3.Transform(xyz, m);
            XMVector sel  = XMVector.Greater(lclr, cutoff);

            // clr = 12.92 * lclr for lclr <= 0.0031308f
            XMVector smallC = XMVector.Multiply(lclr, XMGlobalConstants.MsrgbScale);

            // clr = (1+a)*pow(lclr, 1/2.4) - a for lclr > 0.0031308 (where a = 0.055)
            XMVector largeC = XMVector.Subtract(XMVector.Multiply(XMGlobalConstants.MsrgbA1, XMVector.Pow(lclr, exp)), XMGlobalConstants.MsrgbA);

            XMVector clr = XMVector.Select(smallC, largeC, sel);

            return(XMVector.Select(xyz, clr, XMGlobalConstants.Select1110));
        }