Skip to content

Commit 84b8b37

Browse files
author
Carl Chang
committed
update virtualizingwrappanel;
add thumbnail format option; default to jpeg for thumbnail in DB;
1 parent 83ff922 commit 84b8b37

File tree

8 files changed

+77
-25
lines changed

8 files changed

+77
-25
lines changed

Helpers/SQLiteHelper.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,23 @@ internal static int AddToThumbDB(ImageSource source, string basePath, string sub
109109
if (!(source is BitmapSource bs)) throw new NotSupportedException();
110110

111111
object[] affected = null;
112-
byte[] png;
113-
var enc = new PngBitmapEncoder();
112+
byte[] bytes;
113+
BitmapEncoder enc;
114+
switch (Setting.ThumbnailFormat) {
115+
case Setting.ThumbnailFormats.Jpeg:
116+
default:
117+
enc = new JpegBitmapEncoder() { QualityLevel = 85 };
118+
break;
119+
case Setting.ThumbnailFormats.Png:
120+
enc = new PngBitmapEncoder();
121+
break;
122+
}
114123
enc.Frames.Add(BitmapFrame.Create(bs));
115124
using (var ms = new MemoryStream()) {
116125
enc.Save(ms);
117-
png = ms.ToArray();
126+
bytes = ms.ToArray();
118127
}
119-
if (png.Length == 0) return 0;
128+
if (bytes.Length == 0) return 0;
120129

121130
affected = Execute(Table.Thumbs, (table, con) => {
122131
using (var cmd = new SQLiteCommand(con)) {
@@ -132,8 +141,8 @@ internal static int AddToThumbDB(ImageSource source, string basePath, string sub
132141
cmd.CommandText =
133142
$@"insert into {table.Name}
134143
({Column.BasePath}, {Column.SubPath}, {Column.DecodeWidth}, {Column.DecodeHeight}, {Column.ThumbData}) values
135-
(@basePath, @subPath, {decodeSize.Width}, {decodeSize.Height}, @png)";
136-
cmd.Parameters.Add(new SQLiteParameter("@png", DbType.Binary) { Value = png });
144+
(@basePath, @subPath, {decodeSize.Width}, {decodeSize.Height}, @bytes)";
145+
cmd.Parameters.Add(new SQLiteParameter("@bytes", DbType.Binary) { Value = bytes });
137146
return cmd.ExecuteNonQuery();
138147
}
139148
});

Helpers/Setting.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ public enum Background
6363
[Description("ttl_" + nameof(White), true)]
6464
White
6565
}
66+
public enum ThumbnailFormats
67+
{
68+
[Description("JPEG")]
69+
Jpeg,
70+
[Description("PNG")]
71+
Png
72+
}
6673

6774
private enum ConfigSection
6875
{ AppConfig, CustomCommands, FallbackPasswords }
@@ -94,6 +101,17 @@ public static ObservablePair<int, int> ThumbnailSize {
94101
}
95102
}
96103

104+
private static ThumbnailFormats thumbnailFormat = ThumbnailFormats.Jpeg;
105+
[AppConfig]
106+
public static ThumbnailFormats ThumbnailFormat {
107+
get => thumbnailFormat;
108+
set {
109+
if (thumbnailFormat == value) return;
110+
thumbnailFormat = value;
111+
OnStaticPropertyChanged(nameof(ThumbnailFormat));
112+
}
113+
}
114+
97115
private static Transition viewerTransition = Transition.ZoomFadeBlur;
98116
[AppConfig]
99117
public static Transition ViewerTransition {

Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@
5151
// You can specify all the values or you can default the Build and Revision Numbers
5252
// by using the '*' as shown below:
5353
// [assembly: AssemblyVersion("1.0.*")]
54-
[assembly: AssemblyVersion("1.1.7.0")]
55-
[assembly: AssemblyFileVersion("1.1.7.0")]
54+
[assembly: AssemblyVersion("1.1.8.0")]
55+
[assembly: AssemblyFileVersion("1.1.8.0")]

Resources/Localization.en.xaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
<sys:String x:Key="ttl_ThumbnailSize">Thumbnail Size</sys:String>
77
<Span x:Key="spn_ThumbSizeTip">
88
<Bold>Width</Bold> x <Bold>Height</Bold> in pixels.<LineBreak/>
9-
<Bold>Changing this value invalidates the entire thumbnail cache.</Bold>
9+
<Bold>Changing the size invalidates the entire thumbnail cache.</Bold><LineBreak/>
10+
Use <Bold>JPEG</Bold> thumbnail format results in a much smaller database file at the cost of the quality of the thumbnail. Changing the format will not refresh existing thumbnails in the cache.
1011
</Span>
12+
<sys:String x:Key="ttl_ThumbnailFormat">Thumbnail Format</sys:String>
1113
<sys:String x:Key="ttl_ThumbSwapDelayMultiplier">Thumbnail Swap Delay Multiplier</sys:String>
1214
<sys:String x:Key="msg_ThumbSwapDelayMultiplierTip">The delay of thumbnail change on folders and archives. Higher value results in longer delay.</sys:String>
1315
<sys:String x:Key="ttl_DatabaseDir">Database Directory</sys:String>

Resources/Localization.zh.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
<Span x:Key="spn_ThumbSizeTip">
88
<Bold>宽</Bold> x <Bold>高</Bold>(像素)。<LineBreak/>
99
<Bold>更改此值会使所有当前尺寸的缩略图失效。</Bold>
10+
使用<Bold>JPEG</Bold>缩略图格式可大幅减少数据库文件大小,但质量会有所降低。更改格式不会刷新缓存中已有的缩略图。
1011
</Span>
12+
<sys:String x:Key="ttl_ThumbnailFormat">缩略图格式</sys:String>
1113
<sys:String x:Key="ttl_ThumbSwapDelayMultiplier">缩略图切换延迟速率</sys:String>
1214
<sys:String x:Key="msg_ThumbSwapDelayMultiplierTip">目录和压缩文件缩略图的切换延迟。数值越高延迟越高。</sys:String>
1315
<sys:String x:Key="ttl_DatabaseDir">数据库目录</sys:String>

SettingsWindow.xaml

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
xmlns:local="clr-namespace:ZipImageViewer" mc:Ignorable="d"
7-
Width="800" Height="600" Icon="Resources/ZipImageViewer.ico"
7+
Width="850" Height="600" Icon="Resources/ZipImageViewer.ico"
88
Background="{StaticResource BackgroundBrush}" Foreground="{StaticResource ForegroundBrush}" WindowStartupLocation="CenterOwner"
99
Title="{StaticResource ttl_Settings}" UseLayoutRounding="True" Loaded="SettingsWin_Loaded" Closing="SettingsWin_Closing" PreviewKeyDown="SettingsWin_PreviewKeyDown">
1010
<ScrollViewer>
@@ -43,21 +43,39 @@
4343
</local:PaddedGrid.Resources>
4444

4545
<Border Grid.Row="0">
46-
<DockPanel LastChildFill="False">
47-
<TextBlock DockPanel.Dock="Top" Style="{StaticResource HeaderTextStyle}" Text="{StaticResource ttl_ThumbnailSize}"/>
48-
<StackPanel Orientation="Horizontal" DockPanel.Dock="Left" VerticalAlignment="Top">
49-
<ContentControl>
50-
<TextBox MinWidth="32" VerticalAlignment="Top"
46+
<Grid>
47+
<Grid.ColumnDefinitions>
48+
<ColumnDefinition/>
49+
<ColumnDefinition Width="Auto"/>
50+
<ColumnDefinition/>
51+
</Grid.ColumnDefinitions>
52+
<DockPanel LastChildFill="False" Grid.Column="0">
53+
<TextBlock DockPanel.Dock="Top" Style="{StaticResource HeaderTextStyle}" Text="{StaticResource ttl_ThumbnailSize}"/>
54+
<StackPanel Orientation="Horizontal" DockPanel.Dock="Left" VerticalAlignment="Top">
55+
<ContentControl>
56+
<TextBox MinWidth="32" VerticalAlignment="Top"
5157
Text="{Binding Source={x:Static local:App.Setting}, Path=ThumbnailSize.Item1}"/>
52-
</ContentControl>
53-
<TextBlock Text=" x " VerticalAlignment="Center"/>
54-
<ContentControl>
55-
<TextBox MinWidth="32" VerticalAlignment="Top"
58+
</ContentControl>
59+
<TextBlock Text=" x " VerticalAlignment="Center"/>
60+
<ContentControl>
61+
<TextBox MinWidth="32" VerticalAlignment="Top"
5662
Text="{Binding Source={x:Static local:App.Setting}, Path=ThumbnailSize.Item2}"/>
63+
</ContentControl>
64+
</StackPanel>
65+
<Button DockPanel.Dock="Right" Content="{StaticResource ttl_ReloadView}" VerticalAlignment="Center" Click="Btn_Reload_Click"/>
66+
</DockPanel>
67+
<StackPanel Grid.Column="1" Orientation="Horizontal" Margin="8 0">
68+
<Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" />
69+
</StackPanel>
70+
<StackPanel Grid.Column="2">
71+
<TextBlock Style="{StaticResource HeaderTextStyle}" Text="{StaticResource ttl_ThumbnailFormat}"/>
72+
<ContentControl>
73+
<ComboBox ItemsSource="{Binding Source={local:Enumeration {x:Type local:Setting+ThumbnailFormats}}}"
74+
SelectedValue="{Binding Source={x:Static local:App.Setting}, Path=ThumbnailFormat}"
75+
DisplayMemberPath="Description" SelectedValuePath="Value"/>
5776
</ContentControl>
5877
</StackPanel>
59-
<Button DockPanel.Dock="Right" Content="{StaticResource ttl_ReloadView}" VerticalAlignment="Center" Click="Btn_Reload_Click"/>
60-
</DockPanel>
78+
</Grid>
6179
</Border>
6280
<TextBlock Grid.Row="0" Grid.Column="1" Style="{StaticResource TipTextStyle}">
6381
<StaticResource ResourceKey="spn_ThumbSizeTip"/>
@@ -140,7 +158,7 @@
140158
<Grid>
141159
<Grid.ColumnDefinitions>
142160
<ColumnDefinition/>
143-
<ColumnDefinition Width="8"/>
161+
<ColumnDefinition Width="Auto"/>
144162
<ColumnDefinition/>
145163
</Grid.ColumnDefinitions>
146164
<StackPanel Grid.Column="0">
@@ -151,6 +169,9 @@
151169
DisplayMemberPath="Description" SelectedValuePath="Value"/>
152170
</ContentControl>
153171
</StackPanel>
172+
<StackPanel Grid.Column="1" Orientation="Horizontal" Margin="8 0">
173+
<Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" />
174+
</StackPanel>
154175
<StackPanel Grid.Column="2">
155176
<TextBlock Style="{StaticResource HeaderTextStyle}" Text="{StaticResource ttl_ViewerTransitionSpeed}"/>
156177
<ContentControl>

ZipImageViewer.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@
108108
<Reference Include="System.Xaml">
109109
<RequiredTargetFramework>4.0</RequiredTargetFramework>
110110
</Reference>
111-
<Reference Include="VirtualizingWrapPanel, Version=1.4.2.0, Culture=neutral, processorArchitecture=MSIL">
112-
<HintPath>packages\VirtualizingWrapPanel.1.4.2\lib\net45\VirtualizingWrapPanel.dll</HintPath>
111+
<Reference Include="VirtualizingWrapPanel, Version=1.5.3.0, Culture=neutral, processorArchitecture=MSIL">
112+
<HintPath>packages\VirtualizingWrapPanel.1.5.3\lib\net45\VirtualizingWrapPanel.dll</HintPath>
113113
</Reference>
114114
<Reference Include="WindowsBase" />
115115
<Reference Include="PresentationCore" />

packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
<package id="SevenZipSharp.Net45" version="1.0.19" targetFramework="net472" />
1010
<package id="System.Data.SQLite.Core" version="1.0.112.0" targetFramework="net472" />
1111
<package id="System.Data.SQLite.Linq" version="1.0.112.0" targetFramework="net472" />
12-
<package id="VirtualizingWrapPanel" version="1.4.2" targetFramework="net472" />
12+
<package id="VirtualizingWrapPanel" version="1.5.3" targetFramework="net472" />
1313
</packages>

0 commit comments

Comments
 (0)