예제 #1
0
 public WorkerThreadInit(Bitmap im, int wid, int hei, int threadNo, int threads)
 {
     image  = im;
     id     = threadNo;
     width  = wid;
     height = hei;
     sel    = (n) => (n % threads) == threadNo;
 }
예제 #2
0
 public WorkerThreadInit(IRenderer r, Bitmap im, int wid, int hei, int threadNo, int threads)
 {
     rend   = r;
     image  = im;
     id     = threadNo;
     width  = wid;
     height = hei;
     sel    = (n) => (n % threads) == threadNo;
 }
예제 #3
0
 public WorkerThreadInit(IRenderer r, ITimeDependent sc, ITimeDependent imf, Bitmap im, int wid, int hei, int threadNo, int threads)
 {
     scene  = sc;
     imfunc = imf;
     rend   = r;
     image  = im;
     id     = threadNo;
     width  = wid;
     height = hei;
     sel    = (n) => (n % threads) == threadNo;
 }
예제 #4
0
        /// <summary>
        /// Renders the given rectangle into the given raster image.
        /// Has to be re-entrant since this code is started in multiple parallel threads.
        /// </summary>
        /// <param name="image">Pre-initialized raster image.</param>
        /// <param name="sel">Selector for this working thread.</param>
        public virtual void RenderRectangle(Bitmap image, int x1, int y1, int x2, int y2, ThreadSelector sel)
        {
            bool lead = sel(0L);

            if (lead &&
                ProgressData != null)
            {
                lock (ProgressData)
                {
                    ProgressData.Finished = 0.0f;
                    ProgressData.Message  = "";
                }
            }

            double[] color = new double[3]; // pixel color

            // run several phases of image rendering:
            int cell = 32; // cell size

            while (cell > 1 && cell > Adaptive)
            {
                cell >>= 1;
            }
            int initCell = cell;

            int   x, y;
            bool  xParity, yParity;
            float total   = (x2 - x1) * (y2 - y1);
            long  counter = 0L;
            long  units   = 0;

            do // do one phase
            {
                for (y = y1, yParity = false;
                     y < y2; // one image row
                     y += cell, yParity = !yParity)
                {
                    for (x = x1, xParity = false;
                         x < x2; // one image cell
                         x += cell, xParity = !xParity)
                    {
                        if (cell == initCell ||
                            xParity || yParity) // process the cell
                        {
                            if (!sel(counter++))
                            {
                                continue;
                            }

                            // determine sample color ..
                            RenderPixel(x, y, color);

                            if (Gamma <= 0.001)
                            {
                                for (int b = 0; b < color.Length; b++)
                                {
                                    color[b] = Arith.Clamp(color[b], 0.0, 1.0);
                                }
                            }

                            // .. and render it:
                            Color c = Color.FromArgb((int)(color [0] * 255.0),
                                                     (int)(color [1] * 255.0),
                                                     (int)(color [2] * 255.0));
                            lock (image)
                            {
                                if (cell == 1)
                                {
                                    image.SetPixel(x, y, c);
                                }
                                else
                                {
                                    int xMax = x + cell;
                                    if (xMax > x2)
                                    {
                                        xMax = x2;
                                    }
                                    int yMax = y + cell;
                                    if (yMax > y2)
                                    {
                                        yMax = y2;
                                    }
                                    for (int iy = y; iy < yMax; iy++)
                                    {
                                        for (int ix = x; ix < xMax; ix++)
                                        {
                                            image.SetPixel(ix, iy, c);
                                        }
                                    }
                                }
                            }

                            if ((++units & 63L) == 0L &&
                                ProgressData != null)
                            {
                                lock (ProgressData)
                                {
                                    if (!ProgressData.Continue)
                                    {
                                        return;
                                    }
                                    if (lead)
                                    {
                                        ProgressData.Finished = counter / total;
                                        ProgressData.Sync(image);
                                    }
                                }
                            }
                        }
                    }
                }
            } while ((cell >>= 1) > 0); // do one phase
        }
예제 #5
0
        /// <summary>
        /// Renders the given rectangle into the given raster image.
        /// Has to be re-entrant since this code is started in multiple parallel threads.
        /// </summary>
        /// <param name="image">Pre-initialized raster image.</param>
        /// <param name="sel">Selector for this working thread.</param>
        /// <param name="rnd">Thread-specific random generator.</param>
        public virtual void RenderRectangle( Bitmap image, int x1, int y1, int x2, int y2, ThreadSelector sel, RandomJames rnd )
        {
            bool lead = sel( 0L );
              if ( lead &&
               ProgressData != null )
            lock ( ProgressData )
            {
              ProgressData.Finished = 0.0f;
              ProgressData.Message = "";
            }

              double[] color = new double[ 3 ];     // pixel color

              // run several phases of image rendering:
              int cell = 32;                        // cell size
              while ( cell > 1 && cell > Adaptive )
            cell >>= 1;
              int initCell = cell;

              int x, y;
              bool xParity, yParity;
              float total = (x2 - x1) * (y2 - y1);
              long counter = 0L;
              long units = 0;

              do                                    // do one phase
              {
            for ( y = y1, yParity = false;
              y < y2;                       // one image row
              y += cell, yParity = !yParity )

              for ( x = x1, xParity = false;
                x < x2;                     // one image cell
                x += cell, xParity = !xParity )

            if ( cell == initCell ||
                 xParity || yParity )       // process the cell
            {
              if ( !sel( counter++ ) )
                continue;

              // determine sample color ..
              RenderPixel( x, y, color, rnd );

              if ( Gamma <= 0.001 )
                for ( int b = 0; b < color.Length; b++ )
                  color[ b ] = Arith.Clamp( color[ b ], 0.0, 1.0 );

              // .. and render it:
              Color c = Color.FromArgb( (int)(color[ 0 ] * 255.0),
                                        (int)(color[ 1 ] * 255.0),
                                        (int)(color[ 2 ] * 255.0) );
              lock ( image )
              {
                if ( cell == 1 )
                  image.SetPixel( x, y, c );
                else
                {
                  int xMax = x + cell;
                  if ( xMax > x2 )
                    xMax = x2;
                  int yMax = y + cell;
                  if ( yMax > y2 )
                    yMax = y2;
                  for ( int iy = y; iy < yMax; iy++ )
                    for ( int ix = x; ix < xMax; ix++ )
                      image.SetPixel( ix, iy, c );
                }
              }

              if ( (++units & 63L) == 0L &&
                   ProgressData != null )
                lock ( ProgressData )
                {
                  if ( !ProgressData.Continue )
                    return;
                  if ( lead )
                  {
                    ProgressData.Finished = counter / total;
                    ProgressData.Sync( image );
                  }
                }
            }
              }
              while ( (cell >>= 1) > 0 );         // do one phase
        }