Ejemplo n.º 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>());
        }
 /// <summary>
 /// System.Drawing.Color to C3ui.
 /// </summary>
 public static C3ui ToC3ui(this Color color) => new C3ui(
     Col.UIntFromByte(color.R),
     Col.UIntFromByte(color.G),
     Col.UIntFromByte(color.B));
Ejemplo n.º 3
0
 /// <summary>
 /// Returns the int representation of the supplied C3f color.
 /// </summary>
 public static int FromRgbToInt(this C3f self)
 {
     return(Col.ByteFromDouble(self.R) << 16 |
            Col.ByteFromDouble(self.G) << 8 |
            Col.ByteFromDouble(self.B));
 }
 /// <summary>
 /// System.Drawing.Color to C3us.
 /// </summary>
 public static C3us ToC3us(this Color color) => new C3us(
     Col.UShortFromByte(color.R),
     Col.UShortFromByte(color.G),
     Col.UShortFromByte(color.B));
 /// <summary>
 /// C3ui to System.Drawing.Color.
 /// </summary>
 public static Color ToColor(this C3ui color) => Color.FromArgb(
     Col.ByteFromUInt(color.R),
     Col.ByteFromUInt(color.G),
     Col.ByteFromUInt(color.B));
 /// <summary>
 /// C4d to System.Drawing.Color.
 /// </summary>
 public static Color ToColor(this C4d color) => Color.FromArgb(
     Col.ByteFromDoubleClamped(color.A),
     Col.ByteFromDoubleClamped(color.R),
     Col.ByteFromDoubleClamped(color.G),
     Col.ByteFromDoubleClamped(color.B));
 /// <summary>
 /// System.Drawing.Color to C4d.
 /// </summary>
 public static C4d ToC4d(this Color color) => new C4d(
     Col.DoubleFromByte(color.R),
     Col.DoubleFromByte(color.G),
     Col.DoubleFromByte(color.B),
     Col.DoubleFromByte(color.A));
 /// <summary>
 /// System.Drawing.Color to C4f.
 /// </summary>
 public static C4f ToC4f(this Color color) => new C4f(
     Col.FloatFromByte(color.R),
     Col.FloatFromByte(color.G),
     Col.FloatFromByte(color.B),
     Col.FloatFromByte(color.A));
 /// <summary>
 /// C4f to System.Drawing.Color.
 /// </summary>
 public static Color ToColor(this C4f color) => Color.FromArgb(
     Col.ByteFromFloatClamped(color.A),
     Col.ByteFromFloatClamped(color.R),
     Col.ByteFromFloatClamped(color.G),
     Col.ByteFromFloatClamped(color.B));
 /// <summary>
 /// C4us to System.Drawing.Color.
 /// </summary>
 public static Color ToColor(this C4us color) => Color.FromArgb(
     Col.ByteFromUShort(color.A),
     Col.ByteFromUShort(color.R),
     Col.ByteFromUShort(color.G),
     Col.ByteFromUShort(color.B));
 /// <summary>
 /// System.Drawing.Color to C3d.
 /// </summary>
 public static C3d ToC3d(this Color color) => new C3d(
     Col.DoubleFromByte(color.R),
     Col.DoubleFromByte(color.G),
     Col.DoubleFromByte(color.B));
 /// <summary>
 /// System.Drawing.Color to C3f.
 /// </summary>
 public static C3f ToC3f(this Color color) => new C3f(
     Col.FloatFromByte(color.R),
     Col.FloatFromByte(color.G),
     Col.FloatFromByte(color.B));