Exemple #1
0
        public static void CompressWithoutTransparency(Surface surface,
                                                       EncoderOptions options,
                                                       AvifProgressCallback avifProgress,
                                                       ref uint progressDone,
                                                       uint progressTotal,
                                                       CICPColorData colorInfo,
                                                       out CompressedAV1Image color)
        {
            BitmapData bitmapData = new BitmapData
            {
                scan0  = surface.Scan0.Pointer,
                width  = (uint)surface.Width,
                height = (uint)surface.Height,
                stride = (uint)surface.Stride
            };

            ProgressContext progressContext = new ProgressContext(avifProgress, progressDone, progressTotal);

            using (CompressedAV1DataAllocator allocator = new CompressedAV1DataAllocator(1))
            {
                IntPtr colorImage;

                CompressedAV1OutputAlloc outputAllocDelegate = new CompressedAV1OutputAlloc(allocator.Allocate);
                EncoderStatus            status = EncoderStatus.Ok;

                if (IntPtr.Size == 8)
                {
                    status = AvifNative_64.CompressImage(ref bitmapData,
                                                         options,
                                                         progressContext,
                                                         ref colorInfo,
                                                         outputAllocDelegate,
                                                         out colorImage,
                                                         IntPtr.Zero);
                }
                else
                {
                    status = AvifNative_86.CompressImage(ref bitmapData,
                                                         options,
                                                         progressContext,
                                                         ref colorInfo,
                                                         outputAllocDelegate,
                                                         out colorImage,
                                                         IntPtr.Zero);
                }

                GC.KeepAlive(outputAllocDelegate);

                if (status != EncoderStatus.Ok)
                {
                    HandleError(status, allocator.ExceptionInfo);
                }

                color = new CompressedAV1Image(allocator.GetCompressedAV1Data(colorImage), surface.Width, surface.Height, options.yuvFormat);
            }

            progressDone = progressContext.progressDone;
            GC.KeepAlive(avifProgress);
        }
Exemple #2
0
 internal static unsafe extern EncoderStatus CompressImage(
     [In] ref BitmapData image,
     EncoderOptions options,
     [In, Out] ProgressContext progressContext,
     [In] ref CICPColorData colorInfo,
     [MarshalAs(UnmanagedType.FunctionPtr)] CompressedAV1OutputAlloc outputAllocator,
     out IntPtr colorImage,
     IntPtr alphaImage_MustBeZero);