private static Operation NewFromName(string operationName) { var vop = VipsOperation.VipsOperationNew(operationName); if (vop == IntPtr.Zero) { throw new VipsException($"no such operation {operationName}"); } return(new Operation(vop)); }
private Internal.Enums.VipsOperationFlags GetFlags() { return(VipsOperation.VipsOperationGetFlags(this)); }
/// <summary> /// Turn on libvips cache tracing. /// </summary> /// <param name="trace"></param> public static void VipsCacheSetTrace(int trace) { VipsOperation.VipsCacheSetTrace(trace); }
/// <summary> /// Limit the operation cache by number of open files. /// </summary> /// <param name="maxFiles"></param> public static void VipsCacheSetMaxFiles(int maxFiles) { VipsOperation.VipsCacheSetMaxFiles(maxFiles); }
/// <summary> /// Limit the operation cache by memory use. /// </summary> /// <param name="maxMem"></param> public static void VipsCacheSetMaxMem(ulong maxMem) { VipsOperation.VipsCacheSetMaxMem(maxMem); }
/// <summary> /// Set the maximum number of operations libvips will cache. /// </summary> /// <param name="max"></param> public static void VipsCacheSetMax(int max) { VipsOperation.VipsCacheSetMax(max); }
/// <summary> /// Call a libvips operation. /// </summary> /// <remarks> /// Use this method to call any libvips operation. For example: /// <code language="lang-csharp"> /// var blackImage = Operation.call("black", 10, 10); /// </code> /// See the Introduction for notes on how this works. /// </remarks> /// <param name="operationName"></param> /// <param name="kwargs"></param> /// <param name="args"></param> /// <returns></returns> public static object Call(string operationName, VOption kwargs, params object[] args) { // logger.Debug($"VipsOperation.call: operationName = {operationName}"); // logger.Debug($"VipsOperation.call: args = {args}, kwargs = {kwargs}"); // pull out the special string_options kwarg object stringOptions = null; kwargs?.Remove("string_options", out stringOptions); // logger.Debug($"VipsOperation.call: stringOptions = {stringOptions}"); var op = NewFromName(operationName); var arguments = op.GetArgs(); // logger.Debug($"VipsOperation.call: arguments = {arguments}"); // make a thing to quickly get flags from an arg name var flagsFromName = new Dictionary <string, Internal.Enums.VipsArgumentFlags>(); var nRequired = 0; foreach (var entry in arguments) { var name = entry.Key; var flag = entry.Value; flagsFromName[name] = flag; // count required input args if ((flag & Internal.Enums.VipsArgumentFlags.VIPS_ARGUMENT_INPUT) != 0 && (flag & Internal.Enums.VipsArgumentFlags.VIPS_ARGUMENT_REQUIRED) != 0 && (flag & Internal.Enums.VipsArgumentFlags.VIPS_ARGUMENT_DEPRECATED) == 0) { nRequired++; } } if (nRequired != args.Length) { throw new ArgumentException( $"unable to call {operationName}: {args.Length} arguments given, but {nRequired} required"); } // the first image argument is the thing we expand constants to // match ... look inside tables for images, since we may be passing // an array of image as a single param var matchImage = FindInside <Image>(args); // logger.Debug($"VipsOperation.call: matchImage = {matchImage}"); // set any string options before any args so they can't be // overridden if (stringOptions != null && !op.SetString(stringOptions as string)) { throw new VipsException($"unable to call {operationName}"); } // set required and optional args var n = 0; foreach (var entry in arguments) { var name = entry.Key; var flag = entry.Value; if ((flag & Internal.Enums.VipsArgumentFlags.VIPS_ARGUMENT_INPUT) != 0 && (flag & Internal.Enums.VipsArgumentFlags.VIPS_ARGUMENT_REQUIRED) != 0 && (flag & Internal.Enums.VipsArgumentFlags.VIPS_ARGUMENT_DEPRECATED) == 0) { op.Set(name, flag, matchImage, args[n]); n++; } } if (kwargs != null) { foreach (var entry in kwargs) { var name = entry.Key; var value = entry.Value; if (!flagsFromName.ContainsKey(name)) { throw new Exception($"{operationName} does not support argument {name}"); } op.Set(name, flagsFromName[name], matchImage, value); } } // build operation var vop = VipsOperation.VipsCacheOperationBuild(op); if (vop == IntPtr.Zero) { throw new VipsException($"unable to call {operationName}"); } op = new Operation(vop); // fetch required output args, plus modified input images var result = new List <object>(); foreach (var entry in arguments) { var name = entry.Key; var flag = entry.Value; if ((flag & Internal.Enums.VipsArgumentFlags.VIPS_ARGUMENT_OUTPUT) != 0 && (flag & Internal.Enums.VipsArgumentFlags.VIPS_ARGUMENT_REQUIRED) != 0 && (flag & Internal.Enums.VipsArgumentFlags.VIPS_ARGUMENT_DEPRECATED) == 0) { result.Add(op.Get(name)); } if ((flag & Internal.Enums.VipsArgumentFlags.VIPS_ARGUMENT_INPUT) != 0 && (flag & Internal.Enums.VipsArgumentFlags.VIPS_ARGUMENT_MODIFY) != 0) { result.Add(op.Get(name)); } } // fetch optional output args var opts = new VOption(); if (kwargs != null) { foreach (var entry in kwargs) { var name = entry.Key; var flags = flagsFromName[name]; if ((flags & Internal.Enums.VipsArgumentFlags.VIPS_ARGUMENT_OUTPUT) != 0 && (flags & Internal.Enums.VipsArgumentFlags.VIPS_ARGUMENT_REQUIRED) == 0 && (flags & Internal.Enums.VipsArgumentFlags.VIPS_ARGUMENT_DEPRECATED) == 0) { opts[name] = op.Get(name); } } } Internal.VipsObject.VipsObjectUnrefOutputs(op); if (opts.Count > 0) { result.Add(opts); } // logger.Debug($"VipsOperation.call: result = {result}"); return(result.Count == 0 ? null : (result.Count == 1 ? result[0] : result.ToArray())); }
/// <summary> /// For testing only. /// </summary> public static void VipsOperationFlagsGetType() { VipsOperation.FlagsGetType(); }
/// <summary> /// Limit the operation cache by memory use. /// </summary> /// <param name="maxMem"></param> public static void VipsCacheSetMaxMem(ulong maxMem) { VipsOperation.VipsCacheSetMaxMem(new UIntPtr(maxMem)); }