Ejemplo n.º 1
0
        public ExportImage(FractalParameters fp, RenderingParameters rp)
        {
            _fractalP = fp;
            _renderP = rp;

            InitializeComponent();

            txtViewPosX.Text = _fractalP.viewPort.X.ToString();
            txtViewPosY.Text = _fractalP.viewPort.Y.ToString();
            txtViewWidth.Text = _fractalP.viewPort.Width.ToString();
            txtViewHeight.Text = _fractalP.viewPort.Height.ToString();
        }
Ejemplo n.º 2
0
        public void generateImage(RenderingParameters rp, ParallelOptions po)
        {
            int pixelSize = 4;
            BitmapData bd;

            if (po == null)
                po = new ParallelOptions();
            else
                po.CancellationToken.ThrowIfCancellationRequested();

            // The image exist and has been created in the generate() function
            bd = _resultImage.LockBits(new Rectangle(0, 0, _width, _height), System.Drawing.Imaging.ImageLockMode.WriteOnly, _resultImage.PixelFormat);

            try
            {

                Parallel.For(0, _height, po, j =>
                {
                    byte valR, valG, valB;
                    float val;
                    int posPixel = bd.Stride * j;
                    for (int i = 0; i < _width; i++)
                    {
                        /**
                         * Convert the iteration number in a byte => iteration space to image space
                         * result = log(iter) * contrast + brightness
                         * log(iter) has already been performed in the generation
                         * Do not perform boundary checking
                         **/
                        val = getValAt(i, j) * rp.contrast + rp.brightness;
                        valR = castFloatToByte(val * rp.RedParam, rp.RedExp);
                        valG = castFloatToByte(val * rp.GreenParam, rp.GreenExp);
                        valB = castFloatToByte(val * rp.BlueParam, rp.BlueExp);
                        _tabResultImage[posPixel + 0] = valB;
                        _tabResultImage[posPixel + 1] = valG;
                        _tabResultImage[posPixel + 2] = valR;
                        posPixel += pixelSize;
                    }
                });

                Marshal.Copy(_tabResultImage, 0, bd.Scan0, _height * bd.Stride);
            }
            catch (OperationCanceledException e) { throw e; }
            finally
            {
                _resultImage.UnlockBits(bd);
            }
        }