Skip to content

Commit

Permalink
Fixed a critical issue where images that have power-of-two dimensions…
Browse files Browse the repository at this point in the history
… were resized when the difference between their dimensions was smaller than the threshold

Fixed an issue where instead of treating the images as (Width x Height) they were treated as (Height x Width)
  • Loading branch information
Vicente Jesus Lechuga committed Feb 23, 2022
1 parent 2517b3d commit 8569fb6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Folder2YTD/Folder2YTD.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<DebugType>full</DebugType>
<Platforms>AnyCPU;x64</Platforms>
<FileVersion>0.3.4.0</FileVersion>
<AssemblyVersion>0.3.4.0</AssemblyVersion>
<AssemblyVersion>0.3.4.1</AssemblyVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
44 changes: 30 additions & 14 deletions Folder2YTD/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,25 +220,41 @@ private void ToggleControls(bool State)
}


public (int,int) ConvertHeightAndWidthToPowerOfTwo(int height, int width, double threshold)
public (int,int) ConvertHeightAndWidthToPowerOfTwo(int width, int height, double threshold)
{
if (Math.Abs(height - width) < threshold)


if ((Math.Log2(width) % 1) == 0 && (Math.Log2(height) % 1) == 0)
{
return (width, height);
}
else
{
if (height < width)
if (Math.Abs(height - width) < threshold)
{
width = height;
if (height < width)
{
width = height;

}
else
{
height = width;
}
}
else
{
height = width;
}

height = (int)Math.Pow(2, Math.Round(Math.Log2(height)));
width = (int)Math.Pow(2, Math.Round(Math.Log2(width)));

return (width, height);
}

height = (int)Math.Pow(2, Math.Round(Math.Log2(height)));
width = (int)Math.Pow(2, Math.Round(Math.Log2(width)));

return (height,width);







}
Expand Down Expand Up @@ -582,10 +598,10 @@ private Image<Rgba32> ResizedImage(Image<Rgba32> image)
double ThresholdA = 0;
ThresPower.Dispatcher.Invoke(() => { ThresholdA = ThresPower.Value; });

int Height = ConvertHeightAndWidthToPowerOfTwo(image.Height, image.Width, ThresholdA).Item1;
int Width = ConvertHeightAndWidthToPowerOfTwo(image.Height, image.Width, ThresholdA).Item2;
int Height = ConvertHeightAndWidthToPowerOfTwo(image.Width, image.Height, ThresholdA).Item2;
int Width = ConvertHeightAndWidthToPowerOfTwo(image.Width, image.Height, ThresholdA).Item1;

image.Mutate(x => x.Resize(Height, Width, KnownResamplers.Lanczos3));
image.Mutate(x => x.Resize(Width, Height, KnownResamplers.Lanczos3));
return image;
}
private void btnClose_Click(object sender, RoutedEventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion Folder2YTD/updateinfo.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>0.3.4.0</version>
<version>0.3.4.1</version>
<url>https://github.com/Hancapo/Folder2YTD/releases/latest/download/Folders2YTD.zip</url>
<changelog>https://pastebin.com/raw/6rp2VuLS</changelog>
<mandatory>true</mandatory>
Expand Down

0 comments on commit 8569fb6

Please sign in to comment.