예제 #1
0
        private void InitRow(int row)
        {
            ISurface <TPixel> source = this.source as ISurface <TPixel>;

            if (source != null)
            {
                this.rowPtrs[row] = source.GetRowPointer <TPixel>(row);
            }
            else
            {
                if (this.freeRow == null)
                {
                    this.rows[row] = new TPixel[this.width];
                    this.freeRowMissCount++;
                }
                else
                {
                    this.rows[row] = this.freeRow;
                    this.freeRow   = null;
                    this.freeRowHitCount++;
                }
                this.pinnedRows[row] = SafeGCHandle.Alloc <TPixel[]>(this.rows[row], GCHandleType.Pinned);
                this.rowPtrs[row]    = this.pinnedRows[row].AddrOfPinnedObject();
                SharedSurface <TPixel> dst = new SharedSurface <TPixel>(this.rowPtrs[row], this.width, 1, this.width * RendererRowCache <TPixel> .sizeOfTPixel);
                this.source.Render(dst, new PointInt32(0, row));
                this.rowRenderCounts[row]++;
                this.currentRowCount++;
                this.maxRowCount = Math.Max(this.currentRowCount, this.maxRowCount);
            }
        }
예제 #2
0
 protected override void OnCopyPixels <TBitmapLockData>(TBitmapLockData dst, PointInt32 srcOffset) where TBitmapLockData : IBitmapLockData <ColorBgra32>
 {
     using (SharedSurface <ColorBgra> surface = new SharedSurface <ColorBgra>(dst.Scan0, dst.Size.Width, dst.Size.Height, dst.Stride))
     {
         this.Render(surface, srcOffset);
     }
 }
예제 #3
0
        private void DrawToGraphics(Graphics g)
        {
            PointF tf4;
            Size   clientSize = base.ClientSize;
            PointF tf         = new PointF((this.position.X * this.dragAreaRect.Width) / ((float)clientSize.Width), (this.position.Y * this.dragAreaRect.Height) / ((float)clientSize.Height));
            PointF tf2        = new PointF(((float)clientSize.Width) / 2f, ((float)clientSize.Height) / 2f);
            PointF tf3        = new PointF(((1f + tf.X) * clientSize.Width) / 2f, ((1f + tf.Y) * clientSize.Height) / 2f);

            if (((-1f <= tf.X) && (tf.X <= 1f)) && ((-1f <= tf.Y) && (tf.Y <= 1f)))
            {
                tf4 = new PointF(((1f + tf.X) * clientSize.Width) / 2f, ((1f + tf.Y) * clientSize.Height) / 2f);
            }
            else
            {
                tf4 = new PointF(((1f + tf.X) * clientSize.Width) / 2f, ((1f + tf.Y) * clientSize.Height) / 2f);
                float introduced26 = Math.Abs(tf.X);
                if (introduced26 > Math.Abs(tf.Y))
                {
                    if (tf.X > 0f)
                    {
                        tf4.X = clientSize.Width - 1;
                        tf4.Y = ((1f + (tf.Y / tf.X)) * clientSize.Height) / 2f;
                    }
                    else
                    {
                        tf4.X = 0f;
                        tf4.Y = ((1f - (tf.Y / tf.X)) * clientSize.Height) / 2f;
                    }
                }
                else if (tf.Y > 0f)
                {
                    tf4.X = ((1f + (tf.X / tf.Y)) * clientSize.Width) / 2f;
                    tf4.Y = clientSize.Height - 1;
                }
                else
                {
                    tf4.X = ((1f - (tf.X / tf.Y)) * clientSize.Width) / 2f;
                    tf4.Y = 0f;
                }
            }
            using (g.UseCompositingMode(CompositingMode.SourceCopy))
            {
                g.Clear(this.BackColor);
            }
            using (g.UseCompositingMode(CompositingMode.SourceOver))
            {
                SizeInt32 num;
                Rectangle rectangle;
                if (this.staticImageUnderlay == null)
                {
                    goto Label_05A8;
                }
                if (this.cachedUnderlay != null)
                {
                    num = new SizeInt32(this.cachedUnderlay.Width, this.cachedUnderlay.Height);
                    goto Label_052E;
                }
                Image     reference = this.staticImageUnderlay.Reference;
                Rectangle srcRect   = new Rectangle(0, 0, reference.Width, reference.Height);
                SizeInt32 num2      = new SizeInt32(Math.Max(1, Math.Min(clientSize.Width - 4, srcRect.Width)), Math.Max(1, Math.Min(clientSize.Height - 4, srcRect.Height)));
                num = ThumbnailHelpers.ComputeThumbnailSize(reference.Size.ToSizeInt32(), Math.Min(num2.Width, num2.Height));
                this.cachedUnderlay = new Bitmap(num.Width, num.Height, PixelFormat.Format24bppRgb);
                ISurface <ColorBgra> surface = RendererBgra.Checkers(num).ToSurface();
                Bitmap    image    = surface.CreateAliasedGdipBitmap();
                Rectangle destRect = new Rectangle(0, 0, this.cachedUnderlay.Width, this.cachedUnderlay.Height);
                using (Graphics graphics = Graphics.FromImage(this.cachedUnderlay))
                {
                    graphics.CompositingMode = CompositingMode.SourceOver;
                    graphics.DrawImage(image, destRect, new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);
                    Bitmap bitmap2 = reference as Bitmap;
                    if ((bitmap2 != null) && (bitmap2.PixelFormat == PixelFormat.Format32bppArgb))
                    {
                        BitmapData bitmapdata = bitmap2.LockBits(new Rectangle(new Point(0, 0), bitmap2.Size), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                        try
                        {
                            using (SharedSurface <ColorBgra> surface2 = new SharedSurface <ColorBgra>(bitmapdata.Scan0, bitmapdata.Width, bitmapdata.Height, bitmapdata.Stride))
                            {
                                using (ISurface <ColorBgra> surface3 = surface2.ResizeSuperSampling(num).Parallelize <ColorBgra>(TilingStrategy.HorizontalSlices, 3, WorkItemQueuePriority.Normal).ToSurface())
                                {
                                    using (Bitmap bitmap3 = surface3.CreateAliasedGdipBitmap())
                                    {
                                        graphics.DrawImage(bitmap3, destRect, surface3.Bounds <ColorBgra>().ToGdipRectangle(), GraphicsUnit.Pixel);
                                        goto Label_051A;
                                    }
                                }
                            }
                        }
                        finally
                        {
                            bitmap2.UnlockBits(bitmapdata);
                        }
                    }
                    graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    RectangleF ef = RectangleF.Inflate(destRect, 0.5f, 0.5f);
                    graphics.DrawImage(reference, ef, srcRect, GraphicsUnit.Pixel);
                }
Label_051A:
                image.Dispose();
                image = null;
                surface.Dispose();
                surface = null;
Label_052E:
                rectangle = new Rectangle((clientSize.Width - num.Width) / 2, (clientSize.Height - num.Height) / 2, num.Width, num.Height);
                g.DrawImage(this.cachedUnderlay, rectangle, new Rectangle(0, 0, this.cachedUnderlay.Width, this.cachedUnderlay.Height), GraphicsUnit.Pixel);
                DropShadow.DrawOutside(g, rectangle, 2);
            }
Label_05A8:
            using (g.UsePixelOffsetMode(PixelOffsetMode.Half))
            {
                using (g.UseSmoothingMode(SmoothingMode.HighQuality))
                {
                    using (Pen pen = (Pen)Pens.Black.Clone())
                    {
                        pen.SetLineCap(LineCap.Round, LineCap.DiamondAnchor, DashCap.Flat);
                        pen.EndCap = LineCap.ArrowAnchor;
                        pen.Width  = 2f;
                        pen.Color  = SystemColors.ControlDark;
                        g.DrawLine(pen, tf2, tf4);
                    }
                    using (Pen pen2 = new Pen(Color.White))
                    {
                        pen2.SetLineCap(LineCap.DiamondAnchor, LineCap.DiamondAnchor, DashCap.Flat);
                        pen2.Width = 3f;
                        pen2.Color = Color.White;
                        g.DrawLine(pen2, tf3.X - 5f, tf3.Y, tf3.X + 5f, tf3.Y);
                        g.DrawLine(pen2, tf3.X, tf3.Y - 5f, tf3.X, tf3.Y + 5f);
                        pen2.Width = 2f;
                        pen2.Color = Color.Black;
                        g.DrawLine(pen2, tf3.X - 5f, tf3.Y, tf3.X + 5f, tf3.Y);
                        g.DrawLine(pen2, tf3.X, tf3.Y - 5f, tf3.X, tf3.Y + 5f);
                    }
                }
            }
        }