Skip to content

Commit

Permalink
Merge pull request #8 from dhcgn/add-distance
Browse files Browse the repository at this point in the history
add distance
  • Loading branch information
dhcgn authored Jul 10, 2022
2 parents e43c97b + 66887b0 commit 6dfa2d6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
14 changes: 12 additions & 2 deletions jxlgui.converter/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,28 @@ public class Config
// Quality setting (is remapped to --distance). Range: -inf .. 100.
// 100 = mathematically lossless. Default for already-lossy input (JPEG/GIF).
// Positive quality values roughly match libjpeg quality.
public double Quality { get; set; }
public double? Quality { get; set; }

// Encoder effort setting. Range: 1 .. 9.
// Default: 7. Higher number is more effort (slower)
public int Effort { get; set; }

// The distance level for lossy compression: target max butteraugli
// distance, lower = higher quality. Range: 0 .. 15.
// 0.0 = mathematically lossless (however, use JxlEncoderOptionsSetLossless to use true lossless).
// 1.0 = visually lossless.
// Recommended range: 0.5 .. 3.0.
// Default value: 1.0.
// If JxlEncoderOptionsSetLossless is used, this value is unused and implied to be 0
public double? Distance { get; set; }

public static Config CreateEmpty()
{
return new Config
{
Quality = 99.9,
Effort = 7
Effort = 7,
Distance = null,
};
}

Expand Down
19 changes: 17 additions & 2 deletions jxlgui.converter/JobManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,23 @@ private static string GetArguments(Job job)
switch (job.Operation)
{
case Job.OperationEnum.Encode:
var quality = job.Config.Quality.ToString("N3", System.Globalization.CultureInfo.InvariantCulture);
return $"-q {quality} -e {job.Config.Effort} \"{job.FilePath}\" \"{job.TargetFilePath}\"";
var args = $"-e {job.Config.Effort} ";

if (job.Config.Quality.HasValue)
{
var quality = job.Config.Quality.Value.ToString("N3", System.Globalization.CultureInfo.InvariantCulture);
args+= $" -q {quality} ";
}

if (job.Config.Distance.HasValue)
{
var distance = job.Config.Distance.Value.ToString("N3", System.Globalization.CultureInfo.InvariantCulture);
args+= $" --distance {distance} ";
}

args += $" \"{job.FilePath}\" \"{job.TargetFilePath}\" ";
return args;

case Job.OperationEnum.Decode:
return $" \"{job.FilePath}\" \"{job.TargetFilePath}\"";
default:
Expand Down
4 changes: 3 additions & 1 deletion jxlgui.wpf/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@
</StackPanel>
<StackPanel Orientation="Horizontal"
Visibility="{Binding Config, Converter={StaticResource VisibilityNullConverter}}">
<TextBlock FontSize="8" Text="{Binding Config.Quality, StringFormat=Quality: {0:N3}}" />
<TextBlock FontSize="8" Text="{Binding Config.Quality, StringFormat=Quality: {0:N3}}" Visibility="{Binding Config.Quality, Converter={StaticResource VisibilityNullConverter}}" />
<Border Width="5"></Border>
<TextBlock FontSize="8" Text="{Binding Config.Effort, StringFormat=Effort: {0}}" />
<Border Width="5"></Border>
<TextBlock FontSize="8" Text="{Binding Config.Distance, StringFormat=Distance: {0:N3}}" Visibility="{Binding Config.Distance, Converter={StaticResource VisibilityNullConverter}}" />
</StackPanel>
<TextBlock Text="{Binding State}" FontStyle="Italic" FontSize="8" TextAlignment="Center" />
</StackPanel>
Expand Down

0 comments on commit 6dfa2d6

Please sign in to comment.