Пример #1
0
        public static AudioFormat SingleChannel(AudioFormat other, int componentIndex)
        {
            int otherComponentsLength = other.Components.Length;

            if (otherComponentsLength == 1)
            {
                return(other);
            }

            if (componentIndex > otherComponentsLength)
            {
                throw new System.ArgumentOutOfRangeException("componentIndex");
            }

            Media.Codec.MediaComponent componentNeeded = other.Components[componentIndex];

            return(new AudioFormat(other.SampleRate, other.IsSigned, other.ByteOrder, other.DataLayout, Common.Extensions.Linq.LinqExtensions.Yield(componentNeeded).ToArray()));
        }
Пример #2
0
        public RGB(Image source, Image dest)
            : base(source, dest, Codec.TransformationQuality.Highest)
        {
            //Should be exceptions.
            //Should have a utility method which checks for all required components in one shot.
            if (source.MediaFormat.GetComponentById(Media.Codecs.Image.ImageFormat.RedChannelId) == null)
            {
                return;
            }
            if (source.MediaFormat.GetComponentById(Media.Codecs.Image.ImageFormat.BlueChannelId) == null)
            {
                return;
            }
            if (source.MediaFormat.GetComponentById(Media.Codecs.Image.ImageFormat.GreenChannelId) == null)
            {
                return;
            }

            //Only can convert to YUV right now, not AYUV or YUVA or any other type.
            if (dest.ImageFormat.Components.Length > 3)
            {
                return;
            }

            //Check for the luma channel
            Media.Codec.MediaComponent component = source.MediaFormat.GetComponentById(Media.Codecs.Image.ImageFormat.LumaChannelId);

            //Ensure it at the first component
            if (component == null || source.MediaFormat.IndexOf(component) != 0)
            {
                return;
            }

            //Check for the chroma major component
            component = source.MediaFormat.GetComponentById(Media.Codecs.Image.ImageFormat.ChromaMajorChannelId);

            //Ensure it at the second component
            if (component == null || source.MediaFormat.IndexOf(component) != 1)
            {
                return;
            }

            //Check for the chroma minor component
            component = source.MediaFormat.GetComponentById(Media.Codecs.Image.ImageFormat.ChromaMinorChannelId);

            //Ensure it at the last component
            if (component == null || source.MediaFormat.IndexOf(component) != 2)
            {
                return;
            }

            //Ensure the destination image has been configured for sub sampling
            if (false == dest.ImageFormat.IsSubSampled)
            {
                return;
            }

            //Only can convert to Planar YUV right now (420)
            if (dest.ImageFormat.DataLayout != Codec.DataLayout.Planar)
            {
                return;
            }

            //Should be a constant in ImageFormat, 1 looks weird but >> 1 divides by 2, >> 2 by 4
            //Could also change the WidthsAndHights to be an enum or Rational... SubSampling...
            if (dest.ImageFormat.Heights[1] != 1)
            {
                return;
            }

            if (dest.ImageFormat.Widths[1] != 1)
            {
                return;
            }
        }