diff --git a/src/Properties/Resources.resx b/src/Properties/Resources.resx
index 5d7f8f2..ce74a6b 100644
--- a/src/Properties/Resources.resx
+++ b/src/Properties/Resources.resx
@@ -193,4 +193,7 @@
The image uses a WebP feature that is not supported.
+
+ Lossless
+
\ No newline at end of file
diff --git a/src/WebP/WebP.cpp b/src/WebP/WebP.cpp
index 2a0a4bb..6469c39 100644
--- a/src/WebP/WebP.cpp
+++ b/src/WebP/WebP.cpp
@@ -199,7 +199,7 @@ int __stdcall WebPSave(
config.method = 6; // 6 is the highest quality encoding
config.thread_level = 1;
- if (encodeOptions->quality == 100)
+ if (encodeOptions->lossless)
{
config.lossless = 1;
pic->use_argb = 1;
diff --git a/src/WebP/WebP.h b/src/WebP/WebP.h
index eeb6e58..af86150 100644
--- a/src/WebP/WebP.h
+++ b/src/WebP/WebP.h
@@ -41,6 +41,7 @@ typedef struct EncodeParams
{
float quality;
int preset;
+ bool lossless;
}EncParams;
enum MetadataType
diff --git a/src/WebPFile.cs b/src/WebPFile.cs
index e0fef43..b9594e6 100644
--- a/src/WebPFile.cs
+++ b/src/WebPFile.cs
@@ -123,6 +123,9 @@ internal static unsafe Surface Load(byte[] webpBytes)
/// The output Stream.
/// The WebP save quality.
/// The WebP encoding preset.
+ ///
+ /// if lossless encoding should be used; otherwise, .
+ ///
/// The scratch surface.
/// The progress callback.
/// The image exceeds 16383 pixels in width and/or height.
@@ -133,6 +136,7 @@ internal static void Save(
Stream output,
int quality,
WebPPreset preset,
+ bool lossless,
Surface scratchSurface,
ProgressEventHandler progressCallback)
{
@@ -144,7 +148,8 @@ internal static void Save(
WebPNative.EncodeParams encParams = new()
{
quality = quality,
- preset = preset
+ preset = preset,
+ lossless = lossless
};
scratchSurface.Clear();
diff --git a/src/WebPFileType.cs b/src/WebPFileType.cs
index cd02334..7154326 100644
--- a/src/WebPFileType.cs
+++ b/src/WebPFileType.cs
@@ -32,7 +32,8 @@ private enum PropertyNames
Quality,
KeepMetadata, // Obsolete, but retained to keep the value from being reused for a different property.
ForumLink,
- GitHubLink
+ GitHubLink,
+ Lossless
}
private readonly IWebPStringResourceManager strings;
@@ -201,6 +202,7 @@ public override PropertyCollection OnCreateSavePropertyCollection()
{
StaticListChoiceProperty.CreateForEnum(PropertyNames.Preset, WebPPreset.Photo, false),
new Int32Property(PropertyNames.Quality, 95, 0, 100, false),
+ new BooleanProperty(PropertyNames.Lossless, false),
new UriProperty(PropertyNames.ForumLink, new Uri("https://forums.getpaint.net/topic/21773-webp-filetype/")),
new UriProperty(PropertyNames.GitHubLink, new Uri("https://github.com/0xC0000054/pdn-webp"))
};
@@ -224,6 +226,9 @@ public override ControlInfo OnCreateSaveConfigUI(PropertyCollection props)
info.SetPropertyControlValue(PropertyNames.Quality, ControlInfoPropertyNames.DisplayName, GetString("Quality_DisplayName"));
+ info.SetPropertyControlValue(PropertyNames.Lossless, ControlInfoPropertyNames.DisplayName, string.Empty);
+ info.SetPropertyControlValue(PropertyNames.Lossless, ControlInfoPropertyNames.Description, GetString("Lossless_Description"));
+
PropertyControlInfo forumLinkPCI = info.FindControlForPropertyName(PropertyNames.ForumLink);
forumLinkPCI.ControlProperties[ControlInfoPropertyNames.DisplayName].Value = GetString("ForumLink_DisplayName");
forumLinkPCI.ControlProperties[ControlInfoPropertyNames.Description].Value = GetString("ForumLink_Description");
@@ -239,8 +244,9 @@ protected override void OnSaveT(Document input, Stream output, PropertyBasedSave
{
int quality = token.GetProperty(PropertyNames.Quality).Value;
WebPPreset preset = (WebPPreset)token.GetProperty(PropertyNames.Preset).Value;
+ bool lossless = token.GetProperty(PropertyNames.Lossless).Value;
- WebPFile.Save(input, output, quality, preset, scratchSurface, progressCallback);
+ WebPFile.Save(input, output, quality, preset, lossless, scratchSurface, progressCallback);
}
}
}
diff --git a/src/WebPNative.cs b/src/WebPNative.cs
index aab761f..c6cc44c 100644
--- a/src/WebPNative.cs
+++ b/src/WebPNative.cs
@@ -71,6 +71,8 @@ internal sealed class EncodeParams
public float quality;
[MarshalAs(UnmanagedType.I4)]
public WebPPreset preset;
+ [MarshalAs(UnmanagedType.U1)]
+ public bool lossless;
}
[StructLayout(LayoutKind.Sequential)]