// ==========================================================
// FreeImage 3 .NET wrapper
// Original FreeImage 3 functions and .NET compatible derived functions
//
// Design and implementation by
// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net)
// - Carsten Klein (cklein05@users.sourceforge.net)
//
// Contributors:
// - David Boland (davidboland@vodafone.ie)
//
// Main reference : MSDN Knowlede Base
//
// This file is part of FreeImage 3
//
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
// THIS DISCLAIMER.
//
// Use at your own risk!
// ==========================================================
// ==========================================================
// CVS
// $Revision: 1.9 $
// $Date: 2009/09/15 11:41:37 $
// $Id: FreeImageStaticImports.cs,v 1.9 2009/09/15 11:41:37 cklein05 Exp $
// ==========================================================
using System;
using System.Runtime.InteropServices;
using FreeImageAPI.Plugins;
using FreeImageAPI.IO;
namespace FreeImageAPI
{
public static partial class FreeImage
{
#region Constants
///
/// Filename of the FreeImage library.
///
private const string FreeImageLibrary = "FreeImage";
///
/// Number of bytes to shift left within a 4 byte block.
///
public const int FI_RGBA_RED = 2;
///
/// Number of bytes to shift left within a 4 byte block.
///
public const int FI_RGBA_GREEN = 1;
///
/// Number of bytes to shift left within a 4 byte block.
///
public const int FI_RGBA_BLUE = 0;
///
/// Number of bytes to shift left within a 4 byte block.
///
public const int FI_RGBA_ALPHA = 3;
///
/// Mask indicating the position of the given color.
///
public const uint FI_RGBA_RED_MASK = 0x00FF0000;
///
/// Mask indicating the position of the given color.
///
public const uint FI_RGBA_GREEN_MASK = 0x0000FF00;
///
/// Mask indicating the position of the given color.
///
public const uint FI_RGBA_BLUE_MASK = 0x000000FF;
///
/// Mask indicating the position of the given color.
///
public const uint FI_RGBA_ALPHA_MASK = 0xFF000000;
///
/// Number of bits to shift left within a 32 bit block.
///
public const int FI_RGBA_RED_SHIFT = 16;
///
/// Number of bits to shift left within a 32 bit block.
///
public const int FI_RGBA_GREEN_SHIFT = 8;
///
/// Number of bits to shift left within a 32 bit block.
///
public const int FI_RGBA_BLUE_SHIFT = 0;
///
/// Number of bits to shift left within a 32 bit block.
///
public const int FI_RGBA_ALPHA_SHIFT = 24;
///
/// Mask indicating the position of color components of a 32 bit color.
///
public const uint FI_RGBA_RGB_MASK = (FI_RGBA_RED_MASK | FI_RGBA_GREEN_MASK | FI_RGBA_BLUE_MASK);
///
/// Mask indicating the position of the given color.
///
public const int FI16_555_RED_MASK = 0x7C00;
///
/// Mask indicating the position of the given color.
///
public const int FI16_555_GREEN_MASK = 0x03E0;
///
/// Mask indicating the position of the given color.
///
public const int FI16_555_BLUE_MASK = 0x001F;
///
/// Number of bits to shift left within a 16 bit block.
///
public const int FI16_555_RED_SHIFT = 10;
///
/// Number of bits to shift left within a 16 bit block.
///
public const int FI16_555_GREEN_SHIFT = 5;
///
/// Number of bits to shift left within a 16 bit block.
///
public const int FI16_555_BLUE_SHIFT = 0;
///
/// Mask indicating the position of the given color.
///
public const int FI16_565_RED_MASK = 0xF800;
///
/// Mask indicating the position of the given color.
///
public const int FI16_565_GREEN_MASK = 0x07E0;
///
/// Mask indicating the position of the given color.
///
public const int FI16_565_BLUE_MASK = 0x001F;
///
/// Number of bits to shift left within a 16 bit block.
///
public const int FI16_565_RED_SHIFT = 11;
///
/// Number of bits to shift left within a 16 bit block.
///
public const int FI16_565_GREEN_SHIFT = 5;
///
/// Number of bits to shift left within a 16 bit block.
///
public const int FI16_565_BLUE_SHIFT = 0;
#endregion
#region General functions
///
/// Initialises the library.
///
///
/// When the is true, FreeImage won't make use of external plugins.
///
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Initialise")]
private static extern void Initialise(bool load_local_plugins_only);
///
/// Deinitialises the library.
///
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_DeInitialise")]
private static extern void DeInitialise();
///
/// Returns a string containing the current version of the library.
///
/// The current version of the library.
public static unsafe string GetVersion() { return PtrToStr(GetVersion_()); }
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetVersion")]
private static unsafe extern byte* GetVersion_();
///
/// Returns a string containing a standard copyright message.
///
/// A standard copyright message.
public static unsafe string GetCopyrightMessage() { return PtrToStr(GetCopyrightMessage_()); }
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetCopyrightMessage")]
private static unsafe extern byte* GetCopyrightMessage_();
///
/// Calls the set error message function in FreeImage.
///
/// Format of the bitmaps.
/// The error message.
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_OutputMessageProc")]
public static extern void OutputMessageProc(FREE_IMAGE_FORMAT fif, string message);
///
/// You use the function FreeImage_SetOutputMessage to capture the log string
/// so that you can show it to the user of the program.
/// The callback is implemented in the event of this class.
///
/// The function is private because FreeImage can only have a single
/// callback function. To use the callback use the
/// event of this class.
/// Handler to the callback function.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetOutputMessage")]
internal static extern void SetOutputMessage(OutputMessageFunction omf);
#endregion
#region Bitmap management functions
///
/// Creates a new bitmap in memory.
///
/// Width of the new bitmap.
/// Height of the new bitmap.
/// Bit depth of the new Bitmap.
/// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap
/// Red part of the color layout.
/// eg: 0xFF0000
/// Green part of the color layout.
/// eg: 0x00FF00
/// Blue part of the color layout.
/// eg: 0x0000FF
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Allocate")]
public static extern FIBITMAP Allocate(int width, int height, int bpp,
uint red_mask, uint green_mask, uint blue_mask);
///
/// Creates a new bitmap in memory.
///
/// Type of the image.
/// Width of the new bitmap.
/// Height of the new bitmap.
/// Bit depth of the new Bitmap.
/// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap
/// Red part of the color layout.
/// eg: 0xFF0000
/// Green part of the color layout.
/// eg: 0x00FF00
/// Blue part of the color layout.
/// eg: 0x0000FF
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AllocateT")]
public static extern FIBITMAP AllocateT(FREE_IMAGE_TYPE type, int width, int height, int bpp,
uint red_mask, uint green_mask, uint blue_mask);
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AllocateEx")]
internal static extern FIBITMAP AllocateEx(int width, int height, int bpp,
IntPtr color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette,
uint red_mask, uint green_mask, uint blue_mask);
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AllocateExT")]
internal static extern FIBITMAP AllocateExT(FREE_IMAGE_TYPE type, int width, int height, int bpp,
IntPtr color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette,
uint red_mask, uint green_mask, uint blue_mask);
///
/// Makes an exact reproduction of an existing bitmap, including metadata and attached profile if any.
///
/// Handle to a FreeImage bitmap.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Clone")]
public static extern FIBITMAP Clone(FIBITMAP dib);
///
/// Deletes a previously loaded FIBITMAP from memory.
///
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Unload")]
public static extern void Unload(FIBITMAP dib);
///
/// Decodes a bitmap, allocates memory for it and returns it as a FIBITMAP.
///
/// Type of the bitmap.
/// Name of the file to decode.
/// Flags to enable or disable plugin-features.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_LoadU")]
public static extern FIBITMAP Load(FREE_IMAGE_FORMAT fif, string filename, FREE_IMAGE_LOAD_FLAGS flags);
///
/// Decodes a bitmap, allocates memory for it and returns it as a FIBITMAP.
/// The filename supports UNICODE.
///
/// Type of the bitmap.
/// Name of the file to decode.
/// Flags to enable or disable plugin-features.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_LoadU")]
private static extern FIBITMAP LoadU(FREE_IMAGE_FORMAT fif, string filename, FREE_IMAGE_LOAD_FLAGS flags);
///
/// Loads a bitmap from an arbitrary source.
///
/// Type of the bitmap.
/// A FreeImageIO structure with functionpointers to handle the source.
/// A handle to the source.
/// Flags to enable or disable plugin-features.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_LoadFromHandle")]
public static extern FIBITMAP LoadFromHandle(FREE_IMAGE_FORMAT fif, ref FreeImageIO io, fi_handle handle, FREE_IMAGE_LOAD_FLAGS flags);
///
/// Saves a previosly loaded FIBITMAP to a file.
///
/// Type of the bitmap.
/// Handle to a FreeImage bitmap.
/// Name of the file to save to.
/// Flags to enable or disable plugin-features.
/// Returns true on success, false on failure.
[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);
///
/// Saves a previosly loaded FIBITMAP to a file.
/// The filename supports UNICODE.
///
/// Type of the bitmap.
/// Handle to a FreeImage bitmap.
/// Name of the file to save to.
/// Flags to enable or disable plugin-features.
/// Returns true on success, false on failure.
[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);
///
/// Saves a bitmap to an arbitrary source.
///
/// Type of the bitmap.
/// Handle to a FreeImage bitmap.
/// A FreeImageIO structure with functionpointers to handle the source.
/// A handle to the source.
/// Flags to enable or disable plugin-features.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SaveToHandle")]
public static extern bool SaveToHandle(FREE_IMAGE_FORMAT fif, FIBITMAP dib, ref FreeImageIO io, fi_handle handle,
FREE_IMAGE_SAVE_FLAGS flags);
#endregion
#region Memory I/O streams
///
/// Open a memory stream.
///
/// Pointer to the data in memory.
/// Length of the data in byte.
/// Handle to a memory stream.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_OpenMemory")]
public static extern FIMEMORY OpenMemory(IntPtr data, uint size_in_bytes);
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_OpenMemory")]
internal static extern FIMEMORY OpenMemoryEx(byte[] data, uint size_in_bytes);
///
/// Close and free a memory stream.
///
/// Handle to a memory stream.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CloseMemory")]
public static extern void CloseMemory(FIMEMORY stream);
///
/// Decodes a bitmap from a stream, allocates memory for it and returns it as a FIBITMAP.
///
/// Type of the bitmap.
/// Handle to a memory stream.
/// Flags to enable or disable plugin-features.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_LoadFromMemory")]
public static extern FIBITMAP LoadFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY stream, FREE_IMAGE_LOAD_FLAGS flags);
///
/// Saves a previosly loaded FIBITMAP to a stream.
///
/// Type of the bitmap.
/// Handle to a FreeImage bitmap.
/// Handle to a memory stream.
/// Flags to enable or disable plugin-features.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SaveToMemory")]
public static extern bool SaveToMemory(FREE_IMAGE_FORMAT fif, FIBITMAP dib, FIMEMORY stream, FREE_IMAGE_SAVE_FLAGS flags);
///
/// Gets the current position of a memory handle.
///
/// Handle to a memory stream.
/// The current file position if successful, -1 otherwise.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_TellMemory")]
public static extern int TellMemory(FIMEMORY stream);
///
/// Moves the memory handle to a specified location.
///
/// Handle to a memory stream.
/// Number of bytes from origin.
/// Initial position.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SeekMemory")]
public static extern bool SeekMemory(FIMEMORY stream, int offset, System.IO.SeekOrigin origin);
///
/// Provides a direct buffer access to a memory stream.
///
/// The target memory stream.
/// Pointer to the data in memory.
/// Size of the data in bytes.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AcquireMemory")]
public static extern bool AcquireMemory(FIMEMORY stream, ref IntPtr data, ref uint size_in_bytes);
///
/// Reads data from a memory stream.
///
/// The buffer to store the data in.
/// Size in bytes of the items.
/// Number of items to read.
/// The stream to read from.
/// The memory pointer associated with stream is increased by the number of bytes actually read.
/// The number of full items actually read.
/// May be less than count on error or stream-end.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ReadMemory")]
public static extern uint ReadMemory(byte[] buffer, uint size, uint count, FIMEMORY stream);
///
/// Writes data to a memory stream.
///
/// The buffer to read the data from.
/// Size in bytes of the items.
/// Number of items to write.
/// The stream to write to.
/// The memory pointer associated with stream is increased by the number of bytes actually written.
/// The number of full items actually written.
/// May be less than count on error or stream-end.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_WriteMemory")]
public static extern uint WriteMemory(byte[] buffer, uint size, uint count, FIMEMORY stream);
///
/// Open a multi-page bitmap from a memory stream.
///
/// Type of the bitmap.
/// The stream to decode.
/// Flags to enable or disable plugin-features.
/// Handle to a FreeImage multi-paged bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_LoadMultiBitmapFromMemory")]
public static extern FIMULTIBITMAP LoadMultiBitmapFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY stream, FREE_IMAGE_LOAD_FLAGS flags);
#endregion
#region Plugin functions
///
/// Registers a new plugin to be used in FreeImage.
///
/// Pointer to the function that initialises the plugin.
/// A string describing the format of the plugin.
/// A string describing the plugin.
/// A string witha comma sperated list of extensions. f.e: "pl,pl2,pl4"
/// A regular expression used to identify the bitmap.
/// The format idientifier assigned by FreeImage.
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_RegisterLocalPlugin")]
public static extern FREE_IMAGE_FORMAT RegisterLocalPlugin(InitProc proc_address,
string format, string description, string extension, string regexpr);
///
/// Registers a new plugin to be used in FreeImage. The plugin is residing in a DLL.
/// The Init function must be called “Init” and must use the stdcall calling convention.
///
/// Complete path to the dll file hosting the plugin.
/// A string describing the format of the plugin.
/// A string describing the plugin.
/// A string witha comma sperated list of extensions. f.e: "pl,pl2,pl4"
/// A regular expression used to identify the bitmap.
/// The format idientifier assigned by FreeImage.
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_RegisterExternalPlugin")]
public static extern FREE_IMAGE_FORMAT RegisterExternalPlugin(string path,
string format, string description, string extension, string regexpr);
///
/// Retrieves the number of FREE_IMAGE_FORMAT identifiers being currently registered.
///
/// The number of registered formats.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFCount")]
public static extern int GetFIFCount();
///
/// Enables or disables a plugin.
///
/// The plugin to enable or disable.
/// True: enable the plugin. false: disable the plugin.
/// The previous state of the plugin.
/// 1 - enabled. 0 - disables. -1 plugin does not exist.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetPluginEnabled")]
public static extern int SetPluginEnabled(FREE_IMAGE_FORMAT fif, bool enable);
///
/// Retrieves the state of a plugin.
///
/// The plugin to check.
/// 1 - enabled. 0 - disables. -1 plugin does not exist.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_IsPluginEnabled")]
public static extern int IsPluginEnabled(FREE_IMAGE_FORMAT fif);
///
/// Returns a identifier from the format string that was used to register the FIF.
///
/// The string that was used to register the plugin.
/// A identifier from the format.
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetFIFFromFormat")]
public static extern FREE_IMAGE_FORMAT GetFIFFromFormat(string format);
///
/// Returns a identifier from a MIME content type string
/// (MIME stands for Multipurpose Internet Mail Extension).
///
/// A MIME content type.
/// A identifier from the MIME.
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetFIFFromMime")]
public static extern FREE_IMAGE_FORMAT GetFIFFromMime(string mime);
///
/// Returns the string that was used to register a plugin from the system assigned .
///
/// The assigned .
/// The string that was used to register the plugin.
public static unsafe string GetFormatFromFIF(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFormatFromFIF_(fif)); }
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFormatFromFIF")]
private static unsafe extern byte* GetFormatFromFIF_(FREE_IMAGE_FORMAT fif);
///
/// Returns a comma-delimited file extension list describing the bitmap formats the given plugin can read and/or write.
///
/// The desired .
/// A comma-delimited file extension list.
public static unsafe string GetFIFExtensionList(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFIFExtensionList_(fif)); }
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFExtensionList")]
private static unsafe extern byte* GetFIFExtensionList_(FREE_IMAGE_FORMAT fif);
///
/// Returns a descriptive string that describes the bitmap formats the given plugin can read and/or write.
///
/// The desired .
/// A descriptive string that describes the bitmap formats.
public static unsafe string GetFIFDescription(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFIFDescription_(fif)); }
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFDescription")]
private static unsafe extern byte* GetFIFDescription_(FREE_IMAGE_FORMAT fif);
///
/// Returns a regular expression string that can be used by a regular expression engine to identify the bitmap.
/// FreeImageQt makes use of this function.
///
/// The desired .
/// A regular expression string.
public static unsafe string GetFIFRegExpr(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFIFRegExpr_(fif)); }
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFRegExpr")]
private static unsafe extern byte* GetFIFRegExpr_(FREE_IMAGE_FORMAT fif);
///
/// Given a identifier, returns a MIME content type string (MIME stands for Multipurpose Internet Mail Extension).
///
/// The desired .
/// A MIME content type string.
public static unsafe string GetFIFMimeType(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFIFMimeType_(fif)); }
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFMimeType")]
private static unsafe extern byte* GetFIFMimeType_(FREE_IMAGE_FORMAT fif);
///
/// This function takes a filename or a file-extension and returns the plugin that can
/// read/write files with that extension in the form of a identifier.
///
/// The filename or -extension.
/// The of the plugin.
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFIFFromFilenameU")]
public static extern FREE_IMAGE_FORMAT GetFIFFromFilename(string filename);
///
/// This function takes a filename or a file-extension and returns the plugin that can
/// read/write files with that extension in the form of a identifier.
/// Supports UNICODE filenames.
///
/// The filename or -extension.
/// The of the plugin.
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFIFFromFilenameU")]
private static extern FREE_IMAGE_FORMAT GetFIFFromFilenameU(string filename);
///
/// Checks if a plugin can load bitmaps.
///
/// The of the plugin.
/// True if the plugin can load bitmaps, else false.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsReading")]
public static extern bool FIFSupportsReading(FREE_IMAGE_FORMAT fif);
///
/// Checks if a plugin can save bitmaps.
///
/// The of the plugin.
/// True if the plugin can save bitmaps, else false.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsWriting")]
public static extern bool FIFSupportsWriting(FREE_IMAGE_FORMAT fif);
///
/// Checks if a plugin can save bitmaps in the desired bit depth.
///
/// The of the plugin.
/// The desired bit depth.
/// True if the plugin can save bitmaps in the desired bit depth, else false.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsExportBPP")]
public static extern bool FIFSupportsExportBPP(FREE_IMAGE_FORMAT fif, int bpp);
///
/// Checks if a plugin can save a bitmap in the desired data type.
///
/// The of the plugin.
/// The desired image type.
/// True if the plugin can save bitmaps as the desired type, else false.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsExportType")]
public static extern bool FIFSupportsExportType(FREE_IMAGE_FORMAT fif, FREE_IMAGE_TYPE type);
///
/// Checks if a plugin can load or save an ICC profile.
///
/// The of the plugin.
/// True if the plugin can load or save an ICC profile, else false.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsICCProfiles")]
public static extern bool FIFSupportsICCProfiles(FREE_IMAGE_FORMAT fif);
#endregion
#region Multipage functions
///
/// Loads a FreeImage multi-paged bitmap.
/// Load flags can be provided by the flags parameter.
///
/// Format of the image.
/// The complete name of the file to load.
/// When true a new bitmap is created.
/// When true the bitmap will be loaded read only.
/// When true performance is increased at the cost of memory.
/// Flags to enable or disable plugin-features.
/// Handle to a FreeImage multi-paged bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_OpenMultiBitmap")]
public static extern FIMULTIBITMAP OpenMultiBitmap(FREE_IMAGE_FORMAT fif, string filename, bool create_new,
bool read_only, bool keep_cache_in_memory, FREE_IMAGE_LOAD_FLAGS flags);
///
/// Loads a FreeImage multi-pages bitmap from the specified handle
/// using the specified functions.
/// Load flags can be provided by the flags parameter.
///
/// Format of the image.
/// IO functions used to read from the specified handle.
/// The handle to load the bitmap from.
/// Flags to enable or disable plugin-features.
/// Handle to a FreeImage multi-paged bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_OpenMultiBitmapFromHandle")]
public static extern FIMULTIBITMAP OpenMultiBitmapFromHandle(FREE_IMAGE_FORMAT fif, ref FreeImageIO io,
fi_handle handle, FREE_IMAGE_LOAD_FLAGS flags);
///
/// Closes a previously opened multi-page bitmap and, when the bitmap was not opened read-only, applies any changes made to it.
///
/// Handle to a FreeImage multi-paged bitmap.
/// Flags to enable or disable plugin-features.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CloseMultiBitmap")]
private static extern bool CloseMultiBitmap_(FIMULTIBITMAP bitmap, FREE_IMAGE_SAVE_FLAGS flags);
///
/// Returns the number of pages currently available in the multi-paged bitmap.
///
/// Handle to a FreeImage multi-paged bitmap.
/// Number of pages.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPageCount")]
public static extern int GetPageCount(FIMULTIBITMAP bitmap);
///
/// Appends a new page to the end of the bitmap.
///
/// Handle to a FreeImage multi-paged bitmap.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AppendPage")]
public static extern void AppendPage(FIMULTIBITMAP bitmap, FIBITMAP data);
///
/// Inserts a new page before the given position in the bitmap.
///
/// Handle to a FreeImage multi-paged bitmap.
/// Page has to be a number smaller than the current number of pages available in the bitmap.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_InsertPage")]
public static extern void InsertPage(FIMULTIBITMAP bitmap, int page, FIBITMAP data);
///
/// Deletes the page on the given position.
///
/// Handle to a FreeImage multi-paged bitmap.
/// Number of the page to delete.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_DeletePage")]
public static extern void DeletePage(FIMULTIBITMAP bitmap, int page);
///
/// Locks a page in memory for editing.
///
/// Handle to a FreeImage multi-paged bitmap.
/// Number of the page to lock.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_LockPage")]
public static extern FIBITMAP LockPage(FIMULTIBITMAP bitmap, int page);
///
/// Unlocks a previously locked page and gives it back to the multi-page engine.
///
/// Handle to a FreeImage multi-paged bitmap.
/// Handle to a FreeImage bitmap.
/// If true, the page is applied to the multi-page bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_UnlockPage")]
public static extern void UnlockPage(FIMULTIBITMAP bitmap, FIBITMAP data, bool changed);
///
/// Moves the source page to the position of the target page.
///
/// Handle to a FreeImage multi-paged bitmap.
/// New position of the page.
/// Old position of the page.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_MovePage")]
public static extern bool MovePage(FIMULTIBITMAP bitmap, int target, int source);
///
/// Returns an array of page-numbers that are currently locked in memory.
/// When the pages parameter is null, the size of the array is returned in the count variable.
///
///
///
/// int[] lockedPages = null;
/// int count = 0;
/// GetLockedPageNumbers(dib, lockedPages, ref count);
/// lockedPages = new int[count];
/// GetLockedPageNumbers(dib, lockedPages, ref count);
///
///
/// Handle to a FreeImage multi-paged bitmap.
/// The list of locked pages in the multi-pages bitmap.
/// If set to null, count will contain the number of pages.
/// If is set to null count will contain the number of locked pages.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetLockedPageNumbers")]
public static extern bool GetLockedPageNumbers(FIMULTIBITMAP bitmap, int[] pages, ref int count);
#endregion
#region Filetype functions
///
/// Orders FreeImage to analyze the bitmap signature.
///
/// Name of the file to analyze.
/// Reserved parameter - use 0.
/// Type of the bitmap.
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFileTypeU")]
public static extern FREE_IMAGE_FORMAT GetFileType(string filename, int size);
///
/// Orders FreeImage to analyze the bitmap signature.
/// Supports UNICODE filenames.
///
/// Name of the file to analyze.
/// Reserved parameter - use 0.
/// Type of the bitmap.
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFileTypeU")]
private static extern FREE_IMAGE_FORMAT GetFileTypeU(string filename, int size);
///
/// Uses the structure as described in the topic bitmap management functions
/// to identify a bitmap type.
///
/// A structure with functionpointers to handle the source.
/// A handle to the source.
/// Size in bytes of the source.
/// Type of the bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFileTypeFromHandle")]
public static extern FREE_IMAGE_FORMAT GetFileTypeFromHandle(ref FreeImageIO io, fi_handle handle, int size);
///
/// Uses a memory handle to identify a bitmap type.
///
/// Pointer to the stream.
/// Size in bytes of the source.
/// Type of the bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFileTypeFromMemory")]
public static extern FREE_IMAGE_FORMAT GetFileTypeFromMemory(FIMEMORY stream, int size);
#endregion
#region Helper functions
///
/// Returns whether the platform is using Little Endian.
///
/// Returns true if the platform is using Litte Endian, else false.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_IsLittleEndian")]
public static extern bool IsLittleEndian();
///
/// Converts a X11 color name into a corresponding RGB value.
///
/// Name of the color to convert.
/// Red component.
/// Green component.
/// Blue component.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_LookupX11Color")]
public static extern bool LookupX11Color(string szColor, out byte nRed, out byte nGreen, out byte nBlue);
///
/// Converts a SVG color name into a corresponding RGB value.
///
/// Name of the color to convert.
/// Red component.
/// Green component.
/// Blue component.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_LookupSVGColor")]
public static extern bool LookupSVGColor(string szColor, out byte nRed, out byte nGreen, out byte nBlue);
#endregion
#region Pixel access functions
///
/// Returns a pointer to the data-bits of the bitmap.
///
/// Handle to a FreeImage bitmap.
/// Pointer to the data-bits.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetBits")]
public static extern IntPtr GetBits(FIBITMAP dib);
///
/// Returns a pointer to the start of the given scanline in the bitmap's data-bits.
///
/// Handle to a FreeImage bitmap.
/// Number of the scanline.
/// Pointer to the scanline.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetScanLine")]
public static extern IntPtr GetScanLine(FIBITMAP dib, int scanline);
///
/// Get the pixel index of a palettized image at position (x, y), including range check (slow access).
///
/// Handle to a FreeImage bitmap.
/// Pixel position in horizontal direction.
/// Pixel position in vertical direction.
/// The pixel index.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPixelIndex")]
public static extern bool GetPixelIndex(FIBITMAP dib, uint x, uint y, out byte value);
///
/// Get the pixel color of a 16-, 24- or 32-bit image at position (x, y), including range check (slow access).
///
/// Handle to a FreeImage bitmap.
/// Pixel position in horizontal direction.
/// Pixel position in vertical direction.
/// The pixel color.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPixelColor")]
public static extern bool GetPixelColor(FIBITMAP dib, uint x, uint y, out RGBQUAD value);
///
/// Set the pixel index of a palettized image at position (x, y), including range check (slow access).
///
/// Handle to a FreeImage bitmap.
/// Pixel position in horizontal direction.
/// Pixel position in vertical direction.
/// The new pixel index.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetPixelIndex")]
public static extern bool SetPixelIndex(FIBITMAP dib, uint x, uint y, ref byte value);
///
/// Set the pixel color of a 16-, 24- or 32-bit image at position (x, y), including range check (slow access).
///
/// Handle to a FreeImage bitmap.
/// Pixel position in horizontal direction.
/// Pixel position in vertical direction.
/// The new pixel color.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetPixelColor")]
public static extern bool SetPixelColor(FIBITMAP dib, uint x, uint y, ref RGBQUAD value);
#endregion
#region Bitmap information functions
///
/// Retrieves the type of the bitmap.
///
/// Handle to a FreeImage bitmap.
/// Type of the bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetImageType")]
public static extern FREE_IMAGE_TYPE GetImageType(FIBITMAP dib);
///
/// Returns the number of colors used in a bitmap.
///
/// Handle to a FreeImage bitmap.
/// Palette-size for palletised bitmaps, and 0 for high-colour bitmaps.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetColorsUsed")]
public static extern uint GetColorsUsed(FIBITMAP dib);
///
/// Returns the size of one pixel in the bitmap in bits.
///
/// Handle to a FreeImage bitmap.
/// Size of one pixel in the bitmap in bits.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetBPP")]
public static extern uint GetBPP(FIBITMAP dib);
///
/// Returns the width of the bitmap in pixel units.
///
/// Handle to a FreeImage bitmap.
/// With of the bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetWidth")]
public static extern uint GetWidth(FIBITMAP dib);
///
/// Returns the height of the bitmap in pixel units.
///
/// Handle to a FreeImage bitmap.
/// Height of the bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetHeight")]
public static extern uint GetHeight(FIBITMAP dib);
///
/// Returns the width of the bitmap in bytes.
///
/// Handle to a FreeImage bitmap.
/// With of the bitmap in bytes.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetLine")]
public static extern uint GetLine(FIBITMAP dib);
///
/// Returns the width of the bitmap in bytes, rounded to the next 32-bit boundary,
/// also known as pitch or stride or scan width.
///
/// Handle to a FreeImage bitmap.
/// With of the bitmap in bytes.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPitch")]
public static extern uint GetPitch(FIBITMAP dib);
///
/// Returns the size of the DIB-element of a FIBITMAP in memory.
///
/// Handle to a FreeImage bitmap.
/// Size of the DIB-element
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetDIBSize")]
public static extern uint GetDIBSize(FIBITMAP dib);
///
/// Returns a pointer to the bitmap's palette.
///
/// Handle to a FreeImage bitmap.
/// Pointer to the bitmap's palette.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPalette")]
public static extern IntPtr GetPalette(FIBITMAP dib);
///
/// Returns the horizontal resolution, in pixels-per-meter, of the target device for the bitmap.
///
/// Handle to a FreeImage bitmap.
/// The horizontal resolution, in pixels-per-meter.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetDotsPerMeterX")]
public static extern uint GetDotsPerMeterX(FIBITMAP dib);
///
/// Returns the vertical resolution, in pixels-per-meter, of the target device for the bitmap.
///
/// Handle to a FreeImage bitmap.
/// The vertical resolution, in pixels-per-meter.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetDotsPerMeterY")]
public static extern uint GetDotsPerMeterY(FIBITMAP dib);
///
/// Set the horizontal resolution, in pixels-per-meter, of the target device for the bitmap.
///
/// Handle to a FreeImage bitmap.
/// The new horizontal resolution.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetDotsPerMeterX")]
public static extern void SetDotsPerMeterX(FIBITMAP dib, uint res);
///
/// Set the vertical resolution, in pixels-per-meter, of the target device for the bitmap.
///
/// Handle to a FreeImage bitmap.
/// The new vertical resolution.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetDotsPerMeterY")]
public static extern void SetDotsPerMeterY(FIBITMAP dib, uint res);
///
/// Returns a pointer to the of the DIB-element in a FIBITMAP.
///
/// Handle to a FreeImage bitmap.
/// Poiter to the header of the bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetInfoHeader")]
public static extern IntPtr GetInfoHeader(FIBITMAP dib);
///
/// Alias for FreeImage_GetInfoHeader that returns a pointer to a
/// rather than to a .
///
/// Handle to a FreeImage bitmap.
/// Pointer to the structure for the bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetInfo")]
public static extern IntPtr GetInfo(FIBITMAP dib);
///
/// Investigates the color type of the bitmap by reading the bitmap's pixel bits and analysing them.
///
/// Handle to a FreeImage bitmap.
/// The color type of the bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetColorType")]
public static extern FREE_IMAGE_COLOR_TYPE GetColorType(FIBITMAP dib);
///
/// Returns a bit pattern describing the red color component of a pixel in a FreeImage bitmap.
///
/// Handle to a FreeImage bitmap.
/// The bit pattern for RED.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetRedMask")]
public static extern uint GetRedMask(FIBITMAP dib);
///
/// Returns a bit pattern describing the green color component of a pixel in a FreeImage bitmap.
///
/// Handle to a FreeImage bitmap.
/// The bit pattern for green.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetGreenMask")]
public static extern uint GetGreenMask(FIBITMAP dib);
///
/// Returns a bit pattern describing the blue color component of a pixel in a FreeImage bitmap.
///
/// Handle to a FreeImage bitmap.
/// The bit pattern for blue.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetBlueMask")]
public static extern uint GetBlueMask(FIBITMAP dib);
///
/// Returns the number of transparent colors in a palletised bitmap.
///
/// Handle to a FreeImage bitmap.
/// The number of transparent colors in a palletised bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTransparencyCount")]
public static extern uint GetTransparencyCount(FIBITMAP dib);
///
/// Returns a pointer to the bitmap's transparency table.
///
/// Handle to a FreeImage bitmap.
/// Pointer to the bitmap's transparency table.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTransparencyTable")]
public static extern IntPtr GetTransparencyTable(FIBITMAP dib);
///
/// Tells FreeImage if it should make use of the transparency table
/// or the alpha channel that may accompany a bitmap.
///
/// Handle to a FreeImage bitmap.
/// True to enable the transparency, false to disable.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTransparent")]
public static extern void SetTransparent(FIBITMAP dib, bool enabled);
///
/// Set the bitmap's transparency table. Only affects palletised bitmaps.
///
/// Handle to a FreeImage bitmap.
/// Pointer to the bitmap's new transparency table.
/// The number of transparent colors in the new transparency table.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTransparencyTable")]
internal static extern void SetTransparencyTable(FIBITMAP dib, byte[] table, int count);
///
/// Returns whether the transparency table is enabled.
///
/// Handle to a FreeImage bitmap.
/// Returns true when the transparency table is enabled (1-, 4- or 8-bit images)
/// or when the input dib contains alpha values (32-bit images). Returns false otherwise.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_IsTransparent")]
public static extern bool IsTransparent(FIBITMAP dib);
///
/// Returns whether the bitmap has a file background color.
///
/// Handle to a FreeImage bitmap.
/// Returns true when the image has a file background color, false otherwise.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_HasBackgroundColor")]
public static extern bool HasBackgroundColor(FIBITMAP dib);
///
/// Returns the file background color of an image.
/// For 8-bit images, the color index in the palette is returned in the
/// rgbReserved member of the bkcolor parameter.
///
/// Handle to a FreeImage bitmap.
/// The background color.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetBackgroundColor")]
public static extern bool GetBackgroundColor(FIBITMAP dib, out RGBQUAD bkcolor);
///
/// Set the file background color of an image.
/// When saving an image to PNG, this background color is transparently saved to the PNG file.
///
/// Handle to a FreeImage bitmap.
/// The new background color.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetBackgroundColor")]
public static unsafe extern bool SetBackgroundColor(FIBITMAP dib, ref RGBQUAD bkcolor);
///
/// Set the file background color of an image.
/// When saving an image to PNG, this background color is transparently saved to the PNG file.
/// When the bkcolor parameter is null, the background color is removed from the image.
///
/// This overloaded version of the function with an array parameter is provided to allow
/// passing null in the parameter. This is similar to the
/// original C/C++ function. Passing null as parameter will
/// unset the dib's previously set background color.
///
///
/// Handle to a FreeImage bitmap.
/// The new background color.
/// The first entry in the array is used.
/// Returns true on success, false on failure.
///
///
/// // create a RGBQUAD color
/// RGBQUAD color = new RGBQUAD(Color.Green);
///
/// // set the dib's background color (using the other version of the function)
/// FreeImage.SetBackgroundColor(dib, ref color);
///
/// // remove it again (this only works due to the array parameter RGBQUAD[])
/// FreeImage.SetBackgroundColor(dib, null);
///
///
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetBackgroundColor")]
public static unsafe extern bool SetBackgroundColor(FIBITMAP dib, RGBQUAD[] bkcolor);
///
/// Sets the index of the palette entry to be used as transparent color
/// for the image specified. Does nothing on high color images.
///
/// Handle to a FreeImage bitmap.
/// The index of the palette entry to be set as transparent color.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTransparentIndex")]
public static extern void SetTransparentIndex(FIBITMAP dib, int index);
///
/// Returns the palette entry used as transparent color for the image specified.
/// Works for palletised images only and returns -1 for high color
/// images or if the image has no color set to be transparent.
///
/// Handle to a FreeImage bitmap.
/// the index of the palette entry used as transparent color for
/// the image specified or -1 if there is no transparent color found
/// (e.g. the image is a high color image).
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTransparentIndex")]
public static extern int GetTransparentIndex(FIBITMAP dib);
#endregion
#region ICC profile functions
///
/// Retrieves the data of the bitmap.
/// This function can also be called safely, when the original format does not support profiles.
///
/// Handle to a FreeImage bitmap.
/// The data of the bitmap.
public static FIICCPROFILE GetICCProfileEx(FIBITMAP dib) { unsafe { return *(FIICCPROFILE*)FreeImage.GetICCProfile(dib); } }
///
/// Retrieves a pointer to the data of the bitmap.
/// This function can also be called safely, when the original format does not support profiles.
///
/// Handle to a FreeImage bitmap.
/// Pointer to the data of the bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetICCProfile")]
public static extern IntPtr GetICCProfile(FIBITMAP dib);
///
/// Creates a new block from ICC profile data previously read from a file
/// or built by a color management system. The profile data is attached to the bitmap.
///
/// Handle to a FreeImage bitmap.
/// Pointer to the new data.
/// Size of the data.
/// Pointer to the created structure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CreateICCProfile")]
public static extern IntPtr CreateICCProfile(FIBITMAP dib, byte[] data, int size);
///
/// This function destroys an previously created by .
/// After this call the bitmap will contain no profile information.
/// This function should be called to ensure that a stored bitmap will not contain any profile information.
///
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_DestroyICCProfile")]
public static extern void DestroyICCProfile(FIBITMAP dib);
#endregion
#region Conversion functions
///
/// Converts a bitmap to 4 bits.
/// If the bitmap was a high-color bitmap (16, 24 or 32-bit) or if it was a
/// monochrome or greyscale bitmap (1 or 8-bit), the end result will be a
/// greyscale bitmap, otherwise (1-bit palletised bitmaps) it will be a palletised bitmap.
///
/// Handle to a FreeImage bitmap.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo4Bits")]
public static extern FIBITMAP ConvertTo4Bits(FIBITMAP dib);
///
/// Converts a bitmap to 8 bits. If the bitmap was a high-color bitmap (16, 24 or 32-bit)
/// or if it was a monochrome or greyscale bitmap (1 or 4-bit), the end result will be a
/// greyscale bitmap, otherwise (1 or 4-bit palletised bitmaps) it will be a palletised bitmap.
///
/// Handle to a FreeImage bitmap.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo8Bits")]
public static extern FIBITMAP ConvertTo8Bits(FIBITMAP dib);
///
/// Converts a bitmap to a 8-bit greyscale image with a linear ramp.
///
/// Handle to a FreeImage bitmap.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToGreyscale")]
public static extern FIBITMAP ConvertToGreyscale(FIBITMAP dib);
///
/// Converts a bitmap to 16 bits, where each pixel has a color pattern of
/// 5 bits red, 5 bits green and 5 bits blue. One bit in each pixel is unused.
///
/// Handle to a FreeImage bitmap.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo16Bits555")]
public static extern FIBITMAP ConvertTo16Bits555(FIBITMAP dib);
///
/// Converts a bitmap to 16 bits, where each pixel has a color pattern of
/// 5 bits red, 6 bits green and 5 bits blue.
///
/// Handle to a FreeImage bitmap.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo16Bits565")]
public static extern FIBITMAP ConvertTo16Bits565(FIBITMAP dib);
///
/// Converts a bitmap to 24 bits. A clone of the input bitmap is returned for 24-bit bitmaps.
///
/// Handle to a FreeImage bitmap.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo24Bits")]
public static extern FIBITMAP ConvertTo24Bits(FIBITMAP dib);
///
/// Converts a bitmap to 32 bits. A clone of the input bitmap is returned for 32-bit bitmaps.
///
/// Handle to a FreeImage bitmap.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo32Bits")]
public static extern FIBITMAP ConvertTo32Bits(FIBITMAP dib);
///
/// Quantizes a high-color 24-bit bitmap to an 8-bit palette color bitmap.
///
/// Handle to a FreeImage bitmap.
/// Specifies the color reduction algorithm to be used.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ColorQuantize")]
public static extern FIBITMAP ColorQuantize(FIBITMAP dib, FREE_IMAGE_QUANTIZE quantize);
///
/// ColorQuantizeEx is an extension to the method that
/// provides additional options used to quantize a 24-bit image to any
/// number of colors (up to 256), as well as quantize a 24-bit image using a
/// partial or full provided palette.
///
/// Handle to a FreeImage bitmap.
/// Specifies the color reduction algorithm to be used.
/// Size of the desired output palette.
/// Size of the provided palette of ReservePalette.
/// The provided palette.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ColorQuantizeEx")]
public static extern FIBITMAP ColorQuantizeEx(FIBITMAP dib, FREE_IMAGE_QUANTIZE quantize, int PaletteSize, int ReserveSize, RGBQUAD[] ReservePalette);
///
/// Converts a bitmap to 1-bit monochrome bitmap using a threshold T between [0..255].
/// The function first converts the bitmap to a 8-bit greyscale bitmap.
/// Then, any brightness level that is less than T is set to zero, otherwise to 1.
/// For 1-bit input bitmaps, the function clones the input bitmap and builds a monochrome palette.
///
/// Handle to a FreeImage bitmap.
/// The threshold.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Threshold")]
public static extern FIBITMAP Threshold(FIBITMAP dib, byte t);
///
/// Converts a bitmap to 1-bit monochrome bitmap using a dithering algorithm.
/// For 1-bit input bitmaps, the function clones the input bitmap and builds a monochrome palette.
///
/// Handle to a FreeImage bitmap.
/// The dithering algorithm to use.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Dither")]
public static extern FIBITMAP Dither(FIBITMAP dib, FREE_IMAGE_DITHER algorithm);
///
/// Converts a raw bitmap to a FreeImage bitmap.
///
/// Pointer to the memory block containing the raw bitmap.
/// The width in pixels of the raw bitmap.
/// The height in pixels of the raw bitmap.
/// Defines the total width of a scanline in the raw bitmap,
/// including padding bytes.
/// The bit depth (bits per pixel) of the raw bitmap.
/// The bit mask describing the bits used to store a single
/// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.
/// The bit mask describing the bits used to store a single
/// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.
/// The bit mask describing the bits used to store a single
/// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.
/// If true, the raw bitmap is stored in top-down order (top-left pixel first)
/// and in bottom-up order (bottom-left pixel first) otherwise.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertFromRawBits")]
public static extern FIBITMAP ConvertFromRawBits(IntPtr bits, int width, int height, int pitch,
uint bpp, uint red_mask, uint green_mask, uint blue_mask, bool topdown);
///
/// Converts a raw bitmap to a FreeImage bitmap.
///
/// Array of bytes containing the raw bitmap.
/// The width in pixels of the raw bitmap.
/// The height in pixels of the raw bitmap.
/// Defines the total width of a scanline in the raw bitmap,
/// including padding bytes.
/// The bit depth (bits per pixel) of the raw bitmap.
/// The bit mask describing the bits used to store a single
/// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.
/// The bit mask describing the bits used to store a single
/// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.
/// The bit mask describing the bits used to store a single
/// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.
/// If true, the raw bitmap is stored in top-down order (top-left pixel first)
/// and in bottom-up order (bottom-left pixel first) otherwise.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertFromRawBits")]
public static extern FIBITMAP ConvertFromRawBits(byte[] bits, int width, int height, int pitch,
uint bpp, uint red_mask, uint green_mask, uint blue_mask, bool topdown);
///
/// Converts a FreeImage bitmap to a raw bitmap, that is a raw piece of memory.
///
/// Pointer to the memory block receiving the raw bitmap.
/// Handle to a FreeImage bitmap.
/// The desired total width in bytes of a scanline in the raw bitmap,
/// including any padding bytes.
/// The desired bit depth (bits per pixel) of the raw bitmap.
/// The desired bit mask describing the bits used to store a single
/// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.
/// The desired bit mask describing the bits used to store a single
/// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.
/// The desired bit mask describing the bits used to store a single
/// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.
/// If true, the raw bitmap will be stored in top-down order (top-left pixel first)
/// and in bottom-up order (bottom-left pixel first) otherwise.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToRawBits")]
public static extern void ConvertToRawBits(IntPtr bits, FIBITMAP dib, int pitch, uint bpp,
uint red_mask, uint green_mask, uint blue_mask, bool topdown);
///
/// Converts a FreeImage bitmap to a raw bitmap, that is a raw piece of memory.
///
/// Array of bytes receiving the raw bitmap.
/// Handle to a FreeImage bitmap.
/// The desired total width in bytes of a scanline in the raw bitmap,
/// including any padding bytes.
/// The desired bit depth (bits per pixel) of the raw bitmap.
/// The desired bit mask describing the bits used to store a single
/// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.
/// The desired bit mask describing the bits used to store a single
/// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.
/// The desired bit mask describing the bits used to store a single
/// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.
/// If true, the raw bitmap will be stored in top-down order (top-left pixel first)
/// and in bottom-up order (bottom-left pixel first) otherwise.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToRawBits")]
public static extern void ConvertToRawBits(byte[] bits, FIBITMAP dib, int pitch, uint bpp,
uint red_mask, uint green_mask, uint blue_mask, bool topdown);
///
/// Converts a 24- or 32-bit RGB(A) standard image or a 48-bit RGB image to a FIT_RGBF type image.
///
/// Handle to a FreeImage bitmap.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToRGBF")]
public static extern FIBITMAP ConvertToRGBF(FIBITMAP dib);
///
/// Converts a non standard image whose color type is FIC_MINISBLACK
/// to a standard 8-bit greyscale image.
///
/// Handle to a FreeImage bitmap.
/// When true the conversion is done by scaling linearly
/// each pixel value from [min, max] to an integer value between [0..255],
/// where min and max are the minimum and maximum pixel values in the image.
/// When false the conversion is done by rounding each pixel value to an integer between [0..255].
///
/// Rounding is done using the following formula:
///
/// dst_pixel = (BYTE) MIN(255, MAX(0, q)) where int q = int(src_pixel + 0.5);
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToStandardType")]
public static extern FIBITMAP ConvertToStandardType(FIBITMAP src, bool scale_linear);
///
/// Converts an image of any type to type dst_type.
///
/// Handle to a FreeImage bitmap.
/// Destination type.
/// True to scale linear, else false.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToType")]
public static extern FIBITMAP ConvertToType(FIBITMAP src, FREE_IMAGE_TYPE dst_type, bool scale_linear);
#endregion
#region Tone mapping operators
///
/// Converts a High Dynamic Range image (48-bit RGB or 96-bit RGBF) to a 24-bit RGB image, suitable for display.
///
/// Handle to a FreeImage bitmap.
/// The tone mapping operator to be used.
/// Parmeter depending on the used algorithm
/// Parmeter depending on the used algorithm
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ToneMapping")]
public static extern FIBITMAP ToneMapping(FIBITMAP dib, FREE_IMAGE_TMO tmo, double first_param, double second_param);
///
/// Converts a High Dynamic Range image to a 24-bit RGB image using a global
/// operator based on logarithmic compression of luminance values, imitating the human response to light.
///
/// Handle to a FreeImage bitmap.
/// A gamma correction that is applied after the tone mapping.
/// A value of 1 means no correction.
/// Scale factor allowing to adjust the brightness of the output image.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_TmoDrago03")]
public static extern FIBITMAP TmoDrago03(FIBITMAP src, double gamma, double exposure);
///
/// Converts a High Dynamic Range image to a 24-bit RGB image using a global operator inspired
/// by photoreceptor physiology of the human visual system.
///
/// Handle to a FreeImage bitmap.
/// Controls the overall image intensity in the range [-8, 8].
/// Controls the overall image contrast in the range [0.3, 1.0[.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_TmoReinhard05")]
public static extern FIBITMAP TmoReinhard05(FIBITMAP src, double intensity, double contrast);
///
/// Apply the Gradient Domain High Dynamic Range Compression to a RGBF image and convert to 24-bit RGB.
///
/// Handle to a FreeImage bitmap.
/// Color saturation (s parameter in the paper) in [0.4..0.6]
/// Atenuation factor (beta parameter in the paper) in [0.8..0.9]
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_TmoFattal02")]
public static extern FIBITMAP TmoFattal02(FIBITMAP src, double color_saturation, double attenuation);
#endregion
#region Compression functions
///
/// Compresses a source buffer into a target buffer, using the ZLib library.
///
/// Pointer to the target buffer.
/// Size of the target buffer.
/// Must be at least 0.1% larger than source_size plus 12 bytes.
/// Pointer to the source buffer.
/// Size of the source buffer.
/// The actual size of the compressed buffer, or 0 if an error occurred.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibCompress")]
public static extern uint ZLibCompress(byte[] target, uint target_size, byte[] source, uint source_size);
///
/// Decompresses a source buffer into a target buffer, using the ZLib library.
///
/// Pointer to the target buffer.
/// Size of the target buffer.
/// Must have been saved outlide of zlib.
/// Pointer to the source buffer.
/// Size of the source buffer.
/// The actual size of the uncompressed buffer, or 0 if an error occurred.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibUncompress")]
public static extern uint ZLibUncompress(byte[] target, uint target_size, byte[] source, uint source_size);
///
/// Compresses a source buffer into a target buffer, using the ZLib library.
///
/// Pointer to the target buffer.
/// Size of the target buffer.
/// Must be at least 0.1% larger than source_size plus 24 bytes.
/// Pointer to the source buffer.
/// Size of the source buffer.
/// The actual size of the compressed buffer, or 0 if an error occurred.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibGZip")]
public static extern uint ZLibGZip(byte[] target, uint target_size, byte[] source, uint source_size);
///
/// Decompresses a source buffer into a target buffer, using the ZLib library.
///
/// Pointer to the target buffer.
/// Size of the target buffer.
/// Must have been saved outlide of zlib.
/// Pointer to the source buffer.
/// Size of the source buffer.
/// The actual size of the uncompressed buffer, or 0 if an error occurred.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibGUnzip")]
public static extern uint ZLibGUnzip(byte[] target, uint target_size, byte[] source, uint source_size);
///
/// Generates a CRC32 checksum.
///
/// The CRC32 checksum to begin with.
/// Pointer to the source buffer.
/// If the value is 0, the function returns the required initial value for the crc.
/// Size of the source buffer.
///
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibCRC32")]
public static extern uint ZLibCRC32(uint crc, byte[] source, uint source_size);
#endregion
#region Tag creation and destruction
///
/// Allocates a new object.
/// This object must be destroyed with a call to
/// when no longer in use.
///
/// The new .
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CreateTag")]
public static extern FITAG CreateTag();
///
/// Delete a previously allocated object.
///
/// The to destroy.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_DeleteTag")]
public static extern void DeleteTag(FITAG tag);
///
/// Creates and returns a copy of a object.
///
/// The to clone.
/// The new .
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CloneTag")]
public static extern FITAG CloneTag(FITAG tag);
#endregion
#region Tag accessors
///
/// Returns the tag field name (unique inside a metadata model).
///
/// The tag field.
/// The field name.
public static unsafe string GetTagKey(FITAG tag) { return PtrToStr(GetTagKey_(tag)); }
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetTagKey")]
private static unsafe extern byte* GetTagKey_(FITAG tag);
///
/// Returns the tag description.
///
/// The tag field.
/// The description or NULL if unavailable.
public static unsafe string GetTagDescription(FITAG tag) { return PtrToStr(GetTagDescription_(tag)); }
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetTagDescription")]
private static unsafe extern byte* GetTagDescription_(FITAG tag);
///
/// Returns the tag ID.
///
/// The tag field.
/// The ID or 0 if unavailable.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagID")]
public static extern ushort GetTagID(FITAG tag);
///
/// Returns the tag data type.
///
/// The tag field.
/// The tag type.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagType")]
public static extern FREE_IMAGE_MDTYPE GetTagType(FITAG tag);
///
/// Returns the number of components in the tag (in tag type units).
///
/// The tag field.
/// The number of components.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagCount")]
public static extern uint GetTagCount(FITAG tag);
///
/// Returns the length of the tag value in bytes.
///
/// The tag field.
/// The length of the tag value.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagLength")]
public static extern uint GetTagLength(FITAG tag);
///
/// Returns the tag value.
/// It is up to the programmer to interpret the returned pointer correctly,
/// according to the results of GetTagType and GetTagCount.
///
/// The tag field.
/// Pointer to the value.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagValue")]
public static extern IntPtr GetTagValue(FITAG tag);
///
/// Sets the tag field name.
///
/// The tag field.
/// The new name.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_SetTagKey")]
public static extern bool SetTagKey(FITAG tag, string key);
///
/// Sets the tag description.
///
/// The tag field.
/// The new description.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_SetTagDescription")]
public static extern bool SetTagDescription(FITAG tag, string description);
///
/// Sets the tag ID.
///
/// The tag field.
/// The new ID.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagID")]
public static extern bool SetTagID(FITAG tag, ushort id);
///
/// Sets the tag data type.
///
/// The tag field.
/// The new type.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagType")]
public static extern bool SetTagType(FITAG tag, FREE_IMAGE_MDTYPE type);
///
/// Sets the number of data in the tag.
///
/// The tag field.
/// New number of data.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagCount")]
public static extern bool SetTagCount(FITAG tag, uint count);
///
/// Sets the length of the tag value in bytes.
///
/// The tag field.
/// The new length.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagLength")]
public static extern bool SetTagLength(FITAG tag, uint length);
///
/// Sets the tag value.
///
/// The tag field.
/// Pointer to the new value.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagValue")]
public static extern bool SetTagValue(FITAG tag, byte[] value);
#endregion
#region Metadata iterator
///
/// Provides information about the first instance of a tag that matches the metadata model.
///
/// The model to match.
/// Handle to a FreeImage bitmap.
/// Tag that matches the metadata model.
/// Unique search handle that can be used to call FindNextMetadata or FindCloseMetadata.
/// Null if the metadata model does not exist.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FindFirstMetadata")]
public static extern FIMETADATA FindFirstMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP dib, out FITAG tag);
///
/// Find the next tag, if any, that matches the metadata model argument in a previous call
/// to FindFirstMetadata, and then alters the tag object contents accordingly.
///
/// Unique search handle provided by FindFirstMetadata.
/// Tag that matches the metadata model.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FindNextMetadata")]
public static extern bool FindNextMetadata(FIMETADATA mdhandle, out FITAG tag);
///
/// Closes the specified metadata search handle and releases associated resources.
///
/// The handle to close.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FindCloseMetadata")]
private static extern void FindCloseMetadata_(FIMETADATA mdhandle);
#endregion
#region Metadata setter and getter
///
/// Retrieve a metadata attached to a dib.
///
/// The metadata model to look for.
/// Handle to a FreeImage bitmap.
/// The metadata field name.
/// A FITAG structure returned by the function.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetMetadata")]
public static extern bool GetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP dib, string key, out FITAG tag);
///
/// Attach a new FreeImage tag to a dib.
///
/// The metadata model used to store the tag.
/// Handle to a FreeImage bitmap.
/// The tag field name.
/// The FreeImage tag to be attached.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_SetMetadata")]
public static extern bool SetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP dib, string key, FITAG tag);
#endregion
#region Metadata helper functions
///
/// Returns the number of tags contained in the model metadata model attached to the input dib.
///
/// The metadata model.
/// Handle to a FreeImage bitmap.
/// Number of tags contained in the metadata model.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetMetadataCount")]
public static extern uint GetMetadataCount(FREE_IMAGE_MDMODEL model, FIBITMAP dib);
///
/// Copies the metadata of FreeImage bitmap to another.
///
/// The FreeImage bitmap to copy the metadata to.
/// The FreeImage bitmap to copy the metadata from.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CloneMetadata")]
public static extern bool CloneMetadata(FIBITMAP dst, FIBITMAP src);
///
/// Converts a FreeImage tag structure to a string that represents the interpreted tag value.
/// The function is not thread safe.
///
/// The metadata model.
/// The interpreted tag value.
/// Reserved.
/// The representing string.
public static unsafe string TagToString(FREE_IMAGE_MDMODEL model, FITAG tag, uint Make) { return PtrToStr(TagToString_(model, tag, Make)); }
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_TagToString")]
private static unsafe extern byte* TagToString_(FREE_IMAGE_MDMODEL model, FITAG tag, uint Make);
#endregion
#region Rotation and flipping
///
/// This function rotates a 1-, 8-bit greyscale or a 24-, 32-bit color image by means of 3 shears.
/// 1-bit images rotation is limited to integer multiple of 90°.
/// null is returned for other values.
///
/// Handle to a FreeImage bitmap.
/// The angle of rotation.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_RotateClassic")]
[Obsolete("RotateClassic is deprecated (use Rotate instead).")]
public static extern FIBITMAP RotateClassic(FIBITMAP dib, double angle);
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Rotate")]
internal static extern FIBITMAP Rotate(FIBITMAP dib, double angle, IntPtr backgroundColor);
///
/// This function performs a rotation and / or translation of an 8-bit greyscale,
/// 24- or 32-bit image, using a 3rd order (cubic) B-Spline.
///
/// Handle to a FreeImage bitmap.
/// The angle of rotation.
/// Horizontal image translation.
/// Vertical image translation.
/// Rotation center x-coordinate.
/// Rotation center y-coordinate.
/// When true the irrelevant part of the image is set to a black color,
/// otherwise, a mirroring technique is used to fill irrelevant pixels.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_RotateEx")]
public static extern FIBITMAP RotateEx(FIBITMAP dib, double angle,
double x_shift, double y_shift, double x_origin, double y_origin, bool use_mask);
///
/// Flip the input dib horizontally along the vertical axis.
///
/// Handle to a FreeImage bitmap.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FlipHorizontal")]
public static extern bool FlipHorizontal(FIBITMAP dib);
///
/// Flip the input dib vertically along the horizontal axis.
///
/// Handle to a FreeImage bitmap.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FlipVertical")]
public static extern bool FlipVertical(FIBITMAP dib);
///
/// Performs a lossless rotation or flipping on a JPEG file.
///
/// Source file.
/// Destination file; can be the source file; will be overwritten.
/// The operation to apply.
/// To avoid lossy transformation, you can set the perfect parameter to true.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_JPEGTransformU")]
public static extern bool JPEGTransform(string src_file, string dst_file,
FREE_IMAGE_JPEG_OPERATION operation, bool perfect);
#endregion
#region Upsampling / downsampling
///
/// Performs resampling (or scaling, zooming) of a greyscale or RGB(A) image
/// to the desired destination width and height.
///
/// Handle to a FreeImage bitmap.
/// Destination width.
/// Destination height.
/// The filter to apply.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Rescale")]
public static extern FIBITMAP Rescale(FIBITMAP dib, int dst_width, int dst_height, FREE_IMAGE_FILTER filter);
///
/// Creates a thumbnail from a greyscale or RGB(A) image, keeping aspect ratio.
///
/// Handle to a FreeImage bitmap.
/// Thumbnail square size.
/// When true HDR images are transperantly converted to standard images.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_MakeThumbnail")]
public static extern FIBITMAP MakeThumbnail(FIBITMAP dib, int max_pixel_size, bool convert);
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_EnlargeCanvas")]
internal static extern FIBITMAP EnlargeCanvas(FIBITMAP dib,
int left, int top, int right, int bottom, IntPtr color, FREE_IMAGE_COLOR_OPTIONS options);
#endregion
#region Color manipulation
///
/// Perfoms an histogram transformation on a 8-, 24- or 32-bit image.
///
/// Handle to a FreeImage bitmap.
/// The lookup table.
/// It's size is assumed to be 256 in length.
/// The color channel to be transformed.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustCurve")]
public static extern bool AdjustCurve(FIBITMAP dib, byte[] lookUpTable, FREE_IMAGE_COLOR_CHANNEL channel);
///
/// Performs gamma correction on a 8-, 24- or 32-bit image.
///
/// Handle to a FreeImage bitmap.
/// The parameter represents the gamma value to use (gamma > 0).
/// A value of 1.0 leaves the image alone, less than one darkens it, and greater than one lightens it.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustGamma")]
public static extern bool AdjustGamma(FIBITMAP dib, double gamma);
///
/// Adjusts the brightness of a 8-, 24- or 32-bit image by a certain amount.
///
/// Handle to a FreeImage bitmap.
/// A value 0 means no change,
/// less than 0 will make the image darker and greater than 0 will make the image brighter.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustBrightness")]
public static extern bool AdjustBrightness(FIBITMAP dib, double percentage);
///
/// Adjusts the contrast of a 8-, 24- or 32-bit image by a certain amount.
///
/// Handle to a FreeImage bitmap.
/// A value 0 means no change,
/// less than 0 will decrease the contrast and greater than 0 will increase the contrast of the image.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustContrast")]
public static extern bool AdjustContrast(FIBITMAP dib, double percentage);
///
/// Inverts each pixel data.
///
/// Handle to a FreeImage bitmap.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Invert")]
public static extern bool Invert(FIBITMAP dib);
///
/// Computes the image histogram.
///
/// Handle to a FreeImage bitmap.
/// Array of integers with a size of 256.
/// Channel to compute from.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetHistogram")]
public static extern bool GetHistogram(FIBITMAP dib, int[] histo, FREE_IMAGE_COLOR_CHANNEL channel);
#endregion
#region Channel processing
///
/// Retrieves the red, green, blue or alpha channel of a 24- or 32-bit image.
///
/// Handle to a FreeImage bitmap.
/// The color channel to extract.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetChannel")]
public static extern FIBITMAP GetChannel(FIBITMAP dib, FREE_IMAGE_COLOR_CHANNEL channel);
///
/// Insert a 8-bit dib into a 24- or 32-bit image.
/// Both images must have to same width and height.
///
/// Handle to a FreeImage bitmap.
/// Handle to the bitmap to insert.
/// The color channel to replace.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetChannel")]
public static extern bool SetChannel(FIBITMAP dib, FIBITMAP dib8, FREE_IMAGE_COLOR_CHANNEL channel);
///
/// Retrieves the real part, imaginary part, magnitude or phase of a complex image.
///
/// Handle to a FreeImage bitmap.
/// The color channel to extract.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetComplexChannel")]
public static extern FIBITMAP GetComplexChannel(FIBITMAP src, FREE_IMAGE_COLOR_CHANNEL channel);
///
/// Set the real or imaginary part of a complex image.
/// Both images must have to same width and height.
///
/// Handle to a FreeImage bitmap.
/// Handle to a FreeImage bitmap.
/// The color channel to replace.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetComplexChannel")]
public static extern bool SetComplexChannel(FIBITMAP dst, FIBITMAP src, FREE_IMAGE_COLOR_CHANNEL channel);
#endregion
#region Copy / Paste / Composite routines
///
/// Copy a sub part of the current dib image.
///
/// Handle to a FreeImage bitmap.
/// Specifies the left position of the cropped rectangle.
/// Specifies the top position of the cropped rectangle.
/// Specifies the right position of the cropped rectangle.
/// Specifies the bottom position of the cropped rectangle.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Copy")]
public static extern FIBITMAP Copy(FIBITMAP dib, int left, int top, int right, int bottom);
///
/// Alpha blend or combine a sub part image with the current dib image.
/// The bit depth of the dst bitmap must be greater than or equal to the bit depth of the src.
///
/// Handle to a FreeImage bitmap.
/// Handle to a FreeImage bitmap.
/// Specifies the left position of the sub image.
/// Specifies the top position of the sub image.
/// alpha blend factor.
/// The source and destination images are alpha blended if alpha=0..255.
/// If alpha > 255, then the source image is combined to the destination image.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Paste")]
public static extern bool Paste(FIBITMAP dst, FIBITMAP src, int left, int top, int alpha);
///
/// This function composite a transparent foreground image against a single background color or
/// against a background image.
///
/// Handle to a FreeImage bitmap.
/// When true the background of fg is used if it contains one.
/// The application background is used if useFileBkg is false.
/// Image used as background when useFileBkg is false or fg has no background
/// and appBkColor is null.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Composite")]
public static extern FIBITMAP Composite(FIBITMAP fg, bool useFileBkg, ref RGBQUAD appBkColor, FIBITMAP bg);
///
/// This function composite a transparent foreground image against a single background color or
/// against a background image.
///
/// Handle to a FreeImage bitmap.
/// When true the background of fg is used if it contains one.
/// The application background is used if useFileBkg is false
/// and 'appBkColor' is not null.
/// Image used as background when useFileBkg is false or fg has no background
/// and appBkColor is null.
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Composite")]
public static extern FIBITMAP Composite(FIBITMAP fg, bool useFileBkg, RGBQUAD[] appBkColor, FIBITMAP bg);
///
/// Performs a lossless crop on a JPEG file.
///
/// Source filename.
/// Destination filename.
/// Specifies the left position of the cropped rectangle.
/// Specifies the top position of the cropped rectangle.
/// Specifies the right position of the cropped rectangle.
/// Specifies the bottom position of the cropped rectangle.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_JPEGCropU")]
public static extern bool JPEGCrop(string src_file, string dst_file, int left, int top, int right, int bottom);
///
/// Applies the alpha value of each pixel to its color components.
/// The aplha value stays unchanged.
/// Only works with 32-bits color depth.
///
/// Handle to a FreeImage bitmap.
/// Returns true on success, false on failure.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_PreMultiplyWithAlpha")]
public static extern bool PreMultiplyWithAlpha(FIBITMAP dib);
#endregion
#region Miscellaneous algorithms
///
/// Solves a Poisson equation, remap result pixels to [0..1] and returns the solution.
///
/// Handle to a FreeImage bitmap.
/// Number of cycles in the multigrid algorithm (usually 2 or 3)
/// Handle to a FreeImage bitmap.
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_MultigridPoissonSolver")]
public static extern FIBITMAP MultigridPoissonSolver(FIBITMAP Laplacian, int ncycle);
#endregion
#region Colors
///
/// Creates a lookup table to be used with which may adjusts brightness and
/// contrast, correct gamma and invert the image with a single call to .
///
/// Output lookup table to be used with .
/// The size of 'lookUpTable' is assumed to be 256.
/// Percentage brightness value where -100 <= brightness <= 100.
/// A value of 0 means no change, less than 0 will make the image darker and greater
/// than 0 will make the image brighter.
/// Percentage contrast value where -100 <= contrast <= 100.
/// A value of 0 means no change, less than 0 will decrease the contrast
/// and greater than 0 will increase the contrast of the image.
/// Gamma value to be used for gamma correction.
/// A value of 1.0 leaves the image alone, less than one darkens it,
/// and greater than one lightens it.
/// If set to true, the image will be inverted.
/// The number of adjustments applied to the resulting lookup table
/// compared to a blind lookup table.
///
/// This function creates a lookup table to be used with which may adjust
/// brightness and contrast, correct gamma and invert the image with a single call to
/// . If more than one of these image display properties need to be adjusted,
/// using a combined lookup table should be preferred over calling each adjustment function
/// separately. That's particularly true for huge images or if performance is an issue. Then,
/// the expensive process of iterating over all pixels of an image is performed only once and
/// not up to four times.
///
/// Furthermore, the lookup table created does not depend on the order, in which each single
/// adjustment operation is performed. Due to rounding and byte casting issues, it actually
/// matters in which order individual adjustment operations are performed. Both of the following
/// snippets most likely produce different results:
///
///
/// // snippet 1: contrast, brightness
/// AdjustContrast(dib, 15.0);
/// AdjustBrightness(dib, 50.0);
///
///
///
/// // snippet 2: brightness, contrast
/// AdjustBrightness(dib, 50.0);
/// AdjustContrast(dib, 15.0);
///
///
/// Better and even faster would be snippet 3:
///
///
/// // snippet 3:
/// byte[] lut = new byte[256];
/// GetAdjustColorsLookupTable(lut, 50.0, 15.0, 1.0, false);
/// AdjustCurve(dib, lut, FREE_IMAGE_COLOR_CHANNEL.FICC_RGB);
///
///
/// This function is also used internally by , which does not return the
/// lookup table, but uses it to call on the passed image.
///
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetAdjustColorsLookupTable")]
public static extern int GetAdjustColorsLookupTable(byte[] lookUpTable, double brightness, double contrast, double gamma, bool invert);
///
/// Adjusts an image's brightness, contrast and gamma as well as it may
/// optionally invert the image within a single operation.
///
/// Handle to a FreeImage bitmap.
/// Percentage brightness value where -100 <= brightness <= 100.
/// A value of 0 means no change, less than 0 will make the image darker and greater
/// than 0 will make the image brighter.
/// Percentage contrast value where -100 <= contrast <= 100.
/// A value of 0 means no change, less than 0 will decrease the contrast
/// and greater than 0 will increase the contrast of the image.
/// Gamma value to be used for gamma correction.
/// A value of 1.0 leaves the image alone, less than one darkens it,
/// and greater than one lightens it.
/// This parameter must not be zero or smaller than zero.
/// If so, it will be ignored and no gamma correction will be performed on the image.
/// If set to true, the image will be inverted.
/// Returns true on success, false on failure.
///
/// This function adjusts an image's brightness, contrast and gamma as well as it
/// may optionally invert the image within a single operation. If more than one of
/// these image display properties need to be adjusted, using this function should
/// be preferred over calling each adjustment function separately. That's particularly
/// true for huge images or if performance is an issue.
///
/// This function relies on ,
/// which creates a single lookup table, that combines all adjustment operations requested.
///
/// Furthermore, the lookup table created by does
/// not depend on the order, in which each single adjustment operation is performed.
/// Due to rounding and byte casting issues, it actually matters in which order individual
/// adjustment operations are performed. Both of the following snippets most likely produce
/// different results:
///
///
/// // snippet 1: contrast, brightness
/// AdjustContrast(dib, 15.0);
/// AdjustBrightness(dib, 50.0);
///
///
///
/// // snippet 2: brightness, contrast
/// AdjustBrightness(dib, 50.0);
/// AdjustContrast(dib, 15.0);
///
///
/// Better and even faster would be snippet 3:
///
///
/// // snippet 3:
/// AdjustColors(dib, 50.0, 15.0, 1.0, false);
///
///
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustColors")]
public static extern bool AdjustColors(FIBITMAP dib, double brightness, double contrast, double gamma, bool invert);
///
/// Applies color mapping for one or several colors on a 1-, 4- or 8-bit
/// palletized or a 16-, 24- or 32-bit high color image.
///
/// Handle to a FreeImage bitmap.
/// Array of colors to be used as the mapping source.
/// Array of colors to be used as the mapping destination.
/// The number of colors to be mapped. This is the size of both
/// srccolors and dstcolors.
/// If true, 32-bit images and colors are treated as 24-bit.
/// If true, source and destination colors are swapped, that is,
/// each destination color is also mapped to the corresponding source color.
/// The total number of pixels changed.
///
/// This function maps up to colors specified in
/// to these specified in .
/// Thereby, color srccolors[N], if found in the image, will be replaced by color
/// dstcolors[N]. If is true, additionally all colors
/// specified in are also mapped to these specified
/// in . For high color images, the actual image data will be
/// modified whereas, for palletized images only the palette will be changed.
///
/// The function returns the number of pixels changed or zero, if no pixels were changed.
///
/// Both arrays and are assumed
/// not to hold less than colors.
///
/// For 16-bit images, all colors specified are transparently converted to their
/// proper 16-bit representation (either in RGB555 or RGB565 format, which is determined
/// by the image's red- green- and blue-mask).
///
/// Note, that this behaviour is different from what does,
/// which modifies the actual image data on palletized images.
///
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ApplyColorMapping")]
public static extern uint ApplyColorMapping(FIBITMAP dib, RGBQUAD[] srccolors, RGBQUAD[] dstcolors, uint count, bool ignore_alpha, bool swap);
///
/// Swaps two specified colors on a 1-, 4- or 8-bit palletized
/// or a 16-, 24- or 32-bit high color image.
///
/// Handle to a FreeImage bitmap.
/// One of the two colors to be swapped.
/// The other of the two colors to be swapped.
/// If true, 32-bit images and colors are treated as 24-bit.
/// The total number of pixels changed.
///
/// This function swaps the two specified colors and
/// on a palletized or high color image.
/// For high color images, the actual image data will be modified whereas, for palletized
/// images only the palette will be changed.
///
/// Note, that this behaviour is different from what does,
/// which modifies the actual image data on palletized images.
///
/// This is just a thin wrapper for and resolves to:
///
///
/// return ApplyColorMapping(dib, color_a, color_b, 1, ignore_alpha, true);
///
///
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SwapColors")]
public static extern uint SwapColors(FIBITMAP dib, ref RGBQUAD color_a, ref RGBQUAD color_b, bool ignore_alpha);
///
/// Applies palette index mapping for one or several indices
/// on a 1-, 4- or 8-bit palletized image.
///
/// Handle to a FreeImage bitmap.
/// Array of palette indices to be used as the mapping source.
/// Array of palette indices to be used as the mapping destination.
/// The number of palette indices to be mapped. This is the size of both
/// srcindices and dstindices
/// If true, source and destination palette indices are swapped, that is,
/// each destination index is also mapped to the corresponding source index.
/// The total number of pixels changed.
///
/// This function maps up to palette indices specified in
/// to these specified in .
/// Thereby, index srcindices[N], if present in the image, will be replaced by index
/// dstindices[N]. If is true, additionally all indices
/// specified in are also mapped to these specified in
/// .
///
/// The function returns the number of pixels changed or zero, if no pixels were changed.
/// Both arrays and are assumed not to
/// hold less than indices.
///
/// Note, that this behaviour is different from what does, which
/// modifies the actual image data on palletized images.
///
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ApplyPaletteIndexMapping")]
public static extern uint ApplyPaletteIndexMapping(FIBITMAP dib, byte[] srcindices, byte[] dstindices, uint count, bool swap);
///
/// Swaps two specified palette indices on a 1-, 4- or 8-bit palletized image.
///
/// Handle to a FreeImage bitmap.
/// One of the two palette indices to be swapped.
/// The other of the two palette indices to be swapped.
/// The total number of pixels changed.
///
/// This function swaps the two specified palette indices index_a and
/// index_b on a palletized image. Therefore, not the palette, but the
/// actual image data will be modified.
///
/// Note, that this behaviour is different from what does on palletized images,
/// which only swaps the colors in the palette.
///
/// This is just a thin wrapper for and resolves to:
///
///
/// return ApplyPaletteIndexMapping(dib, index_a, index_b, 1, true);
///
///
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SwapPaletteIndices")]
public static extern uint SwapPaletteIndices(FIBITMAP dib, ref byte index_a, ref byte index_b);
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FillBackground")]
internal static extern bool FillBackground(FIBITMAP dib, IntPtr color, FREE_IMAGE_COLOR_OPTIONS options);
#endregion
}
}