コード例 #1
0
        public void ConvertFromRgb(int inputBufferLength, int resultBufferLength, int seed)
        {
            var converter = JpegColorConverter.GetConverter(JpegColorSpace.RGB);

            JpegColorConverter.ComponentValues values = CreateRandomValues(3, inputBufferLength, seed);
            Vector4[] result = new Vector4[resultBufferLength];

            converter.ConvertToRGBA(values, result);

            for (int i = 0; i < resultBufferLength; i++)
            {
                float   r        = values.Component0[i];
                float   g        = values.Component1[i];
                float   b        = values.Component2[i];
                Vector4 rgba     = result[i];
                var     actual   = new Rgb(rgba.X, rgba.Y, rgba.Z);
                var     expected = new Rgb(r / 255F, g / 255F, b / 255F);

                Assert.True(actual.AlmostEquals(expected, Precision));
                Assert.Equal(1, rgba.W);
            }
        }
コード例 #2
0
        public void ConvertFromYcck(int inputBufferLength, int resultBufferLength, int seed)
        {
            var v     = new Vector4(0, 0, 0, 1F);
            var scale = new Vector4(1 / 255F, 1 / 255F, 1 / 255F, 1F);

            var converter = JpegColorConverter.GetConverter(JpegColorSpace.Ycck);

            JpegColorConverter.ComponentValues values = CreateRandomValues(4, inputBufferLength, seed);
            var result = new Vector4[resultBufferLength];

            converter.ConvertToRGBA(values, result);

            for (int i = 0; i < resultBufferLength; i++)
            {
                float y  = values.Component0[i];
                float cb = values.Component1[i] - 128F;
                float cr = values.Component2[i] - 128F;
                float k  = values.Component3[i] / 255F;

                v.X = (255F - (float)Math.Round(y + (1.402F * cr), MidpointRounding.AwayFromZero)) * k;
                v.Y = (255F - (float)Math.Round(
                           y - (0.344136F * cb) - (0.714136F * cr),
                           MidpointRounding.AwayFromZero)) * k;
                v.Z = (255F - (float)Math.Round(y + (1.772F * cb), MidpointRounding.AwayFromZero)) * k;
                v.W = 1F;

                v *= scale;

                Vector4 rgba     = result[i];
                var     actual   = new Rgb(rgba.X, rgba.Y, rgba.Z);
                var     expected = new Rgb(v.X, v.Y, v.Z);

                Assert.True(actual.AlmostEquals(expected, Precision));
                Assert.Equal(1, rgba.W);
            }
        }