예제 #1
0
        public void ConversionPremulTest <TSrcPixel, TDstPixel>()
            where TSrcPixel : unmanaged, Pixel.IConvertTo, Pixel.IValueSetter <Pixel.BGRA32>
            where TDstPixel : unmanaged, Pixel.IConvertTo, Pixel.IValueSetter <Pixel.BGRA32>
        {
            var srcFmt = PixelFormat.TryIdentifyFormat <TSrcPixel>();
            var dstFmt = PixelFormat.TryIdentifyFormat <TDstPixel>();

            var src = new TSrcPixel[5];
            var dst = new TDstPixel[5];
            var cvt = Pixel.GetByteCopyConverter(srcFmt, dstFmt);

            for (int i = 0; i < 5; ++i)
            {
                src[i].SetValue(new Pixel.BGRA32(i * 50, 255 - i * 50, i * 30, 20 + i * 30));
            }

            Pixel.GetPixelCopyConverter <TSrcPixel, TDstPixel>().Invoke(src, dst);

            for (int i = 0; i < 5; ++i)
            {
                var srcA = src[i].To <Pixel.BGRA32>();
                var dstA = dst[i].To <Pixel.BGRA32>();

                var srcP = new Pixel.RGBP32(srcA);
                var dstP = new Pixel.RGBP32(dstA);

                Assert.AreEqual(srcP.PreR, dstP.PreR, 1);
                Assert.AreEqual(srcP.PreG, dstP.PreG, 1);
                Assert.AreEqual(srcP.PreB, dstP.PreB, 1);
                Assert.AreEqual(srcP.A, dstP.A, 1);
            }
        }
예제 #2
0
        public void ConversionTest <TSrcPixel, TDstPixel>()
            where TSrcPixel : unmanaged, Pixel.IConvertTo, Pixel.IValueSetter <Pixel.BGRA32>
            where TDstPixel : unmanaged, Pixel.IConvertTo, Pixel.IValueSetter <Pixel.BGRA32>
        {
            var srcFmt = PixelFormat.TryIdentifyFormat <TSrcPixel>();
            var dstFmt = PixelFormat.TryIdentifyFormat <TDstPixel>();

            var src = new TSrcPixel[5];
            var dst = new TDstPixel[5];

            for (int i = 0; i < 5; ++i)
            {
                src[i].SetValue(new Pixel.BGRA32(i * 50, 255 - i * 50, i * 30, 20 + i * 30));
            }

            Pixel.GetPixelCopyConverter <TSrcPixel, TDstPixel>().Invoke(src, dst);

            for (int i = 0; i < 5; ++i)
            {
                var srcP = src[i].To <Pixel.BGRA32>();
                var dstP = dst[i].To <Pixel.BGRA32>();

                if (!srcFmt.HasUnpremulAlpha || !dstFmt.HasUnpremulAlpha)
                {
                    srcP = new Pixel.BGRA32(srcP.R, srcP.G, srcP.B, (Byte)255);
                    dstP = new Pixel.BGRA32(dstP.R, dstP.G, dstP.B, (Byte)255);
                }

                Assert.AreEqual(srcP, dstP);
            }
        }