예제 #1
0
        private void SetupFilter()
        {
            foreach (FilterMode mode in Enum.GetValues(typeof(FilterMode)))
            {
                switch (mode)
                {
                case FilterMode.None:
                    FilterModes.Add(mode, Resources.MainWindow_CurrentWorkspace_FilterMode_None);
                    break;

                case FilterMode.Downloaded:
                    FilterModes.Add(mode, Resources.MainWindow_CurrentWorkspace_FilterMode_Downloaded);
                    break;

                case FilterMode.NotDownloaded:
                    FilterModes.Add(mode, Resources.MainWindow_CurrentWorkspace_FilterMode_NotDownloaded);
                    break;

                case FilterMode.Downloading:
                    FilterModes.Add(mode, Resources.MainWindow_CurrentWorkspace_FilterMode_Downloading);
                    break;

                case FilterMode.Queued:
                    FilterModes.Add(mode, Resources.MainWindow_CurrentWorkspace_FilterMode_Queued);
                    break;
                }
            }

            SelectedFilterMode = FilterMode.None;
        }
        private void SetupFilter()
        {
            foreach (var mode in Enum.GetNames(typeof(FilterMode)))
            {
                var attributes = typeof(FilterMode).GetMember(mode)[0].GetCustomAttributes(
                    typeof(DescriptionAttribute), false);
                FilterModes.Add((FilterMode)Enum.Parse(typeof(FilterMode), mode),
                                ((DescriptionAttribute)attributes[0]).Description);
            }

            SelectedFilterMode = FilterMode.None;
        }
예제 #3
0
        public static DictionaryFilter <TKey, TValue> CreateFilter <TKey, TValue>(FilterModes mode, IReadOnlyCollection <TKey> fields)
        {
            switch (mode)
            {
            case FilterModes.Pass:
                return(new PassFilter <TKey, TValue>(fields));

            case FilterModes.Reject:
                return(new RejectFilter <TKey, TValue>(fields));
            }

            return(new NoFilter <TKey, TValue>());
        }
예제 #4
0
 public Filter(bool ac, FilterModes m, FilterCaptureFuncs f, FilterActions a, string n, uint plMin, uint plMax, uint nta, Dictionary <int, byte> s, Dictionary <int, byte> r)
 {
     Active          = ac;
     Mode            = m;
     Functions       = f;
     Actions         = a;
     Name            = n;
     PacketLengthMin = plMin;
     PacketLengthMax = plMax;
     NumTimesApply   = nta;
     Searches        = s;
     Replaces        = r;
 }
예제 #5
0
        /// <summary>
        /// Loads all the data out of the reader, assuming the document is
        /// well-formed, otherwise the error must be caught and thrown.
        /// By the end of this method the reader must be finished reading.
        /// This method needs to be implemented by the sub-class.
        /// </summary>
        protected override void LoadFromReader()
        {
            if (_reader.Name == "filter")
            {
                _reader.Read();
                string filterModeStr = _reader.GetAttribute("filterMode");
                _filterMode = (FilterModes)Enum.Parse(typeof(FilterModes), filterModeStr);
                _columns    = Convert.ToInt32(_reader.GetAttribute("columns"));
            }
            _reader.Read();

            while (_reader.Name == "filterProperty")
            {
                string propertyName            = _reader.GetAttribute("name");
                string label                   = _reader.GetAttribute("label");
                string filterType              = _reader.GetAttribute("filterType");
                string filterTypeAssembly      = _reader.GetAttribute("filterTypeAssembly");
                string filterClauseOperatorStr = _reader.GetAttribute("operator");
                FilterClauseOperator filterClauseOperator
                    = (FilterClauseOperator)Enum.Parse(typeof(FilterClauseOperator), filterClauseOperatorStr);
                Dictionary <string, string> parameters        = new Dictionary <string, string>();
                IFilterPropertyDef          filterPropertyDef =
                    _defClassFactory.CreateFilterPropertyDef(propertyName, label, filterType, filterTypeAssembly, filterClauseOperator, parameters);

                _reader.Read();

                if (_reader.Name == "parameter")
                {
                    while (_reader.Name == "parameter")
                    {
                        string name  = _reader.GetAttribute("name");
                        string value = _reader.GetAttribute("value");
                        parameters.Add(name, value);
                        _reader.Read();
                    }
                    _reader.Read();
                }
                _propertyDefs.Add(filterPropertyDef);
                if (!_reader.IsStartElement())
                {
                    _reader.ReadEndElement();
                }
                filterPropertyDef.Parameters = parameters;
            }
            while (_reader.Name == "filter")
            {
                _reader.Read();
            }
        }
예제 #6
0
        public static void EditFilter(int index, bool active, FilterModes mode, FilterCaptureFuncs functions, FilterActions actions, string name, uint packetLenghtMin, uint packetLengthMax, uint numTimesApply, Dictionary <int, byte> searches, Dictionary <int, byte> replaces)
        {
            var filter = _filterList.ElementAt(index);

            filter.Active          = active;
            filter.Mode            = mode;
            filter.Functions       = functions;
            filter.Actions         = actions;
            filter.Name            = name;
            filter.PacketLengthMin = packetLenghtMin;
            filter.PacketLengthMax = packetLengthMax;
            filter.NumTimesApply   = numTimesApply;
            filter.Searches        = searches;
            filter.Replaces        = replaces;
        }
예제 #7
0
        /// <summary>
        /// Loads all the data out of the reader, assuming the document is 
        /// well-formed, otherwise the error must be caught and thrown.
        /// By the end of this method the reader must be finished reading.
        /// This method needs to be implemented by the sub-class.
        /// </summary>
        protected override void LoadFromReader()
        {
            if (_reader.Name == "filter")
            {
                _reader.Read();
                string filterModeStr = _reader.GetAttribute("filterMode");
                _filterMode = (FilterModes) Enum.Parse(typeof (FilterModes), filterModeStr);
                _columns = Convert.ToInt32(_reader.GetAttribute("columns"));

            }
            _reader.Read();

            while (_reader.Name == "filterProperty")
            {

                string propertyName = _reader.GetAttribute("name");
                string label = _reader.GetAttribute("label");
                string filterType = _reader.GetAttribute("filterType");
                string filterTypeAssembly = _reader.GetAttribute("filterTypeAssembly");
                string filterClauseOperatorStr = _reader.GetAttribute("operator");
                FilterClauseOperator filterClauseOperator 
                    = (FilterClauseOperator) Enum.Parse(typeof (FilterClauseOperator), filterClauseOperatorStr);
                Dictionary<string, string> parameters = new Dictionary<string, string>();
                IFilterPropertyDef filterPropertyDef = 
                    _defClassFactory.CreateFilterPropertyDef(propertyName, label, filterType, filterTypeAssembly, filterClauseOperator, parameters);
              
                _reader.Read();
              
                if (_reader.Name == "parameter")
                {
                    while (_reader.Name == "parameter")
                    {
                        string name = _reader.GetAttribute("name");
                        string value = _reader.GetAttribute("value");
                        parameters.Add(name, value);
                        _reader.Read();
                    }
                     _reader.Read();
                }
                _propertyDefs.Add(filterPropertyDef);
                if (!_reader.IsStartElement()) _reader.ReadEndElement();
                filterPropertyDef.Parameters = parameters;
            }
            while (_reader.Name == "filter") _reader.Read();
        }
 public DynamicFilteredTextBoxXml(string text, string name, bool isRequired, string errorMessage, string validationGroup, double width, double height, int maxLength,
     FilterTypes filterType, FilterModes filterMode, int filterInterval, string validChars, string invalidChars,
     DynamicLabel label, string css, string style, bool visible)
 {
     _text = text;
     Name = name;
     _isRequired = isRequired;
     _errorMessage = errorMessage;
     _validationGroup = validationGroup;
     _width = width;
     _height = height;
     _maxLength = maxLength;
     _filterType = filterType;
     _filterMode = filterMode;
     _filterInterval = filterInterval;
     _validChars = validChars;
     _invalidChars = invalidChars;
     Label = label;
     Css = css;
     Style = style;
     Visible = visible;
 }
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);

        #region "Watermark extender"

        // Watermark extender
        // Disable watermark extender for nonempty fields (issue with value which is same as the watermark text)
        string resolvedWatermarkText = ContextResolver.ResolveMacros(WatermarkText);
        if (!String.IsNullOrEmpty(WatermarkText) && !String.IsNullOrEmpty(resolvedWatermarkText) && !CMSString.Equals(textbox.Text, WatermarkText))
        {
            // Create extender
            TextBoxWatermarkExtender exWatermark = new TextBoxWatermarkExtender();
            exWatermark.ID = "exWatermark";
            exWatermark.TargetControlID = textbox.ID;
            exWatermark.EnableViewState = false;
            Controls.Add(exWatermark);

            // Initialize extender
            exWatermark.WatermarkText     = resolvedWatermarkText;
            exWatermark.WatermarkCssClass = textbox.CssClass + " " + ValidationHelper.GetString(GetValue("WatermarkCssClass"), WatermarkCssClass);
        }

        #endregion


        #region "Filter extender"

        if (FilterEnabled)
        {
            // Create extender
            FilteredTextBoxExtender exFilter = new FilteredTextBoxExtender();
            exFilter.ID = "exFilter";
            exFilter.TargetControlID = textbox.ID;
            exFilter.EnableViewState = false;
            Controls.Add(exFilter);

            // Filter extender
            exFilter.FilterInterval = FilterInterval;

            // Set the filter type
            if (FilterTypeValue == null)
            {
                exFilter.FilterType = FilterType;
            }
            else
            {
                if (!string.IsNullOrEmpty(FilterTypeValue))
                {
                    FilterTypes filterType = 0;
                    string[]    types      = FilterTypeValue.Split(new char[] { ';', '|' }, StringSplitOptions.RemoveEmptyEntries);
                    if (types.Length > 0)
                    {
                        foreach (string typeStr in types)
                        {
                            int type = ValidationHelper.GetInteger(typeStr, 0);
                            switch (type)
                            {
                            case FILTER_NUMBERS:
                                filterType |= FilterTypes.Numbers;
                                break;

                            case FILTER_LOWERCASE:
                                filterType |= FilterTypes.LowercaseLetters;
                                break;

                            case FILTER_UPPERCASE:
                                filterType |= FilterTypes.UppercaseLetters;
                                break;

                            case FILTER_CUSTOM:
                                filterType |= FilterTypes.Custom;
                                break;
                            }
                        }
                        exFilter.FilterType = filterType;
                    }
                }
            }

            FilterModes filterMode = FilterMode;

            // Set valid and invalid characters
            if (exFilter.FilterType == FilterTypes.Custom)
            {
                // When filter type is Custom only, filter mode can be anything
                exFilter.FilterMode = filterMode;

                if (filterMode == FilterModes.InvalidChars)
                {
                    exFilter.InvalidChars = InvalidChars;
                }
                else
                {
                    exFilter.ValidChars = ValidChars;
                }
            }
            else
            {
                // Otherwise filter type must be valid chars
                exFilter.FilterMode = FilterModes.ValidChars;

                // Set valid chars only if original filter mode was valid chars and filter type contains Custom
                if ((filterMode == FilterModes.ValidChars) && ((exFilter.FilterType & FilterTypes.Custom) != 0))
                {
                    exFilter.ValidChars = ValidChars;
                }
            }
        }

        #endregion


        #region "Autocomplete extender"

        // Autocomplete extender
        if (!string.IsNullOrEmpty(AutoCompleteServiceMethod) && !string.IsNullOrEmpty(AutoCompleteServicePath))
        {
            // Create extender
            AutoCompleteExtender exAuto = new AutoCompleteExtender();
            exAuto.ID = "exAuto";
            exAuto.TargetControlID = textbox.ID;
            exAuto.EnableViewState = false;
            Controls.Add(exAuto);

            exAuto.ServiceMethod                           = AutoCompleteServiceMethod;
            exAuto.ServicePath                             = URLHelper.ResolveUrl(AutoCompleteServicePath);
            exAuto.MinimumPrefixLength                     = AutoCompleteMinimumPrefixLength;
            exAuto.ContextKey                              = ContextResolver.ResolveMacros(AutoCompleteContextKey);
            exAuto.CompletionInterval                      = AutoCompleteCompletionInterval;
            exAuto.EnableCaching                           = AutoCompleteEnableCaching;
            exAuto.CompletionSetCount                      = AutoCompleteCompletionSetCount;
            exAuto.CompletionListCssClass                  = AutoCompleteCompletionListCssClass;
            exAuto.CompletionListItemCssClass              = AutoCompleteCompletionListItemCssClass;
            exAuto.CompletionListHighlightedItemCssClass   = AutoCompleteCompletionListHighlightedItemCssClass;
            exAuto.DelimiterCharacters                     = AutoCompleteDelimiterCharacters;
            exAuto.FirstRowSelected                        = AutoCompleteFirstRowSelected;
            exAuto.ShowOnlyCurrentWordInCompletionListItem = AutoCompleteShowOnlyCurrentWordInCompletionListItem;
        }

        #endregion
    }
예제 #10
0
        internal unsafe static IntPtr FilterImageData(byte *image, int width, int height, int pixelSize, FilterModes filter, int threadCount)
        {
            threadCount = Math.Min(threadCount, height);

            IntPtr filteredMemory = Marshal.AllocHGlobal(height * (1 + width * pixelSize));

            int stride = width * pixelSize;

            byte *filteredPointer = (byte *)filteredMemory;

            IntPtr[] tempBuffers = new IntPtr[threadCount];

            Thread[]          threads            = new Thread[threadCount];
            int[]             rowsByThread       = new int[threadCount];
            EventWaitHandle[] signalsFromThreads = new EventWaitHandle[threadCount];
            EventWaitHandle[] signalsToThreads   = new EventWaitHandle[threadCount];

            int firstNeededRow = threadCount;

            for (int i = 0; i < threadCount; i++)
            {
                rowsByThread[i]       = i;
                signalsFromThreads[i] = new EventWaitHandle(false, EventResetMode.ManualReset);
                signalsToThreads[i]   = new EventWaitHandle(false, EventResetMode.ManualReset);

                if (filter == FilterModes.Adaptive)
                {
                    tempBuffers[i] = Marshal.AllocHGlobal(5 * width * pixelSize);
                }
                else
                {
                    tempBuffers[i] = IntPtr.Zero;
                }

                byte *tempPointer = (byte *)tempBuffers[i];

                int threadIndex = i;

                threads[i] = new Thread(() =>
                {
                    while (rowsByThread[threadIndex] >= 0)
                    {
                        FilterRow(image, width, pixelSize, stride, rowsByThread[threadIndex], filter, filteredPointer, tempPointer);
                        EventWaitHandle.SignalAndWait(signalsFromThreads[threadIndex], signalsToThreads[threadIndex]);
                        signalsToThreads[threadIndex].Reset();
                    }
                });
            }

            int finished = 0;

            for (int i = 0; i < threadCount; i++)
            {
                threads[i].Start();
            }

            while (finished < threadCount)
            {
                int threadInd = EventWaitHandle.WaitAny(signalsFromThreads);

                signalsFromThreads[threadInd].Reset();

                if (firstNeededRow < height)
                {
                    rowsByThread[threadInd] = firstNeededRow;
                    firstNeededRow++;
                    signalsToThreads[threadInd].Set();
                }
                else
                {
                    rowsByThread[threadInd] = -1;
                    signalsToThreads[threadInd].Set();
                    finished++;
                }
            }

            for (int i = 0; i < threadCount; i++)
            {
                if (filter == FilterModes.Adaptive)
                {
                    Marshal.FreeHGlobal(tempBuffers[i]);
                }
            }

            return(filteredMemory);
        }
예제 #11
0
        internal unsafe static IntPtr FilterImageData(byte *image, int width, int height, int pixelSize, FilterModes filter)
        {
            IntPtr filteredMemory = Marshal.AllocHGlobal(height * (1 + width * pixelSize));

            IntPtr tempBuffer;

            if (filter == FilterModes.Adaptive)
            {
                tempBuffer = Marshal.AllocHGlobal(5 * width * pixelSize);
            }
            else
            {
                tempBuffer = IntPtr.Zero;
            }

            int stride = width * pixelSize;

            byte *filteredPointer = (byte *)filteredMemory;

            byte *tempPointer = (byte *)tempBuffer;

            for (int y = 0; y < height; y++)
            {
                FilterRow(image, width, pixelSize, stride, y, filter, filteredPointer, tempPointer);
            }

            Marshal.FreeHGlobal(tempBuffer);

            return(filteredMemory);
        }
예제 #12
0
        public unsafe static void SavePNG(byte *image, int width, int height, bool hasAlpha, Stream fs, FilterModes filter, int threadCount = 0)
        {
            if (threadCount == 0)
            {
                threadCount = filter == FilterModes.Adaptive ? Math.Max(1, Math.Min(width / 600, Environment.ProcessorCount - 2)) : 1;
            }

            //Header
            fs.Write(new byte[] { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A }, 0, 8);

            //IHDR chunk
            fs.WriteInt(13);
            using (MemoryStream ihdr = new MemoryStream(13))
            {
                ihdr.WriteASCIIString("IHDR");
                ihdr.WriteInt(width);
                ihdr.WriteInt(height);
                ihdr.WriteByte(8); //Bit depth

                if (hasAlpha)
                {
                    ihdr.WriteByte(6); //Colour type
                }
                else
                {
                    ihdr.WriteByte(2); //Colour type
                }

                ihdr.WriteByte(0); //Compression method
                ihdr.WriteByte(0); //Filter method
                ihdr.WriteByte(0); //Interlace

                ihdr.Seek(0, SeekOrigin.Begin);
                ihdr.CopyTo(fs);

                fs.WriteUInt(CRC32.ComputeCRC(ihdr));
            }

            //IDAT chunk
            IntPtr filteredImage;

            if (threadCount > 1)
            {
                filteredImage = FilterImageData(image, width, height, hasAlpha ? 4 : 3, FilterModes.Adaptive, threadCount);
            }
            else
            {
                filteredImage = FilterImageData(image, width, height, hasAlpha ? 4 : 3, FilterModes.Adaptive);
            }

            using (MemoryStream compressedImage = StreamUtils.ZLibCompress(filteredImage, height * (width * (hasAlpha ? 4 : 3) + 1)))
            {
                compressedImage.Seek(0, SeekOrigin.Begin);
                fs.WriteUInt((uint)compressedImage.Length);
                fs.WriteASCIIString("IDAT");
                compressedImage.Seek(0, SeekOrigin.Begin);
                compressedImage.CopyTo(fs);

                fs.WriteUInt(CRC32.ComputeCRC(compressedImage.GetBuffer(), (int)compressedImage.Length, new byte[] { 73, 68, 65, 84 }));
            }

            Marshal.FreeHGlobal(filteredImage);

            //IEND chunk
            fs.WriteInt(0);
            fs.WriteASCIIString("IEND");
            fs.Write(new byte[] { 0xAE, 0x42, 0x60, 0x82 }, 0, 4);
        }
예제 #13
0
        internal unsafe static void FilterRow(byte *image, int width, int pixelSize, int stride, int y, FilterModes filter, byte *destinationImage, byte *tempBuffer)
        {
            int startIndex       = y * stride;
            int destinationIndex = y * (stride + 1);

            if (filter == FilterModes.None)
            {
                destinationImage[destinationIndex++] = 0;
                for (int x = 0; x < width; x++)
                {
                    destinationImage[destinationIndex++] = image[startIndex++];
                    destinationImage[destinationIndex++] = image[startIndex++];
                    destinationImage[destinationIndex++] = image[startIndex++];

                    if (pixelSize == 4)
                    {
                        destinationImage[destinationIndex++] = image[startIndex++];
                    }
                }
            }
            else if (filter == FilterModes.Sub)
            {
                destinationImage[destinationIndex++] = 1;
                for (int x = 0; x < width; x++)
                {
                    if (x > 0)
                    {
                        destinationImage[destinationIndex++] = (byte)(image[startIndex] - image[startIndex++ - pixelSize]);
                        destinationImage[destinationIndex++] = (byte)(image[startIndex] - image[startIndex++ - pixelSize]);
                        destinationImage[destinationIndex++] = (byte)(image[startIndex] - image[startIndex++ - pixelSize]);
                        if (pixelSize == 4)
                        {
                            destinationImage[destinationIndex++] = (byte)(image[startIndex] - image[startIndex++ - pixelSize]);
                        }
                    }
                    else
                    {
                        destinationImage[destinationIndex++] = image[startIndex++];
                        destinationImage[destinationIndex++] = image[startIndex++];
                        destinationImage[destinationIndex++] = image[startIndex++];
                        if (pixelSize == 4)
                        {
                            destinationImage[destinationIndex++] = image[startIndex++];
                        }
                    }
                }
            }
            else if (filter == FilterModes.Up)
            {
                destinationImage[destinationIndex++] = 2;
                for (int x = 0; x < width; x++)
                {
                    if (y > 0)
                    {
                        destinationImage[destinationIndex++] = (byte)(image[startIndex] - image[startIndex++ - stride]);
                        destinationImage[destinationIndex++] = (byte)(image[startIndex] - image[startIndex++ - stride]);
                        destinationImage[destinationIndex++] = (byte)(image[startIndex] - image[startIndex++ - stride]);
                        if (pixelSize == 4)
                        {
                            destinationImage[destinationIndex++] = (byte)(image[startIndex] - image[startIndex++ - stride]);
                        }
                    }
                    else
                    {
                        destinationImage[destinationIndex++] = image[startIndex++];
                        destinationImage[destinationIndex++] = image[startIndex++];
                        destinationImage[destinationIndex++] = image[startIndex++];
                        if (pixelSize == 4)
                        {
                            destinationImage[destinationIndex++] = image[startIndex++];
                        }
                    }
                }
            }
            else if (filter == FilterModes.Average)
            {
                destinationImage[destinationIndex++] = 3;
                for (int x = 0; x < width; x++)
                {
                    if (x > 0 && y > 0)
                    {
                        destinationImage[destinationIndex++] = (byte)(image[startIndex] - (image[startIndex - pixelSize] + image[startIndex++ - stride]) / 2);
                        destinationImage[destinationIndex++] = (byte)(image[startIndex] - (image[startIndex - pixelSize] + image[startIndex++ - stride]) / 2);
                        destinationImage[destinationIndex++] = (byte)(image[startIndex] - (image[startIndex - pixelSize] + image[startIndex++ - stride]) / 2);
                        if (pixelSize == 4)
                        {
                            destinationImage[destinationIndex++] = (byte)(image[startIndex] - (image[startIndex - pixelSize] + image[startIndex++ - stride]) / 2);
                        }
                    }
                    else if (x > 0 && y == 0)
                    {
                        destinationImage[destinationIndex++] = (byte)(image[startIndex] - image[startIndex++ - pixelSize] / 2);
                        destinationImage[destinationIndex++] = (byte)(image[startIndex] - image[startIndex++ - pixelSize] / 2);
                        destinationImage[destinationIndex++] = (byte)(image[startIndex] - image[startIndex++ - pixelSize] / 2);
                        if (pixelSize == 4)
                        {
                            destinationImage[destinationIndex++] = (byte)(image[startIndex] - image[startIndex++ - pixelSize] / 2);
                        }
                    }
                    else if (x == 0 && y > 0)
                    {
                        destinationImage[destinationIndex++] = (byte)(image[startIndex] - image[startIndex++ - stride] / 2);
                        destinationImage[destinationIndex++] = (byte)(image[startIndex] - image[startIndex++ - stride] / 2);
                        destinationImage[destinationIndex++] = (byte)(image[startIndex] - image[startIndex++ - stride] / 2);
                        if (pixelSize == 4)
                        {
                            destinationImage[destinationIndex++] = (byte)(image[startIndex] - image[startIndex++ - stride] / 2);
                        }
                    }
                    else
                    {
                        destinationImage[destinationIndex++] = image[startIndex++];
                        destinationImage[destinationIndex++] = image[startIndex++];
                        destinationImage[destinationIndex++] = image[startIndex++];
                        if (pixelSize == 4)
                        {
                            destinationImage[destinationIndex++] = image[startIndex++];
                        }
                    }
                }
            }
            else if (filter == FilterModes.Paeth)
            {
                destinationImage[destinationIndex++] = 4;
                for (int x = 0; x < width; x++)
                {
                    if (x > 0 && y > 0)
                    {
                        destinationImage[destinationIndex++] = (byte)(image[startIndex] - PaethPredictor(image[startIndex - pixelSize], image[startIndex - stride], image[startIndex++ - pixelSize - stride]));
                        destinationImage[destinationIndex++] = (byte)(image[startIndex] - PaethPredictor(image[startIndex - pixelSize], image[startIndex - stride], image[startIndex++ - pixelSize - stride]));
                        destinationImage[destinationIndex++] = (byte)(image[startIndex] - PaethPredictor(image[startIndex - pixelSize], image[startIndex - stride], image[startIndex++ - pixelSize - stride]));
                        if (pixelSize == 4)
                        {
                            destinationImage[destinationIndex++] = (byte)(image[startIndex] - PaethPredictor(image[startIndex - pixelSize], image[startIndex - stride], image[startIndex++ - pixelSize - stride]));
                        }
                    }
                    else if (x > 0 && y == 0)
                    {
                        destinationImage[destinationIndex++] = (byte)(image[startIndex] - image[startIndex++ - pixelSize]);
                        destinationImage[destinationIndex++] = (byte)(image[startIndex] - image[startIndex++ - pixelSize]);
                        destinationImage[destinationIndex++] = (byte)(image[startIndex] - image[startIndex++ - pixelSize]);
                        if (pixelSize == 4)
                        {
                            destinationImage[destinationIndex++] = (byte)(image[startIndex] - image[startIndex++ - pixelSize]);
                        }
                    }
                    else if (x == 0 && y > 0)
                    {
                        destinationImage[destinationIndex++] = (byte)(image[startIndex] - image[startIndex++ - stride]);
                        destinationImage[destinationIndex++] = (byte)(image[startIndex] - image[startIndex++ - stride]);
                        destinationImage[destinationIndex++] = (byte)(image[startIndex] - image[startIndex++ - stride]);
                        if (pixelSize == 4)
                        {
                            destinationImage[destinationIndex++] = (byte)(image[startIndex] - image[startIndex++ - stride]);
                        }
                    }
                    else
                    {
                        destinationImage[destinationIndex++] = image[startIndex++];
                        destinationImage[destinationIndex++] = image[startIndex++];
                        destinationImage[destinationIndex++] = image[startIndex++];
                        if (pixelSize == 4)
                        {
                            destinationImage[destinationIndex++] = image[startIndex++];
                        }
                    }
                }
            }
            else if (filter == FilterModes.Adaptive)
            {
                int tempIndex = 0;

                int none    = 0;
                int sub     = 0;
                int up      = 0;
                int average = 0;
                int paeth   = 0;

                for (int x = 0; x < width; x++)
                {
                    for (int i = 0; i < pixelSize; i++)
                    {
                        //none
                        tempBuffer[tempIndex] = image[startIndex];

                        //sub
                        if (x > 0)
                        {
                            tempBuffer[tempIndex + stride] = (byte)(image[startIndex] - image[startIndex - pixelSize]);
                        }
                        else
                        {
                            tempBuffer[tempIndex + stride] = image[startIndex];
                        }

                        //up
                        if (y > 0)
                        {
                            tempBuffer[tempIndex + stride * 2] = (byte)(image[startIndex] - image[startIndex - stride]);
                        }
                        else
                        {
                            tempBuffer[tempIndex + stride * 2] = image[startIndex];
                        }

                        //average
                        if (x > 0 && y > 0)
                        {
                            tempBuffer[tempIndex + stride * 3] = (byte)(image[startIndex] - (image[startIndex - pixelSize] + image[startIndex - stride]) / 2);
                        }
                        else if (x > 0 && y == 0)
                        {
                            tempBuffer[tempIndex + stride * 3] = (byte)(image[startIndex] - image[startIndex - pixelSize] / 2);
                        }
                        else if (x == 0 && y > 0)
                        {
                            tempBuffer[tempIndex + stride * 3] = (byte)(image[startIndex] - image[startIndex - stride] / 2);
                        }
                        else
                        {
                            tempBuffer[tempIndex + stride * 3] = image[startIndex];
                        }

                        //paeth
                        if (x > 0 && y > 0)
                        {
                            tempBuffer[tempIndex + stride * 4] = (byte)(image[startIndex] - PaethPredictor(image[startIndex - pixelSize], image[startIndex - stride], image[startIndex - pixelSize - stride]));
                        }
                        else if (x > 0 && y == 0)
                        {
                            tempBuffer[tempIndex + stride * 4] = (byte)(image[startIndex] - image[startIndex - pixelSize]);
                        }
                        else if (x == 0 && y > 0)
                        {
                            tempBuffer[tempIndex + stride * 4] = (byte)(image[startIndex] - image[startIndex - stride]);
                        }
                        else
                        {
                            tempBuffer[tempIndex + stride * 4] = image[startIndex];
                        }

                        none    += tempBuffer[tempIndex];
                        sub     += tempBuffer[tempIndex + stride];
                        up      += tempBuffer[tempIndex + stride * 2];
                        average += tempBuffer[tempIndex + stride * 3];
                        paeth   += tempBuffer[tempIndex + stride * 4];
                        tempIndex++;
                        startIndex++;
                    }
                }

                if (paeth <= average && paeth <= up && paeth <= sub && paeth <= none)
                {
                    destinationImage[destinationIndex++] = 4;
                    tempIndex = stride * 4;
                    for (int i = 0; i < stride; i++)
                    {
                        destinationImage[destinationIndex++] = tempBuffer[tempIndex++];
                    }
                }
                else if (average <= up && average <= sub && average <= none)
                {
                    destinationImage[destinationIndex++] = 3;
                    tempIndex = stride * 3;
                    for (int i = 0; i < stride; i++)
                    {
                        destinationImage[destinationIndex++] = tempBuffer[tempIndex++];
                    }
                }
                else if (up <= sub && up <= none)
                {
                    destinationImage[destinationIndex++] = 2;
                    tempIndex = stride * 2;
                    for (int i = 0; i < stride; i++)
                    {
                        destinationImage[destinationIndex++] = tempBuffer[tempIndex++];
                    }
                }
                else if (sub <= none)
                {
                    destinationImage[destinationIndex++] = 1;
                    tempIndex = stride;
                    for (int i = 0; i < stride; i++)
                    {
                        destinationImage[destinationIndex++] = tempBuffer[tempIndex++];
                    }
                }
                else
                {
                    destinationImage[destinationIndex++] = 0;
                    tempIndex = 0;
                    for (int i = 0; i < stride; i++)
                    {
                        destinationImage[destinationIndex++] = tempBuffer[tempIndex++];
                    }
                }
            }
        }
예제 #14
0
        private void btnApply_Click(object sender, EventArgs e)
        {
            var         searches   = new Dictionary <int, byte>();
            var         replaces   = new Dictionary <int, byte>();
            FilterModes filterMode = FilterModes.SearchAndReplaceFromBegin;
            Byte        result;

            for (var i = 0; i < 501; i++)
            {
                if (dataGridViewSearch[i, 0].Value != null && Byte.TryParse(dataGridViewSearch[i, 0].Value.ToString(), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out result))
                {
                    searches.Add(i, result);
                }
            }

            if ((radioButton2.Checked || radioButton3.Checked) && (searches.Count == 0 || !searches.ContainsKey(0)))
            {
                MessageBox.Show(@"The chain to search must start at the offset 0");
                return;
            }

            if (radioButton1.Checked)
            {
                filterMode = FilterModes.SearchAndReplaceFromBegin;
                for (var i = 0; i < 501; i++)
                {
                    if (dataGridViewSearch[i, 1].Value != null && Byte.TryParse(dataGridViewSearch[i, 1].Value.ToString(), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out result))
                    {
                        replaces.Add(i, result);
                    }
                }
            }
            else if (radioButton2.Checked)
            {
                filterMode = FilterModes.SearchOcurrenceReplaceFromBegin;
                for (var i = 0; i < 501; i++)
                {
                    if (dataGridViewReplace[i, 0].Value != null && Byte.TryParse(dataGridViewReplace[i, 0].Value.ToString(), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out result))
                    {
                        replaces.Add(i, result);
                    }
                }
            }
            else if (radioButton3.Checked)
            {
                filterMode = FilterModes.SearchOcurrenceReplaceFromPosition;
                for (var i = 0; i < 501; i++)
                {
                    if (dataGridViewReplace2[i, 0].Value != null && Byte.TryParse(dataGridViewReplace2[i, 0].Value.ToString(), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out result))
                    {
                        replaces.Add(i, result);
                    }
                }
            }

            FilterCaptureFuncs functions = BuildFunctionsBitMask();
            FilterActions      actions   = BuildActionsBitMask();
            uint packetLengthMin         = 0;
            uint packetLengthMax         = 0;

            if (chkPackeLength.Checked)
            {
                packetLengthMin = (uint)nudPacketLengthMin.Value;
                packetLengthMax = (uint)nudPacketLengthMax.Value;
            }

            string name = txtFilterName.Text;

            if (name == "" && _filterIndex == -1)
            {
                name = "Filter " + (FilterManager.GetNumberOfFiltersInList() + 1).ToString("D2");
            }

            if (_filterIndex == -1)
            {
                FilterManager.NewFilter(chkActive.Checked, filterMode, functions, actions, name, packetLengthMin, packetLengthMax, (uint)nudNumTimesApply.Value, searches, replaces);
            }
            else
            {
                FilterManager.EditFilter(_filterIndex, chkActive.Checked, filterMode, functions, actions, name, packetLengthMin, packetLengthMax, (uint)nudNumTimesApply.Value, searches, replaces);
            }

            Program.mainForm.LoadFilterItems();
            Program.mainForm.ActionStartStopFiltering(false);
            Close();
        }
예제 #15
0
        public static void NewFilter(bool active, FilterModes mode, FilterCaptureFuncs functions, FilterActions actions, string name, uint maxPacketLeghtMin, uint maxPacketLeghtMax, uint numTimesApply, Dictionary <int, byte> searches, Dictionary <int, byte> replaces)
        {
            var filter = new Filter(active, mode, functions, actions, name, maxPacketLeghtMin, maxPacketLeghtMax, numTimesApply, searches, replaces);

            _filterList.Add(filter);
        }