Ejemplo n.º 1
0
        public override int Update(IntPtr handle, IntPtr device, int x, int y, int w, int h)
        {
            if (_viewer.ProgressiveUpdate)
            {
                int bytesPerPixel = 3;

                if (_srcImage != IntPtr.Zero)
                {
                    _destImage.Lock();

                    int destStrideSize = (((_destImage.Width * bytesPerPixel) + 3) & ~3);
                    int tileStride     = (((w * bytesPerPixel) + 3) & ~3);

                    if (_synchTriggered)
                    {
                        _synchTriggered = false;

                        ImageMemoryHelper.Set24bppRgbImageColor(_destImage.Scan0, _destImage.Width, _destImage.Height, 255, 255, 255);
                    }

                    if (w == _destImage.Width && h == _destImage.Height)
                    {
                        //IntPtr bkp = Marshal.AllocCoTaskMem(destStrideSize * h);

                        //ImageMemoryHelper.CopyImagePartFrom(_destImage.Scan0, bkp, 0, 0, w, h, destStrideSize, bytesPerPixel);
                        //ImageMemoryHelper.CopyImagePartTo(_destImage.Scan0, _srcImage, 0, 0, w, h, destStrideSize, bytesPerPixel);
                        //ImageMemoryHelper.CopyImagePartTo(_destImage.Scan0, bkp, 0, 0, w, h, destStrideSize, bytesPerPixel);

                        //Marshal.FreeCoTaskMem(bkp);

                        _destImage.Unlock();

                        return(0);
                    }

                    IntPtr tempTile = Marshal.AllocHGlobal(tileStride * h);

                    ImageMemoryHelper.CopyImagePartFrom(_srcImage, tempTile, x, y, w, h, _srcStride, bytesPerPixel);

                    ImageMemoryHelper.FlipImageVertically(tempTile, tempTile, h, tileStride);

                    int tileMirrorY = _destImage.Height - y - h;

                    ImageMemoryHelper.CopyImagePartTo(_destImage.Scan0, tempTile, x, tileMirrorY, w, h, destStrideSize, bytesPerPixel);

                    Marshal.FreeHGlobal(tempTile);

                    _destImage.Unlock();

                    if (Environment.TickCount - _lastUpdateTime > _viewer.ProgressiveUpdateInterval)
                    {
                        _lastUpdateTime = Environment.TickCount;

                        _viewer.RaiseDisplayUpdate(new GhostscriptViewerViewEventArgs(_destImage, new Rectangle(0, 0, _destImage.Width, _destImage.Height)));
                    }
                }
            }

            return(0);
        }
        public override int Page(IntPtr handle, IntPtr device, int copies, int flush)
        {
            _viewer.FormatHandler.ShowPagePostScriptCommandInvoked = true;

            if (!_viewer.ProgressiveUpdate)
            {
                int bytesPerPixel = 3;

                _destImage.Lock();

                IntPtr tempTile = Marshal.AllocHGlobal(_destImage.Stride * _destImage.Height);

                ImageMemoryHelper.CopyImagePartFrom(_srcImage, tempTile, 0, 0, _destImage.Width, _destImage.Height, _srcStride, bytesPerPixel);
                ImageMemoryHelper.FlipImageVertically(tempTile, _destImage.Scan0, _destImage.Height, _destImage.Stride);

                Marshal.FreeHGlobal(tempTile);

                _destImage.Unlock();
            }

            _viewer.RaiseDisplayPage(new GhostscriptViewerViewEventArgs(_destImage, new Rectangle(0, 0, _destImage.Width, _destImage.Height)));

            return(0);
        }