예제 #1
0
파일: XCore.cs 프로젝트: phjungDiones/merge
        public bool Histogram()
        {
            int[] pHist = m_cHist.Hist;
            if (m_InputImage != null)
            {
                for (int n = 0; n < 256; n++)
                {
                    pHist[n] = 0;
                }

                int        nHeight       = InputImage.Height;
                int        nWidth        = InputImage.Width;
                Rectangle  Rect          = new Rectangle(0, 0, nWidth, nHeight);
                BitmapData SocBitmapData = InputImage.LockBits(Rect
                                                               , ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);

                try
                {
                    if (SocBitmapData != null)
                    {
                        unsafe
                        {
                            byte *Soc     = (byte *)SocBitmapData.Scan0.ToPointer();
                            int   nStride = SocBitmapData.Stride;

                            for (int nH = 0; nH < nHeight; nH++)
                            {
                                for (int nW = 0; nW < nStride; nW += 8)
                                {
                                    pHist[Soc[nW]]++;
                                    pHist[Soc[nW + 1]]++;
                                    pHist[Soc[nW + 2]]++;
                                    pHist[Soc[nW + 3]]++;
                                    pHist[Soc[nW + 4]]++;
                                    pHist[Soc[nW + 5]]++;
                                    pHist[Soc[nW + 6]]++;
                                    pHist[Soc[nW + 7]]++;
                                }
                                Soc += nStride;
                            }
                        }
                        InputImage.UnlockBits(SocBitmapData);
                    }
                }
                catch (Exception pe)
                {
                    string sMsg = pe.ToString();
                    return(false);
                }
            }
            return(true);
        }