示例#1
0
        public static unsafe byte[] ConvertToBytes <TIn>(
            this IImageFormatter <TIn, IntPtr> Formatter, [In] ref ImageBuffer <TIn> In,
            PixelFlags Options = DefaultOptions)
        {
            if (null == Formatter)
            {
                throw new NullReferenceException("Formatter was null");
            }

            if (In.Dimensions.ByteCount == 0)
            {
                return(null);
            }

            int Size = Formatter.CalculateByteSize(ref In);

            if (Size <= 0)
            {
                return(null);
            }
            byte[] Buf = new byte[Size];
            fixed(byte *ptr = Buf)
            {
                var O = new ImageBuffer <IntPtr>((IntPtr)ptr, In.Dimensions / Options, (uint)Size);

                if (!Formatter.Convert(ref In, ref O))
                {
                    Buf = null;
                }
            }

            return(Buf);
        }
示例#2
0
 public static bool Convert <TIn, TOut>(
     this IImageFormatter <TIn, TOut[]> Formatter,
     [In] ref ImageBuffer <TIn> In,
     TOut[] Out,
     PixelFlags Options = DefaultOptions)
 {
     return(Formatter.Convert <TIn, TOut[]>(
                In: ref In,
                Out: ref Out,
                Offset: 0u,
                Length: (uint)Out.Length,
                Options: Options));
 }
示例#3
0
        public static bool Convert <TIn, TOut>(
            this IImageFormatter <TIn, TOut> Formatter,
            [In] ref ImageBuffer <TIn> In,
            [In, Out] ref TOut Out, uint Offset, uint Length, PixelFlags Options = DefaultOptions)
        {
            if (null == Formatter)
            {
                throw new NullReferenceException("Formatter was null");
            }
            var OutBuf = new ImageBuffer <TOut>(Out, In.Dimensions / Options, Offset, Length);

            try
            {
                return(Formatter.Convert(ref In, ref OutBuf));
            }
            finally
            {
                Out = OutBuf.Buffer;
            }
        }