/// <summary> /// Set a GObject property. The value is converted to the property type, if possible. /// </summary> /// <param name="name">The name of the property to set.</param> /// <param name="flags">See <see cref="Enums.ArgumentFlags"/>.</param> /// <param name="matchImage">A <see cref="Image"/> used as guide.</param> /// <param name="value">The value.</param> /// <param name="gtype">The GType of the property.</param> private void Set(IntPtr gtype, Enums.ArgumentFlags flags, Image matchImage, string name, object value) { // logger.Debug($"Operation.Set: name = {name}, flags = {flags}, " + // $"matchImage = {matchImage} value = {value}"); // if the object wants an image and we have a constant, Imageize it // // if the object wants an image array, Imageize any constants in the // array if (matchImage != null) { if (gtype == GValue.ImageType) { value = Image.Imageize(matchImage, value); } else if (gtype == GValue.ArrayImageType) { if (!(value is Array values) || values.Rank != 1) { throw new Exception( $"unsupported value type {value.GetType()} for VipsArrayImage"); } var images = new Image[values.Length]; for (var i = 0; i < values.Length; i++) { ref var image = ref images[i]; image = Image.Imageize(matchImage, values.GetValue(i)); } value = images; } }
/// <summary> /// Set a GObject property. The value is converted to the property type, if possible. /// </summary> /// <param name="gtype">The GType of the property.</param> /// <param name="flags">See <see cref="Enums.ArgumentFlags"/>.</param> /// <param name="name">The name of the property to set.</param> /// <param name="value">The value.</param> private void Set(IntPtr gtype, Enums.ArgumentFlags flags, string name, object value) { // MODIFY args need to be copied before they are set if ((flags & Enums.ArgumentFlags.MODIFY) != 0 && value is Image image) { // logger.Debug($"copying MODIFY arg {name}"); // make sure we have a unique copy value = image.Copy().CopyMemory(); } Set(gtype, name, value); }