Skip to content

Commit

Permalink
Regenerate methods/enums for libvips 8.15
Browse files Browse the repository at this point in the history
  • Loading branch information
kleisauke committed Nov 4, 2023
1 parent 7571d91 commit 522f133
Show file tree
Hide file tree
Showing 12 changed files with 1,095 additions and 639 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ All notable changes to NetVips will be documented in this file. See [here](CHANG

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.4.0] - ???
### Changed
- Update methods/enums for libvips 8.15.

### Fixed
- Ensure correct calling convention for unmanaged-to-managed callbacks.

## [2.3.1] - 2023-06-29
### Fixed
- Ensure `Image.FindLoad()` works on UTF-8 strings ([#210](https://github.com/kleisauke/net-vips/issues/210)).
Expand Down Expand Up @@ -212,6 +219,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Added
- First release!

[2.4.0]: https://github.com/kleisauke/net-vips/compare/v2.3.1...v2.4.0
[2.3.1]: https://github.com/kleisauke/net-vips/compare/v2.3.0...v2.3.1
[2.3.0]: https://github.com/kleisauke/net-vips/compare/v2.2.0...v2.3.0
[2.2.0]: https://github.com/kleisauke/net-vips/compare/v2.1.0...v2.2.0
Expand Down
5 changes: 0 additions & 5 deletions samples/NetVips.Samples/Samples/GenerateEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ private string Generate()

foreach (var name in allEnums)
{
if (name.StartsWith("Gsf"))
{
continue;
}

var gtype = NetVips.TypeFromName(name);
var csharpName = RemovePrefix(name);

Expand Down
37 changes: 33 additions & 4 deletions samples/NetVips.Samples/Samples/GenerateImageClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public class GenerateImageClass : ISample
/// </summary>
public static readonly IntPtr FailOnType = NetVips.TypeFromName("VipsFailOn");

/// <summary>
/// The fundamental type for VipsForeignKeep. See <see cref="Enums.ForeignKeep"/>.
/// </summary>
public static readonly IntPtr ForeignKeepType = NetVips.TypeFromName("VipsForeignKeep");

public GenerateImageClass()
{
// Classes
Expand All @@ -57,12 +62,17 @@ public GenerateImageClass()
_gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsDemandStyle"), "Enums.DemandStyle");
_gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsDirection"), "Enums.Direction");
_gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsExtend"), "Enums.Extend");
_gTypeToCSharpDict.Add(FailOnType, "Enums.FailOn");
if (FailOnType != IntPtr.Zero)
{
_gTypeToCSharpDict.Add(FailOnType, "Enums.FailOn");
}

if (NetVips.TypeFind("VipsOperation", "dzsave") != IntPtr.Zero)
{
_gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsForeignDzContainer"), "Enums.ForeignDzContainer");
_gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsForeignDzLayout"), "Enums.ForeignDzLayout");
}

_gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsForeignDzDepth"), "Enums.ForeignDzDepth");
_gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsForeignHeifCompression"), "Enums.ForeignHeifCompression");
_gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsForeignPpmFormat"), "Enums.ForeignPpmFormat");
Expand Down Expand Up @@ -97,6 +107,10 @@ public GenerateImageClass()
// Flags
_gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsForeignFlags"), "Enums.ForeignFlags");
_gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsForeignPngFilter"), "Enums.ForeignPngFilter");
if (ForeignKeepType != IntPtr.Zero)
{
_gTypeToCSharpDict.Add(ForeignKeepType, "Enums.ForeignKeep");
}
}

/// <summary>
Expand Down Expand Up @@ -410,9 +424,24 @@ string ToCref(string name) =>
? $"nameof({arg.Name})"
: $"\"{arg.Name}\"";

result.AppendLine(arg.Type == FailOnType
? $"{indent} options.AddFailOn({safeIdentifier});"
: $"{indent} options.AddIfPresent({optionsName}, {safeIdentifier});");
if (operationName.StartsWith("dzsave") && arg.Name == "imagename")
{
result.AppendLine(
$"{indent} options.AddIfPresent(NetVips.AtLeastLibvips(8, 15) ? {optionsName} : \"basename\", {safeIdentifier});");
}
else if (arg.Type == FailOnType)
{
result.AppendLine($"{indent} options.AddFailOn({safeIdentifier});");
}
else if (arg.Type == ForeignKeepType)
{
result.Append($"{indent} options.AddForeignKeep({safeIdentifier}");
result.AppendLine(operationName.StartsWith("dzsave") ? ", true);" : ");");
}
else
{
result.AppendLine($"{indent} options.AddIfPresent({optionsName}, {safeIdentifier});");
}
}

result.AppendLine();
Expand Down
4 changes: 2 additions & 2 deletions samples/NetVips.Samples/Samples/ThumbnailPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@ public void Execute(string[] args)

thumb.WriteToFile("thumbnail.webp", new VOption
{
{"strip", true}
{"keep", Enums.ForeignKeep.None}
});

// Or:
/*buffer = thumb.WriteToBuffer(".webp", new VOption
{
{"strip", true}
{"keep", Enums.ForeignKeep.None}
});*/

Console.WriteLine("See thumbnail.webp");
Expand Down
28 changes: 28 additions & 0 deletions src/NetVips/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,34 @@ public enum ForeignPngFilter
All = None | Sub | Up | Avg | Paeth // "all"
}

/// <summary>
/// Which metadata to retain.
/// </summary>
[Flags]
public enum ForeignKeep
{
/// <summary>Don't attach metadata.</summary>
None = 0, // "none"

/// <summary>Keep Exif metadata.</summary>
Exif = 1 << 0, // "exif"

/// <summary>Keep XMP metadata.</summary>
Xmp = 1 << 1, // "xmp"

/// <summary>Keep IPTC metadata.</summary>
Iptc = 1 << 2, // "iptc"

/// <summary>Keep ICC metadata.</summary>
Icc = 1 << 3, // "icc"

/// <summary>Keep other metadata (e.g. PNG comments and some TIFF tags)</summary>
Other = 1 << 4, // "other"

/// <summary>Keep all metadata.</summary>
All = Exif | Xmp | Iptc | Icc | Other // "all"
}

/// <summary>
/// The selected encoder to use.
/// </summary>
Expand Down
27 changes: 27 additions & 0 deletions src/NetVips/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,5 +272,32 @@ internal static void AddFailOn(this VOption options, Enums.FailOn? failOn = null
options.Add("fail", failOn > Enums.FailOn.None);
}
}

/// <summary>
/// Compatibility method to call savers with the <see cref="Enums.ForeignKeep"/> enum.
/// </summary>
/// <param name="options">The optional arguments for the saver.</param>
/// <param name="keep">The optional <see cref="Enums.ForeignKeep"/> parameter.</param>
/// <param name="isDzsave">Whether this operation is <see cref="Image.Dzsave"/>-like.</param>
internal static void AddForeignKeep(this VOption options, Enums.ForeignKeep? keep = null, bool isDzsave = false)
{
if (!keep.HasValue)
{
return;
}

if (NetVips.AtLeastLibvips(8, 15))
{
options.Add(nameof(keep), keep);
}
else if (isDzsave)
{
options.Add("no_strip", keep != Enums.ForeignKeep.None);
}
else
{
options.Add("strip", keep == Enums.ForeignKeep.None);
}
}
}
}
Loading

0 comments on commit 522f133

Please sign in to comment.