Skip to content

Commit a97f7aa

Browse files
authored
Fix thumbnails being too small at extra large size
1 parent c934cad commit a97f7aa

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

PetzThumbnailHandler.cs

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@
66
using SharpShell.SharpThumbnailHandler;
77
using System;
88
using System.Drawing;
9+
using System.Drawing.Drawing2D;
910
using System.IO;
1011
using System.Linq;
1112
using System.Reflection;
1213
using System.Runtime.InteropServices;
1314
using System.Text;
15+
using AsmResolver.PE;
1416
using static System.Drawing.Imaging.ImageLockMode;
1517
using static System.Drawing.Imaging.PixelFormat;
1618

1719
namespace PetzThumbnails
1820
{
21+
1922
[ComVisible(true)]
2023
[COMServerAssociation(AssociationType.FileExtension, ".pet")]
2124
public class PetzThumbnailHandler : SharpThumbnailHandler
@@ -40,7 +43,7 @@ protected override Bitmap GetThumbnailImage(uint width)
4043
var bitmap = new Bitmap(mem);
4144
var transcolor = bitmap.Palette.Entries[253];
4245
bitmap.MakeTransparent(transcolor);
43-
return bitmap;
46+
return width > bitmap.Width ? Helper.ResizeBitmap(bitmap) : bitmap;
4447
}
4548
}
4649
catch (Exception e)
@@ -53,7 +56,7 @@ protected override Bitmap GetThumbnailImage(uint width)
5356
var bitmap = new Bitmap(mem);
5457
var transcolor = bitmap.Palette.Entries[253];
5558
bitmap.MakeTransparent(transcolor);
56-
return bitmap;
59+
return width > bitmap.Width ? Helper.ResizeBitmap(bitmap) : bitmap;
5760
}
5861
}
5962
finally
@@ -66,7 +69,7 @@ protected override Bitmap GetThumbnailImage(uint width)
6669
public class Helper
6770
{
6871
public static readonly Bitmap palette = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("PetzThumbnails.PALETTE.bmp"));
69-
public static Bitmap GetThumbnail(byte[] bytes, string type)
72+
public static Bitmap GetThumbnail(byte[] bytes, string type, uint width)
7073
{
7174
var flhname = "restinga";
7275
if (type == "clo")
@@ -108,10 +111,10 @@ public static Bitmap GetThumbnail(byte[] bytes, string type)
108111
bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
109112
bitmap.MakeTransparent(palette.Palette.Entries[253]);
110113

111-
return bitmap;
114+
return width > bitmap.Width ? Helper.ResizeBitmap(bitmap) : bitmap;
112115
}
113-
114-
public static Bitmap GetBreedThumbnailImage(Stream SelectedItemStream)
116+
117+
public static Bitmap GetBreedThumbnailImage(Stream SelectedItemStream, uint width)
115118
{
116119
byte[] data = new byte[SelectedItemStream.Length];
117120
SelectedItemStream.Read(data, 0, data.Length);
@@ -120,11 +123,14 @@ public static Bitmap GetBreedThumbnailImage(Stream SelectedItemStream)
120123
var breedStringTable = asm.Resources.GetDirectory(ResourceType.String)
121124
.GetDirectory(63).GetData(1033).Contents.WriteIntoArray();
122125
string name;
123-
using (var binaryReader = new BinaryReader(new MemoryStream(breedStringTable.SkipWhile(x => x == 0x0).ToArray()), Encoding.Unicode))
126+
using (var binaryReader =
127+
new BinaryReader(new MemoryStream(breedStringTable.SkipWhile(x => x == 0x0).ToArray()),
128+
Encoding.Unicode))
124129
{
125-
var nameLength = binaryReader.ReadInt16();
126-
name = new string(binaryReader.ReadChars(nameLength)).ToUpper();
130+
var nameLength = binaryReader.ReadInt16();
131+
name = new string(binaryReader.ReadChars(nameLength)).ToUpper();
127132
}
133+
128134
var bmpResourceDir = (IResourceDirectory)asm.Resources.Entries.Where(x => x.Name == "BMP").First();
129135
bmpResourceDir = (IResourceDirectory)bmpResourceDir.Entries.Where(x => x.Name == name).First();
130136
var bmpResource = (IResourceData)bmpResourceDir.Entries.First();
@@ -141,9 +147,21 @@ public static Bitmap GetBreedThumbnailImage(Stream SelectedItemStream)
141147
{
142148
// ok - wrong palette - don't bother making transparent
143149
}
144-
return bitmap;
150+
151+
return width > bitmap.Width ? Helper.ResizeBitmap(bitmap) : bitmap;
145152
}
146153
}
154+
155+
public static Bitmap ResizeBitmap(Bitmap bitmap)
156+
{
157+
var scaledbitmap = new Bitmap(bitmap.Width * 2, bitmap.Height * 2);
158+
using (Graphics g = Graphics.FromImage(scaledbitmap))
159+
{
160+
g.InterpolationMode = InterpolationMode.NearestNeighbor;
161+
g.DrawImage(bitmap, new Rectangle(Point.Empty, scaledbitmap.Size));
162+
return scaledbitmap;
163+
}
164+
}
147165
}
148166

149167

@@ -156,7 +174,7 @@ protected override Bitmap GetThumbnailImage(uint width)
156174
byte[] data = new byte[SelectedItemStream.Length];
157175
SelectedItemStream.Read(data, 0, data.Length);
158176
SelectedItemStream.Close();
159-
return Helper.GetThumbnail(data, "toy");
177+
return Helper.GetThumbnail(data, "toy", width);
160178
}
161179

162180
}
@@ -170,7 +188,7 @@ protected override Bitmap GetThumbnailImage(uint width)
170188
byte[] data = new byte[SelectedItemStream.Length];
171189
SelectedItemStream.Read(data, 0, data.Length);
172190
SelectedItemStream.Close();
173-
return Helper.GetThumbnail(data, "clo");
191+
return Helper.GetThumbnail(data, "clo", width);
174192
}
175193
}
176194

@@ -180,7 +198,7 @@ public class DogThumbnailHandler : SharpThumbnailHandler
180198
{
181199
protected override Bitmap GetThumbnailImage(uint width)
182200
{
183-
return Helper.GetBreedThumbnailImage(SelectedItemStream);
201+
return Helper.GetBreedThumbnailImage(SelectedItemStream, width);
184202
}
185203
}
186204

@@ -190,7 +208,7 @@ public class CatThumbnailHandler : SharpThumbnailHandler
190208
{
191209
protected override Bitmap GetThumbnailImage(uint width)
192210
{
193-
return Helper.GetBreedThumbnailImage(SelectedItemStream);
211+
return Helper.GetBreedThumbnailImage(SelectedItemStream, width);
194212
}
195213
}
196214
}

installer.iss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
33

44
#define MyAppName "Petz Thumbnails Extension"
5-
#define MyAppVersion "5.2"
5+
#define MyAppVersion "5.3"
66
#define MyAppPublisher "-"
77
#define MyAppURL "-"
88
#define MyAppExeName "PetzThumbnailsInstaller.exe"

0 commit comments

Comments
 (0)