/// <summary> /// Initializes a new instance of the <see cref="GmicImageList"/> class. /// </summary> /// <exception cref="GmicException"> /// The native library could not be found or loaded. /// /// or /// /// The GmicSharp and libGmicSharpNative versions do not match. /// /// or /// /// Failed to create the native G'MIC image list. /// </exception> public GmicImageList() { GmicSharpNative.Initialize(); nativeImageList = GmicNative.CreateGmicImageList(); if (nativeImageList == null || nativeImageList.IsInvalid) { throw new GmicException("Failed to create the native G'MIC image list."); } disposed = false; }
/// <summary> /// Adds the specified bitmap. /// </summary> /// <param name="bitmap">The bitmap.</param> /// <param name="name">The name.</param> /// <exception cref="ObjectDisposedException">The object has been disposed.</exception> /// <exception cref="OutOfMemoryException">Insufficient memory to add the image.</exception> public void Add(GmicBitmap bitmap, string name) { if (bitmap is null) { ExceptionUtil.ThrowArgumentNullException(nameof(bitmap)); } VerifyNotDisposed(); uint width = (uint)bitmap.Width; uint height = (uint)bitmap.Height; GmicPixelFormat format = bitmap.GetGmicPixelFormat(); NativeImageFormat nativeImageFormat; GmicImageListPixelData pixelData; // G'MIC uses a planar format, so the stride between rows is the image width. int planeStride = (int)width; // Add a new image to the native G'MIC image list. GmicNative.GmicImageListAdd(nativeImageList, width, height, format, name, out pixelData, out nativeImageFormat); // Copy the pixel data to the native image. bitmap.CopyToGmicImage(nativeImageFormat, pixelData, planeStride); }
/// <summary> /// Gets the image data. /// </summary> /// <param name="index">The index.</param> /// <param name="data">The image data.</param> /// <exception cref="GmicException">The image list index is invalid.</exception> /// <exception cref="ObjectDisposedException">The object has been disposed.</exception> public void GetImageData(uint index, out GmicImageListImageData data) { VerifyNotDisposed(); GmicNative.GmicImageListGetImageData(nativeImageList, index, out data); }
/// <summary> /// Clears the image list. /// </summary> /// <exception cref="ObjectDisposedException">The object has been disposed.</exception> public void Clear() { VerifyNotDisposed(); GmicNative.GmicImageListClear(nativeImageList); }
private unsafe void GmicWorker(GmicWorkerArgs args) { Exception error = null; bool canceled = false; CancellationTokenRegistration cancellationTokenRegistration = new CancellationTokenRegistration(); try { if (args.Task != null) { if (args.CanBeCanceled) { if (args.CancellationToken.IsCancellationRequested) { canceled = true; } else { cancellationTokenRegistration = args.CancellationToken.Register(SignalCancelRequest); } } } else { canceled = shouldAbort != 0; } if (!canceled) { GmicOptions options = new GmicOptions(args.Command, args.CustomResourcePath, args.HostName); if (args.HasProgressEvent) { if (args.CanBeCanceled) { fixed(float *pProgress = &progress) fixed(byte *pShouldAbort = &shouldAbort) { options.progress = pProgress; options.abort = pShouldAbort; GmicNative.RunGmic(args.ImageList.SafeImageListHandle, options); } canceled = shouldAbort != 0; } else { fixed(float *pProgress = &progress) { options.progress = pProgress; GmicNative.RunGmic(args.ImageList.SafeImageListHandle, options); } } } else if (args.CanBeCanceled) { fixed(byte *pShouldAbort = &shouldAbort) { options.abort = pShouldAbort; GmicNative.RunGmic(args.ImageList.SafeImageListHandle, options); } canceled = shouldAbort != 0; } else { GmicNative.RunGmic(args.ImageList.SafeImageListHandle, options); } } } catch (Exception ex) { error = ex; } finally { cancellationTokenRegistration.Dispose(); } GmicWorkerCompleted(error, canceled, args.Task); }