Beispiel #1
0
        public WicPlanarCacheSource(IWICPlanarBitmapSourceTransform source, WICBitmapPlaneDescription descY, WICBitmapPlaneDescription descC, WICRect crop, WICBitmapTransformOptions transformOptions, uint width, uint height, double ratio)
        {
            // TODO fractional ratio support?
            subsampleRatioX = Math.Ceiling((double)descY.Width / descC.Width);
            subsampleRatioY = Math.Ceiling((double)descY.Height / descC.Height);

            var scrop = new WICRect();

            scrop.X      = (int)Math.Floor(crop.X / ratio);
            scrop.Y      = (int)Math.Floor(crop.Y / ratio);
            scrop.Width  = Math.Min((int)Math.Ceiling(crop.Width / ratio), (int)descY.Width);
            scrop.Height = Math.Min((int)Math.Ceiling(crop.Height / ratio), (int)descY.Height);

            if (subsampleRatioX > 1d)
            {
                descC.Width = Math.Min((uint)Math.Ceiling(scrop.Width / subsampleRatioX), descC.Width);
                descY.Width = (uint)Math.Min(descC.Width * subsampleRatioX, scrop.Width);

                if (scrop.X % subsampleRatioX > 0)
                {
                    scrop.X = (int)(scrop.X / subsampleRatioX) * (int)subsampleRatioX;
                }
            }
            else
            {
                descC.Width = descY.Width = (uint)scrop.Width;
            }

            if (subsampleRatioY > 1d)
            {
                descC.Height = Math.Min((uint)Math.Ceiling(scrop.Height / subsampleRatioY), descC.Height);
                descY.Height = (uint)Math.Min(descC.Height * subsampleRatioY, scrop.Height);

                if (scrop.Y % subsampleRatioY > 0)
                {
                    scrop.Y = (int)(scrop.Y / subsampleRatioY) * (int)subsampleRatioY;
                }
            }
            else
            {
                descC.Height = descY.Height = (uint)scrop.Height;
            }

            sourceTransform        = source;
            sourceTransformOptions = transformOptions;
            planeDescriptionY      = descY;
            planeDescriptionC      = descC;
            scaledCrop             = scrop;
            scaledWidth            = width;
            scaledHeight           = height;

            strideY     = (uint)scrop.Width + 3u & ~3u;
            buffHeightY = 16u;

            strideC     = (uint)(Math.Ceiling(scrop.Width / subsampleRatioX)) * 2u + 3u & ~3u;
            buffHeightC = (uint)(buffHeightY / subsampleRatioY);

            sourceY = new WicPlanarSource(this, WicPlane.Luma, descY);
            sourceC = new WicPlanarSource(this, WicPlane.Chroma, descC);
        }
Beispiel #2
0
        public void Rotate(WICBitmapTransformOptions options)
        {
            var clip = WICImagingFactory.CreateBitmapFlipRotator();

            clip.Object.Initialize(_comObject.Object, options).ThrowOnError();
            _comObject?.Dispose();
            _comObject = clip;
        }
        public virtual int Initialize(
            IWICBitmapSource pISource,
            WICBitmapTransformOptions options
            )
        {
            var fp = GetFunctionPointer(8);

            if (m_InitializeFunc == null)
            {
                m_InitializeFunc = (InitializeFunc)Marshal.GetDelegateForFunctionPointer(fp, typeof(InitializeFunc));
            }

            return(m_InitializeFunc(m_ptr, pISource != null ? pISource.Ptr : IntPtr.Zero, options));
        }
        public virtual int DoesSupportTransform(
            WICBitmapTransformOptions dstTransform,
            out int pfIsSupported
            )
        {
            var fp = GetFunctionPointer(6);

            if (m_DoesSupportTransformFunc == null)
            {
                m_DoesSupportTransformFunc = (DoesSupportTransformFunc)Marshal.GetDelegateForFunctionPointer(fp, typeof(DoesSupportTransformFunc));
            }

            return(m_DoesSupportTransformFunc(m_ptr, dstTransform, out pfIsSupported));
        }
Beispiel #5
0
        /// <summary>
        /// Check the transformation to see if it's a simple scale and/or rotation and/or flip.
        /// </summary>
        internal void GetParamsFromTransform(
            Transform newTransform,
            out double scaleX,
            out double scaleY,
            out WICBitmapTransformOptions options)
        {
            Matrix m = newTransform.Value;

            if (DoubleUtil.IsZero(m.M12) && DoubleUtil.IsZero(m.M21))
            {
                scaleX = Math.Abs(m.M11);
                scaleY = Math.Abs(m.M22);

                options = WICBitmapTransformOptions.WICBitmapTransformRotate0;

                if (m.M11 < 0)
                {
                    options |= WICBitmapTransformOptions.WICBitmapTransformFlipHorizontal;
                }

                if (m.M22 < 0)
                {
                    options |= WICBitmapTransformOptions.WICBitmapTransformFlipVertical;
                }
            }
            else
            {
                Debug.Assert(DoubleUtil.IsZero(m.M11) && DoubleUtil.IsZero(m.M22));

                scaleX = Math.Abs(m.M12);
                scaleY = Math.Abs(m.M21);

                options = WICBitmapTransformOptions.WICBitmapTransformRotate90;

                if (m.M12 < 0)
                {
                    options |= WICBitmapTransformOptions.WICBitmapTransformFlipHorizontal;
                }

                if (m.M21 >= 0)
                {
                    options |= WICBitmapTransformOptions.WICBitmapTransformFlipVertical;
                }
            }
        }
Beispiel #6
0
        public virtual int CopyPixels(
            ref WICRect prcSource,
            uint uiWidth,
            uint uiHeight,
            WICBitmapTransformOptions dstTransform,
            WICPlanarOptions dstPlanarOptions,
            ref WICBitmapPlane pDstPlanes,
            uint cPlanes
            )
        {
            var fp = GetFunctionPointer(4);

            if (m_CopyPixelsFunc == null)
            {
                m_CopyPixelsFunc = (CopyPixelsFunc)Marshal.GetDelegateForFunctionPointer(fp, typeof(CopyPixelsFunc));
            }

            return(m_CopyPixelsFunc(m_ptr, ref prcSource, uiWidth, uiHeight, dstTransform, dstPlanarOptions, ref pDstPlanes, cPlanes));
        }
        public virtual int CopyPixels(
            ref WICRect prc,
            uint uiWidth,
            uint uiHeight,
            out Guid pguidDstFormat,
            WICBitmapTransformOptions dstTransform,
            uint nStride,
            uint cbBufferSize,
            out byte pbBuffer
            )
        {
            var fp = GetFunctionPointer(3);

            if (m_CopyPixelsFunc == null)
            {
                m_CopyPixelsFunc = (CopyPixelsFunc)Marshal.GetDelegateForFunctionPointer(fp, typeof(CopyPixelsFunc));
            }

            return(m_CopyPixelsFunc(m_ptr, ref prc, uiWidth, uiHeight, out pguidDstFormat, dstTransform, nStride, cbBufferSize, out pbBuffer));
        }
Beispiel #8
0
        public virtual int DoesSupportTransform(
            out uint puiWidth,
            out uint puiHeight,
            WICBitmapTransformOptions dstTransform,
            WICPlanarOptions dstPlanarOptions,
            ref Guid pguidDstFormats,
            out WICBitmapPlaneDescription pPlaneDescriptions,
            uint cPlanes,
            out int pfIsSupported
            )
        {
            var fp = GetFunctionPointer(3);

            if (m_DoesSupportTransformFunc == null)
            {
                m_DoesSupportTransformFunc = (DoesSupportTransformFunc)Marshal.GetDelegateForFunctionPointer(fp, typeof(DoesSupportTransformFunc));
            }

            return(m_DoesSupportTransformFunc(m_ptr, out puiWidth, out puiHeight, dstTransform, dstPlanarOptions, ref pguidDstFormats, out pPlaneDescriptions, cPlanes, out pfIsSupported));
        }
Beispiel #9
0
        private static WICBitmapTransformOptions TransformOptionsFromUshort(ushort value)
        {
            WICBitmapTransformOptions result = WICBitmapTransformOptions.WICBitmapTransformRotate0;

            switch (value)
            {
            case 2:
                result = WICBitmapTransformOptions.WICBitmapTransformFlipHorizontal;
                break;

            case 3:
                result = WICBitmapTransformOptions.WICBitmapTransformRotate180;
                break;

            case 4:
                result = WICBitmapTransformOptions.WICBitmapTransformFlipVertical;
                break;

            case 5:
                result = (WICBitmapTransformOptions.WICBitmapTransformRotate90 | WICBitmapTransformOptions.WICBitmapTransformRotate180 | WICBitmapTransformOptions.WICBitmapTransformFlipHorizontal);
                break;

            case 6:
                result = WICBitmapTransformOptions.WICBitmapTransformRotate90;
                break;

            case 7:
                result = (WICBitmapTransformOptions.WICBitmapTransformRotate90 | WICBitmapTransformOptions.WICBitmapTransformFlipHorizontal);
                break;

            case 8:
                result = WICBitmapTransformOptions.WICBitmapTransformRotate270;
                break;
            }
            return(result);
        }
Beispiel #10
0
 public void CopyPixels([In] ref WICRect prc, [In] uint uiWidth, [In] uint uiHeight, Guid dstFormat, [In] WICBitmapTransformOptions dstTransform, [In] uint nStride, [In] uint cbBufferSize, byte[] pbBuffer)
 {
     try
     {
         Log.Trace($"Trans CopyPixels called");
         Log.Trace($"Trans CopyPixels called: {uiWidth}, {uiHeight} {dstFormat}");
         if (dstFormat == GUID_WICPixelFormat32bppBGRA)
         {
             CopyBGRA(ref prc, nStride, cbBufferSize, pbBuffer);
         }
         if (prc.Y + prc.Height == rgbmap.Height)
         {
             rgbmap.Dispose();
         }
         Log.Trace("CopyPixels finished");
     }
     catch (Exception e)
     {
         Log.Error("CopyPixels failed: " + e);
         throw;
     }
 }
Beispiel #11
0
 public HRESULT DoesSupportTransform(WICBitmapTransformOptions dstTransform, BOOL *pfIsSupported)
 {
     return(((delegate * unmanaged <IWICBitmapSourceTransform *, WICBitmapTransformOptions, BOOL *, int>)(lpVtbl[6]))((IWICBitmapSourceTransform *)Unsafe.AsPointer(ref this), dstTransform, pfIsSupported));
 }
 internal static extern int /* HRESULT */ InitializeBitmapFlipRotator( 
     IntPtr /* IWICBitmapFlipRotator */ THIS_PTR,
     IntPtr /* IWICBitmapSource */ source,
     WICBitmapTransformOptions options);
Beispiel #13
0
 public void DoesSupportTransform([In] WICBitmapTransformOptions dstTransform, out int pfIsSupported)
 {
     Log.Trace($"Trans DoesSupportTransform called");
     pfIsSupported = 0;
 }
Beispiel #14
0
        public static IWICBitmapSource GetOrientedImageSource(this IWICImagingFactory factory, IWICBitmapSource source, WICBitmapTransformOptions opt)
        {
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }
            if (opt == WICBitmapTransformOptions.WICBitmapTransformRotate0)
            {
                return(source);
            }
            IWICBitmap iwicbitmap = null;

            factory.CreateBitmapFromSource(source, WICBitmapCreateCacheOption.WICBitmapCacheOnDemand, out iwicbitmap);
            IWICBitmapFlipRotator iwicbitmapFlipRotator = null;

            factory.CreateBitmapFlipRotator(out iwicbitmapFlipRotator);
            iwicbitmapFlipRotator.Initialize(iwicbitmap, opt);
            IWICBitmapSource result = iwicbitmapFlipRotator;

            GraphicsInteropNativeMethods.SafeReleaseComObject(iwicbitmap);
            return(result);
        }
 public HRESULT CopyPixels([NativeTypeName("const WICRect *")] WICRect *prcSource, uint uiWidth, uint uiHeight, WICBitmapTransformOptions dstTransform, WICPlanarOptions dstPlanarOptions, [NativeTypeName("const WICBitmapPlane *")] WICBitmapPlane *pDstPlanes, uint cPlanes)
 {
     return(((delegate * unmanaged <IWICPlanarBitmapSourceTransform *, WICRect *, uint, uint, WICBitmapTransformOptions, WICPlanarOptions, WICBitmapPlane *, uint, int>)(lpVtbl[4]))((IWICPlanarBitmapSourceTransform *)Unsafe.AsPointer(ref this), prcSource, uiWidth, uiHeight, dstTransform, dstPlanarOptions, pDstPlanes, cPlanes));
 }
 public WicPlanarCache(IWICPlanarBitmapSourceTransform source, ReadOnlySpan <WICBitmapPlaneDescription> desc, WICBitmapTransformOptions transformOptions, uint width, uint height, in PixelArea crop)
 public static bool RequiresCache(this WICBitmapTransformOptions opt) =>
 opt != WICBitmapTransformOptions.WICBitmapTransformRotate0 && opt != WICBitmapTransformOptions.WICBitmapTransformFlipHorizontal;
Beispiel #18
0
        /// <summary>
        /// Check the transformation to see if it's a simple scale and/or rotation and/or flip.
        /// </summary>
        internal void GetParamsFromTransform(
            Transform newTransform,
            out double scaleX,
            out double scaleY,
            out WICBitmapTransformOptions options)
        {
            Matrix m = newTransform.Value;

            if (DoubleUtil.IsZero(m.M12) && DoubleUtil.IsZero(m.M21))
            {
                scaleX = Math.Abs(m.M11);
                scaleY = Math.Abs(m.M22);

                options = WICBitmapTransformOptions.WICBitmapTransformRotate0;

                if (m.M11 < 0)
                {
                    options |= WICBitmapTransformOptions.WICBitmapTransformFlipHorizontal;
                }

                if (m.M22 < 0)
                {
                    options |= WICBitmapTransformOptions.WICBitmapTransformFlipVertical;
                }
            }
            else
            {
                Debug.Assert(DoubleUtil.IsZero(m.M11) && DoubleUtil.IsZero(m.M22));

                scaleX = Math.Abs(m.M12);
                scaleY = Math.Abs(m.M21);

                options = WICBitmapTransformOptions.WICBitmapTransformRotate90;

                if (m.M12 < 0)
                {
                    options |= WICBitmapTransformOptions.WICBitmapTransformFlipHorizontal;
                }

                if (m.M21 >= 0)
                {
                    options |= WICBitmapTransformOptions.WICBitmapTransformFlipVertical;
                }
            }
        }
Beispiel #19
0
 public int CopyPixels([NativeTypeName("const WICRect *")] WICRect *prc, [NativeTypeName("UINT")] uint uiWidth, [NativeTypeName("UINT")] uint uiHeight, [NativeTypeName("WICPixelFormatGUID *")] Guid *pguidDstFormat, WICBitmapTransformOptions dstTransform, [NativeTypeName("UINT")] uint nStride, [NativeTypeName("UINT")] uint cbBufferSize, [NativeTypeName("BYTE *")] byte *pbBuffer)
 {
     return(((delegate * unmanaged <IWICBitmapSourceTransform *, WICRect *, uint, uint, Guid *, WICBitmapTransformOptions, uint, uint, byte *, int>)(lpVtbl[3]))((IWICBitmapSourceTransform *)Unsafe.AsPointer(ref this), prc, uiWidth, uiHeight, pguidDstFormat, dstTransform, nStride, cbBufferSize, pbBuffer));
 }
Beispiel #20
0
 public int DoesSupportTransform(WICBitmapTransformOptions dstTransform, [NativeTypeName("BOOL *")] int *pfIsSupported)
 {
     return(((delegate * unmanaged <IWICBitmapSourceTransform *, WICBitmapTransformOptions, int *, int>)(lpVtbl[6]))((IWICBitmapSourceTransform *)Unsafe.AsPointer(ref this), dstTransform, pfIsSupported));
 }
 internal static extern int /* HRESULT */ InitializeBitmapFlipRotator(
     IntPtr /* IWICBitmapFlipRotator */ THIS_PTR,
     IntPtr /* IWICBitmapSource */ source,
     WICBitmapTransformOptions options);
Beispiel #22
0
        public WicPlanarCache(IWICPlanarBitmapSourceTransform source, WICBitmapPlaneDescription descY, WICBitmapPlaneDescription descC, WICRect crop, WICBitmapTransformOptions transformOptions, uint width, uint height, double ratio)
        {
            subsampleRatioX = Math.Ceiling((double)descY.Width / descC.Width);
            subsampleRatioY = Math.Ceiling((double)descY.Height / descC.Height);

            var scrop = new WICRect {
                X      = (int)Math.Floor(crop.X / ratio),
                Y      = (int)Math.Floor(crop.Y / ratio),
                Width  = Math.Min((int)Math.Ceiling(crop.Width / ratio), (int)descY.Width),
                Height = Math.Min((int)Math.Ceiling(crop.Height / ratio), (int)descY.Height)
            };

            if (subsampleRatioX > 1d)
            {
                if (scrop.X % subsampleRatioX > double.Epsilon)
                {
                    scrop.X = (int)(scrop.X / subsampleRatioX) * (int)subsampleRatioX;
                }
                if (scrop.Width % subsampleRatioX > double.Epsilon)
                {
                    scrop.Width = (int)Math.Min(Math.Ceiling(scrop.Width / subsampleRatioX) * (int)subsampleRatioX, descY.Width - scrop.X);
                }

                descC.Width = Math.Min((uint)Math.Ceiling(scrop.Width / subsampleRatioX), descC.Width);
                descY.Width = (uint)Math.Min(descC.Width * subsampleRatioX, scrop.Width);
            }
            else
            {
                descC.Width = descY.Width = (uint)scrop.Width;
            }

            if (subsampleRatioY > 1d)
            {
                if (scrop.Y % subsampleRatioY > double.Epsilon)
                {
                    scrop.Y = (int)(scrop.Y / subsampleRatioY) * (int)subsampleRatioY;
                }
                if (scrop.Height % subsampleRatioY > double.Epsilon)
                {
                    scrop.Height = (int)Math.Min(Math.Ceiling(scrop.Height / subsampleRatioY) * (int)subsampleRatioY, descY.Height - scrop.Y);
                }

                descC.Height = Math.Min((uint)Math.Ceiling(scrop.Height / subsampleRatioY), descC.Height);
                descY.Height = (uint)Math.Min(descC.Height * subsampleRatioY, scrop.Height);
            }
            else
            {
                descC.Height = descY.Height = (uint)scrop.Height;
            }

            sourceTransform        = source;
            sourceTransformOptions = transformOptions;
            scaledCrop             = scrop;
            scaledWidth            = width;
            scaledHeight           = height;

            strideY     = scrop.Width + 3 & ~3;
            strideC     = (int)Math.Ceiling(scrop.Width / subsampleRatioX) * 2 + 3 & ~3;
            buffHeightY = Math.Min(scrop.Height, transformOptions.RequiresCache() ? scrop.Height : 16);
            buffHeightC = (int)Math.Ceiling(buffHeightY / subsampleRatioY);

            sourceY = new PlanarPixelSource(this, WicPlane.Luma, descY);
            sourceC = new PlanarPixelSource(this, WicPlane.Chroma, descC);
        }
 internal static extern int /* HRESULT */ Initialize( 
     System.Windows.Media.SafeMILHandle /* IWICBitmapFlipRotator */ THIS_PTR,
     System.Windows.Media.SafeMILHandle /* IWICBitmapSource */ source, 
     WICBitmapTransformOptions options);
Beispiel #24
0
        public WicPlanarCacheSource(IWICPlanarBitmapSourceTransform source, WICBitmapPlaneDescription descY, WICBitmapPlaneDescription descC, WICRect crop, WICBitmapTransformOptions transformOptions, uint width, uint height, double ratio, bool cacheFull)
        {
            this.cacheFull = cacheFull;

            // TODO fractional ratio support?
            subsampleRatioX = Math.Ceiling((double)descY.Width / descC.Width);
            subsampleRatioY = Math.Ceiling((double)descY.Height / descC.Height);

            var scrop = new WICRect {
                X      = (int)Math.Floor(crop.X / ratio),
                Y      = (int)Math.Floor(crop.Y / ratio),
                Width  = Math.Min((int)Math.Ceiling(crop.Width / ratio), (int)descY.Width),
                Height = Math.Min((int)Math.Ceiling(crop.Height / ratio), (int)descY.Height)
            };

            if (subsampleRatioX > 1d)
            {
                if (scrop.X % subsampleRatioX > 0d)
                {
                    scrop.X = (int)(scrop.X / subsampleRatioX) * (int)subsampleRatioX;
                }
                if (scrop.Width % subsampleRatioX > 0d)
                {
                    scrop.Width = (int)Math.Min(Math.Ceiling(scrop.Width / subsampleRatioX) * (int)subsampleRatioX, descY.Width);
                }

                descC.Width = Math.Min((uint)Math.Ceiling(scrop.Width / subsampleRatioX), descC.Width);
                descY.Width = (uint)Math.Min(descC.Width * subsampleRatioX, scrop.Width);
            }
            else
            {
                descC.Width = descY.Width = (uint)scrop.Width;
            }

            if (subsampleRatioY > 1d)
            {
                if (scrop.Y % subsampleRatioY > 0d)
                {
                    scrop.Y = (int)(scrop.Y / subsampleRatioY) * (int)subsampleRatioY;
                }
                if (scrop.Height % subsampleRatioY > 0d)
                {
                    scrop.Height = (int)Math.Min(Math.Ceiling(scrop.Height / subsampleRatioY) * (int)subsampleRatioY, descY.Height);
                }

                descC.Height = Math.Min((uint)Math.Ceiling(scrop.Height / subsampleRatioY), descC.Height);
                descY.Height = (uint)Math.Min(descC.Height * subsampleRatioY, scrop.Height);
            }
            else
            {
                descC.Height = descY.Height = (uint)scrop.Height;
            }

            sourceTransform        = source;
            sourceTransformOptions = transformOptions;
            scaledCrop             = scrop;
            scaledWidth            = width;
            scaledHeight           = height;

            strideY     = scrop.Width + 3 & ~3;
            buffHeightY = Math.Min(scrop.Height, cacheFull ? scrop.Height : 16);

            strideC     = (int)Math.Ceiling(scrop.Width / subsampleRatioX) * 2 + 3 & ~3;
            buffHeightC = (int)Math.Ceiling(buffHeightY / subsampleRatioY);

            sourceY = new WicPlanarSource(this, WicPlane.Luma, descY);
            sourceC = new WicPlanarSource(this, WicPlane.Chroma, descC);
        }
 public int Initialize([NativeTypeName("IWICBitmapSource *")] IWICBitmapSource *pISource, WICBitmapTransformOptions options)
 {
     return(((delegate * unmanaged <IWICBitmapFlipRotator *, IWICBitmapSource *, WICBitmapTransformOptions, int>)(lpVtbl[8]))((IWICBitmapFlipRotator *)Unsafe.AsPointer(ref this), pISource, options));
 }
 public HRESULT DoesSupportTransform(uint *puiWidth, uint *puiHeight, WICBitmapTransformOptions dstTransform, WICPlanarOptions dstPlanarOptions, [NativeTypeName("const WICPixelFormatGUID *")] Guid *pguidDstFormats, WICBitmapPlaneDescription *pPlaneDescriptions, uint cPlanes, BOOL *pfIsSupported)
 {
     return(((delegate * unmanaged <IWICPlanarBitmapSourceTransform *, uint *, uint *, WICBitmapTransformOptions, WICPlanarOptions, Guid *, WICBitmapPlaneDescription *, uint, BOOL *, int>)(lpVtbl[3]))((IWICPlanarBitmapSourceTransform *)Unsafe.AsPointer(ref this), puiWidth, puiHeight, dstTransform, dstPlanarOptions, pguidDstFormats, pPlaneDescriptions, cPlanes, pfIsSupported));
 }