Skip to content

Commit

Permalink
Adjust FreeImage methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Jklawreszuk committed Jun 11, 2024
1 parent 6cde552 commit 3d6c94d
Showing 1 changed file with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ internal static extern FIBITMAP AllocateExT(FREE_IMAGE_TYPE type, int width, int
/// <param name="flags">Flags to enable or disable plugin-features.</param>
/// <returns>Handle to a FreeImage bitmap.</returns>
[DllImport(FreeImageLibrary, CharSet = CharSet.Auto, EntryPoint = "FreeImage_Load")]
public static extern FIBITMAP Load(FREE_IMAGE_FORMAT fif, string filename, FREE_IMAGE_LOAD_FLAGS flags);
private static extern FIBITMAP LoadNU(FREE_IMAGE_FORMAT fif, string filename, FREE_IMAGE_LOAD_FLAGS flags);

/// <summary>
/// Decodes a bitmap, allocates memory for it and returns it as a FIBITMAP.
Expand All @@ -316,6 +316,11 @@ internal static extern FIBITMAP AllocateExT(FREE_IMAGE_TYPE type, int width, int
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_LoadU")]
private static extern FIBITMAP LoadU(FREE_IMAGE_FORMAT fif, string filename, FREE_IMAGE_LOAD_FLAGS flags);

public static FIBITMAP Load(FREE_IMAGE_FORMAT fif, string filename, FREE_IMAGE_LOAD_FLAGS flags)
{
return OperatingSystem.IsWindows() ? LoadU(fif, filename, flags) : LoadNU(fif, filename, flags);
}

/// <summary>
/// Loads a bitmap from an arbitrary source.
/// </summary>
Expand All @@ -336,7 +341,7 @@ internal static extern FIBITMAP AllocateExT(FREE_IMAGE_TYPE type, int width, int
/// <param name="flags">Flags to enable or disable plugin-features.</param>
/// <returns>Returns true on success, false on failure.</returns>
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_SaveU")]
public static extern bool Save(FREE_IMAGE_FORMAT fif, FIBITMAP dib, string filename, FREE_IMAGE_SAVE_FLAGS flags);
private static extern bool SaveNU(FREE_IMAGE_FORMAT fif, FIBITMAP dib, string filename, FREE_IMAGE_SAVE_FLAGS flags);

/// <summary>
/// Saves a previosly loaded FIBITMAP to a file.
Expand All @@ -349,6 +354,11 @@ internal static extern FIBITMAP AllocateExT(FREE_IMAGE_TYPE type, int width, int
/// <returns>Returns true on success, false on failure.</returns>
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_SaveU")]
private static extern bool SaveU(FREE_IMAGE_FORMAT fif, FIBITMAP dib, string filename, FREE_IMAGE_SAVE_FLAGS flags);

public static bool Save(FREE_IMAGE_FORMAT fif, FIBITMAP dib, string filename, FREE_IMAGE_SAVE_FLAGS flags)
{
return OperatingSystem.IsWindows() ? SaveU(fif, dib, filename, flags) : SaveNU(fif, dib, filename, flags);
}

/// <summary>
/// Saves a bitmap to an arbitrary source.
Expand Down Expand Up @@ -597,7 +607,7 @@ public static extern FREE_IMAGE_FORMAT RegisterExternalPlugin(string path,
/// <param name="filename">The filename or -extension.</param>
/// <returns>The <see cref="FREE_IMAGE_FORMAT"/> of the plugin.</returns>
[DllImport(FreeImageLibrary, CharSet = CharSet.Auto, EntryPoint = "FreeImage_GetFIFFromFilename")]
public static extern FREE_IMAGE_FORMAT GetFIFFromFilename(string filename);
private static extern FREE_IMAGE_FORMAT GetFIFFromFilenameNU(string filename);

/// <summary>
/// This function takes a filename or a file-extension and returns the plugin that can
Expand All @@ -609,6 +619,11 @@ public static extern FREE_IMAGE_FORMAT RegisterExternalPlugin(string path,
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFIFFromFilenameU")]
public static extern FREE_IMAGE_FORMAT GetFIFFromFilenameU(string filename);

public static FREE_IMAGE_FORMAT GetFIFFromFilename(string filename)
{
return OperatingSystem.IsWindows() ? GetFIFFromFilenameU(filename) : GetFIFFromFilenameNU(filename);
}

/// <summary>
/// Checks if a plugin can load bitmaps.
/// </summary>
Expand Down Expand Up @@ -786,7 +801,7 @@ public static extern FIMULTIBITMAP OpenMultiBitmapFromHandle(FREE_IMAGE_FORMAT f
/// <param name="size">Reserved parameter - use 0.</param>
/// <returns>Type of the bitmap.</returns>
[DllImport(FreeImageLibrary, CharSet = CharSet.Auto, EntryPoint = "FreeImage_GetFileType")]
public static extern FREE_IMAGE_FORMAT GetFileType(string filename, int size);
private static extern FREE_IMAGE_FORMAT GetFileTypeNU(string filename, int size);


/// <summary>
Expand All @@ -799,6 +814,11 @@ public static extern FIMULTIBITMAP OpenMultiBitmapFromHandle(FREE_IMAGE_FORMAT f
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFileTypeU")]
public static extern FREE_IMAGE_FORMAT GetFileTypeU(string filename, int size);

public static FREE_IMAGE_FORMAT GetFileType(string filename, int size)
{
return OperatingSystem.IsWindows() ? GetFIFFromFilenameU(filename) : GetFIFFromFilenameNU(filename);
}

/// <summary>
/// Uses the <see cref="FreeImageIO"/> structure as described in the topic bitmap management functions
/// to identify a bitmap type.
Expand Down

0 comments on commit 3d6c94d

Please sign in to comment.