Beispiel #1
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()));
        }
Beispiel #3
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;
        }