/// <summary> /// Copy function for color conversions. Note that the /// new color format must have the same number of channels /// as the old one, and the result of the supplied conversion /// function is reinterpreted as a color in the new format. /// </summary> /// <typeparam name="Tv"></typeparam> /// <param name="fun"></param> /// <param name="format"></param> /// <returns></returns> public PixImage <T> Copy <Tv>(Func <Tv, Tv> fun, Col.Format format) { var mat = GetVolume <Tv>().MapWindow(fun); var vol = new Volume <T>(mat.Data, Volume.Info); return(new PixImage <T>(format, vol)); }
public static void CodeColFormat(this ICoder coder, ref Col.Format colFormat) { var reading = coder.IsReading; string formatName = reading ? null : colFormat.GetName().ToString(); coder.CodeString(ref formatName); if (reading) { colFormat = Col.FormatOfName(formatName); } }
protected static Tup <PixelFormat, Col.Format> GetStoreFormats(Type type, Col.Format format) { Tup <PixelFormat, Col.Format> formatPair; if (s_pixelFormatOfFormat.TryGetValue(new PixFormat(type, format), out formatPair)) { return(formatPair); } throw new ArgumentException("unsupported pixel type"); }
public PixVolume <T> ToPixVolume <T>(Col.Format format) { var castVolume = this as PixVolume <T>; if (castVolume != null && castVolume.Format == format && castVolume.ChannelCount == format.ChannelCount()) { return(castVolume); } return(new PixVolume <T>(format, this)); }
public static PixImage <T> ToPixImage <T>(this Volume <T> volume, Col.Format format) { var ch = format.ChannelCount(); if (ch > volume.Size.Z) { throw new ArgumentException("volume has not enough channels for requested format"); } if (ch < volume.Size.Z) { volume = volume.SubVolume(V3l.Zero, new V3l(volume.SX, volume.SY, ch)); } return(new PixImage <T>(format, volume.ToImage())); }
public PixVolume <T> ToFormat(Col.Format format) { return(Format == format ? this : new PixVolume <T>(format, this)); }
public PixVolume(Col.Format format) { Format = format; }
/// <summary> /// Copy constructor: ALWAYS creates a copy of the data! /// </summary> public PixVolume(Col.Format format, PixVolume pixImage) { var size = pixImage.Size; var channelCount = format.ChannelCount(); var tensor4 = CreateTensor4 <T>(size.X, size.Y, size.Z, channelCount); var order = format.ChannelOrder(); var typedPixImage = pixImage as PixVolume <T>; if (channelCount != pixImage.ChannelCount && !(channelCount == 3 && pixImage.ChannelCount == 4)) { if (channelCount == 4 && pixImage.ChannelCount == 3) { channelCount = 3; // only copy three channels, and set channel 4 (implied alpha) to 'opaque' tensor4.SubXYZVolume(3).Set(Col.Info <T> .MaxValue); } else if (channelCount > 1 && pixImage.ChannelCount == 1) { if (typedPixImage != null) { var vol = typedPixImage.Volume; for (int i = 0; i < channelCount; i++) { tensor4.SubXYZVolume(i).Set(vol); } } else { for (int i = 0; i < channelCount; i++) { pixImage.CopyChannelTo(0, tensor4.SubXYZVolume(i)); } } Tensor4 = tensor4; Format = format; return; } else { throw new ArgumentException("cannot perform color space conversion"); } } if (format.IsPremultiplied() != pixImage.Format.IsPremultiplied()) { throw new NotImplementedException( "conversion between alpha and premultiplied alpha not implemented yet"); } if (typedPixImage != null) { var channelArray = typedPixImage.ChannelArray; for (int i = 0; i < channelCount; i++) { tensor4.SubXYZVolume(order[i]).Set(channelArray[i]); } } else { for (int i = 0; i < channelCount; i++) { pixImage.CopyChannelTo(i, tensor4.SubXYZVolume(order[i])); } } Tensor4 = tensor4; Format = format; }
public PixVolume(Col.Format format, int sizeX, int sizeY, int sizeZ, int channelCount) : this(format, CreateTensor4 <T>(sizeX, sizeY, sizeZ, channelCount)) { }
public PixVolume(Col.Format format, V3i size, int channelCount) : this(format, CreateTensor4 <T>(size.X, size.Y, size.Z, channelCount)) { }
public PixVolume(Col.Format format, V3i size) : this(format, CreateTensor4 <T>(size.X, size.Y, size.Z, Col.ChannelCount(format))) { }
public PixVolume(Col.Format format, Tensor4 <T> tensor4) : base(format) { Tensor4 = tensor4; }
public abstract PixVolume ToPixVolume(Col.Format format);