Beispiel #1
0
        public void YCbCrColorShouldConvertToAndFromString(string expected)
        {
            Color      color      = ColorTranslator.FromHtml(expected);
            YCbCrColor yCbCrColor = YCbCrColor.FromColor(color);
            string     result     = ColorTranslator.ToHtml(yCbCrColor);

            result.Should().Be(expected);
        }
Beispiel #2
0
        public void TestSerialization()
        {
            Color c = new Color(255, 10, 255, 10);

            Utils.CheckSerialization(c);
            Color c1 = Utils.SerializeDeserialize(c);

            Assert.AreEqual(c, c1);

            YCbCrColor yc = new YCbCrColor(2, 3, 4);

            Utils.CheckSerialization(yc);
        }
Beispiel #3
0
            public void then_should_return_rgba_version_of_ycbcr_color_given_red()
            {
                // Arrange
                var yCbCrColor = YCbCrColor.FromColor(Color.Red);

                // Act
                var rgbaColor = (RgbaColor)yCbCrColor;

                // Assert
                Assert.That(rgbaColor.R, Is.EqualTo(254)); //Conversion not perfect
                Assert.That(rgbaColor.G, Is.EqualTo(0));
                Assert.That(rgbaColor.B, Is.EqualTo(0));
                Assert.That(rgbaColor.A, Is.EqualTo(255));
            }
            public void then_should_return_cmyk_version_of_ycbcr_color_given_red()
            {
                // Arrange
                var yCbCrColor = YCbCrColor.FromColor(Color.Red); // :*( [See Below]

                // Act
                var cmyk = (CmykColor)yCbCrColor;

                // Assert
                Assert.That(cmyk.C, Is.EqualTo(0));
                Assert.That(Math.Round(cmyk.M), Is.EqualTo(100)); // See, here's the thing
                Assert.That(cmyk.Y, Is.EqualTo(100));             // YCbCr doesn't happily convert to RGB
                Assert.That(Math.Round(cmyk.K), Is.EqualTo(0));   // Sad for me
            }
            public void then_should_return_hsla_version_of_ycbcr_color_given_red()
            {
                // Arrange
                var yCbCrColor = YCbCrColor.FromColor(Color.Red);

                // Act
                var hslaColor = (HslaColor)yCbCrColor;

                // Assert
                Assert.That(hslaColor.H, Is.EqualTo(0));
                Assert.That(hslaColor.S, Is.EqualTo(1.0f));
                Assert.That(Math.Round(hslaColor.L, 1), Is.EqualTo(.5f));   //YCbCr rounding issue
                Assert.That(hslaColor.A, Is.EqualTo(1.0f));
            }
Beispiel #6
0
        public void TestYCbCr()
        {
            Color      c1 = new Color(100, 100, 100);
            YCbCrColor yc = YCbCrColor.YCbCrFromColor(c1);

            Assert.AreEqual(yc.Y, 101);
            Assert.AreEqual(yc.Cb, 128);
            Assert.AreEqual(yc.Cr, 125);
            Color c2 = yc.RGBColor();

            /* Conversions is not 1-1 */
            Assert.AreNotEqual(c1, c2);
            Assert.AreEqual(c2.R, 94);
            Assert.AreEqual(c2.G, 101);
            Assert.AreEqual(c2.B, 98);
        }
Beispiel #7
0
        private void Render(Surface dst, Surface src, Rectangle rect)
        {
            for (int x = rect.Left; x < rect.Right; x++)
            {
                for (int y = rect.Top; y < rect.Bottom; y++)
                {
                    if (src.IsVisible(x, y))
                    {
                        YCbCrColor color = YCbCrColor.FromRgb(src[x, y]);

                        color.Cb = _selectedColor.Cb;
                        color.Cr = _selectedColor.Cr;

                        dst[x, y] = color.ToRgb();
                    }
                }
            }
        }
Beispiel #8
0
        private static YCbCrColor[][] ToYCbCr(Surface source)
        {
            YCbCrColor[][] picture = new YCbCrColor[source.Width][];

            for (int x = 0; x < picture.Length; x++)
            {
                picture[x] = new YCbCrColor[source.Height];
            }

            for (int x = 0; x < picture.Length; x++)
            {
                for (int y = 0; y < picture[x].Length; y++)
                {
                    picture[x][y] = YCbCrColor.FromRgb(source[x, y]);
                }
            }

            return(picture);
        }
Beispiel #9
0
        /// <summary>
        /// Sets global effect parameters.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <param name="dstArgs">The destination picture arguments.</param>
        /// <param name="srcArgs">The source picture arguments.</param>
        protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            int color = parameters.GetProperty <Int32Property>("Color").Value;

            _selectedColor = YCbCrColor.FromRgb(ColorBgra.FromUInt32((UInt32)color));
        }
Beispiel #10
0
        public static void SaveAsFile(string sFile, ref int[,] rgbArray, int width, int height, int quality)
        {
            int size           = width * height;
            int numRemainingY  = quality * size / 100;
            int numRemainingCg = quality * size / 25;
            int numRemainingCo = quality * size / 25;

            int newWidth, newHeight;
            // int[,] rgbArray = new int[width, height];
            // RGBColor.FillRGBArrayFromBitmap(bmp, ref rgbArray);
            FileStream   fs = new FileStream(sFile, FileMode.Create, FileAccess.Write, FileShare.None);
            MemoryStream ms = new MemoryStream();

            newWidth  = IntegerMath.ToPowerOf2(width);
            newHeight = IntegerMath.ToPowerOf2(height);

            float[,] imgOrgY  = new float[width, height];
            float[,] imgOrgCg = new float[width, height];
            float[,] imgOrgCo = new float[width, height];
            float[,] imgY     = new float[newWidth, newHeight];
            float[,] imgCg    = new float[newWidth, newHeight];
            float[,] imgCo    = new float[newWidth, newHeight];
            int[,] imgIY      = new int[newWidth, newHeight];
            int[,] imgICg     = new int[newWidth, newHeight];
            int[,] imgICo     = new int[newWidth, newHeight];
            //YCgCoColor.RGBArrayToYCgCoArrays(ref rgbArray, width, height, ref imgOrgY, ref imgOrgCg, ref imgOrgCo);
            YCbCrColor.RGBArrayToYCbCrArrays(ref rgbArray, width, height, ref imgOrgY, ref imgOrgCg, ref imgOrgCo);
            ArrayHelper2D.ResizeArray2D(ref imgOrgY, ref imgY, width, height, newWidth, newHeight, ArrayHelper2D.ResizeFilter.NONE_CLAMP);
            ArrayHelper2D.ResizeArray2D(ref imgOrgCg, ref imgCg, width, height, newWidth, newHeight, ArrayHelper2D.ResizeFilter.NONE_CLAMP);
            ArrayHelper2D.ResizeArray2D(ref imgOrgCo, ref imgCo, width, height, newWidth, newHeight, ArrayHelper2D.ResizeFilter.NONE_CLAMP);
            Biorthogonal53Wavelet2D wavelet = new Biorthogonal53Wavelet2D(newWidth, newHeight, 8, 8, true);

            wavelet.TransformIsotropic2D(ref imgY);
            wavelet.TransformIsotropic2D(ref imgCg);
            wavelet.TransformIsotropic2D(ref imgCo);
            ArrayHelper2D.RemoveSmallestCoefficients2D(ref imgY, newWidth, newHeight, numRemainingY);
            ArrayHelper2D.RemoveSmallestCoefficients2D(ref imgCg, newWidth, newHeight, numRemainingCg);
            ArrayHelper2D.RemoveSmallestCoefficients2D(ref imgCo, newWidth, newHeight, numRemainingCo);

            //simple quantification
            float quant = 1.0f / (float)((100.0f - quality) + 1.0f);

            for (int y = 0; y < newHeight; y++)
            {
                for (int x = 0; x < newWidth; x++)
                {
                    imgY[x, y]  *= quant;
                    imgCg[x, y] *= quant;
                    imgCo[x, y] *= quant;
                }
            }

            ArrayHelper2D.ConvertFloatToInt(ref imgY, ref imgIY, newWidth, newHeight);
            ArrayHelper2D.ConvertFloatToInt(ref imgCg, ref imgICg, newWidth, newHeight);
            ArrayHelper2D.ConvertFloatToInt(ref imgCo, ref imgICo, newWidth, newHeight);
            BinaryWriter writer = new BinaryWriter(ms);

            writer.Write(width);
            writer.Write(height);
            writer.Write(quality);
            for (int y = 0; y < newHeight; y++)
            {
                for (int x = 0; x < newWidth; x++)
                {
                    writer.Write(imgIY[x, y]);
                    writer.Write(imgICg[x, y]);
                    writer.Write(imgICo[x, y]);
                }
            }
            writer.Close();
            byte[] buffer     = ms.GetBuffer();
            byte[] compressed = Memory.CompressBuffer(ref buffer);
            fs.Write(compressed, 0, compressed.Length);
            fs.Close();
        }
Beispiel #11
0
        public static int[,] LoadFromFile(string sFile, ref int width, ref int height)
        {
            FileStream   fs = new FileStream(sFile, FileMode.Open, FileAccess.Read, FileShare.Read);
            MemoryStream ms = new MemoryStream();

            byte[] buffer = new byte[fs.Length];
            fs.Read(buffer, 0, (int)fs.Length);
            byte[] decompressed = Memory.DecompressBuffer(ref buffer);
            ms.Write(decompressed, 0, (int)decompressed.Length);
            ms.Seek(0, 0);
            fs.Close();
            BinaryReader br = new BinaryReader(ms);
            //int width, height;
            int newWidth, newHeight;

            width  = br.ReadInt32();
            height = br.ReadInt32();
            int quality = br.ReadInt32();

            newWidth  = IntegerMath.ToPowerOf2(width);
            newHeight = IntegerMath.ToPowerOf2(height);

            int[,] imgOrg  = new int[width, height];
            float[,] imgY  = new float[newWidth, newHeight];
            float[,] imgCg = new float[newWidth, newHeight];
            float[,] imgCo = new float[newWidth, newHeight];
            int[,] imgIY   = new int[newWidth, newHeight];
            int[,] imgICg  = new int[newWidth, newHeight];
            int[,] imgICo  = new int[newWidth, newHeight];

            for (int y = 0; y < newHeight; y++)
            {
                for (int x = 0; x < newWidth; x++)
                {
                    imgIY[x, y]  = br.ReadInt32();
                    imgICg[x, y] = br.ReadInt32();
                    imgICo[x, y] = br.ReadInt32();
                }
            }

            br.Close();
            ArrayHelper2D.ConvertIntToFloat(ref imgIY, ref imgY, newWidth, newHeight);
            ArrayHelper2D.ConvertIntToFloat(ref imgICg, ref imgCg, newWidth, newHeight);
            ArrayHelper2D.ConvertIntToFloat(ref imgICo, ref imgCo, newWidth, newHeight);
            Biorthogonal53Wavelet2D wavelet = new Biorthogonal53Wavelet2D(newWidth, newHeight, 8, 8, true);

            //revert simple quantification
            float quant = (float)((100.0f - quality) + 1.0f);

            for (int y = 0; y < newHeight; y++)
            {
                for (int x = 0; x < newWidth; x++)
                {
                    imgY[x, y]  *= quant;
                    imgCg[x, y] *= quant;
                    imgCo[x, y] *= quant;
                }
            }

            wavelet.BackTransformIsotropic2D(ref imgY);
            wavelet.BackTransformIsotropic2D(ref imgCg);
            wavelet.BackTransformIsotropic2D(ref imgCo);
            YCbCrColor.YCbCrArraysToRGBArray(ref imgY, ref imgCg, ref imgCo, width, height, ref imgOrg);
            return(imgOrg);
            //return RGBColor.CreateBitmapFromRGBArray(ref imgOrg, width, height);
        }