1
// ==========================================================
4
// Design and implementation by
5
// - David Boland (davidboland@vodafone.ie)
11
// This file is part of FreeImage 3
13
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS,
14
// WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
15
// INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS
16
// FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR
17
// NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE
18
// OF THE COVERED CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE
19
// DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY
20
// OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING,
21
// REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN
22
// ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS
23
// AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
25
// Use at your own risk!
27
// ==========================================================
31
using System.Runtime.InteropServices;
33
namespace FreeImageAPI
38
using FIBITMAP = UInt32;
40
Handle to a multipage file
42
using FIMULTIBITMAP = UInt32;
44
Handle to a memory I/O stream
46
using FIMEMORY = UInt32;
48
Handle to a metadata model
50
using FIMETADATA = UInt32;
52
Handle to a FreeImage tag
56
/* [StructLayout(LayoutKind.Sequential)]
57
public class FreeImageIO
59
public FI_ReadProc readProc;
60
public FI_WriteProc writeProc;
61
public FI_SeekProc seekProc;
62
public FI_TellProc tellProc;
65
[StructLayout(LayoutKind.Sequential)]
66
public class FI_Handle
68
public FileStream stream;
70
public delegate void FI_ReadProc(IntPtr buffer, uint size, uint count, IntPtr handle);
71
public delegate void FI_WriteProc(IntPtr buffer, uint size, uint count, IntPtr handle);
72
public delegate int FI_SeekProc(IntPtr handle, long offset, int origin);
73
public delegate int FI_TellProc(IntPtr handle);
76
// Types used in the library (directly copied from Windows) -----------------
78
[StructLayout(LayoutKind.Sequential)]
79
public class RGBQUAD {
83
public byte rgbReserved;
86
[StructLayout(LayoutKind.Sequential)]
87
public class RGBTRIPLE {
89
public byte rgbtGreen;
94
These structures should not be used by a wrapper
95
[StructLayout(LayoutKind.Sequential)]
96
public class BITMAPINFOHEADER {
100
public ushort biPlanes;
101
public ushort biBitCount;
102
public uint biCompression;
103
public uint biSizeImage;
104
public int biXPelsPerMeter;
105
public int biYPelsPerMeter;
106
public uint biClrUsed;
107
public uint biClrImportant;
110
[StructLayout(LayoutKind.Sequential)]
111
public class BITMAPINFO {
112
public BITMAPINFOHEADER bmiHeader;
113
public RGBQUAD bmiColors;
117
// Types used in the library (specific to FreeImage) ------------------------
120
[StructLayout(LayoutKind.Sequential)]
121
public class FIRGB16 {
129
[StructLayout(LayoutKind.Sequential)]
130
public class FIRGBA16 {
139
[StructLayout(LayoutKind.Sequential)]
140
public class FIRGBF {
146
/** 128-bit RGBA Float
148
[StructLayout(LayoutKind.Sequential)]
149
public class FIRGBAF {
156
/** Data structure for COMPLEX type (complex number)
158
[StructLayout(LayoutKind.Sequential)]
159
public class FICOMPLEX {
166
// ICC profile support ------------------------------------------------------
168
public enum ICCFlags {
169
FIICC_DEFAULT = 0x00,
170
FIICC_COLOR_IS_CMYK = 0x01
173
[StructLayout(LayoutKind.Sequential)]
174
public class FIICCPROFILE {
175
public ushort flags; // info flag
176
public uint size; // profile's size measured in bytes
177
public IntPtr data; // points to a block of contiguous memory containing the profile
180
// Important enums ----------------------------------------------------------
182
public enum LoadSaveFlags {
187
EXR_DEFAULT = 0, // save data as half with piz-based wavelet compression
188
EXR_FLOAT = 0x0001, // save data as float instead of as half (not recommended)
189
EXR_NONE = 0x0002, // save with no compression
190
EXR_ZIP = 0x0004, // save with zlib compression, in blocks of 16 scan lines
191
EXR_PIZ = 0x0008, // save with piz-based wavelet compression
192
EXR_PXR24 = 0x0010, // save with lossy 24-bit float compression
193
EXR_B44 = 0x0020, // save with lossy 44% float compression - goes to 22% when combined with EXR_LC
194
EXR_LC = 0x0040, // save images with one luminance and two chroma channels, rather than as RGB (lossy compression)
197
GIF_LOAD256 = 1, // Load the image as a 256 color image with ununsed palette entries, if it's 16 or 2 color
198
GIF_PLAYBACK = 2, // 'Play' the GIF to generate each frame (as 32bpp) instead of returning raw frame data when loading
201
ICO_MAKEALPHA = 1, // convert to 32bpp and create an alpha channel from the AND-mask when loading
203
J2K_DEFAULT = 0, // save with a 16:1 rate
204
JP2_DEFAULT = 0, // save with a 16:1 rate
208
JPEG_QUALITYSUPERB = 0x80,
209
JPEG_QUALITYGOOD = 0x100,
210
JPEG_QUALITYNORMAL = 0x200,
211
JPEG_QUALITYAVERAGE = 0x400,
212
JPEG_QUALITYBAD = 0x800,
213
JPEG_CMYK = 0x1000, // load separated CMYK "as is" (use | to combine with other flags)
218
PCD_BASE = 1, // load the bitmap sized 768 x 512
219
PCD_BASEDIV4 = 2, // load the bitmap sized 384 x 256
220
PCD_BASEDIV16 = 3, // load the bitmap sized 192 x 128
223
PNG_IGNOREGAMMA = 1, // avoid gamma correction
225
PNM_SAVE_RAW = 0, // If set the writer saves in RAW format (i.e. P4, P5 or P6)
226
PNM_SAVE_ASCII = 1, // If set the writer saves in ASCII format (i.e. P1, P2 or P3)
230
TARGA_LOAD_RGB888 = 1, // If set the loader converts RGB555 and ARGB8888 -> RGB888.
232
TIFF_CMYK = 0x0001, // reads/stores tags for separated CMYK (use | to combine with compression flags)
233
TIFF_PACKBITS = 0x0100, // save using PACKBITS compression
234
TIFF_DEFLATE = 0x0200, // save using DEFLATE compression (a.k.a. ZLIB compression)
235
TIFF_ADOBE_DEFLATE = 0x0400, // save using ADOBE DEFLATE compression
236
TIFF_NONE = 0x0800, // save without any compression
237
TIFF_CCITTFAX3 = 0x1000, // save using CCITT Group 3 fax encoding
238
TIFF_CCITTFAX4 = 0x2000, // save using CCITT Group 4 fax encoding
239
TIFF_LZW = 0x4000, // save using LZW compression
240
TIFF_JPEG = 0x8000, // save using JPEG compression
246
/** I/O image format identifiers.
248
public enum FREE_IMAGE_FORMAT {
285
/** Image type used in FreeImage.
287
public enum FREE_IMAGE_TYPE {
288
FIT_UNKNOWN = 0, // unknown type
289
FIT_BITMAP = 1, // standard image : 1-, 4-, 8-, 16-, 24-, 32-bit
290
FIT_UINT16 = 2, // array of unsigned short : unsigned 16-bit
291
FIT_INT16 = 3, // array of short : signed 16-bit
292
FIT_UINT32 = 4, // array of unsigned long : unsigned 32-bit
293
FIT_INT32 = 5, // array of long : signed 32-bit
294
FIT_FLOAT = 6, // array of float : 32-bit IEEE floating point
295
FIT_DOUBLE = 7, // array of double : 64-bit IEEE floating point
296
FIT_COMPLEX = 8, // array of FICOMPLEX : 2 x 64-bit IEEE floating point
297
FIT_RGB16 = 9, // 48-bit RGB image : 3 x 16-bit
298
FIT_RGBA16 = 10, // 64-bit RGBA image : 4 x 16-bit
299
FIT_RGBF = 11, // 96-bit RGB float image : 3 x 32-bit IEEE floating point
300
FIT_RGBAF = 12 // 128-bit RGBA float image : 4 x 32-bit IEEE floating point
303
/** Image color type used in FreeImage.
305
public enum FREE_IMAGE_COLOR_TYPE {
306
FIC_MINISWHITE = 0, // min value is white
307
FIC_MINISBLACK = 1, // min value is black
308
FIC_RGB = 2, // RGB color model
309
FIC_PALETTE = 3, // color map indexed
310
FIC_RGBALPHA = 4, // RGB color model with alpha channel
311
FIC_CMYK = 5 // CMYK color model
314
/** Color quantization algorithms.
315
Constants used in FreeImage_ColorQuantize.
317
public enum FREE_IMAGE_QUANTIZE {
318
FIQ_WUQUANT = 0, // Xiaolin Wu color quantization algorithm
319
FIQ_NNQUANT = 1 // NeuQuant neural-net quantization algorithm by Anthony Dekker
322
/** Dithering algorithms.
323
Constants used in FreeImage_Dither.
325
public enum FREE_IMAGE_DITHER {
326
FID_FS = 0, // Floyd & Steinberg error diffusion
327
FID_BAYER4x4 = 1, // Bayer ordered dispersed dot dithering (order 2 dithering matrix)
328
FID_BAYER8x8 = 2, // Bayer ordered dispersed dot dithering (order 3 dithering matrix)
329
FID_CLUSTER6x6 = 3, // Ordered clustered dot dithering (order 3 - 6x6 matrix)
330
FID_CLUSTER8x8 = 4, // Ordered clustered dot dithering (order 4 - 8x8 matrix)
331
FID_CLUSTER16x16= 5, // Ordered clustered dot dithering (order 8 - 16x16 matrix)
332
FID_BAYER16x16 = 6 // Bayer ordered dispersed dot dithering (order 4 dithering matrix)
334
/** Lossless JPEG transformations
335
Constants used in FreeImage_JPEGTransform
337
public enum FREE_IMAGE_JPEG_OPERATION {
338
FIJPEG_OP_NONE = 0, // no transformation
339
FIJPEG_OP_FLIP_H = 1, // horizontal flip
340
FIJPEG_OP_FLIP_V = 2, // vertical flip
341
FIJPEG_OP_TRANSPOSE = 3, // transpose across UL-to-LR axis
342
FIJPEG_OP_TRANSVERSE = 4, // transpose across UR-to-LL axis
343
FIJPEG_OP_ROTATE_90 = 5, // 90-degree clockwise rotation
344
FIJPEG_OP_ROTATE_180 = 6, // 180-degree rotation
345
FIJPEG_OP_ROTATE_270 = 7 // 270-degree clockwise (or 90 ccw)
348
/** Tone mapping operators.
349
Constants used in FreeImage_ToneMapping.
351
public enum FREE_IMAGE_TMO {
352
FITMO_DRAGO03 = 0, // Adaptive logarithmic mapping (F. Drago, 2003)
353
FITMO_REINHARD05 = 1, // Dynamic range reduction inspired by photoreceptor physiology (E. Reinhard, 2005)
354
FITMO_FATTAL02 = 2 // Gradient domain high dynamic range compression (R. Fattal, 2002)
357
/** Upsampling / downsampling filters.
358
Constants used in FreeImage_Rescale.
360
public enum FREE_IMAGE_FILTER {
361
FILTER_BOX = 0, // Box, pulse, Fourier window, 1st order (constant) b-spline
362
FILTER_BICUBIC = 1, // Mitchell & Netravali's two-param cubic filter
363
FILTER_BILINEAR = 2, // Bilinear filter
364
FILTER_BSPLINE = 3, // 4th order (cubic) b-spline
365
FILTER_CATMULLROM = 4, // Catmull-Rom spline, Overhauser spline
366
FILTER_LANCZOS3 = 5 // Lanczos3 filter
370
Constants used in color manipulation routines.
372
public enum FREE_IMAGE_COLOR_CHANNEL {
373
FICC_RGB = 0, // Use red, green and blue channels
374
FICC_RED = 1, // Use red channel
375
FICC_GREEN = 2, // Use green channel
376
FICC_BLUE = 3, // Use blue channel
377
FICC_ALPHA = 4, // Use alpha channel
378
FICC_BLACK = 5, // Use black channel
379
FICC_REAL = 6, // Complex images: use real part
380
FICC_IMAG = 7, // Complex images: use imaginary part
381
FICC_MAG = 8, // Complex images: use magnitude
382
FICC_PHASE = 9 // Complex images: use phase
385
// Metadata support ---------------------------------------------------------
388
Tag data type information (based on TIFF specifications)
390
Note: RATIONALs are the ratio of two 32-bit integer values.
392
public enum FREE_IMAGE_MDTYPE {
393
FIDT_NOTYPE = 0, // placeholder
394
FIDT_BYTE = 1, // 8-bit unsigned integer
395
FIDT_ASCII = 2, // 8-bit bytes w/ last byte null
396
FIDT_SHORT = 3, // 16-bit unsigned integer
397
FIDT_LONG = 4, // 32-bit unsigned integer
398
FIDT_RATIONAL = 5, // 64-bit unsigned fraction
399
FIDT_SBYTE = 6, // 8-bit signed integer
400
FIDT_UNDEFINED = 7, // 8-bit untyped data
401
FIDT_SSHORT = 8, // 16-bit signed integer
402
FIDT_SLONG = 9, // 32-bit signed integer
403
FIDT_SRATIONAL = 10, // 64-bit signed fraction
404
FIDT_FLOAT = 11, // 32-bit IEEE floating point
405
FIDT_DOUBLE = 12, // 64-bit IEEE floating point
406
FIDT_IFD = 13, // 32-bit unsigned integer (offset)
407
FIDT_PALETTE = 14 // 32-bit RGBQUAD
411
Metadata models supported by FreeImage
413
public enum FREE_IMAGE_MDMODEL {
415
FIMD_COMMENTS = 0, // single comment or keywords
416
FIMD_EXIF_MAIN = 1, // Exif-TIFF metadata
417
FIMD_EXIF_EXIF = 2, // Exif-specific metadata
418
FIMD_EXIF_GPS = 3, // Exif GPS metadata
419
FIMD_EXIF_MAKERNOTE = 4, // Exif maker note metadata
420
FIMD_EXIF_INTEROP = 5, // Exif interoperability metadata
421
FIMD_IPTC = 6, // IPTC/NAA metadata
422
FIMD_XMP = 7, // Abobe XMP metadata
423
FIMD_GEOTIFF = 8, // GeoTIFF metadata
424
FIMD_ANIMATION = 9, // Animation metadata
425
FIMD_CUSTOM = 10 // Used to attach other metadata types to a dib
429
// Message output function --------------------------------------------------
431
public delegate void FreeImage_OutputMessageFunction(FREE_IMAGE_FORMAT format, string msg);
435
See the FreeImage PDF documentation for a definition of each function.
437
public class FreeImage {
439
private const string dllName = "FreeImaged.dll";
441
private const string dllName = "FreeImage.dll";
444
// Init/Error routines ----------------------------------------
446
[DllImport(dllName, EntryPoint="FreeImage_Initialise")]
447
public static extern void Initialise(bool loadLocalPluginsOnly);
449
// alias for Americans :)
450
[DllImport(dllName, EntryPoint="FreeImage_Initialise")]
451
public static extern void Initialize(bool loadLocalPluginsOnly);
453
[DllImport(dllName, EntryPoint="FreeImage_DeInitialise")]
454
public static extern void DeInitialise();
456
// alias for Americians :)
457
[DllImport(dllName, EntryPoint="FreeImage_DeInitialise")]
458
public static extern void DeInitialize();
460
// Version routines -------------------------------------------
462
[DllImport(dllName, EntryPoint="FreeImage_GetVersion")]
463
public static extern string GetVersion();
465
[DllImport(dllName, EntryPoint="FreeImage_GetCopyrightMessage")]
466
public static extern string GetCopyrightMessage();
468
// Message Output routines ------------------------------------
470
[DllImport(dllName, EntryPoint="FreeImage_SetOutputMessage")]
471
public static extern void SetOutputMessage(FreeImage_OutputMessageFunction omf);
473
// Allocate / Clone / Unload routines ---------------------------------------
475
[DllImport(dllName, EntryPoint="FreeImage_Allocate")]
476
public static extern FIBITMAP Allocate(int width, int height,
477
int bpp, uint red_mask, uint green_mask, uint blue_mask);
479
[DllImport(dllName, EntryPoint="FreeImage_AllocateT")]
480
public static extern FIBITMAP AllocateT(FREE_IMAGE_TYPE ftype, int width,
481
int height, int bpp, uint red_mask, uint green_mask, uint blue_mask);
483
[DllImport(dllName, EntryPoint="FreeImage_Clone")]
484
public static extern FIBITMAP Clone(FIBITMAP dib);
486
[DllImport(dllName, EntryPoint="FreeImage_Unload")]
487
public static extern void Unload(FIBITMAP dib);
489
// Load / Save routines -----------------------------------------------------
491
[DllImport(dllName, EntryPoint="FreeImage_Load")]
492
public static extern FIBITMAP Load(FREE_IMAGE_FORMAT format, string filename, int flags);
494
// missing FIBITMAP FreeImage_LoadFromHandle(FREE_IMAGE_FORMAT fif,
495
// FreeImageIO *io, fi_handle handle, int flags);
497
[DllImport(dllName, EntryPoint="FreeImage_Save")]
498
public static extern bool Save(FREE_IMAGE_FORMAT format, FIBITMAP dib, string filename, int flags);
500
// missing BOOL FreeImage_SaveToHandle(FREE_IMAGE_FORMAT fif, FIBITMAP *dib,
501
// FreeImageIO *io, fi_handle handle, int flags);
503
// Memory I/O stream routines -----------------------------------------------
505
[DllImport(dllName, EntryPoint="FreeImage_OpenMemory")]
506
public static extern FIMEMORY OpenMemory(IntPtr bits, Int32 size_in_bytes);
508
[DllImport(dllName, EntryPoint="FreeImage_CloseMemory")]
509
public static extern void CloseMemory(FIMEMORY stream);
511
[DllImport(dllName, EntryPoint="FreeImage_LoadFromMemory")]
512
public static extern FIBITMAP LoadFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY stream, int flags);
514
[DllImport(dllName, EntryPoint="FreeImage_SaveToMemory")]
515
public static extern bool SaveToMemory(FREE_IMAGE_FORMAT fif, FIBITMAP dib, FIMEMORY stream, int flags);
517
[DllImport(dllName, EntryPoint="FreeImage_TellMemory")]
518
public static extern long TellMemory(FIMEMORY stream, int flags);
520
[DllImport(dllName, EntryPoint="FreeImage_SeekMemory")]
521
public static extern bool SeekMemory(FIMEMORY stream, long offset, int origin);
523
[DllImport(dllName, EntryPoint="FreeImage_AcquireMemory")]
524
public static extern long AcquireMemory(FIMEMORY stream, ref IntPtr data, ref int size_in_bytes);
527
// Plugin interface -------------------------------------------
529
// missing FREE_IMAGE_FORMAT FreeImage_RegisterLocalPlugin(FI_InitProc proc_address,
530
// const char *format, const char *description,
531
// const char *extension, const char *regexpr);
533
// missing FREE_IMAGE_FORMAT FreeImage_RegisterExternalPlugin(const char *path,
534
// const char *format, const char *description,
535
// const char *extension, const char *regexpr);
537
[DllImport(dllName, EntryPoint="FreeImage_GetFIFCount")]
538
public static extern int GetFIFCount();
540
[DllImport(dllName, EntryPoint="FreeImage_SetPluginEnabled")]
541
public static extern int SetPluginEnabled(FREE_IMAGE_FORMAT format, bool enabled);
543
[DllImport(dllName, EntryPoint="FreeImage_IsPluginEnabled")]
544
public static extern int IsPluginEnabled(FREE_IMAGE_FORMAT format);
546
[DllImport(dllName, EntryPoint="FreeImage_GetFIFFromFormat")]
547
public static extern FREE_IMAGE_FORMAT GetFIFFromFormat(string format);
549
[DllImport(dllName, EntryPoint="FreeImage_GetFIFFromMime")]
550
public static extern FREE_IMAGE_FORMAT GetFIFFromMime(string mime);
552
[DllImport(dllName, EntryPoint="FreeImage_GetFormatFromFIF")]
553
public static extern string GetFormatFromFIF(FREE_IMAGE_FORMAT format);
555
[DllImport(dllName, EntryPoint="FreeImage_GetFIFExtensionList")]
556
public static extern string GetFIFExtensionList(FREE_IMAGE_FORMAT format);
558
[DllImport(dllName, EntryPoint="FreeImage_GetFIFDescription")]
559
public static extern string GetFIFDescription(FREE_IMAGE_FORMAT format);
561
[DllImport(dllName, EntryPoint="FreeImage_GetFIFRegExpr")]
562
public static extern string GetFIFRegExpr(FREE_IMAGE_FORMAT format);
564
[DllImport(dllName, EntryPoint="FreeImage_GetFIFFromFilename")]
565
public static extern FREE_IMAGE_FORMAT GetFIFFromFilename(string filename);
567
[DllImport(dllName, EntryPoint="FreeImage_FIFSupportsReading")]
568
public static extern bool FIFSupportsReading(FREE_IMAGE_FORMAT format);
570
[DllImport(dllName, EntryPoint="FreeImage_FIFSupportsWriting")]
571
public static extern bool FIFSupportsWriting(FREE_IMAGE_FORMAT format);
573
[DllImport(dllName, EntryPoint="FreeImage_FIFSupportsExportBPP")]
574
public static extern bool FIFSupportsExportBPP(FREE_IMAGE_FORMAT format, int bpp);
576
[DllImport(dllName, EntryPoint="FreeImage_FIFSupportsExportType")]
577
public static extern bool FIFSupportsExportType(FREE_IMAGE_FORMAT format, FREE_IMAGE_TYPE ftype);
579
[DllImport(dllName, EntryPoint="FreeImage_FIFSupportsICCProfiles")]
580
public static extern bool FIFSupportsICCProfiles(FREE_IMAGE_FORMAT format, FREE_IMAGE_TYPE ftype);
582
// Multipage interface ----------------------------------------
584
[DllImport(dllName, EntryPoint="FreeImage_OpenMultiBitmap")]
585
public static extern FIMULTIBITMAP OpenMultiBitmap(
586
FREE_IMAGE_FORMAT format, string filename, bool createNew, bool readOnly, bool keepCacheInMemory, int flags);
588
[DllImport(dllName, EntryPoint="FreeImage_CloseMultiBitmap")]
589
public static extern long CloseMultiBitmap(FIMULTIBITMAP bitmap, int flags);
591
[DllImport(dllName, EntryPoint="FreeImage_GetPageCount")]
592
public static extern int GetPageCount(FIMULTIBITMAP bitmap);
594
[DllImport(dllName, EntryPoint="FreeImage_AppendPage")]
595
public static extern void AppendPage(FIMULTIBITMAP bitmap, FIBITMAP data);
597
[DllImport(dllName, EntryPoint="FreeImage_InsertPage")]
598
public static extern void InsertPage(FIMULTIBITMAP bitmap, int page, FIBITMAP data);
600
[DllImport(dllName, EntryPoint="FreeImage_DeletePage")]
601
public static extern void DeletePage(FIMULTIBITMAP bitmap, int page);
603
[DllImport(dllName, EntryPoint="FreeImage_LockPage")]
604
public static extern FIBITMAP LockPage(FIMULTIBITMAP bitmap, int page);
606
[DllImport(dllName, EntryPoint="FreeImage_UnlockPage")]
607
public static extern void UnlockPage(FIMULTIBITMAP bitmap, FIBITMAP data, bool changed);
609
[DllImport(dllName, EntryPoint="FreeImage_MovePage")]
610
public static extern bool MovePage(FIMULTIBITMAP bitmap, int target, int source);
612
[DllImport(dllName, EntryPoint="FreeImage_GetLockedPageNumbers")]
613
public static extern bool GetLockedPageNumbers(FIMULTIBITMAP bitmap, IntPtr pages, IntPtr count);
615
// File type request routines ---------------------------------
617
[DllImport(dllName, EntryPoint="FreeImage_GetFileType")]
618
public static extern FREE_IMAGE_FORMAT GetFileType(string filename, int size);
620
// missing FREE_IMAGE_FORMAT FreeImage_GetFileTypeFromHandle(FreeImageIO *io,
621
// fi_handle handle, int size);
623
[DllImport(dllName, EntryPoint="FreeImage_GetFileTypeFromMemory")]
624
public static extern FREE_IMAGE_FORMAT GetFileTypeFromMemory(FIMEMORY stream, int size);
626
// Image type request routines --------------------------------
628
[DllImport(dllName, EntryPoint="FreeImage_GetImageType")]
629
public static extern FREE_IMAGE_TYPE GetImageType(FIBITMAP dib);
631
// FreeImage helper routines ------------------------------------------------
633
[DllImport(dllName, EntryPoint="FreeImage_IsLittleEndian")]
634
public static extern bool IsLittleEndian();
636
[DllImport(dllName, EntryPoint="FreeImage_LookupX11Color")]
637
public static extern bool LookupX11Color(string szColor, ref int red, ref int green, ref int blue);
639
[DllImport(dllName, EntryPoint="FreeImage_LookupSVGColor")]
640
public static extern bool LookupSVGColor(string szColor, ref int red, ref int green, ref int blue);
642
// Pixel access functions -------------------------------------
644
[DllImport(dllName, EntryPoint="FreeImage_GetBits")]
645
public static extern IntPtr GetBits(FIBITMAP dib);
647
[DllImport(dllName, EntryPoint="FreeImage_GetScanLine")]
648
public static extern IntPtr GetScanLine(FIBITMAP dib, int scanline);
650
[DllImport(dllName, EntryPoint="FreeImage_GetPixelIndex")]
651
public static extern bool GetPixelIndex(FIBITMAP dib, uint x, uint y, ref byte value);
653
[DllImport(dllName, EntryPoint="FreeImage_GetPixelColor")]
654
public static extern bool GetPixelColor(FIBITMAP dib, uint x, uint y,
655
[Out, MarshalAs(UnmanagedType.LPStruct)]RGBQUAD value);
657
[DllImport(dllName, EntryPoint="FreeImage_SetPixelIndex")]
658
public static extern bool SetPixelIndex(FIBITMAP dib, uint x, uint y, ref byte value);
660
[DllImport(dllName, EntryPoint="FreeImage_SetPixelColor")]
661
public static extern bool SetPixelColor(FIBITMAP dib, uint x, uint y,
662
[In, MarshalAs(UnmanagedType.LPStruct)] RGBQUAD value);
664
// DIB info routines --------------------------------------------------------
666
[DllImport(dllName, EntryPoint="FreeImage_GetColorsUsed")]
667
public static extern uint GetColorsUsed(FIBITMAP dib);
669
[DllImport(dllName, EntryPoint="FreeImage_GetBPP")]
670
public static extern uint GetBPP(FIBITMAP dib);
672
[DllImport(dllName, EntryPoint="FreeImage_GetWidth")]
673
public static extern uint GetWidth(FIBITMAP dib);
675
[DllImport(dllName, EntryPoint="FreeImage_GetHeight")]
676
public static extern uint GetHeight(FIBITMAP dib);
678
[DllImport(dllName, EntryPoint="FreeImage_GetLine")]
679
public static extern uint GetLine(FIBITMAP dib);
681
[DllImport(dllName, EntryPoint="FreeImage_GetPitch")]
682
public static extern uint GetPitch(FIBITMAP dib);
684
[DllImport(dllName, EntryPoint="FreeImage_GetDIBSize")]
685
public static extern uint GetDIBSize(FIBITMAP dib);
688
Returns a pointer to the bitmapļæ½s palette. If the bitmap doesnļæ½t have a palette
689
(i.e. when the pixel bit depth is greater than 8), this function returns NULL.
690
@param dib Bitmap to get the palette for.
691
@return Pointer to the start of the palette data.
693
[DllImport(dllName, EntryPoint="FreeImage_GetPalette")]
694
private static extern UIntPtr GetRawPalette(FIBITMAP dib);
697
Get a deep copy of the image palette.
698
@param bitmap Pointer to a loaded image.
699
@return Array or RGBQUAD values representing the image palette.
701
public static unsafe RGBQUAD [] GetPaletteCopy(FIBITMAP dib) {
702
RGBQUAD [] paletteCopy = new FreeImageAPI.RGBQUAD[256];
704
// Only interested in indexed images.
705
if (GetBPP(dib) <= 8) {
706
UIntPtr palette = GetRawPalette(dib);
707
byte * ptr = (byte *)(void*)palette;
708
for (int q = 0; q < 256; q++) {
709
paletteCopy[q] = new FreeImageAPI.RGBQUAD();
710
paletteCopy[q].rgbBlue = (byte)*ptr;
712
paletteCopy[q].rgbGreen = (byte)*ptr;
714
paletteCopy[q].rgbRed = (byte)*ptr;
716
paletteCopy[q].rgbReserved = (byte)*ptr;
724
[DllImport(dllName, EntryPoint="FreeImage_GetDotsPerMeterX")]
725
public static extern uint GetDotsPerMeterX(FIBITMAP dib);
727
[DllImport(dllName, EntryPoint="FreeImage_GetDotsPerMeterY")]
728
public static extern uint GetDotsPerMeterY(FIBITMAP dib);
730
[DllImport(dllName, EntryPoint="FreeImage_SetDotsPerMeterX")]
731
public static extern void SetDotsPerMeterX(FIBITMAP dib, uint res);
733
[DllImport(dllName, EntryPoint="FreeImage_SetDotsPerMeterY")]
734
public static extern void SetDotsPerMeterY(FIBITMAP dib, uint res);
736
[DllImport(dllName, EntryPoint = "FreeImage_GetInfoHeader")]
737
public static extern IntPtr FreeImage_GetInfoHeader(FIBITMAP dib);
739
[DllImport(dllName, EntryPoint = "FreeImage_GetInfo")]
740
public static extern IntPtr FreeImage_GetInfo(FIBITMAP dib);
742
[DllImport(dllName, EntryPoint="FreeImage_GetColorType")]
743
public static extern FREE_IMAGE_COLOR_TYPE GetColorType(FIBITMAP dib);
745
[DllImport(dllName, EntryPoint="FreeImage_GetRedMask")]
746
public static extern uint GetRedMask(FIBITMAP dib);
748
[DllImport(dllName, EntryPoint="FreeImage_GetGreenMask")]
749
public static extern uint GetGreenMask(FIBITMAP dib);
751
[DllImport(dllName, EntryPoint="FreeImage_GetBlueMask")]
752
public static extern uint GetBlueMask(FIBITMAP dib);
754
[DllImport(dllName, EntryPoint="FreeImage_GetTransparencyCount")]
755
public static extern uint GetTransparencyCount(FIBITMAP dib);
757
[DllImport(dllName, EntryPoint="FreeImage_GetTransparencyTable")]
758
public static extern IntPtr GetTransparencyTable(FIBITMAP dib);
760
[DllImport(dllName, EntryPoint="FreeImage_SetTransparent")]
761
public static extern void SetTransparent(FIBITMAP dib, bool enabled);
763
[DllImport(dllName, EntryPoint="FreeImage_SetTransparencyTable")]
764
public static extern void SetTransparencyTable(FIBITMAP dib, IntPtr table, int count);
766
[DllImport(dllName, EntryPoint="FreeImage_IsTransparent")]
767
public static extern bool IsTransparent(FIBITMAP dib);
769
[DllImport(dllName, EntryPoint="FreeImage_HasBackgroundColor")]
770
public static extern bool HasBackgroundColor(FIBITMAP dib);
772
[DllImport(dllName, EntryPoint="FreeImage_GetBackgroundColor")]
773
public static extern bool GetBackgroundColor(FIBITMAP dib,
774
[Out, MarshalAs(UnmanagedType.LPStruct)]RGBQUAD bkcolor);
776
[DllImport(dllName, EntryPoint="FreeImage_SetBackgroundColor")]
777
public static extern bool SetBackgroundColor(FIBITMAP dib,
778
[In, MarshalAs(UnmanagedType.LPStruct)]RGBQUAD bkcolor);
780
// ICC profile routines -----------------------------------------------------
782
[DllImport(dllName,EntryPoint="FreeImage_DestroyICCProfile")]
783
public static extern void DestroyICCProfile(FIBITMAP dib);
785
[DllImport(dllName,EntryPoint="FreeImage_GetICCProfile")]
786
public static extern FIICCPROFILE GetICCProfile(FIBITMAP dib);
788
[DllImport(dllName,EntryPoint="FreeImage_CreateICCProfile")]
789
public static extern FIICCPROFILE CreateICCProfile(FIBITMAP dib, IntPtr data, uint size);
791
// Smart conversion routines ------------------------------------------------
793
[DllImport(dllName, EntryPoint="FreeImage_ConvertTo4Bits")]
794
public static extern FIBITMAP ConvertTo4Bits(FIBITMAP dib);
796
[DllImport(dllName, EntryPoint="FreeImage_ConvertTo8Bits")]
797
public static extern FIBITMAP ConvertTo8Bits(FIBITMAP dib);
799
[DllImport(dllName, EntryPoint="FreeImage_ConvertTo16Bits555")]
800
public static extern FIBITMAP ConvertTo16Bits555(FIBITMAP dib);
802
[DllImport(dllName, EntryPoint="FreeImage_ConvertTo16Bits565")]
803
public static extern FIBITMAP ConvertTo16Bits565(FIBITMAP dib);
805
[DllImport(dllName, EntryPoint="FreeImage_ConvertTo24Bits")]
806
public static extern FIBITMAP ConvertTo24Bits(FIBITMAP dib);
808
[DllImport(dllName, EntryPoint="FreeImage_ConvertTo32Bits")]
809
public static extern FIBITMAP ConvertTo32Bits(FIBITMAP dib);
811
[DllImport(dllName, EntryPoint="FreeImage_ColorQuantize")]
812
public static extern FIBITMAP ColorQuantize(FIBITMAP dib, FREE_IMAGE_QUANTIZE quantize);
814
[DllImport(dllName, EntryPoint="FreeImage_Threshold")]
815
public static extern FIBITMAP Threshold(FIBITMAP dib, uint T);
817
[DllImport(dllName, EntryPoint="FreeImage_Dither")]
818
public static extern FIBITMAP Dither(FIBITMAP dib, FREE_IMAGE_DITHER algorithm);
820
[DllImport(dllName, EntryPoint="FreeImage_ConvertFromRawBits")]
821
public static extern FIBITMAP ConvertFromRawBits(byte[] bits, int width, int height,
822
int pitch, uint bpp, uint redMask, uint greenMask, uint blueMask, bool topDown);
824
[DllImport(dllName, EntryPoint="FreeImage_ConvertToRawBits")]
825
public static extern void ConvertToRawBits(IntPtr bits, FIBITMAP dib, int pitch,
826
uint bpp, uint redMask, uint greenMask, uint blueMask, bool topDown);
828
[DllImport(dllName, EntryPoint="FreeImage_ConvertToStandardType")]
829
public static extern FIBITMAP ConvertToStandardType(FIBITMAP dib, FREE_IMAGE_TYPE dst_type, bool scale_linear);
831
[DllImport(dllName, EntryPoint="FreeImage_ConvertToType")]
832
public static extern FIBITMAP ConvertToType(FIBITMAP dib, FREE_IMAGE_TYPE dst_type, bool scale_linear);
834
[DllImport(dllName, EntryPoint="FreeImage_ConvertToRGBF")]
835
public static extern FIBITMAP ConvertToRGBF(FIBITMAP dib);
837
[DllImport(dllName, EntryPoint="FreeImage_ToneMapping")]
838
public static extern FIBITMAP ToneMapping(FIBITMAP dib, FREE_IMAGE_TMO tmo, double first_param, double second_param);
840
[DllImport(dllName, EntryPoint="FreeImage_TmoDrago03")]
841
public static extern FIBITMAP TmoDrago03(FIBITMAP dib, double gamma, double exposure);
843
[DllImport(dllName, EntryPoint="FreeImage_TmoReinhard05")]
844
public static extern FIBITMAP TmoReinhard05(FIBITMAP dib, double intensity, double contrast);
846
// ZLib interface -----------------------------------------------------------
848
[DllImport(dllName, EntryPoint="FreeImage_ZLibCompress")]
849
public static extern Int32 ZLibCompress(IntPtr target, Int32 target_size, IntPtr source, Int32 source_size);
851
[DllImport(dllName, EntryPoint="FreeImage_ZLibUncompress")]
852
public static extern Int32 ZLibUncompress(IntPtr target, Int32 target_size, IntPtr source, Int32 source_size);
854
[DllImport(dllName, EntryPoint="FreeImage_ZLibGZip")]
855
public static extern Int32 ZLibGZip(IntPtr target, Int32 target_size, IntPtr source, Int32 source_size);
857
[DllImport(dllName, EntryPoint="FreeImage_ZLibGUnzip")]
858
public static extern Int32 ZLibGUnzip(IntPtr target, Int32 target_size, IntPtr source, Int32 source_size);
860
[DllImport(dllName, EntryPoint="FreeImage_ZLibCRC32")]
861
public static extern Int32 ZLibCRC32(Int32 crc, IntPtr source, Int32 source_size);
863
// --------------------------------------------------------------------------
864
// Image manipulation toolkit -----------------------------------------------
865
// --------------------------------------------------------------------------
867
// rotation and flipping
869
[DllImport(dllName, EntryPoint="FreeImage_RotateClassic")]
870
public static extern FIBITMAP RotateClassic(FIBITMAP dib, double angle);
872
[DllImport(dllName, EntryPoint="FreeImage_RotateEx")]
873
public static extern FIBITMAP RotateEx(
874
FIBITMAP dib, double angle, double xShift, double yShift, double xOrigin, double yOrigin, bool useMask);
876
[DllImport(dllName, EntryPoint="FreeImage_FlipHorizontal")]
877
public static extern bool FlipHorizontal(FIBITMAP dib);
879
[DllImport(dllName, EntryPoint="FreeImage_FlipVertical")]
880
public static extern bool FlipVertical(FIBITMAP dib);
882
[DllImport(dllName, EntryPoint="FreeImage_JPEGTransform")]
883
public static extern bool JPEGTransform(string src_file, string dst_file, FREE_IMAGE_JPEG_OPERATION operation, bool perfect);
885
// upsampling / downsampling
887
[DllImport(dllName, EntryPoint="FreeImage_Rescale")]
888
public static extern FIBITMAP Rescale(FIBITMAP dib, int dst_width, int dst_height, FREE_IMAGE_FILTER filter);
890
// color manipulation routines (point operations)
892
[DllImport(dllName, EntryPoint="FreeImage_AdjustCurve")]
893
public static extern bool AdjustCurve(FIBITMAP dib, byte[] lut, FREE_IMAGE_COLOR_CHANNEL channel);
895
[DllImport(dllName, EntryPoint="FreeImage_AdjustGamma")]
896
public static extern bool AdjustGamma(FIBITMAP dib, double gamma);
898
[DllImport(dllName, EntryPoint="FreeImage_AdjustBrightness")]
899
public static extern bool AdjustBrightness(FIBITMAP dib, double percentage);
901
[DllImport(dllName, EntryPoint="FreeImage_AdjustContrast")]
902
public static extern bool AdjustContrast(FIBITMAP dib, double percentage);
904
[DllImport(dllName, EntryPoint="FreeImage_Invert")]
905
public static extern bool Invert(FIBITMAP dib);
907
[DllImport(dllName, EntryPoint="FreeImage_GetHistogram")]
908
public static extern bool GetHistogram(FIBITMAP dib, IntPtr histo, FREE_IMAGE_COLOR_CHANNEL channel);
910
// channel processing routines
912
[DllImport(dllName, EntryPoint="FreeImage_GetChannel")]
913
public static extern FIBITMAP GetChannel(FIBITMAP dib, FREE_IMAGE_COLOR_CHANNEL channel);
915
[DllImport(dllName, EntryPoint="FreeImage_SetChannel")]
916
public static extern bool SetChannel(FIBITMAP dib, FIBITMAP dib8, FREE_IMAGE_COLOR_CHANNEL channel);
918
// copy / paste / composite routines
920
[DllImport(dllName, EntryPoint="FreeImage_Copy")]
921
public static extern FIBITMAP Copy(FIBITMAP dib, int left, int top, int right, int bottom);
923
[DllImport(dllName, EntryPoint="FreeImage_Paste")]
924
public static extern bool Paste(FIBITMAP dst, FIBITMAP src, int left, int top, int alpha);
926
[DllImport(dllName, EntryPoint="FreeImage_Composite")]
927
public static extern FIBITMAP Composite(FIBITMAP fg, bool useFileBkg,
928
[In, MarshalAs(UnmanagedType.LPStruct)] RGBQUAD appBkColor, FIBITMAP bg);