/// <summary>
        /// Performs the inverse mapping to MapOutputRectToInputRects.
        /// </summary>
        public RectL MapInputRectsToOutputRect(RectL[] inputRects, RectL[] inputOpaqueSubRects, out RectL outputOpaqueSubRect)
        {
            RectL rc = inputRects[0];

            _inputRect = rc;
            var newSize = new Size2F(rc.Width, rc.Height);

            if (_constBuffer.Size != newSize)
            {
                _constBuffer.Size = newSize;
                UpdateConstants();
            }
            outputOpaqueSubRect = RectL.Empty;
            return(rc);
        }
Exemplo n.º 2
0
 public Header(MetafileReader reader)
 {
     Bounds                         = new RectL(reader);
     Frame                          = new RectL(reader);
     Signature                      = reader.ReadUInt32();
     Version                        = reader.ReadUInt32();
     NumberOfBytes                  = reader.ReadUInt32();
     NumberOfRecords                = reader.ReadUInt32();
     NumberOfObjects                = reader.ReadUInt16();
     Reserved                       = reader.ReadUInt16();
     DescriptionLength              = reader.ReadUInt32();
     DescriptionOffset              = reader.ReadUInt32();
     NumberOfPaletteEntries         = reader.ReadUInt32();
     ReferenceDeviceSizePixels      = new SizeL(reader);
     ReferenceDeviceSizeMillimeters = new SizeL(reader);
 }
Exemplo n.º 3
0
 public EmrBitBlt(MetafileReader reader) : base(reader)
 {
     Bounds               = new RectL(reader);
     DestX                = reader.ReadInt32();
     DestY                = reader.ReadInt32();
     DestWidth            = reader.ReadInt32();
     DestHeight           = reader.ReadInt32();
     RasterOperation      = (TernaryRasterOperation)reader.ReadUInt32();
     SrcX                 = reader.ReadInt32();
     SrcY                 = reader.ReadInt32();
     WorldToPageTransform = new XForm(reader);
     SrcBackgroundColor   = reader.ReadUInt32();
     SrcUsage             = (DIBColors)reader.ReadUInt32();
     BitmapHeaderOffset   = reader.ReadUInt32();
     BitmapHeaderSize     = reader.ReadUInt32();
     BitmapBitsOffset     = reader.ReadUInt32();
     BitmapBitsSize       = reader.ReadUInt32();
 }
Exemplo n.º 4
0
        public RedEyeCorrectionEffect(MetafileReader reader) : base(ImageEffects.RedEyeCorrectionEffectGuid)
        {
            NumberOfAreas = reader.ReadInt32();

            if (NumberOfAreas > 0)
            {
                var areas = new List <RectL>(NumberOfAreas);
                for (int i = 0; i < NumberOfAreas; i++)
                {
                    var area = new RectL(reader);
                    areas.Add(area);
                }
                Areas = areas;
            }
            else
            {
                Areas = Enumerable.Empty <RectL>();
            }
        }
Exemplo n.º 5
0
        void ExportToGrayscale()
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter          = "Jpeg Files (*.jpg)|*.jpg";
            sfd.CheckPathExists = true;

            // the user should pick the output file
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                // the render target object
                var rt = _d2dContext;

                // create the target Direct2D bitmap for the given DXGI.Surface
                var bpTarget = new D2D.BitmapProperties1(
                    new D2D.PixelFormat(DXGI.Format.B8G8R8A8_UNorm, D2D.AlphaMode.Premultiplied),
                    (float)_bitmap.DpiX, (float)_bitmap.DpiY, D2D.BitmapOptions.Target | D2D.BitmapOptions.CannotDraw);
                Size2L bmpSize   = new Size2L(_bitmap.PixelWidth, _bitmap.PixelHeight);
                var    targetBmp = D2D.Bitmap1.Create(rt, bmpSize, bpTarget);

                // associate the target bitmap with render target
                rt.SetTarget(targetBmp);

                // start drawing
                rt.BeginDraw();

                // clear the target bitmap
                rt.Clear(null);

                // convert C1Bitmap image to Direct2D image
                var d2dBitmap = _bitmap.ToD2DBitmap1(rt, D2D.BitmapOptions.None);

                // create the Grayscale effect
                _colorMatrix.SetInput(0, d2dBitmap);
                _colorMatrix.Matrix = new Matrix5x4(
                    0.299f, 0.299f, 0.299f, 0,
                    0.587f, 0.587f, 0.587f, 0,
                    0.114f, 0.114f, 0.114f, 0,
                    0, 0, 0, 1,
                    0, 0, 0, 0
                    );

                // and draw the result
                rt.DrawImage(_colorMatrix, Point2F.Empty);
                d2dBitmap.Dispose();

                // now let's draw the text label with shadow
                rt.Transform = Matrix3x2.Rotation(-90f) * Matrix3x2.Translation(6f, 344f);
                _brush.SetColor(ColorF.White);
                rt.DrawTextLayout(new Point2F(-1f, -1f), _textLayout, _brush);
                _brush.SetColor(ColorF.DimGray);
                rt.DrawTextLayout(Point2F.Empty, _textLayout, _brush);
                rt.Transform = Matrix3x2.Identity;

                // finish drawing (all drawing commands are executed now)
                rt.EndDraw();

                // detach the target bitmap
                rt.SetTarget(null);

                // create a temporary C1Bitmap object
                var exportBitmap = new C1Bitmap(_bitmap.ImagingFactory);

                // import the image from Direct2D target bitmap to C1Bitmap
                var srcRect = new RectL(_bitmap.PixelWidth, _bitmap.PixelHeight);
                exportBitmap.Import(targetBmp, rt, srcRect);
                targetBmp.Dispose();

                // save the image to file
                exportBitmap.SaveAsJpeg(sfd.FileName, null);
                exportBitmap.Dispose();
            }
        }
Exemplo n.º 6
0
        void UpdateImageSource(bool applyWarpEffect)
        {
            Point2L surfaceOffset;

            DXGI.Surface dxgiSurface;

            int w  = _bitmap.PixelWidth;
            int h  = _bitmap.PixelHeight;
            var hr = _sisNative.BeginDraw(new RectL(w, h), out surfaceOffset, out dxgiSurface);

            if (hr == DXGI.ResultCode.DeviceRemoved || hr == DXGI.ResultCode.DeviceReset)
            {
                DiscardDeviceResources();
                CreateDeviceResources();
                _sisNative.SetDevice(_dxgiDevice);
                return;
            }
            hr.CheckError();

            var rt = _d2dContext;

            var bpTarget = new D2D.BitmapProperties1(
                new D2D.PixelFormat(DXGI.Format.B8G8R8A8_UNorm, D2D.AlphaMode.Premultiplied),
                (float)_bitmap.DpiX, (float)_bitmap.DpiY, D2D.BitmapOptions.Target | D2D.BitmapOptions.CannotDraw);

            var targetBmp = D2D.Bitmap1.Create(rt, dxgiSurface, bpTarget);

            dxgiSurface.Dispose();

            rt.SetTarget(targetBmp);

            rt.BeginDraw();
            rt.Clear(null);

            var buffer = _bitmap.ToD2DBitmap1(rt, D2D.BitmapOptions.None);

            if (!applyWarpEffect)
            {
                rt.DrawBitmap(buffer, new RectF(surfaceOffset.X, surfaceOffset.Y, w, h));
            }
            else
            {
                _warp.SetNormPositions(_warpStart, _warpEnd);
                _warp.Effect.SetInput(0, buffer);

                rt.DrawImage(_warp.Effect, new Point2F(surfaceOffset.X, surfaceOffset.Y));

                //_blur.SetInputEffect(0, _warp.Effect);
                //rt.DrawImage(_blur, new Point2F(surfaceOffset.X, surfaceOffset.Y));
            }
            buffer.Dispose();

            rt.EndDraw();
            rt.SetTarget(null);

            if (applyWarpEffect)
            {
                var srcRect = new RectL(surfaceOffset.X, surfaceOffset.Y, w, h);
                _bitmap.ImportAsFragment(targetBmp, rt, srcRect, 0, 0);
            }
            targetBmp.Dispose();

            _sisNative.EndDraw();
        }
Exemplo n.º 7
0
        async Task ExportGrayscale()
        {
            var picker = new FileSavePicker();

            picker.FileTypeChoices.Add("Jpeg files", new List <string> {
                ".jpg"
            });
            picker.DefaultFileExtension = ".jpg";

            // the user should pick the output file
            StorageFile file = await picker.PickSaveFileAsync();

            if (file != null)
            {
                // the render target object
                var rt = _d2dContext;

                // create the target Direct2D bitmap for the given DXGI.Surface
                var bpTarget = new D2D.BitmapProperties1(
                    new D2D.PixelFormat(DXGI.Format.B8G8R8A8_UNorm, D2D.AlphaMode.Premultiplied),
                    (float)_bitmap.DpiX, (float)_bitmap.DpiY, D2D.BitmapOptions.Target | D2D.BitmapOptions.CannotDraw);
                Size2L bmpSize   = new Size2L(_bitmap.PixelWidth, _bitmap.PixelHeight);
                var    targetBmp = D2D.Bitmap1.Create(rt, bmpSize, bpTarget);

                // associate the target bitmap with render target
                rt.SetTarget(targetBmp);

                // start drawing
                rt.BeginDraw();

                // clear the target bitmap
                rt.Clear(null);

                // convert C1Bitmap image to Direct2D image
                var d2dBitmap = _bitmap.ToD2DBitmap1(rt, D2D.BitmapOptions.None);

                // create the Grayscale effect
                _colorMatrix.SetInput(0, d2dBitmap);
                _colorMatrix.Matrix = new Matrix5x4(
                    0.299f, 0.299f, 0.299f, 0,
                    0.587f, 0.587f, 0.587f, 0,
                    0.114f, 0.114f, 0.114f, 0,
                    0, 0, 0, 1,
                    0, 0, 0, 0
                    );

                // and draw the result
                rt.DrawImage(_colorMatrix, Point2F.Empty);
                d2dBitmap.Dispose();

                // now let's draw the additional text label with shadow
                rt.Transform = Matrix3x2.Rotation(-90f) * Matrix3x2.Translation(6f, 344f);
                _brush.SetColor(ColorF.White);
                rt.DrawTextLayout(new Point2F(-1f, -1f), _textLayout, _brush);
                _brush.SetColor(ColorF.DimGray);
                rt.DrawTextLayout(Point2F.Empty, _textLayout, _brush);
                rt.Transform = Matrix3x2.Identity;

                // finish drawing (all drawing commands are executed now)
                if (!rt.EndDraw(true))
                {
                    // clean up and return if the GPU device was removed and we can't draw
                    targetBmp.Dispose();
                    return;
                }

                // detach the target bitmap
                rt.SetTarget(null);

                // create a temporary C1Bitmap object
                var exportBitmap = new C1Bitmap(_bitmap.ImagingFactory);

                // import the image from Direct2D target bitmap to C1Bitmap
                var srcRect = new RectL(_bitmap.PixelWidth, _bitmap.PixelHeight);
                exportBitmap.Import(targetBmp, rt, srcRect);
                targetBmp.Dispose();

                // save the image to file
                await exportBitmap.SaveAsJpegAsync(file, null);

                exportBitmap.Dispose();
            }
        }
 /// <summary>
 /// Sets the input rectangles for this rendering pass into the transform.
 /// </summary>
 public RectL MapInvalidRect(int inputIndex, RectL invalidInputRect)
 {
     return(_inputRect);
 }
 /// <summary>
 /// Allows a transform to state how it would map a rectangle requested on its output to a set of sample rectangles on its input.
 /// </summary>
 public void MapOutputRectToInputRects(RectL outputRect, RectL[] inputRects)
 {
     inputRects[0] = _inputRect;
 }