using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
namespace FreeImageAPI.Plugins
{
///
/// Class representing all registered in FreeImage.
///
public static class PluginRepository
{
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private static readonly List plugins = null;
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private static readonly List localPlugins = null;
static PluginRepository()
{
plugins = new List(FreeImage.GetFIFCount());
localPlugins = new List(0);
for (int i = 0; i < plugins.Capacity; i++)
{
plugins.Add(new FreeImagePlugin((FREE_IMAGE_FORMAT)i));
}
}
///
/// Adds local plugin to this class.
///
/// The registered plugin.
internal static void RegisterLocalPlugin(LocalPlugin localPlugin)
{
FreeImagePlugin plugin = new FreeImagePlugin(localPlugin.Format);
plugins.Add(plugin);
localPlugins.Add(plugin);
}
///
/// Returns an instance of , representing the given format.
///
/// The representing format.
/// An instance of .
public static FreeImagePlugin Plugin(FREE_IMAGE_FORMAT fif)
{
return Plugin((int)fif);
}
///
/// Returns an instance of ,
/// representing the format at the given index.
///
/// The index of the representing format.
/// An instance of .
public static FreeImagePlugin Plugin(int index)
{
return (index >= 0) ? plugins[index] : null;
}
///
/// Returns an instance of .
/// is searched in:
/// Format, RegExpr,
/// ValidExtension and ValidFilename.
///
/// The expression to search for.
/// An instance of .
public static FreeImagePlugin Plugin(string expression)
{
FreeImagePlugin result = null;
expression = expression.ToLower();
foreach (FreeImagePlugin plugin in plugins)
{
if (plugin.Format.ToLower().Contains(expression) ||
plugin.RegExpr.ToLower().Contains(expression) ||
plugin.ValidExtension(expression, StringComparison.CurrentCultureIgnoreCase) ||
plugin.ValidFilename(expression, StringComparison.CurrentCultureIgnoreCase))
{
result = plugin;
break;
}
}
return result;
}
///
/// Returns an instance of for the given format.
///
/// The format of the Plugin.
/// An instance of .
public static FreeImagePlugin PluginFromFormat(string format)
{
return Plugin(FreeImage.GetFIFFromFormat(format));
}
///
/// Returns an instance of for the given filename.
///
/// The valid filename for the plugin.
/// An instance of .
public static FreeImagePlugin PluginFromFilename(string filename)
{
return Plugin(FreeImage.GetFIFFromFilename(filename));
}
///
/// Returns an instance of for the given mime.
///
/// The valid mime for the plugin.
/// An instance of .
public static FreeImagePlugin PluginFromMime(string mime)
{
return Plugin(FreeImage.GetFIFFromMime(mime));
}
///
/// Gets the number of registered plugins.
///
public static int FIFCount
{
get
{
return FreeImage.GetFIFCount();
}
}
///
/// Gets a readonly collection of all plugins.
///
public static ReadOnlyCollection PluginList
{
get
{
return plugins.AsReadOnly();
}
}
///
/// Gets a list of plugins that are only able to
/// read but not to write.
///
public static List ReadOnlyPlugins
{
get
{
List list = new List();
foreach (FreeImagePlugin p in plugins)
{
if (p.SupportsReading && !p.SupportsWriting)
{
list.Add(p);
}
}
return list;
}
}
///
/// Gets a list of plugins that are only able to
/// write but not to read.
///
public static List WriteOnlyPlugins
{
get
{
List list = new List();
foreach (FreeImagePlugin p in plugins)
{
if (!p.SupportsReading && p.SupportsWriting)
{
list.Add(p);
}
}
return list;
}
}
///
/// Gets a list of plugins that are not able to
/// read or write.
///
public static List StupidPlugins
{
get
{
List list = new List();
foreach (FreeImagePlugin p in plugins)
{
if (!p.SupportsReading && !p.SupportsWriting)
{
list.Add(p);
}
}
return list;
}
}
///
/// Gets a list of plugins that are able to read.
///
public static List ReadablePlugins
{
get
{
List list = new List();
foreach (FreeImagePlugin p in plugins)
{
if (p.SupportsReading)
{
list.Add(p);
}
}
return list;
}
}
///
/// Gets a list of plugins that are able to write.
///
public static List WriteablePlugins
{
get
{
List list = new List();
foreach (FreeImagePlugin p in plugins)
{
if (p.SupportsWriting)
{
list.Add(p);
}
}
return list;
}
}
///
/// Gets a list of local plugins.
///
public static ReadOnlyCollection LocalPlugins
{
get
{
return localPlugins.AsReadOnly();
}
}
///
/// Gets a list of built-in plugins.
///
public static List BuiltInPlugins
{
get
{
List list = new List();
foreach (FreeImagePlugin p in plugins)
{
if (!localPlugins.Contains(p))
{
list.Add(p);
}
}
return list;
}
}
///
/// Windows or OS/2 Bitmap File (*.BMP)
///
public static FreeImagePlugin BMP { get { return plugins[0]; } }
///
/// Independent JPEG Group (*.JPG, *.JIF, *.JPEG, *.JPE)
///
public static FreeImagePlugin ICO { get { return plugins[1]; } }
///
/// Independent JPEG Group (*.JPG, *.JIF, *.JPEG, *.JPE)
///
public static FreeImagePlugin JPEG { get { return plugins[2]; } }
///
/// JPEG Network Graphics (*.JNG)
///
public static FreeImagePlugin JNG { get { return plugins[3]; } }
///
/// Commodore 64 Koala format (*.KOA)
///
public static FreeImagePlugin KOALA { get { return plugins[4]; } }
///
/// Amiga IFF (*.IFF, *.LBM)
///
public static FreeImagePlugin LBM { get { return plugins[5]; } }
///
/// Amiga IFF (*.IFF, *.LBM)
///
public static FreeImagePlugin IFF { get { return plugins[5]; } }
///
/// Multiple Network Graphics (*.MNG)
///
public static FreeImagePlugin MNG { get { return plugins[6]; } }
///
/// Portable Bitmap (ASCII) (*.PBM)
///
public static FreeImagePlugin PBM { get { return plugins[7]; } }
///
/// Portable Bitmap (BINARY) (*.PBM)
///
public static FreeImagePlugin PBMRAW { get { return plugins[8]; } }
///
/// Kodak PhotoCD (*.PCD)
///
public static FreeImagePlugin PCD { get { return plugins[9]; } }
///
/// Zsoft Paintbrush PCX bitmap format (*.PCX)
///
public static FreeImagePlugin PCX { get { return plugins[10]; } }
///
/// Portable Graymap (ASCII) (*.PGM)
///
public static FreeImagePlugin PGM { get { return plugins[11]; } }
///
/// Portable Graymap (BINARY) (*.PGM)
///
public static FreeImagePlugin PGMRAW { get { return plugins[12]; } }
///
/// Portable Network Graphics (*.PNG)
///
public static FreeImagePlugin PNG { get { return plugins[13]; } }
///
/// Portable Pixelmap (ASCII) (*.PPM)
///
public static FreeImagePlugin PPM { get { return plugins[14]; } }
///
/// Portable Pixelmap (BINARY) (*.PPM)
///
public static FreeImagePlugin PPMRAW { get { return plugins[15]; } }
///
/// Sun Rasterfile (*.RAS)
///
public static FreeImagePlugin RAS { get { return plugins[16]; } }
///
/// truevision Targa files (*.TGA, *.TARGA)
///
public static FreeImagePlugin TARGA { get { return plugins[17]; } }
///
/// Tagged Image File Format (*.TIF, *.TIFF)
///
public static FreeImagePlugin TIFF { get { return plugins[18]; } }
///
/// Wireless Bitmap (*.WBMP)
///
public static FreeImagePlugin WBMP { get { return plugins[19]; } }
///
/// Adobe Photoshop (*.PSD)
///
public static FreeImagePlugin PSD { get { return plugins[20]; } }
///
/// Dr. Halo (*.CUT)
///
public static FreeImagePlugin CUT { get { return plugins[21]; } }
///
/// X11 Bitmap Format (*.XBM)
///
public static FreeImagePlugin XBM { get { return plugins[22]; } }
///
/// X11 Pixmap Format (*.XPM)
///
public static FreeImagePlugin XPM { get { return plugins[23]; } }
///
/// DirectDraw Surface (*.DDS)
///
public static FreeImagePlugin DDS { get { return plugins[24]; } }
///
/// Graphics Interchange Format (*.GIF)
///
public static FreeImagePlugin GIF { get { return plugins[25]; } }
///
/// High Dynamic Range (*.HDR)
///
public static FreeImagePlugin HDR { get { return plugins[26]; } }
///
/// Raw Fax format CCITT G3 (*.G3)
///
public static FreeImagePlugin FAXG3 { get { return plugins[27]; } }
///
/// Silicon Graphics SGI image format (*.SGI)
///
public static FreeImagePlugin SGI { get { return plugins[28]; } }
///
/// OpenEXR format (*.EXR)
///
public static FreeImagePlugin EXR { get { return plugins[29]; } }
///
/// JPEG-2000 format (*.J2K, *.J2C)
///
public static FreeImagePlugin J2K { get { return plugins[30]; } }
///
/// JPEG-2000 format (*.JP2)
///
public static FreeImagePlugin JP2 { get { return plugins[31]; } }
///
/// Portable FloatMap (*.PFM)
///
public static FreeImagePlugin PFM { get { return plugins[32]; } }
///
/// Macintosh PICT (*.PICT)
///
public static FreeImagePlugin PICT { get { return plugins[33]; } }
///
/// RAW camera image (*.*)
///
public static FreeImagePlugin RAW { get { return plugins[34]; } }
}
}