Example #1
0
        private static bool TryGetMessageFromErrorInfo(GmicErrorInfo errorInfo, out string message)
        {
            if (errorInfo is null)
            {
                message = string.Empty;

                return(false);
            }

            message = GetStringFromByteArray(errorInfo.errorMessage);

            return(!string.IsNullOrWhiteSpace(message));
        }
Example #2
0
        internal static void RunGmic(SafeGmicImageList list, GmicOptions options)
        {
            if (options is null)
            {
                ExceptionUtil.ThrowArgumentNullException(nameof(options));
            }

            ValidateGmicImageList(list);

            GmicErrorInfo errorInfo = new GmicErrorInfo();

            GmicStatus status = GmicNativeMethods.Instance.RunGmic(list, options, errorInfo);

            if (status != GmicStatus.Ok)
            {
                HandleError(status, errorInfo);
            }
        }
Example #3
0
        private static void HandleError(GmicStatus status, GmicErrorInfo errorInfo)
        {
            switch (status)
            {
            case GmicStatus.Ok:
                break;

            case GmicStatus.InvalidParameter:
                throw new GmicException("An invalid parameter was passed to a native function.");

            case GmicStatus.OutOfMemory:
                throw new OutOfMemoryException();

            case GmicStatus.UnknownImageFormat:
                throw new GmicException("The image uses an unknown format.");

            case GmicStatus.GmicError:
                if (errorInfo != null && TryGetMessageFromErrorInfo(errorInfo, out string message))
                {
                    string command = GetStringFromByteArray(errorInfo.commandName);

                    throw new GmicException(message, command);
                }
                else
                {
                    throw new GmicException("An unspecified error occurred when executing G'MIC.");
                }

            case GmicStatus.GmicResourcePathInitFailed:
                break;

            case GmicStatus.GmicUnsupportedChannelCount:
                throw new GmicException("The output G'MIC image has an unsupported number of channels.");

            case GmicStatus.ImageListIndexOutOfRange:
                throw new GmicException("The image list index is not valid.");

            case GmicStatus.UnknownError:
            default:
                throw new GmicException("An unspecified error occurred.");
            }
        }
Example #4
0
 internal GmicStatus RunGmic(SafeGmicImageList list,
                             GmicOptions options,
                             GmicErrorInfo errorInfo)
 {
     return(runGmic(list, options, errorInfo));
 }