public override void PixBltPixelArray(IPixelArray pixBuff, int x, int y)
        {
            //NewTOAPIA.Kernel.PrecisionTimer timer = new NewTOAPIA.Kernel.PrecisionTimer();

            // 1. convert the pixel array to a Bitmap object
            Bitmap bm = PixelBufferHelper.CreateBitmapFromPixelArray(pixBuff);

            // 2. Write this bitmap to a memory stream as a compressed JPEG image
            MemoryStream ms = new MemoryStream();
            bm.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);

            // 3. Get the bytes from the stream
            byte[] imageBytes = ms.GetBuffer();

            // 4. Allocate a buffer chunk to accomodate the bytes, plus some more
            BufferChunk chunk = new BufferChunk(imageBytes.Length + 128);

            // 5. Put the command, destination, and data size into the buffer first
            chunk += (int)UICommands.PixBltJPG;
            ChunkUtils.Pack(chunk, x, y);
            chunk += (int)imageBytes.Length;

            // 6. Put the image bytes into the chunk
            chunk += imageBytes;
            //double duration = timer.GetElapsedSeconds();
            //Console.WriteLine("Encoder - Time to pack image: {0}", duration);

            // Finally, send the packet
            SendCommand(chunk);
        }
Example #2
0
        private void RenderMultiThreaded(IPixelArray pixelArray, Camera camera, Scene scene, bool useKdTree)
        {
            var rayTracer = CreateRayTracer(camera, _renderData, scene, useKdTree);

            ThreadPool.SetMinThreads(rayTracer.RenderData.NumThreads * 3, rayTracer.RenderData.NumThreads * 3);

            var queueDataAvailableEvent = new AutoResetEvent(false);
            var rowQueue    = new ConcurrentQueue <int>();
            var resultQueue = new ConcurrentQueue <RenderLineResult>();

            for (var y = 0; y < rayTracer.RenderData.Height; y++)
            {
                rowQueue.Enqueue(y);
            }

            var tasks = new List <Task>();

            for (var thid = 0; thid < rayTracer.RenderData.NumThreads; thid++)
            {
                tasks.Add(Task.Run(() => RenderFunc(rayTracer, rowQueue, resultQueue, queueDataAvailableEvent)));
            }

            tasks.Add(Task.Run(() => ResultFunc(pixelArray, resultQueue, queueDataAvailableEvent)));

            Task.WaitAll(tasks.ToArray());
        }
Example #3
0
        private void RenderSingleThreaded(IPixelArray pixelArray, Camera camera, Scene scene, bool useKdTree)
        {
            var tracer = CreateRayTracer(camera, _renderData, scene, useKdTree);

            for (var y = 0; y < _renderData.Height; y++)
            {
                try
                {
                    pixelArray.Lock();
                    for (var x = 0; x < _renderData.Width; x++)
                    {
                        var color = tracer.GetPixelColor(x, y);
                        pixelArray.SetPixelColor(x, y, color);
                    }
                }
                finally
                {
                    pixelArray.Unlock();
                }

                Progress?.Invoke(
                    this,
                    new RenderProgressEventArgs((Convert.ToDouble(y) * 100.0) / Convert.ToDouble(_renderData.Height)));
            }
        }
Example #4
0
        public PictureWindow(int x, int y)
            : base("Targa Viewer", x, y, 320, 600)
        {
            //picture = TargaLoader.CreatePixelArrayFromFile("marbles.tga");
            //picture = TargaLoader.CreatePixelArrayFromFile("xing_b24.tga");
            //picture = TargaLoader.CreatePixelArrayFromFile("xing_b32.tga");
            //picture = TargaLoader.CreatePixelArrayFromFile("xing_t24.tga");
            //picture = TargaLoader.CreatePixelArrayFromFile("xing_t32.tga");
            //picture = TargaLoader.CreatePixelArrayFromFile("ctc24.tga");
            //picture = TargaLoader.CreatePixelArrayFromFile("flag_t32.tga");
            //picture = TargaLoader.CreatePixelArrayFromFile("flag_b32.tga");
            //picture = TargaLoader.CreatePixelDataFromFile("utc32.tga");
            //picture = TargaLoader.CreatePixelDataFromFile("utc24.tga");

            // Create a copy of the original
            copyBuffer = (IPixelArray)picture.Clone();


            //UnaryColorOperations.SetLuminance op = new UnaryColorOperations.SetLuminance();
            //UnaryColorOperations.SetColor op = new UnaryColorOperations.SetColor(new ColorRGBA(0.5f,1,0.5f));
            //UnaryColorOperations.NOT op = new UnaryColorOperations.NOT();
            //op.PerformUnaryOperation(picture.ColorAccessor);

            // Create an alpha fade from left to right
            PixelArray<BGRAb> alphaBuffer = CreateAlphaMask(picture.Width, picture.Height);
            IBinaryColorOperator binop = new ApplySourceAlpha();
            copyBuffer.ApplyBinaryColorOperator(binop, alphaBuffer);

            // Subtract the alpha fade from the copied image and display the copy
            //binop = new ColorBinaryOperations.SubtractSource();
            //binop.PerformBinaryOperation(copyBuffer.ColorAccessor, picture);

        }
Example #5
0
        public GraphicImage(string name, int x, int y, int width, int height, IPixelArray pbuff)
            :base(name, x,y,width,height)
        {
            fPixmap = pbuff;
            fOpacity = 1.0;
            fUseOpacity = false;

            Debug = true;
        }
Example #6
0
        public void Render(IPixelArray pixelArray, Camera camera, Scene scene, bool useKdTree)
        {
            Progress?.Invoke(this, new RenderProgressEventArgs(0.0));

            if (_renderData.NumThreads <= 1)
            {
                RenderSingleThreaded(pixelArray, camera, scene, useKdTree);
            }

            RenderMultiThreaded(pixelArray, camera, scene, useKdTree);
        }
Example #7
0
        private void Render(IPixelArray pixelArray, Scene scene, Camera camera, string name)
        {
            var renderer = new Renderer(_renderData, true);

            using (new LogTimer($"Render {name}"))
            {
                renderer.Progress += (sender, args) =>
                {
                    Dispatcher.Invoke(() => { RenderProgress.Value = args.PercentComplete; });
                };
                Task.Run(() =>
                {
                    Dispatcher.Invoke(() => RenderButton.IsEnabled = false);
                    renderer.Render(pixelArray, camera, scene, true);
                    Dispatcher.Invoke(() => RenderButton.IsEnabled = true);
                });
                //string filename = UseExTracer ? $"{name}_scene_ex.png" : $"{name}_scene.png";
                //pixelArray.SaveAsFile(Path.Combine(OutputDirectory, filename));
            }
        }
Example #8
0
        private void ResultFunc(
            IPixelArray pixelArray,
            ConcurrentQueue <RenderLineResult> resultQueue,
            AutoResetEvent queueDataAvailableEvent)
        {
            var incompleteRows = new HashSet <int>();

            for (var y = 0; y < pixelArray.Height; y++)
            {
                incompleteRows.Add(y);
            }

            while (incompleteRows.Count > 0)
            {
                queueDataAvailableEvent.WaitOne();

                try
                {
                    pixelArray.Lock();
                    while (resultQueue.TryDequeue(out var renderLineResult))
                    {
                        // assert pixelArray.Width == renderLineResult.Count
                        pixelArray.SetPixelRowColors(renderLineResult.Y, renderLineResult.RowPixels);
                        incompleteRows.Remove(renderLineResult.Y);

                        var totalRows       = Convert.ToDouble(pixelArray.Height);
                        var completeRows    = Convert.ToDouble(pixelArray.Height - incompleteRows.Count);
                        var percentComplete = completeRows / totalRows * 100.0;
                        Console.WriteLine($"Percent Complete: {percentComplete:F}%");

                        Progress?.Invoke(
                            this,
                            new RenderProgressEventArgs(percentComplete));
                    }
                }
                finally
                {
                    pixelArray.Unlock();
                }
            }
        }
Example #9
0
        public virtual void PixmapShardBlt(IPixelArray pixmap, Rectangle srcBoundary, Rectangle destinationRect)
        {
            int srcX = srcBoundary.X;
            int srcY = srcBoundary.Y;
            int width = srcBoundary.Width;
            int height = srcBoundary.Height;

            int dstX = destinationRect.X;
            int dstY = destinationRect.Y;

            // Now we have srcRect representing the fraction of the pixArray that we want to display.
            // It's been clipped to the boundary of the IPixelArray that we're holding onto

            // 2.  Copy the pixels from the source to our destination
            // Perform a simple color copy
            for (int column = 0; column < width; column++)
                for (int row = 0; row < height; row++)
                {
                    ColorRGBA aColor = pixmap.GetColor(column + srcX, row + srcY);
                    fDstAccess.SetColor(column + dstX, row + dstY, aColor);
                }
        }
Example #10
0
        public virtual void PixBlt(IPixelArray pixArray, int x, int y)
        {
            // 1. Calculate the intersection intended destination rectangle
            // of the pixArray and the boundary of the pixelArray we're
            // holding onto.
            Rectangle srcRect = new Rectangle(x, y, pixArray.Width, pixArray.Height);

            // Create the boundary rectangle for our destination
            Rectangle dstRect = new Rectangle(0, 0, fDstAccess.Width, fDstAccess.Height);

            // Create the intersection of the dstRect and the srcRect
            srcRect.Intersect(dstRect);

            // If there is no intersection, then just return
            if (srcRect.IsEmpty)
                return;

            Rectangle srcBoundary = srcRect;
            srcBoundary.Offset(-x, -y);
            PixmapShardBlt(pixArray, srcBoundary, srcRect);

        }
Example #11
0
        public PictureWindow(int locx, int locy)
            : base("Run Length Encoding Viewer", locx, locy, 640, 480)
        {
            //picture = NewTOAPIA.Drawing.TargaLoader.CreatePixelDataFromFile("marbles.tga");
            //picture = NewTOAPIA.Drawing.TargaLoader.CreatePixelDataFromFile("xing_b24.tga");
            //picture = NewTOAPIA.Drawing.TargaLoader.CreatePixelDataFromFile("xing_b32.tga");
            //picture = NewTOAPIA.Drawing.TargaLoader.CreatePixelDataFromFile("xing_t24.tga");
            //picture = NewTOAPIA.Drawing.TargaLoader.CreatePixelDataFromFile("xing_t32.tga");
            //picture = NewTOAPIA.Drawing.TargaLoader.CreatePixelDataFromFile("ctc24.tga");
            //picture = NewTOAPIA.Drawing.TargaLoader.CreatePixelDataFromFile("flag_t32.tga");
            //picture = NewTOAPIA.Drawing.TargaLoader.CreatePixelDataFromFile("flag_b32.tga");
            //picture = NewTOAPIA.Drawing.TargaLoader.CreatePixelDataFromFile("utc32.tga");
            //picture = NewTOAPIA.Drawing.TargaLoader.CreatePixelDataFromFile("utc24.tga");
            //picture = CreateColorTestImage(40,40);
            //picture = CreateSteppedTestImage(128, 32);
            picture = CreateBarsTestImage(10);

            // Perform the runlength encoding on the image
            pixMap = new PixelArray<BGRb>(picture);

            RLC rlc = new RLC();
            //NewTOAPIA.Imaging.RunLengthCodec rlc = new RunLengthCodec();
            MemoryStream ms = new MemoryStream();

            rlc.Encode(new PixelAccessorBGRb(pixMap), ms);
            byte[] imageBytes = ms.GetBuffer();


            //Console.WriteLine("Image Bytes: {0}", imageBytes.Length);

            // Now decode the bytes back into a new image
            ms.Seek(0, SeekOrigin.Begin);

            tPic = new PixelArray<BGRb>(pixMap.Width, pixMap.Height, pixMap.Orientation, new PixelInformation(PixelLayout.Bgr, PixelComponentType.Byte));
            PixelAccessorBGRb accessor = new PixelAccessorBGRb(tPic);
            rlc.Decode(ms, accessor);
        }
Example #12
0
 // Generalized bit block transfer
 // Can transfer from any device context to this one.
 public virtual void PixBlt(IPixelArray bitmap, int x, int y)
 {
     // Convert to a Bitmap object
     // Blit that
 }
Example #13
0
 public GraphicImage(string name, IPixelArray pbuff)
     : this(name, 0, 0, pbuff.Width, pbuff.Height, pbuff)
 {
 }
Example #14
0
 public virtual void PixBltPixelArray(IPixelArray pixBuff, int x, int y)
 {
     if (null != PixBltPixelArrayHandler)
         PixBltPixelArrayHandler(pixBuff, x, y);
 }
Example #15
0
 public virtual void PixmapShardBlt(IPixelArray bitmap, Rectangle srcRect, Rectangle dstRect)
 {
     // Convert to a Bitmap object
     // Blit that
 }
Example #16
0
 public PixmapShard(IPixelArray pixmap, Rectangle boundary, Rectangle frame)
 {
     fPixmap = pixmap;
     fBoundary = boundary;
     fFrame = frame;
 }
Example #17
0
        // Generalized bit block transfer
        // Can transfer from any device context to this one.
        public virtual void PixBlt(IPixelArray pixmap, int x, int y)
        {
            if (null == pixmap)
                return;

            BITMAPINFO bmi = new BITMAPINFO();
            bmi.Init();
            
            bmi.bmiHeader.biBitCount = (ushort)pixmap.BitsPerPixel;
            bmi.bmiHeader.biWidth = pixmap.Width;

            if (pixmap.Orientation == PixmapOrientation.TopToBottom)
                bmi.bmiHeader.biHeight = -pixmap.Height;
            else
                bmi.bmiHeader.biHeight = pixmap.Height;

            bmi.bmiHeader.biSizeImage = (uint)(pixmap.BytesPerRow * pixmap.Height);
            bmi.bmiHeader.biPlanes = 1;
            bmi.bmiHeader.biClrImportant = 0;
            bmi.bmiHeader.biClrUsed = 0;
            bmi.bmiHeader.biCompression = 0;

            int result = GDI32.StretchDIBits(DeviceContext, x, y, pixmap.Width, pixmap.Height, 0, 0, pixmap.Width, pixmap.Height, pixmap.Pixels,
                ref bmi, GDI32.DIB_RGB_COLORS, (uint)TernaryRasterOps.SRCCOPY);

            //Console.WriteLine("Result: {0}", result);
        }
Example #18
0
 public RenderPixelBuffer(IPixelArray dstAccess)
 {
     fDstAccess = dstAccess;
 }
Example #19
0
        public virtual void PixmapShardBlt(IPixelArray pixmap, Rectangle srcRect, Rectangle dstRect)
        {
            if (null == pixmap)
                return;

            int result = DeviceContext.PixelBlt(srcRect, dstRect, pixmap.Pixels, (BitCount)pixmap.BitsPerPixel);
            
            //Console.WriteLine("Result: {0}", result);
        }