public static TPixel GetReferenceBGRP32 <TPixel>(this Pixel.BGRP32 pixel)
            where TPixel : unmanaged
        {
            if (typeof(TPixel) == typeof(Pixel.BGR24))
            {
                var pix = pixel.GetReferenceBGR24();
                return(MEMUNSAFE.As <Pixel.BGR24, TPixel>(ref pix));
            }

            if (typeof(TPixel) == typeof(Pixel.RGB24))
            {
                var pix = pixel.GetReferenceRGB24();
                return(MEMUNSAFE.As <Pixel.RGB24, TPixel>(ref pix));
            }

            if (typeof(TPixel) == typeof(Pixel.BGRA32))
            {
                var pix = pixel.GetReferenceBGRA32();
                return(MEMUNSAFE.As <Pixel.BGRA32, TPixel>(ref pix));
            }

            if (typeof(TPixel) == typeof(Pixel.RGBA32))
            {
                var pix = pixel.GetReferenceRGBA32();
                return(MEMUNSAFE.As <Pixel.RGBA32, TPixel>(ref pix));
            }

            if (typeof(TPixel) == typeof(Pixel.ARGB32))
            {
                var pix = pixel.GetReferenceARGB32();
                return(MEMUNSAFE.As <Pixel.ARGB32, TPixel>(ref pix));
            }

            throw new NotImplementedException(typeof(TPixel).Name);
        }
Exemple #2
0
        // 9.215 ns
        public static Pixel.BGRA32 ToUnpremulReference(Pixel.BGRP32 src)
        {
            uint aa = src.A;

            return(new Pixel.BGRA32
                   (
                       (Byte)((src.PreR * 255u) / aa),
                       (Byte)((src.PreG * 255u) / aa),
                       (Byte)((src.PreB * 255u) / aa),
                       src.A));
        }
Exemple #3
0
 // 8.054 ns
 public Pixel.BGRA32 ToUnpremulFast1(Pixel.BGRP32 src)
 {
     if (src.A == 0)
     {
         return(default);