public static PixImage ToPixImage(this IPixImage2d image) { if (image is PixImage pixImage) { return(pixImage); } var size = image.Size; var pixFormat = image.PixFormat; if (image.Data.GetType().GetElementType() != pixFormat.Type) { throw new ArgumentException("type mismatch in supplied IPixImage2d"); } return(PixImage.Create(image.Data, pixFormat.Format, size.X, size.Y)); }
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>()); }