コード例 #1
0
 protected override void OnRender(IDrawingContext dc, RectFloat clipRect, CanvasView canvasView)
 {
     if ((canvasView.ScaleRatio >= 2.0) && GetIsPixelGridEnabled(canvasView))
     {
         SizeDouble      canvasSize = base.Owner.CanvasSize;
         RectDouble      b          = new RectDouble(PointDouble.Zero, canvasSize);
         RectInt32       rect       = RectDouble.Intersect(clipRect, b).Int32Bound;
         Matrix3x2Double transform  = dc.Transform;
         double          num6       = 1.0 / canvasView.CanvasHairWidth;
         RectDouble      num7       = transform.Transform(rect);
         double          num9       = DoubleUtil.Clamp((canvasView.ScaleRatio - 2.0) / 4.0, 0.0, 1.0) / 2.0;
         this.stippleBitmapBrush.Opacity = num9;
         using (dc.UseAntialiasMode(AntialiasMode.Aliased))
         {
             using (dc.UseTransform(Matrix3x2Float.Identity))
             {
                 using (dc.UseAxisAlignedClip((RectFloat)num7, AntialiasMode.Aliased))
                 {
                     for (int i = -(rect.Width & 1); i <= rect.Width; i++)
                     {
                         dc.DrawLine(num7.X + (i * num6), num7.Y, num7.X + (i * num6), num7.Y + num7.Height, this.stippleBitmapBrush, 1.0);
                     }
                     for (int j = -(rect.Height & 1); j <= rect.Height; j++)
                     {
                         dc.DrawLine(num7.X, num7.Y + (j * num6), num7.X + num7.Width, num7.Y + (j * num6), this.stippleBitmapBrush, 1.0);
                     }
                 }
             }
         }
     }
     base.OnRender(dc, clipRect, canvasView);
 }
コード例 #2
0
        public void BeforeRender(RectFloat clipRect)
        {
            if ((!this.afterRenderCalled || this.beforeRenderCalled) || this.renderCalled)
            {
                throw new PaintDotNet.InternalErrorException();
            }
            this.afterRenderCalled  = false;
            this.beforeRenderCalled = true;
            base.VerifyAccess();
            double scaleRatio = this.canvasView.ScaleRatio;
            bool   flag       = scaleRatio == ((int)scaleRatio);
            int    index      = (int)DoubleUtil.Clamp(this.ConvertScaleRatioToMipLevel(scaleRatio), 0.0, (double)(this.MipLevelCount - 1));
            DocumentCanvasLayerViewMipLayer item = this.mipLayers[index];

            if (this.mipLayerZOrder.IndexOf(item) != 0)
            {
                this.mipLayerZOrder.Remove(item);
                this.mipLayerZOrder.Insert(0, item);
                item.IsVisible = true;
                item.IsActive  = true;
                this.canvasView.Invalidate();
            }
            this.tileCaches[this.mipLayerZOrder[0].MipLevel].ProcessTileRenderedQueue();
            this.mipLayerZOrder[0].BeforeRender(clipRect);
            for (int i = this.mipLayerZOrder.Count - 1; i >= 1; i--)
            {
                this.mipLayerZOrder[i].BeforeRender(clipRect);
                this.mipLayerZOrder[i].IsActive = false;
            }
        }
コード例 #3
0
 public void Render(IDrawingContext dc, RectFloat clipRect)
 {
     if ((!this.beforeRenderCalled || this.renderCalled) || this.afterRenderCalled)
     {
         throw new PaintDotNet.InternalErrorException();
     }
     this.renderCalled = true;
     using (dc.UseAntialiasMode(AntialiasMode.Aliased))
     {
         double scaleRatio = this.canvasView.ScaleRatio;
         double d          = this.ConvertScaleRatioToMipLevel(scaleRatio);
         int    num3       = (int)Math.Floor(d);
         bool   flag       = Math.Abs((double)(d - Math.Round(d, MidpointRounding.AwayFromZero))) < 0.01;
         bool   isHighQualityScalingEnabled = DocumentCanvasLayer.GetIsHighQualityScalingEnabled(this.canvasView);
         for (int i = this.mipLayerZOrder.Count - 1; i >= 0; i--)
         {
             DocumentCanvasLayerViewMipLayer layer = this.mipLayerZOrder[i];
             if (layer.MipLevel == 0)
             {
                 if (flag)
                 {
                     layer.Render(dc, clipRect, 1f, BitmapInterpolationMode.NearestNeighbor);
                 }
                 else if (scaleRatio < 1.0)
                 {
                     layer.Render(dc, clipRect, 1f, isHighQualityScalingEnabled ? BitmapInterpolationMode.Linear : BitmapInterpolationMode.NearestNeighbor);
                 }
                 else
                 {
                     layer.Render(dc, clipRect, 1f, BitmapInterpolationMode.NearestNeighbor);
                     if ((scaleRatio < 2.0) & isHighQualityScalingEnabled)
                     {
                         double num5 = d - num3;
                         double num6 = 1.0 - (((1.0 - num5) * (1.0 - num5)) * (1.0 - num5));
                         double num7 = DoubleUtil.Clamp(num6, 0.0, 1.0);
                         layer.Render(dc, clipRect, (float)num7, BitmapInterpolationMode.Linear);
                     }
                 }
             }
             else
             {
                 layer.Render(dc, clipRect, 1f, isHighQualityScalingEnabled ? BitmapInterpolationMode.Linear : BitmapInterpolationMode.NearestNeighbor);
             }
         }
     }
 }
コード例 #4
0
ファイル: DocumentView.cs プロジェクト: ykafia/Paint.Net4
        protected void ZoomViaCurrentMousePosition(PaintDotNet.ScaleFactor newScaleFactor)
        {
            PointDouble center;
            PointInt32  pt = Control.MousePosition.ToPointInt32();
            RectDouble  visibleCanvasBounds = this.CanvasView.GetVisibleCanvasBounds();
            RectDouble  num3 = this.RectangleToScreen(this.DocumentToClient(visibleCanvasBounds));

            if (num3.Contains(pt))
            {
                double x = DoubleUtil.Clamp((double)pt.X, num3.Left, num3.Right);
                center = new PointDouble(x, DoubleUtil.Clamp((double)pt.Y, num3.Top, num3.Bottom));
            }
            else
            {
                center = num3.Center;
            }
            PointDouble clientPt         = this.PointToClient(center);
            PointDouble anchorPtViewport = this.CanvasView.ConvertCanvasToViewport(this.ClientToDocument(clientPt));

            this.ZoomToWithCentering(newScaleFactor, () => this.CanvasView.ConvertViewportToCanvas(anchorPtViewport));
        }
コード例 #5
0
        private double GetGradientStopAlpha(double offset)
        {
            double num5;

            if ((offset < 0.0) || (offset > 1.0))
            {
                throw new ArgumentOutOfRangeException();
            }
            double effectiveHardness       = GetEffectiveHardness(this.hardness, base.Antialiased);
            double hardnessInflationFactor = GetHardnessInflationFactor(this.hardness, base.Antialiased);
            double num3 = effectiveHardness;
            double num4 = 1.0 - num3;

            if (offset <= num3)
            {
                num5 = 1.0;
            }
            else
            {
                double x = (offset - num3) / num4;
                num5 = MathUtil.Gaussian(x, 1.0, 0.0, 0.275);
            }
            return(DoubleUtil.Clamp(num5, 0.0, 1.0));
        }
コード例 #6
0
 private void OnOpacityVariableValueChanged(object sender, EventArgs e)
 {
     base.Opacity = (float)DoubleUtil.Clamp(this.opacityVariable.Value, 0.0, 1.0);
 }
コード例 #7
0
ファイル: RectDoubleUtil.cs プロジェクト: ykafia/Paint.Net4
 public static PointDouble Clamp(RectDouble bounds, PointDouble point) =>
 new PointDouble(DoubleUtil.Clamp(point.x, bounds.Left, bounds.Right), DoubleUtil.Clamp(point.y, bounds.Top, bounds.Bottom));
コード例 #8
0
ファイル: DdsFile.cs プロジェクト: ykafia/Paint.Net4
        public void Save(Stream output, Surface surface, DdsFileFormat fileFormat, DdsCompressorType compressorType, DdsErrorMetric errorMetric, bool generateMipMaps, ResamplingAlgorithm mipMapResamplingAlgorithm, bool weightColorByAlpha, ProgressEventHandler progressCallback)
        {
            int  num21;
            int  num      = 0;
            bool flag     = ((fileFormat == DdsFileFormat.DDS_FORMAT_DXT1) || (fileFormat == DdsFileFormat.DDS_FORMAT_DXT3)) || (fileFormat == DdsFileFormat.DDS_FORMAT_DXT5);
            int  num2     = 1;
            int  mipWidth = surface.Width;
            int  height   = surface.Height;

            if (generateMipMaps)
            {
                while ((mipWidth > 1) || (height > 1))
                {
                    num2++;
                    mipWidth /= 2;
                    height   /= 2;
                }
            }
            this.m_header.m_size        = this.m_header.Size();
            this.m_header.m_headerFlags = 0x1007;
            if (flag)
            {
                this.m_header.m_headerFlags |= 0x80000;
            }
            else
            {
                this.m_header.m_headerFlags |= 8;
            }
            if (num2 > 1)
            {
                this.m_header.m_headerFlags |= 0x20000;
            }
            this.m_header.m_height = (uint)surface.Height;
            this.m_header.m_width  = (uint)surface.Width;
            if (flag)
            {
                int num5 = ((surface.Width + 3) / 4) * ((surface.Height + 3) / 4);
                int num6 = (fileFormat == DdsFileFormat.DDS_FORMAT_DXT1) ? 8 : 0x10;
                this.m_header.m_pitchOrLinearSize = (uint)(num5 * num6);
            }
            else
            {
                switch (fileFormat)
                {
                case DdsFileFormat.DDS_FORMAT_A8R8G8B8:
                case DdsFileFormat.DDS_FORMAT_X8R8G8B8:
                case DdsFileFormat.DDS_FORMAT_A8B8G8R8:
                case DdsFileFormat.DDS_FORMAT_X8B8G8R8:
                    num = 4;
                    break;

                case DdsFileFormat.DDS_FORMAT_A1R5G5B5:
                case DdsFileFormat.DDS_FORMAT_A4R4G4B4:
                case DdsFileFormat.DDS_FORMAT_R5G6B5:
                    num = 2;
                    break;

                case DdsFileFormat.DDS_FORMAT_R8G8B8:
                    num = 3;
                    break;
                }
                this.m_header.m_pitchOrLinearSize = (uint)(this.m_header.m_width * num);
            }
            this.m_header.m_depth        = 0;
            this.m_header.m_mipMapCount  = (num2 == 1) ? 0 : ((uint)num2);
            this.m_header.m_reserved1_0  = 0;
            this.m_header.m_reserved1_1  = 0;
            this.m_header.m_reserved1_2  = 0;
            this.m_header.m_reserved1_3  = 0;
            this.m_header.m_reserved1_4  = 0;
            this.m_header.m_reserved1_5  = 0;
            this.m_header.m_reserved1_6  = 0;
            this.m_header.m_reserved1_7  = 0;
            this.m_header.m_reserved1_8  = 0;
            this.m_header.m_reserved1_9  = 0;
            this.m_header.m_reserved1_10 = 0;
            this.m_header.m_pixelFormat.Initialise(fileFormat);
            this.m_header.m_surfaceFlags = 0x1000;
            if (num2 > 1)
            {
                this.m_header.m_surfaceFlags |= 0x400008;
            }
            this.m_header.m_cubemapFlags = 0;
            this.m_header.m_reserved2_0  = 0;
            this.m_header.m_reserved2_1  = 0;
            this.m_header.m_reserved2_2  = 0;
            output.WriteUInt32(0x20534444);
            this.m_header.Write(output);
            int squishFlags = this.GetSquishFlags(fileFormat, compressorType, errorMetric, weightColorByAlpha);

            mipWidth = surface.Width;
            height   = surface.Height;
            SizeInt32[] numArray        = new SizeInt32[num2];
            int[]       numArray2       = new int[num2];
            int[]       pixelsCompleted = new int[num2];
            long        totalPixels     = 0L;

            for (int i = 0; i < num2; i++)
            {
                SizeInt32 num8 = new SizeInt32((mipWidth > 0) ? mipWidth : 1, (height > 0) ? height : 1);
                numArray[i] = num8;
                int num9 = num8.Width * num8.Height;
                numArray2[i] = num9;
                if (i == 0)
                {
                    pixelsCompleted[i] = 0;
                }
                else
                {
                    pixelsCompleted[i] = pixelsCompleted[i - 1] + numArray2[i - 1];
                }
                totalPixels += num9;
                mipWidth    /= 2;
                height      /= 2;
            }
            mipWidth = surface.Width;
            height   = surface.Height;
            for (int mipLoop = 0; mipLoop < num2; mipLoop = num21 + 1)
            {
                byte[]    buffer;
                SizeInt32 size     = numArray[mipLoop];
                Surface   surface2 = new Surface(size);
                if (mipLoop == 0)
                {
                    surface2 = surface;
                }
                else
                {
                    IRenderer <ColorBgra> renderer;
                    SizeInt32             newSize = surface2.Size <ColorBgra>();
                    switch (mipMapResamplingAlgorithm)
                    {
                    case ResamplingAlgorithm.NearestNeighbor:
                        renderer = surface.ResizeNearestNeighbor(newSize);
                        break;

                    case ResamplingAlgorithm.Bilinear:
                        renderer = surface.ResizeBilinear(newSize);
                        break;

                    case ResamplingAlgorithm.Bicubic:
                        renderer = surface.ResizeBicubic(newSize);
                        break;

                    case ResamplingAlgorithm.SuperSampling:
                        renderer = surface.ResizeSuperSampling(newSize);
                        break;

                    case ResamplingAlgorithm.Fant:
                        renderer = surface.ResizeFant(newSize);
                        break;

                    default:
                        throw ExceptionUtil.InvalidEnumArgumentException <ResamplingAlgorithm>(mipMapResamplingAlgorithm, "mipMapResamplingAlgorithm");
                    }
                    renderer.Render <ColorBgra>(surface2);
                }
                DdsSquish.ProgressFn fn = delegate(int workDone, int workTotal) {
                    long   num  = workDone * mipWidth;
                    long   num2 = pixelsCompleted[mipLoop];
                    double num3 = (num + num2) / ((double)totalPixels);
                    progressCallback(this, new ProgressEventArgs(DoubleUtil.Clamp(100.0 * num3, 0.0, 100.0)));
                };
                if ((fileFormat >= DdsFileFormat.DDS_FORMAT_DXT1) && (fileFormat <= DdsFileFormat.DDS_FORMAT_DXT5))
                {
                    buffer = DdsSquish.CompressImage(surface2, squishFlags, (progressCallback == null) ? null : fn);
                }
                else
                {
                    int num12 = num * surface2.Width;
                    buffer = new byte[num12 * surface2.Height];
                    buffer.Initialize();
                    for (int j = 0; j < surface2.Height; j++)
                    {
                        for (int k = 0; k < surface2.Width; k++)
                        {
                            ColorBgra point = surface2.GetPoint(k, j);
                            uint      num15 = 0;
                            switch (fileFormat)
                            {
                            case DdsFileFormat.DDS_FORMAT_A8R8G8B8:
                                num15 = (uint)((((point.A << 0x18) | (point.R << 0x10)) | (point.G << 8)) | point.B);
                                break;

                            case DdsFileFormat.DDS_FORMAT_X8R8G8B8:
                                num15 = (uint)(((point.R << 0x10) | (point.G << 8)) | point.B);
                                break;

                            case DdsFileFormat.DDS_FORMAT_A8B8G8R8:
                                num15 = (uint)((((point.A << 0x18) | (point.B << 0x10)) | (point.G << 8)) | point.R);
                                break;

                            case DdsFileFormat.DDS_FORMAT_X8B8G8R8:
                                num15 = (uint)(((point.B << 0x10) | (point.G << 8)) | point.R);
                                break;

                            case DdsFileFormat.DDS_FORMAT_A1R5G5B5:
                                num15 = (uint)((((((point.A != null) ? 1 : 0) << 15) | ((point.R >> 3) << 10)) | ((point.G >> 3) << 5)) | (point.B >> 3));
                                break;

                            case DdsFileFormat.DDS_FORMAT_A4R4G4B4:
                                num15 = (uint)(((((point.A >> 4) << 12) | ((point.R >> 4) << 8)) | ((point.G >> 4) << 4)) | (point.B >> 4));
                                break;

                            case DdsFileFormat.DDS_FORMAT_R8G8B8:
                                num15 = (uint)(((point.R << 0x10) | (point.G << 8)) | point.B);
                                break;

                            case DdsFileFormat.DDS_FORMAT_R5G6B5:
                                num15 = (uint)((((point.R >> 3) << 11) | ((point.G >> 2) << 5)) | (point.B >> 3));
                                break;
                            }
                            int num16 = (j * num12) + (k * num);
                            for (int m = 0; m < num; m++)
                            {
                                buffer[num16 + m] = (byte)((num15 >> (8 * m)) & 0xff);
                            }
                        }
                        if (progressCallback != null)
                        {
                            long   num18 = (j + 1) * mipWidth;
                            long   num19 = pixelsCompleted[mipLoop];
                            double num20 = (num18 + num19) / ((double)totalPixels);
                            progressCallback(this, new ProgressEventArgs(100.0 * num20));
                        }
                    }
                }
                output.Write(buffer, 0, buffer.GetLength(0));
                mipWidth /= 2;
                height   /= 2;
                num21     = mipLoop;
            }
        }
コード例 #9
0
        private bool AutoScrollIfNecessary(PointDouble position)
        {
            if (!this.autoScroll || !this.CanPan())
            {
                return(false);
            }
            RectDouble   viewportCanvasBounds = this.CanvasView.ViewportCanvasBounds;
            RectDouble   canvasBounds         = this.CanvasView.GetCanvasBounds();
            double       x     = DoubleUtil.Lerp((viewportCanvasBounds.Left + viewportCanvasBounds.Right) / 2.0, position.X, 1.02);
            PointDouble  num3  = new PointDouble(x, DoubleUtil.Lerp((viewportCanvasBounds.Top + viewportCanvasBounds.Bottom) / 2.0, position.Y, 1.02));
            double       num15 = (num3.X < viewportCanvasBounds.Left) ? ((double)(-1)) : ((num3.X > viewportCanvasBounds.Right) ? ((double)1) : ((double)0));
            double       y     = (num3.Y < viewportCanvasBounds.Top) ? ((double)(-1)) : ((num3.Y > viewportCanvasBounds.Bottom) ? ((double)1) : ((double)0));
            VectorDouble vec   = new VectorDouble(num15, y);

            if (vec.IsCloseToZero())
            {
                return(false);
            }
            TimeSpan span = (TimeSpan)(DateTime.UtcNow - this.lastAutoScrollTime);
            double   num5 = DoubleUtil.Clamp(span.TotalSeconds, 0.0, 0.1);

            if (DoubleUtil.IsCloseToZero(num5))
            {
                return(false);
            }
            double          num6                 = (double)AppSettings.Instance.Workspace.AutoScrollViewportPxPerSecond.Value;
            VectorDouble    viewportVec          = (VectorDouble)((num5 * vec) * num6);
            PointDouble     viewportCanvasOffset = this.CanvasView.ViewportCanvasOffset;
            VectorDouble    num9                 = this.CanvasView.ConvertViewportToCanvas(viewportVec);
            double          left                 = UIUtil.ScaleWidth((double)5.0);
            double          top   = UIUtil.ScaleHeight((double)5.0);
            ThicknessDouble num12 = new ThicknessDouble(left, top, left, top);
            VectorDouble    zero  = VectorDouble.Zero;

            if ((num9.X < 0.0) && (viewportCanvasBounds.Left > -num12.Left))
            {
                zero.X = Math.Max(num9.X, -(viewportCanvasBounds.Left + num12.Left));
            }
            if ((num9.Y < 0.0) && (viewportCanvasBounds.Top > -num12.Top))
            {
                zero.Y = Math.Max(num9.Y, -(viewportCanvasBounds.Top + num12.Top));
            }
            if ((num9.X > 0.0) && (viewportCanvasBounds.Right < (canvasBounds.Right + num12.Right)))
            {
                zero.X = Math.Min(num9.X, (canvasBounds.Right + num12.Right) - viewportCanvasBounds.Right);
            }
            if ((num9.Y > 0.0) && (viewportCanvasBounds.Bottom < (canvasBounds.Bottom + num12.Bottom)))
            {
                zero.Y = Math.Min(num9.Y, (canvasBounds.Bottom + num12.Bottom) - viewportCanvasBounds.Bottom);
            }
            if (zero.IsCloseToZero())
            {
                return(false);
            }
            PointDouble num14 = viewportCanvasOffset + zero;

            this.ResetLastAutoScrollTime();
            this.CanvasView.ViewportCanvasOffset = num14;
            this.Update();
            return(true);
        }