예제 #1
0
        public static PixImage <T> ToPixImage <T>(this IPixImage2d image)
        {
            if (image is PixImage <T> pixImage)
            {
                return(pixImage);
            }
            var size      = image.Size;
            var pixFormat = image.PixFormat;

            if (image.Data is T[] data)
            {
                if (data.GetType().GetElementType() != pixFormat.Type)
                {
                    throw new ArgumentException("type mismatch in supplied IPixImage2d");
                }
                var volume = data.CreateImageVolume(new V3l(size.X, size.Y, Col.ChannelCount(pixFormat.Format)));
                return(new PixImage <T>(pixFormat.Format, volume));
            }
            return(image.ToPixImage().ToPixImage <T>());
        }