예제 #1
0
        /// <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));
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        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");
        }
예제 #4
0
        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()));
        }
예제 #6
0
 public PixVolume <T> ToFormat(Col.Format format)
 {
     return(Format == format ? this : new PixVolume <T>(format, this));
 }
예제 #7
0
 public PixVolume(Col.Format format)
 {
     Format = format;
 }
예제 #8
0
        /// <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;
        }
예제 #9
0
 public PixVolume(Col.Format format, int sizeX, int sizeY, int sizeZ, int channelCount)
     : this(format, CreateTensor4 <T>(sizeX, sizeY, sizeZ, channelCount))
 {
 }
예제 #10
0
 public PixVolume(Col.Format format, V3i size, int channelCount)
     : this(format, CreateTensor4 <T>(size.X, size.Y, size.Z, channelCount))
 {
 }
예제 #11
0
 public PixVolume(Col.Format format, V3i size)
     : this(format, CreateTensor4 <T>(size.X, size.Y, size.Z, Col.ChannelCount(format)))
 {
 }
예제 #12
0
 public PixVolume(Col.Format format, Tensor4 <T> tensor4)
     : base(format)
 {
     Tensor4 = tensor4;
 }
예제 #13
0
 public abstract PixVolume ToPixVolume(Col.Format format);