Esempio n. 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();
            }
Esempio n. 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();
            }
Esempio n. 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();
            }
Esempio n. 4
0
            /// <summary>
            /// 刪除取樣點
            /// </summary>
            /// <param name="removePickIndex">移除取樣點索引</param>
            public void RemovePick(int removePickIndex)
            {
                if (removePickIndex >= _PickInfos.Count || removePickIndex < 0)
                {
                    return;
                }

                Pick removePick = _PickInfos[removePickIndex];

                _PickInfos.Remove(removePick);
                CurrentPickIndex = -1;

                int      cot    = ConvertImage.PixelCount;
                BitArray useMap = new BitArray(cot);

                foreach (Pick pick in _PickInfos)
                {
                    useMap.Or(pick.UseMap);
                }

                IntPtr convertPtr = ConvertImage.LockBitsAndGetScan0(ImageLockMode.WriteOnly);

                unsafe
                {
                    byte *convertP = (byte *)convertPtr.ToPointer();
                    for (int i = 0; i < cot; i++)
                    {
                        if (removePick.UseMap[i] && !useMap[i])
                        {
                            byte v = (byte)((convertP[0] + convertP[1] + convertP[2]) / 3);
                            convertP[0] = v;
                            convertP[1] = v;
                            convertP[2] = v;
                        }
                        convertP += 4;
                    }
                }
                ConvertImage.UnlockBits();
            }