Esempio n. 1
0
        public void Receive(PinIn <Image> pin, Image img)
        {
            /* choose an angle */
            double angle        = minAngle + (maxAngle - minAngle) * random.NextDouble();
            double angleRadians = -angle * Math.PI / 180; /*
                                                           *
                                                           * /* figure out new width and height as well as appropriate place to put rotated image */
            double s            = Math.Sin(angleRadians);
            double c            = Math.Cos(angleRadians);
            double newWidth     = img.Width * Math.Abs(c) + img.Height * Math.Abs(s);
            double newHeight    = img.Height * Math.Abs(c) + img.Width * Math.Abs(s);
            double minX         = Math.Min(0, Math.Min(c * img.Width, Math.Min(s * img.Height, c * img.Width + s * img.Height)));
            double minY         = Math.Min(0, Math.Min(-s * img.Width, Math.Min(c * img.Height, c * img.Height - s * img.Width)));

            /* create the rotated image */
            Graphics gOld     = Graphics.FromImage(img);
            Image    outImage = new Bitmap(1 + (int)newWidth, 1 + (int)newHeight, gOld);

            gOld.Dispose();
            Graphics g = Graphics.FromImage(outImage);

            g.SmoothingMode     = SmoothingMode.AntiAlias;
            g.PixelOffsetMode   = PixelOffsetMode.HighQuality;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.TranslateTransform(-(float)minX + 1, -(float)minY + 1);
            g.RotateTransform((float)angle);
            g.DrawImage(img, 0, 0);
            g.Dispose();

            OutputPin.Send(outImage);
        }
Esempio n. 2
0
 public GenericFilter(Predicate <T> filterFunction)
 {
     this.filterFunction = filterFunction;
     this.InputPin       = new PinIn <T>(this);
     this.SuccessPin     = new PinOut <T>();
     this.FailurePin     = new PinOut <T>();
 }
Esempio n. 3
0
        public GenericDelay(TimeSpan interval)
        {
            InputPin  = new PinIn <T>(this);
            OutputPin = new PinOut <T>();

            this.interval = interval;
            next          = DateTime.Now;
        }
Esempio n. 4
0
        public void Receive(PinIn <Image> pin, Image img)
        {
            lock (this)
            {
                dff.SetPicture(img);
            }

            OutputPin.Send(img);
        }
Esempio n. 5
0
        public RotateFilter(float minAngle, float maxAngle)
        {
            InputPin  = new PinIn <Image>(this);
            OutputPin = new PinOut <Image>();
            random    = new Random();

            this.minAngle = minAngle;
            this.maxAngle = maxAngle;
        }
Esempio n. 6
0
        public CanvasFilter()
        {
            PictureInputPin = new PinIn <Image>(this);
            CanvasInputPin  = new PinIn <Image>(this);
            OutputPin       = new PinOut <Image>();

            pic    = null;
            canvas = null;
            random = new Random();
        }
Esempio n. 7
0
    public void Connect(PinIn target)
    {
        target.source = this;
        targets.Add(target);

        module.core.WireTarget(index, target.GetSignal());
        target.line.SetColor(color);

        module.core.MarkActive();
    }
Esempio n. 8
0
    public void Disconnect(PinIn target)
    {
        target.source = null;
        targets.Remove(target);

        if (!module.core.RemoveWire(index, target.GetSignal()))
        {
            Debug.LogError("Failed to remove wire!");
        }
    }
Esempio n. 9
0
        public DisplayFilter()
        {
            InputPin  = new PinIn <Image>(this);
            OutputPin = new PinOut <Image>();

            dff = new DisplayFilterForm();

            Thread thr = new Thread(new ParameterizedThreadStart(DispForm));

            thr.IsBackground = true;
            thr.Start(dff);
        }
Esempio n. 10
0
        public BorderFilter(Color borderColor, int borderSize)
        {
            if (borderSize < 0)
            {
                throw new ArgumentException("borderWidth must be positive");
            }

            InputPin  = new PinIn <Image>(this);
            OutputPin = new PinOut <Image>();

            this.borderColor = borderColor;
            this.borderSize  = borderSize;
        }
Esempio n. 11
0
        public void Receive(PinIn <Image> pin, Image img)
        {
            string wallName = Path.Combine(Environment.CurrentDirectory, "wall.bmp");

            lock (this)
            {
                FileStream wallStream = new FileStream(wallName, FileMode.OpenOrCreate);
                img.Save(wallStream, ImageFormat.Bmp);
                wallStream.Close();
                SetWallpaper(wallName);
            }

            OutputPin.Send(img);
        }
Esempio n. 12
0
        public void Receive(PinIn <Image> pin, Image img)
        {
            Graphics gOld     = Graphics.FromImage(img);
            Bitmap   outImage = new Bitmap(img.Width + 2 * borderSize, img.Height + 2 * borderSize, gOld);

            gOld.Dispose();
            Graphics g = Graphics.FromImage(outImage);

            g.Clear(borderColor);
            g.DrawImage(img, new Point(borderSize, borderSize));
            g.Dispose();

            OutputPin.Send(outImage);
        }
            public Shift165N(int PLPin, int CPPin, int CEPin, int Q7Pin, int NumOfRegisters)
            {
                this.PinPL = new PinOut(PLPin);
                this.PinCP = new PinOut(CPPin);
                this.PinCE = new PinOut(CEPin);
                this.PinQ7 = new PinIn(Q7Pin);

                //calculate the number of bits that need to be set
                PinQT = NumOfRegisters * 8 - 1;

                this.currentstate = new BitArray(PinQT + 1);

                read();
                this.timer = ThreadPoolTimer.CreatePeriodicTimer(Timer_tick, TimeSpan.FromMilliseconds(125));
            }
Esempio n. 14
0
        public void Receive(PinIn <Image> pin, Image item)
        {
            bool  timeToOutput = false;
            Image myPic        = null;
            Image myCanvas     = null;

            lock (this)
            {
                if (pin == PictureInputPin)
                {
                    pic = item;
                }
                if (pin == CanvasInputPin)
                {
                    canvas = item;
                }

                if (pic != null && pin != null)
                {
                    timeToOutput = true;
                    myPic        = pic;
                    myCanvas     = canvas;
                    pic          = null;
                    canvas       = null;
                }
            }

            if (timeToOutput)
            {
                Graphics g = Graphics.FromImage(myCanvas);

                double X = myCanvas.Width * random.NextDouble() - myPic.Width / 2;   /* [-pic.width/2, canvas.width - pic.width/2] */
                double Y = myCanvas.Height * random.NextDouble() - myPic.Height / 2; /* ditto but for height */

                g.DrawImage(myPic, (float)X, (float)Y);
                g.Dispose();

                OutputPin.Send(myCanvas);
            }
        }
Esempio n. 15
0
        public void Receive(PinIn <T> pin, T item)
        {
            TimeSpan delay;

            lock (this)
            {
                delay = next - DateTime.Now;
                if (next < DateTime.Now)
                {
                    next = DateTime.Now + interval;
                }
                else
                {
                    next = next + interval;
                }
            }

            if (delay.TotalSeconds > 0)
            {
                Thread.Sleep(delay);
            }
            OutputPin.Send(item);
        }
Esempio n. 16
0
        /*
         * TIVO Files Pin Mapping (pin name between ||) (NOTE: XXXX changes from each machine and AC3 changes if the audio codec changes)
         *  Audio       -> Source Pin |Output| -> MainConcept MPEG DeMultiplexer |Input| |AC3 (PID XXXX @ Prog# 1)|    -> Dump |Input|
         *  Video       -> Source Pin |Output| -> MainConcept MPEG DeMultiplexer |Input| |Video (PID XXXX @ Prog# 1)|  -> Dump |Input|
         */
        public void BuildGraph()
        {
            int hr;

            IntPtr    fetched  = IntPtr.Zero;
            IntPtr    fetched2 = IntPtr.Zero;
            IEnumPins FilterPins;

            IPin[] pins = new IPin[1];
            string PinID;

            // TiVO Directshow filters are only accessible through userspace otherwise decryption fails, so if we are running the engine as a service (instead of command line) we should prompt the user
            if ((_Ext == "tivo") && GlobalDefs.IsEngineRunningAsService)
            {
                _jobLog.WriteEntry(this, "You need to start MCEBuddy engine as a Command line program. TiVO Desktop Directshow decryption filters do not work with a Windows Service.", Log.LogEntryType.Error);
            }

            // Create the source filter for dvrms or wtv or TIVO (will automatically connect to TIVODecryptorTag in source itself)
            _jobLog.WriteEntry(this, "Loading file using DirectShow source filter", Log.LogEntryType.Debug);
            hr = _gb.AddSourceFilter(_SourceFile, "Source Filter", out _SourceF);
            checkHR(hr);

            // If this is a TIVO while, while the source filter automatically decrypts the inputs we need to connect the MPEG demultiplexer to get the audio and video output pins
            if (_Ext == "tivo")
            {
                IPin               PinOut, PinIn;
                IntPtr             ptr;
                PinInfo            demuxPinInfo;
                List <IBaseFilter> filterList = new List <IBaseFilter>();

                // Check if the source filter is a TiVO source filter (otherwise sometimes it tries to use the normal source filter which will fail since the stream in encrypted)
                string     vendorInfo;
                FilterInfo filterInfo;

                _SourceF.QueryFilterInfo(out filterInfo);
                _SourceF.QueryVendorInfo(out vendorInfo);

                _jobLog.WriteEntry(this, "TiVO Source filter loaded by Directshow -> " + filterInfo.achName + " (" + vendorInfo + ")", Log.LogEntryType.Debug);

                if (vendorInfo == null || !vendorInfo.ToLower().Contains("tivo"))
                {
                    string exception = "";

                    // Check if you are running 64Bit MCEBuddy, TiVO needs 32bit MCEBuddy since TiVO directshow dll are 32bit and can only be loaded by 32bit processes
                    if (IntPtr.Size == 8)
                    {
                        exception += "You need to run 32bit MCEBuddy, TiVO Directshow fiters cannot be accessed by a 64bit program.";
                    }
                    else
                    {
                        exception += "TiVO Desktop installation not detected by Windows DirectShow.";
                    }

                    throw new Exception(exception); // Get out of here and let the parent know something is wrong
                }

                hr = _SourceF.FindPin("Output", out PinOut); // Get the Source filter pinOut |Output|
                checkHR(hr);

                // When TIVO desktop is installed, Render automatically builds the filter graph with the necessary demuxing filters - we cannot manually add the MainConcept demux filter since the class isn't registered but somehow Render is able to find it and load it (along with other redundant filters like DTV, audio etc which we need to remove)
                _jobLog.WriteEntry(this, "DirectShow building TiVO filter chain", Log.LogEntryType.Debug);
                hr = _gb.Render(PinOut);
                checkHR(hr);

                hr = PinOut.ConnectedTo(out ptr); // Find out which input Pin (Mainconcept Demux filter) the output of the Source Filter is connected to
                checkHR(hr);
                PinIn = (IPin)Marshal.GetObjectForIUnknown(ptr);

                hr = PinIn.QueryPinInfo(out demuxPinInfo); // Get the mainconcept demux filter from the pin
                checkHR(hr);

                demuxPinInfo.filter.QueryFilterInfo(out filterInfo);
                demuxPinInfo.filter.QueryVendorInfo(out vendorInfo);
                _jobLog.WriteEntry(this, "Checking downstream TiVO filter chain starting with TiVO Demux filter -> " + filterInfo.achName + " (" + vendorInfo + ")", Log.LogEntryType.Debug);
                if (!GetFilterChain(demuxPinInfo.filter, PinDirection.Output, filterList)) // Get the list of all downstreams (redudant) filters (like DTV, Audio, video render etc) from the demux filter that were added by the automatic Render function above (check if there are no downstream filters, then TIVO desktop is not installed)
                {
                    throw new Exception("Unable to get TIVO filter chain");
                }

                // Now remove all the filters in the chain downstream after the demux filter from the graph builder (we dont' need them, we will add out own filters later)
                _jobLog.WriteEntry(this, "Removing redundant filters from TiVO filter chain", Log.LogEntryType.Debug);
                foreach (IBaseFilter filter in filterList)
                {
                    filter.QueryFilterInfo(out filterInfo);
                    filter.QueryVendorInfo(out vendorInfo);
                    _jobLog.WriteEntry(this, "Removing filter -> " + filterInfo.achName + " (" + vendorInfo + ")", Log.LogEntryType.Debug);
                    _gb.RemoveFilter(filter);
                    Marshal.FinalReleaseComObject(filter); // Release the COM object
                }

                // Now the TIVO MainConcept Demux Filter is our new "Source" filter
                _SourceF = demuxPinInfo.filter;
            }

            // TODO: We need to find a way to insert a filter which can allow us to select audio streams (e.g. LAV filter, currently it only allows us access to the default audio stream and not multiple audio streams)

            // Cycle through pins, connecting as appropriate
            hr = _SourceF.EnumPins(out FilterPins);
            checkHR(hr);
            while (FilterPins.Next(pins.Length, pins, fetched) == 0)
            {
                IntPtr          ptypes = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(IntPtr)));
                AMMediaType     mtypes;
                IEnumMediaTypes enummtypes;
                IntPtr          ptrEnum;
                pins[0].EnumMediaTypes(out ptrEnum);
                enummtypes = (IEnumMediaTypes)Marshal.GetObjectForIUnknown(ptrEnum);
                while (enummtypes.Next(1, ptypes, fetched2) == 0)
                {
                    /* Extract Audio, Video or Subtitle streams -> References:
                     * http://nate.deepcreek.org.au/svn/DigitalWatch/trunk/bin/MediaTypes.txt
                     * http://msdn.microsoft.com/en-us/library/ms932033.aspx
                     * https://sourceforge.net/p/tsubget/home/Dumping%20a%20Stream/
                     * http://msdn.microsoft.com/en-us/library/windows/desktop/dd695343(v=vs.85).aspx
                     * http://msdn.microsoft.com/en-us/library/windows/desktop/dd390660(v=vs.85).aspx
                     * http://msdn.microsoft.com/en-us/library/windows/desktop/dd407354(v=vs.85).aspx
                     * http://whrl.pl/RcRv5p (extracting Teletext from WTV/DVRMS)
                     */
                    IntPtr ptrStructure = Marshal.ReadIntPtr(ptypes);
                    mtypes = (AMMediaType)Marshal.PtrToStructure(ptrStructure, typeof(AMMediaType));
                    if ((mtypes.majorType == MediaType.Video) ||
                        (mtypes.majorType == MediaType.Audio) ||
                        (mtypes.majorType == MediaType.Mpeg2PES) ||
                        (mtypes.majorType == MediaType.Stream) ||
                        (mtypes.majorType == MediaType.AuxLine21Data) ||
                        (mtypes.majorType == MediaType.VBI) ||
                        (mtypes.majorType == MediaType.MSTVCaption) ||
                        (mtypes.majorType == MediaType.DTVCCData) ||
                        (mtypes.majorType == MediaType.Mpeg2Sections && mtypes.subType == MediaSubType.None && mtypes.formatType == FormatType.None))
                    {
                        string DumpFileName = "";

                        if ((mtypes.majorType == MediaType.Video) && ((_extractMediaType & ExtractMediaType.Video) != 0)) // Video
                        {
                            DumpFileName = Path.Combine(_workPath, Path.GetFileNameWithoutExtension(_SourceFile) + "_VIDEO");
                            _VideoPart   = DumpFileName;
                            _jobLog.WriteEntry(this, "Found Video stream, extracting -> " + DumpFileName, Log.LogEntryType.Debug);
                        }
                        else if (((mtypes.majorType == MediaType.Audio) || // Audio types https://msdn.microsoft.com/en-us/library/windows/desktop/dd390676(v=vs.85).aspx
                                  ((mtypes.majorType == MediaType.Mpeg2PES) && ((mtypes.subType == MediaSubType.DolbyAC3) || (mtypes.subType == MediaSubType.DTS) || (mtypes.subType == MediaSubType.DvdLPCMAudio) || (mtypes.subType == MediaSubType.Mpeg2Audio))) ||
                                  ((mtypes.majorType == MediaType.Stream) && ((mtypes.subType == MediaSubType.DolbyAC3) || (mtypes.subType == MediaSubType.MPEG1Audio) || (mtypes.subType == MediaSubType.Mpeg2Audio) || (mtypes.subType == MediaSubType.DolbyDDPlus) || (mtypes.subType == MediaSubType.MpegADTS_AAC) || (mtypes.subType == MediaSubType.MpegLOAS)))
                                  ) &&
                                 ((_extractMediaType & ExtractMediaType.Audio) != 0))
                        {
                            DumpFileName = Path.Combine(_workPath, Path.GetFileNameWithoutExtension(_SourceFile) + "_AUDIO" + AudioParts.Count.ToString());
                            _AudioParts.Add(DumpFileName);
                            _jobLog.WriteEntry(this, "Found Audio stream, extracting -> " + DumpFileName, Log.LogEntryType.Debug);
                        }
                        else if ((_extractMediaType & ExtractMediaType.Subtitle) != 0)// Subtitles
                        {
                            DumpFileName = Path.Combine(_workPath, Path.GetFileNameWithoutExtension(_SourceFile) + "_SUBTITLE" + SubtitleParts.Count.ToString());
                            SubtitleParts.Add(DumpFileName);
                            _jobLog.WriteEntry(this, "Found Subtitle stream, extracting -> " + DumpFileName, Log.LogEntryType.Debug);
                        }

                        if (!String.IsNullOrWhiteSpace(DumpFileName)) // If we are asked to extract something
                        {
                            hr = pins[0].QueryId(out PinID);
                            ConnectDecryptedDump(PinID, DumpFileName);
                        }
                    }
                    else
                    {
                        // Debug - looking for more subtitle types (very poorly documented by Microsoft)
                        Guid type        = mtypes.majorType;
                        Guid subtype     = mtypes.subType;
                        Guid formattyype = mtypes.formatType;
                    }
                }
                Marshal.FreeCoTaskMem(ptypes); // Free up the memory
            }
        }
Esempio n. 17
0
        public void Receive(PinIn <T> pin, T item)
        {
            PinOut <T> outPin = filterFunction(item) ? SuccessPin : FailurePin;

            outPin.Send(item);
        }
Esempio n. 18
0
 public void Receive(PinIn <T> pin, T item)
 {
     OutputPin.Send(transformFunction(item));
 }
Esempio n. 19
0
 public GenericTransform(Func <T, T> transformFunction)
 {
     this.transformFunction = transformFunction;
     this.InputPin          = new PinIn <T>(this);
     this.OutputPin         = new PinOut <T>();
 }
Esempio n. 20
0
 public WallpaperFilter()
 {
     InputPin  = new PinIn <Image>(this);
     OutputPin = new PinOut <Image>();
 }
Esempio n. 21
0
 public PinyinImpl()
 {
     p = new();
 }