Esempio n. 1
0
 public void Process()
 {
     for (int i = _from; i < _to; i++)
     {
         var maxInLine = _data.GetMaxInLine(i);
         for (int j = 0; j < _data.GetWidth(); j++)
         {
             var offset     = ((i * _data.GetWidth()) + j) * _depth;
             int pixelColor = _currentState.Process(_data.Data[i][j], maxInLine);
             _buffer[offset + 0] = _buffer[offset + 1] = _buffer[offset + 2] = (byte)pixelColor;
         }
     }
 }
Esempio n. 2
0
        public Bitmap CreateImage(int threadNumber, State currentState)
        {
            _bitmap = new Bitmap(_data.GetWidth(), _data.GetHeight(), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            var bitmapData = _bitmap.LockBits(new Rectangle(0, 0, _data.GetWidth(), _data.GetHeight()), System.Drawing.Imaging.ImageLockMode.ReadWrite, _bitmap.PixelFormat);
            var depth      = Bitmap.GetPixelFormatSize(bitmapData.PixelFormat) / 8;

            var buffer = new byte[_data.GetWidth() * _data.GetHeight() * depth];

            List <Thread> threads = new List <Thread>(threadNumber);

            for (int i = 0; i <= threadNumber - 1; i++)
            {
                int from = (_data.GetHeight() / threadNumber) * i;
                int to   = (_data.GetHeight() / threadNumber) * (i + 1);

                ImagePart imagePart;

                if (i == threadNumber - 1)
                {
                    imagePart = new ImagePart(_data, from, _data.GetHeight(), buffer, depth, currentState);
                    imagePart.Process();
                }
                else
                {
                    imagePart = new ImagePart(_data, from, to, buffer, depth, currentState);
                    Thread thread = new Thread(new ThreadStart(imagePart.Process));
                    thread.Start();
                    threads.Add(thread);
                }
            }

            foreach (var thread in threads)
            {
                thread.Join();
            }

            Marshal.Copy(buffer, 0, bitmapData.Scan0, buffer.Length);

            _bitmap.UnlockBits(bitmapData);

            return(_bitmap);
        }