Skip to content

Commit

Permalink
Test build for PR 3585
Browse files Browse the repository at this point in the history
  • Loading branch information
kleisauke committed Oct 3, 2023
1 parent c533ba2 commit 1c4acef
Show file tree
Hide file tree
Showing 5 changed files with 420 additions and 277 deletions.
21 changes: 20 additions & 1 deletion 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 @@ -419,6 +433,11 @@ string ToCref(string name) =>
{
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});");
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 1c4acef

Please sign in to comment.