Пример #1
0
            /// <summary>
            /// 清除取樣點
            /// </summary>
            public void ClearPick()
            {
                _UseMap.SetAll(false);
                _PickInfos.Clear();
                CurrentPickIndex = -1;

                int    cot        = BaseImage.PixelCount;
                IntPtr basePtr    = BaseImage.LockBitsAndGetScan0(ImageLockMode.ReadOnly);
                IntPtr convertPtr = ConvertImage.LockBitsAndGetScan0(ImageLockMode.WriteOnly);

                unsafe
                {
                    byte *baseP    = (byte *)basePtr.ToPointer();
                    byte *convertP = (byte *)convertPtr.ToPointer();
                    for (int i = 0; i < cot; i++)
                    {
                        byte v = (byte)((baseP[0] + baseP[1] + baseP[2]) / 3);
                        convertP[0] = v;
                        convertP[1] = v;
                        convertP[2] = v;
                        baseP      += 4;
                        convertP   += 4;
                    }
                }
                BaseImage.UnlockBits();
                ConvertImage.UnlockBits();
            }
Пример #2
0
            /// <summary>
            /// 使用採樣暫存地圖調整主要採樣點的數值
            /// </summary>
            public void CurrentValueSet(int allowance, int range)
            {
                if (CurrentPickIndex >= _PickInfos.Count || CurrentPickIndex < 0)
                {
                    return;
                }
                Pick currentPick = _PickInfos[CurrentPickIndex];

                int oldAllowance = currentPick.Allowance;
                int oldRange     = currentPick.Range;

                currentPick.Allowance = allowance;
                currentPick.Range     = range;
                if (oldAllowance == currentPick.Allowance && oldRange == currentPick.Range)
                {
                    return;
                }

                int    cot        = BaseImage.PixelCount;
                IntPtr basePtr    = BaseImage.LockBitsAndGetScan0(ImageLockMode.ReadOnly);
                IntPtr convertPtr = ConvertImage.LockBitsAndGetScan0(ImageLockMode.WriteOnly);

                unsafe
                {
                    byte *baseP    = (byte *)basePtr.ToPointer();
                    byte *convertP = (byte *)convertPtr.ToPointer();
                    for (int i = 0; i < cot; i++)
                    {
                        if (_ColorMap[i] <= currentPick.Allowance && _DistanceMap[i] <= currentPick.Range)
                        {
                            if (!_UseMap[i] && !currentPick.UseMap[i])
                            {
                                convertP[0] = baseP[0];
                                convertP[1] = baseP[1];
                                convertP[2] = baseP[2];
                            }
                            currentPick.UseMap[i] = true;
                        }
                        else
                        {
                            if (!_UseMap[i] && currentPick.UseMap[i])
                            {
                                byte v = (byte)((baseP[0] + baseP[1] + baseP[2]) / 3);
                                convertP[0] = v;
                                convertP[1] = v;
                                convertP[2] = v;
                            }
                            currentPick.UseMap[i] = false;
                        }
                        baseP    += 4;
                        convertP += 4;
                    }
                }
                BaseImage.UnlockBits();
                ConvertImage.UnlockBits();
            }
Пример #3
0
            /// <summary>
            /// 增加取樣點並設定容許值及範圍
            /// </summary>
            public void AddPick(Color color, Point pickPoint, int allowance, int range)
            {
                Pick newPick = new Pick()
                {
                    Allowance    = allowance,
                    Range        = range,
                    PickPoint    = pickPoint,
                    DisplayPoint = new Point((int)(pickPoint.X * _DisplayScale), (int)(pickPoint.Y * _DisplayScale)),
                    Color        = color,
                    UseMap       = new BitArray(ConvertImage.PixelCount)
                };

                _PickInfos.Add(newPick);

                int    cot        = BaseImage.PixelCount;
                IntPtr basePtr    = BaseImage.LockBitsAndGetScan0(ImageLockMode.ReadOnly);
                IntPtr convertPtr = ConvertImage.LockBitsAndGetScan0(ImageLockMode.WriteOnly);

                unsafe
                {
                    byte * baseP       = (byte *)basePtr.ToPointer();
                    byte * convertP    = (byte *)convertPtr.ToPointer();
                    double maxDistance = MaxRange / BaseImage.MaxDistance;
                    int    i           = 0;
                    for (int y = 0; y < BaseImage.Height; y++)
                    {
                        for (int x = 0; x < BaseImage.Width; x++)
                        {
                            byte  r  = baseP[2];
                            byte  g  = baseP[1];
                            byte  b  = baseP[0];
                            int   dR = Math.Abs(newPick.Color.R - r);
                            int   dG = Math.Abs(newPick.Color.G - g);
                            int   dB = Math.Abs(newPick.Color.B - b);
                            short c  = (byte)Math.Max(Math.Max(dR, dG), dB);
                            short d  = (short)(Function.GetDistance(x, y, newPick.PickPoint.X, newPick.PickPoint.Y) * maxDistance);
                            if (c <= newPick.Allowance && d <= newPick.Range)
                            {
                                convertP[0]       = baseP[0];
                                convertP[1]       = baseP[1];
                                convertP[2]       = baseP[2];
                                newPick.UseMap[i] = true;
                            }
                            baseP    += 4;
                            convertP += 4;
                            i++;
                        }
                    }
                }
                BaseImage.UnlockBits();
                ConvertImage.UnlockBits();
            }
Пример #4
0
            /// <summary>
            /// 設定主要採樣點並建立採樣暫存地圖
            /// </summary>
            /// <param name="currentPickIndex">主要採樣點索引</param>
            public void SetCurrentIndex(int currentPickIndex)
            {
                if (currentPickIndex >= _PickInfos.Count || currentPickIndex < 0)
                {
                    return;
                }

                CurrentPickIndex = currentPickIndex;
                Pick   currentPick = _PickInfos[currentPickIndex];
                IntPtr basePtr     = BaseImage.LockBitsAndGetScan0(ImageLockMode.ReadOnly);

                unsafe
                {
                    byte * baseP       = (byte *)basePtr.ToPointer();
                    double maxDistance = MaxRange / BaseImage.MaxDistance;
                    int    i           = 0;
                    for (int y = 0; y < BaseImage.Height; y++)
                    {
                        for (int x = 0; x < BaseImage.Width; x++)
                        {
                            byte r = baseP[2];
                            byte g = baseP[1];
                            byte b = baseP[0];

                            int dR = Math.Abs(currentPick.Color.R - r);
                            int dG = Math.Abs(currentPick.Color.G - g);
                            int dB = Math.Abs(currentPick.Color.B - b);

                            short d = (short)(Function.GetDistance(x, y, currentPick.PickPoint.X, currentPick.PickPoint.Y) * maxDistance);
                            _ColorMap[i]    = (byte)Math.Max(Math.Max(dR, dG), dB);
                            _DistanceMap[i] = d;
                            baseP          += 4;
                            i++;
                        }
                    }
                }

                _UseMap.SetAll(false);
                foreach (Pick pick in _PickInfos)
                {
                    if (pick == currentPick)
                    {
                        continue;
                    }
                    _UseMap.Or(pick.UseMap);
                }
                BaseImage.UnlockBits();
            }