Skip to content

Commit

Permalink
Simplify ThumbnailPipeline sample
Browse files Browse the repository at this point in the history
  • Loading branch information
kleisauke committed Oct 27, 2023
1 parent d8052ef commit d471e33
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions samples/NetVips.Samples/Samples/ThumbnailPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class ThumbnailPipeline : ISample
public bool LoaderSupportPage(string loader)
{
return loader.StartsWith("VipsForeignLoadPdf") ||
loader.StartsWith("VipsForeignLoadGif") ||
loader.StartsWith("VipsForeignLoadNsgif") ||
loader.StartsWith("VipsForeignLoadTiff") ||
loader.StartsWith("VipsForeignLoadWebp") ||
loader.StartsWith("VipsForeignLoadHeif") ||
Expand Down Expand Up @@ -85,9 +85,7 @@ public void Execute(string[] args)
int inputWidth;
int inputHeight;
int pageHeight;
bool isCmyk;
bool isLabs;
bool embeddedProfile;
bool hasIccProfile;

Image image = null;
try
Expand All @@ -109,9 +107,7 @@ public void Execute(string[] args)
}

pageHeight = image.PageHeight;
isCmyk = image.Interpretation == Enums.Interpretation.Cmyk;
isLabs = image.Interpretation == Enums.Interpretation.Labs;
embeddedProfile = image.Contains(VipsMetaIccName);
hasIccProfile = image.Contains(VipsMetaIccName);
}
catch (VipsException e)
{
Expand All @@ -128,17 +124,17 @@ public void Execute(string[] args)
string exportProfile = null;
Enums.Intent? intent = null;

// Ensure we're using a device-independent color space
if ((embeddedProfile || isCmyk) && !isLabs)
// If there's some kind of import profile, we can transform to the
// output.
if (hasIccProfile)
{
// Embedded profile; fallback in case the profile embedded in the image
// is broken. No embedded profile; import using default CMYK profile.
importProfile = isCmyk ? "cmyk" : "srgb";
// Fallback to sRGB.
importProfile = "srgb";

// Convert to sRGB using embedded or import profile.
exportProfile = "srgb";

// Use "perceptual" intent to better match imagemagick.
// Use "perceptual" intent to better match *magick.
intent = Enums.Intent.Perceptual;
}

Expand Down Expand Up @@ -209,7 +205,7 @@ public void Execute(string[] args)
// shrink-on-load tricks are possible. This can make thumbnailing of large
// images extremely slow.
using var thumb = Image.ThumbnailBuffer(buffer, thumbnailWidth, stringOptions, thumbnailHeight, size,
false, importProfile: importProfile, exportProfile: exportProfile, intent: intent);
importProfile: importProfile, exportProfile: exportProfile, intent: intent);

thumb.WriteToFile("thumbnail.webp", new VOption
{
Expand Down

0 comments on commit d471e33

Please sign in to comment.