Ejemplo n.º 1
0
        /// <summary>
        /// Set video type for the specified pin interface
        /// </summary>
        /// <param name="streamConfig"></param>
        /// <param name="newValue"></param>
        public void setMediaSubType(IAMStreamConfig streamConfig, ColorSpaceEnum newValue)
        {
            IntPtr      pmt       = IntPtr.Zero;
            AMMediaType mediaType = new AMMediaType();

            try
            {
                // Get the current format info
                int hr = streamConfig.GetFormat(out pmt);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }
                Marshal.PtrToStructure(pmt, mediaType);

                // Change the media subtype
                // Each enum value has a Guid associated with it
                // We store the Guid as a string in a LabelAttribute
                // applied to each enum value. See the ColorSpaceEnum.
                mediaType.subType = new Guid(LabelAttribute.FromMember(newValue));

                // Save the changes
                hr = streamConfig.SetFormat(mediaType);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }
            }
            finally
            {
                DsUtils.FreeAMMediaType(mediaType);
                Marshal.FreeCoTaskMem(pmt);
            }
        }
Ejemplo n.º 2
0
        private void UpdateInterface(ColorSpaceEnum space)
        {
            UpdateRgb();
            UpdateHls();
            UpdateCmyk();

            UpdateBox();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get the video type for the specified pin interface
        /// </summary>
        /// <param name="streamConfig"></param>
        /// <returns></returns>
        public ColorSpaceEnum getMediaSubType(IAMStreamConfig streamConfig)
        {
            ColorSpaceEnum retval = ColorSpaceEnum.RGB24;
            bool           found;
            IntPtr         pmt       = IntPtr.Zero;
            AMMediaType    mediaType = new AMMediaType();

            try
            {
                // Get the current format info
                int hr = streamConfig.GetFormat(out pmt);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }
                Marshal.PtrToStructure(pmt, mediaType);

                // Search the Guids to find the correct enum value.
                // Each enum value has a Guid associated with it
                // We store the Guid as a string in a LabelAttribute
                // applied to each enum value. See the ColorSpaceEnum.
                found = false;
                foreach (object c in Enum.GetValues(typeof(ColorSpaceEnum)))
                {
                    if (mediaType.subType == new Guid(LabelAttribute.FromMember(c)))
                    {
                        found  = true;
                        retval = (ColorSpaceEnum)c;
                    }
                }
                if (!found)
                {
#if DEBUG
                    String mediaSubType;
                    MakeFourCC(mediaType.subType, out mediaSubType);
                    Debug.WriteLine("Unknown color space (media subtype=" + mediaSubType + "):" + mediaType.subType);
#endif
                    throw new ApplicationException("Unknown color space (media subtype):" + mediaType.subType);
                }
            }
            finally
            {
                DsUtils.FreeAMMediaType(mediaType);
                Marshal.FreeCoTaskMem(pmt);
            }

            return(retval);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Find media data by trial and error, just try every media type
        /// in the list, the ones that do not return an error, are accepted.
        /// This function might be handy if DShowNET is used as library
        /// instead of DirectShowLib.
        /// This function should be called with a derendered graph only,
        /// so with capture device only and no rendering of audio, video or
        /// VBI.
        /// </summary>
        /// <param name="streamConfig"></param>
        /// <returns></returns>
        public bool FindMediaData(IAMStreamConfig streamConfig)
        {
            bool result = false;

            try
            {
                ColorSpaceEnum currentValue = this.getMediaSubType(streamConfig);
                if (this.subTypeList != null)
                {
                    this.subTypeList.Clear();
                }

                foreach (object c in Enum.GetValues(typeof(ColorSpaceEnum)))
                {
                    Guid subType = new Guid(LabelAttribute.FromMember(c));
                    if (this.setMediaSubType(streamConfig, subType))
                    {
                        if (this.subTypeList == null)
                        {
                            this.subTypeList = new ArrayList();
                        }
                        // Check if subtype is already in list,
                        // if so then do not add, else add to list
                        bool notinlist = true;
                        for (int i = 0; (i < this.subTypeList.Count) && (notinlist); i++)
                        {
                            if (((Guid)this.subTypeList[i]) == subType)
                            {
                                notinlist = false;
                            }
                        }

                        if (notinlist)
                        {
                            this.subTypeList.Add(subType);
                            result = true;
                        }
                    }
                }
                this.setMediaSubType(streamConfig, currentValue);
                return(result);
            }
            catch {}
            return(result);
        }
Ejemplo n.º 5
0
        private void RestoreValues(ColorSpaceEnum space)
        {
            switch (space)
            {
            case ColorSpaceEnum.RGB:
                UpdateRgb();
                break;

            case ColorSpaceEnum.HSL:

                break;

            case ColorSpaceEnum.CMYK:
                UpdateCmyk();
                break;

            default:
                break;
            }
        }
Ejemplo n.º 6
0
        // TextChanged events
        private void TextBoxChanged(ColorSpaceEnum space, ValidatorType validatorType, TextBox textBox)
        {
            // Supress declining partial typing
            if (textBox.Text.Length > 0 && (textBox.Text[0] == ',' || (textBox.Text[textBox.Text.Length - 1] == ',')))
            {
                return;
            }

            if (_validators[validatorType].Validate(textBox.Text))
            {
                if (!_changeInProgress)
                {
                    ChangeColor(space);
                    textBox.ClearUndo();
                }
            }
            else
            {
                RestoreValues(space);
                InfoLabel.Text = _validationErrors[space];
            }
        }
Ejemplo n.º 7
0
        private void ChangeColor(ColorSpaceEnum space)
        {
            _changeInProgress = true;

            switch (space)
            {
            case ColorSpaceEnum.RGB:
                _colorHolder.RgbColor = new RgbColor(
                    Double.Parse(RgbRBox.Text),
                    Double.Parse(RgbGBox.Text),
                    Double.Parse(RgbBBox.Text));
                break;

            case ColorSpaceEnum.HSL:
                _colorHolder.HslColor = new HslColor(
                    Double.Parse(HslHBox.Text),
                    Double.Parse(HslLBox.Text),
                    Double.Parse(HslSBox.Text));
                break;

            case ColorSpaceEnum.CMYK:
                _colorHolder.CmykColor = new CmykColor(
                    Double.Parse(CmykCBox.Text),
                    Double.Parse(CmykMBox.Text),
                    Double.Parse(CmykYBox.Text),
                    Double.Parse(CmykKBox.Text));
                break;

            default:
                break;
            }

            UpdateInterface(space);

            _changeInProgress = false;
        }
Ejemplo n.º 8
0
		/// <summary>
		/// Set video type for the specified pin interface
		/// </summary>
		/// <param name="streamConfig"></param>
		/// <param name="newValue"></param>
		public void setMediaSubType(IAMStreamConfig streamConfig, ColorSpaceEnum newValue)
		{
#if DSHOWNET
			IntPtr pmt = IntPtr.Zero;
#endif
			AMMediaType mediaType = new AMMediaType();

			try 
			{
				// Get the current format info
#if DSHOWNET
				int hr = streamConfig.GetFormat(out pmt);
				if(hr < 0)
				{
					Marshal.ThrowExceptionForHR(hr);
				}
				Marshal.PtrToStructure(pmt, mediaType);
#else
				int hr = streamConfig.GetFormat(out mediaType);
				if(hr < 0)
				{
					Marshal.ThrowExceptionForHR(hr);
				}
#endif

				// Change the media subtype
				// Each enum value has a Guid associated with it
				// We store the Guid as a string in a LabelAttribute
				// applied to each enum value. See the ColorSpaceEnum.
				mediaType.subType = new Guid(LabelAttribute.FromMember(newValue));

				// Save the changes
				hr = streamConfig.SetFormat(mediaType);
				if(hr < 0)
				{
					Marshal.ThrowExceptionForHR(hr);
				}		
			}
			finally
			{
				DsUtils.FreeAMMediaType(mediaType);
#if DSHOWNET
				Marshal.FreeCoTaskMem(pmt);
#endif
			}
		}