1
// ==========================================================
2
// FreeImage 3 .NET wrapper
3
// Original FreeImage 3 functions and .NET compatible derived functions
5
// Design and implementation by
6
// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net)
7
// - Carsten Klein (cklein05@users.sourceforge.net)
10
// - David Boland (davidboland@vodafone.ie)
12
// Main reference : MSDN Knowlede Base
14
// This file is part of FreeImage 3
16
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
17
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
18
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
19
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
20
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
21
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
22
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
23
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
26
// Use at your own risk!
27
// ==========================================================
29
// ==========================================================
30
// To build the project without VS use the following commandline:
31
// "csc.exe /out:FreeImageNET.dll /target:library /doc:FreeImageNET.XML /debug- /o /unsafe+ /filealign:512 FreeImage.cs"
32
// ==========================================================
35
using System.Collections;
36
using System.Collections.Generic;
37
using System.Collections.ObjectModel;
38
using System.Diagnostics;
40
using System.Drawing.Imaging;
42
using System.Reflection;
43
using System.Resources;
44
using System.Runtime.CompilerServices;
45
using System.Runtime.InteropServices;
46
using System.Runtime.Serialization;
48
using System.Text.RegularExpressions;
51
using FreeImageAPI.IO;
52
using FreeImageAPI.Metadata;
53
using FreeImageAPI.Plugins;
55
/////////////////////////////////////////////////////
57
// FreeImage.h import //
59
/////////////////////////////////////////////////////
63
namespace FreeImageAPI
66
/// The <b>BITMAP</b> structure defines the type, width, height, color format, and bit values of a bitmap.
69
/// The bitmap formats currently used are monochrome and color. The monochrome bitmap uses a one-bit,
70
/// one-plane format. Each scan is a multiple of 32 bits.
72
/// Scans are organized as follows for a monochrome bitmap of height n:
84
/// The pixels on a monochrome device are either black or white. If the corresponding bit in the
85
/// bitmap is 1, the pixel is set to the foreground color; if the corresponding bit in the bitmap
86
/// is zero, the pixel is set to the background color.
88
/// All devices that have the RC_BITBLT device capability support bitmaps. For more information,
89
/// see <b>GetDeviceCaps</b>.
91
/// Each device has a unique color format. To transfer a bitmap from one device to another,
92
/// use the <b>GetDIBits</b> and <b>SetDIBits</b> functions.
94
[Serializable, StructLayout(LayoutKind.Sequential)]
98
/// Specifies the bitmap type. This member must be zero.
102
/// Specifies the width, in pixels, of the bitmap. The width must be greater than zero.
106
/// Specifies the height, in pixels, of the bitmap. The height must be greater than zero.
110
/// Specifies the number of bytes in each scan line. This value must be divisible by 2,
111
/// because the system assumes that the bit values of a bitmap form an array that is word aligned.
113
public int bmWidthBytes;
115
/// Specifies the count of color planes.
117
public ushort bmPlanes;
119
/// Specifies the number of bits required to indicate the color of a pixel.
121
public ushort bmBitsPixel;
123
/// Pointer to the location of the bit values for the bitmap.
124
/// The <b>bmBits</b> member must be a long pointer to an array of character (1-byte) values.
126
public IntPtr bmBits;
130
namespace FreeImageAPI
133
/// This structure contains information about the dimensions and color format
134
/// of a device-independent bitmap (DIB).
137
/// The <see cref="FreeImageAPI.BITMAPINFO"/> structure combines the
138
/// <b>BITMAPINFOHEADER</b> structure and a color table to provide a complete
139
/// definition of the dimensions and colors of a DIB.
141
[Serializable, StructLayout(LayoutKind.Sequential)]
142
public struct BITMAPINFOHEADER : IEquatable<BITMAPINFOHEADER>
145
/// Specifies the size of the structure, in bytes.
149
/// Specifies the width of the bitmap, in pixels.
151
/// <b>Windows 98/Me, Windows 2000/XP:</b> If <b>biCompression</b> is BI_JPEG or BI_PNG,
152
/// the <b>biWidth</b> member specifies the width of the decompressed JPEG or PNG image file,
157
/// Specifies the height of the bitmap, in pixels. If <b>biHeight</b> is positive, the bitmap
158
/// is a bottom-up DIB and its origin is the lower-left corner. If <b>biHeight</b> is negative,
159
/// the bitmap is a top-down DIB and its origin is the upper-left corner.
161
/// If <b>biHeight</b> is negative, indicating a top-down DIB, <b>biCompression</b> must be
162
/// either BI_RGB or BI_BITFIELDS. Top-down DIBs cannot be compressed.
164
/// <b>Windows 98/Me, Windows 2000/XP:</b> If <b>biCompression</b> is BI_JPEG or BI_PNG,
165
/// the <b>biHeight</b> member specifies the height of the decompressed JPEG or PNG image file,
170
/// Specifies the number of planes for the target device. This value must be set to 1.
172
public ushort biPlanes;
174
/// Specifies the number of bits per pixel.The biBitCount member of the <b>BITMAPINFOHEADER</b>
175
/// structure determines the number of bits that define each pixel and the maximum number of
176
/// colors in the bitmap. This member must be one of the following values.
179
/// <list type="table">
181
/// <term>Value</term>
182
/// <description>Meaning</description>
188
/// <b>Windows 98/Me, Windows 2000/XP:</b> The number of bits-per-pixel is specified
189
/// or is implied by the JPEG or PNG format.
196
/// The bitmap is monochrome, and the bmiColors member of <see cref="FreeImageAPI.BITMAPINFO"/>
197
/// contains two entries. Each bit in the bitmap array represents a pixel. If the bit is clear,
198
/// the pixel is displayed with the color of the first entry in the bmiColors table; if the bit
199
/// is set, the pixel has the color of the second entry in the table.
206
/// The bitmap has a maximum of 16 colors, and the <b>bmiColors</b> member of <b>BITMAPINFO</b>
207
/// contains up to 16 entries. Each pixel in the bitmap is represented by a 4-bit index into the
208
/// color table. For example, if the first byte in the bitmap is 0x1F, the byte represents two
209
/// pixels. The first pixel contains the color in the second table entry, and the second pixel
210
/// contains the color in the sixteenth table entry.</description>
216
/// The bitmap has a maximum of 256 colors, and the <b>bmiColors</b> member of <b>BITMAPINFO</b>
217
/// contains up to 256 entries. In this case, each byte in the array represents a single pixel.
224
/// The bitmap has a maximum of 2^16 colors. If the <b>biCompression</b> member of the
225
/// <b>BITMAPINFOHEADER</b> is BI_RGB, the <b>bmiColors</b> member of <b>BITMAPINFO</b> is NULL.
226
/// Each <b>WORD</b> in the bitmap array represents a single pixel. The relative intensities
227
/// of red, green, and blue are represented with five bits for each color component.
228
/// The value for blue is in the least significant five bits, followed by five bits each for
229
/// green and red. The most significant bit is not used. The <b>bmiColors</b> color table is used
230
/// for optimizing colors used on palette-based devices, and must contain the number of entries
231
/// specified by the <b>biClrUsed</b> member of the <b>BITMAPINFOHEADER</b>.
233
/// If the <b>biCompression</b> member of the <b>BITMAPINFOHEADER</b> is BI_BITFIELDS, the
234
/// <b>bmiColors</b> member contains three <b>DWORD</b> color masks that specify the red, green,
235
/// and blue components, respectively, of each pixel. Each <b>WORD</b> in the bitmap array represents
238
/// <b>Windows NT/Windows 2000/XP:</b> When the <b>biCompression</b> member is BI_BITFIELDS,
239
/// bits set in each <b>DWORD</b> mask must be contiguous and should not overlap the bits
240
/// of another mask. All the bits in the pixel do not have to be used.
242
/// <b>Windows 95/98/Me:</b> When the <b>biCompression</b> member is BI_BITFIELDS, the system
243
/// supports only the following 16bpp color masks: A 5-5-5 16-bit image, where the blue mask is
244
/// 0x001F, the green mask is 0x03E0, and the red mask is 0x7C00; and a 5-6-5 16-bit image,
245
/// where the blue mask is 0x001F, the green mask is 0x07E0, and the red mask is 0xF800.
252
/// The bitmap has a maximum of 2^24 colors, and the <b>bmiColors</b> member of <b>BITMAPINFO</b>
253
/// is NULL. Each 3-byte triplet in the bitmap array represents the relative intensities of blue,
254
/// green, and red, respectively, for a pixel. The <b>bmiColors</b> color table is used for
255
/// optimizing colors used on palette-based devices, and must contain the number of entries
256
/// specified by the <b>biClrUsed</b> member of the <b>BITMAPINFOHEADER</b>.
263
/// The bitmap has a maximum of 2^32 colors. If the <b>biCompression</b> member of the
264
/// <b>BITMAPINFOHEADER</b> is BI_RGB, the <b>bmiColors</b> member of <b>BITMAPINFO</b> is NULL.
265
/// Each <b>DWORD</b> in the bitmap array represents the relative intensities of blue, green, and red,
266
/// respectively, for a pixel. The high byte in each <b>DWORD</b> is not used. The <b>bmiColors</b>
267
/// color table is used for optimizing colors used on palette-based devices, and must contain the
268
/// number of entries specified by the <b>biClrUsed</b> member of the <b>BITMAPINFOHEADER</b>.
270
/// If the <b>biCompression</b> member of the <b>BITMAPINFOHEADER</b> is BI_BITFIELDS,
271
/// the <b>bmiColors</b> member contains three <b>DWORD</b> color masks that specify the red, green,
272
/// and blue components, respectively, of each pixel. Each <b>DWORD</b> in the bitmap array represents
275
/// <b>Windows NT/ 2000:</b> When the <b>biCompression</b> member is BI_BITFIELDS, bits set in each
276
/// <b>DWORD</b> mask must be contiguous and should not overlap the bits of another mask. All the
277
/// bits in the pixel do not need to be used.
279
/// <b>Windows 95/98/Me:</b> When the <b>biCompression</b> member is BI_BITFIELDS, the system
280
/// supports only the following 32-bpp color mask: The blue mask is 0x000000FF, the green mask is
281
/// 0x0000FF00, and the red mask is 0x00FF0000.
286
public ushort biBitCount;
288
/// Specifies the type of compression for a compressed bottom-up bitmap (top-down DIBs cannot be
290
/// <list type="table">
292
/// <term>Value</term>
293
/// <description>Meaning</description>
297
/// <term>BI_RGB</term>
298
/// <description>An uncompressed format.</description>
302
/// <term>BI_RLE8</term>
303
/// <description>A run-length encoded (RLE) format for bitmaps with 8 bpp. The compression format
304
/// is a 2-byte format consisting of a count byte followed by a byte containing a color index.
309
/// <term>BI_RLE4</term>
310
/// <description>An RLE format for bitmaps with 4 bpp. The compression format is a 2-byte format
311
/// consisting of a count byte followed by two word-length color indexes.</description>
315
/// <term>BI_BITFIELDS</term>
316
/// <description>Specifies that the bitmap is not compressed and that the color table consists
317
/// of three <b>DWORD</b> color masks that specify the red, green, and blue components, respectively,
318
/// of each pixel. This is valid when used with 16- and 32-bpp bitmaps.</description>
322
/// <term>BI_JPEG</term>
323
/// <description><b>Windows 98/Me, Windows 2000/XP:</b> Indicates that the image is a JPEG image.
328
/// <term>BI_PNG</term>
329
/// <description><b>Windows 98/Me, Windows 2000/XP:</b> Indicates that the image is a PNG image.
335
public uint biCompression;
337
/// Specifies the size, in bytes, of the image. This may be set to zero for BI_RGB bitmaps.
339
/// <b>Windows 98/Me, Windows 2000/XP:</b> If <b>biCompression</b> is BI_JPEG or BI_PNG,
340
/// <b>biSizeImage</b> indicates the size of the JPEG or PNG image buffer, respectively.
342
public uint biSizeImage;
344
/// Specifies the horizontal resolution, in pixels-per-meter, of the target device for the bitmap.
345
/// An application can use this value to select a bitmap from a resource group that best matches
346
/// the characteristics of the current device.
348
public int biXPelsPerMeter;
350
/// Specifies the vertical resolution, in pixels-per-meter, of the target device for the bitmap.
352
public int biYPelsPerMeter;
354
/// Specifies the number of color indexes in the color table that are actually used by the bitmap.
355
/// If this value is zero, the bitmap uses the maximum number of colors corresponding to the value
356
/// of the biBitCount member for the compression mode specified by <b>biCompression</b>.
358
/// If <b>iClrUsed</b> is nonzero and the <b>biBitCount</b> member is less than 16, the <b>biClrUsed</b>
359
/// member specifies the actual number of colors the graphics engine or device driver accesses.
360
/// If <b>biBitCount</b> is 16 or greater, the <b>biClrUsed</b> member specifies the size of the color
361
/// table used to optimize performance of the system color palettes. If <b>biBitCount</b> equals 16 or 32,
362
/// the optimal color palette starts immediately following the three <b>DWORD</b> masks.
364
/// When the bitmap array immediately follows the <see cref="BITMAPINFO"/> structure, it is a packed bitmap.
365
/// Packed bitmaps are referenced by a single pointer. Packed bitmaps require that the
366
/// <b>biClrUsed</b> member must be either zero or the actual size of the color table.
368
public uint biClrUsed;
370
/// Specifies the number of color indexes that are required for displaying the bitmap. If this value
371
/// is zero, all colors are required.
373
public uint biClrImportant;
376
/// Tests whether two specified <see cref="BITMAPINFOHEADER"/> structures are equivalent.
378
/// <param name="left">The <see cref="BITMAPINFOHEADER"/> that is to the left of the equality operator.</param>
379
/// <param name="right">The <see cref="BITMAPINFOHEADER"/> that is to the right of the equality operator.</param>
381
/// <b>true</b> if the two <see cref="BITMAPINFOHEADER"/> structures are equal; otherwise, <b>false</b>.
383
public static bool operator ==(BITMAPINFOHEADER left, BITMAPINFOHEADER right)
385
return ((left.biSize == right.biSize) &&
386
(left.biWidth == right.biWidth) &&
387
(left.biHeight == right.biHeight) &&
388
(left.biPlanes == right.biPlanes) &&
389
(left.biBitCount == right.biBitCount) &&
390
(left.biCompression == right.biCompression) &&
391
(left.biSizeImage == right.biSizeImage) &&
392
(left.biXPelsPerMeter == right.biXPelsPerMeter) &&
393
(left.biYPelsPerMeter == right.biYPelsPerMeter) &&
394
(left.biClrUsed == right.biClrUsed) &&
395
(left.biClrImportant == right.biClrImportant));
399
/// Tests whether two specified <see cref="BITMAPINFOHEADER"/> structures are different.
401
/// <param name="left">The <see cref="BITMAPINFOHEADER"/> that is to the left of the inequality operator.</param>
402
/// <param name="right">The <see cref="BITMAPINFOHEADER"/> that is to the right of the inequality operator.</param>
404
/// <b>true</b> if the two <see cref="BITMAPINFOHEADER"/> structures are different; otherwise, <b>false</b>.
406
public static bool operator !=(BITMAPINFOHEADER left, BITMAPINFOHEADER right)
408
return !(left == right);
412
/// Tests whether the specified <see cref="BITMAPINFOHEADER"/> structure is equivalent to this <see cref="BITMAPINFOHEADER"/> structure.
414
/// <param name="other">A <see cref="BITMAPINFOHEADER"/> structure to compare to this instance.</param>
415
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="BITMAPINFOHEADER"/> structure
416
/// equivalent to this <see cref="BITMAPINFOHEADER"/> structure; otherwise, <b>false</b>.</returns>
417
public bool Equals(BITMAPINFOHEADER other)
419
return (this == other);
423
/// Tests whether the specified object is a <see cref="BITMAPINFOHEADER"/> structure
424
/// and is equivalent to this <see cref="BITMAPINFOHEADER"/> structure.
426
/// <param name="obj">The object to test.</param>
427
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="BITMAPINFOHEADER"/> structure
428
/// equivalent to this <see cref="BITMAPINFOHEADER"/> structure; otherwise, <b>false</b>.</returns>
429
public override bool Equals(object obj)
431
return ((obj is BITMAPINFOHEADER) && (this == (BITMAPINFOHEADER)obj));
435
/// Returns a hash code for this <see cref="BITMAPINFOHEADER"/> structure.
437
/// <returns>An integer value that specifies the hash code for this <see cref="BITMAPINFOHEADER"/>.</returns>
438
public override int GetHashCode()
440
return base.GetHashCode();
445
namespace FreeImageAPI
448
/// The <b>BITMAPINFO</b> structure defines the dimensions and color information for a DIB.
451
/// A DIB consists of two distinct parts: a <b>BITMAPINFO</b> structure describing the dimensions
452
/// and colors of the bitmap, and an array of bytes defining the pixels of the bitmap. The bits in
453
/// the array are packed together, but each scan line must be padded with zeroes to end on a
454
/// <b>LONG</b> data-type boundary. If the height of the bitmap is positive, the bitmap is a
455
/// bottom-up DIB and its origin is the lower-left corner. If the height is negative, the bitmap is
456
/// a top-down DIB and its origin is the upper left corner.
458
/// A bitmap is packed when the bitmap array immediately follows the <b>BITMAPINFO</b> header.
459
/// Packed bitmaps are referenced by a single pointer. For packed bitmaps, the <b>biClrUsed</b>
460
/// member must be set to an even number when using the DIB_PAL_COLORS mode so that the DIB bitmap
461
/// array starts on a <b>DWORD</b> boundary.
463
/// <b>Note</b> The <b>bmiColors</b> member should not contain palette indexes if the bitmap is to
464
/// be stored in a file or transferred to another application.
466
/// Unless the application has exclusive use and control of the bitmap, the bitmap color table
467
/// should contain explicit RGB values.
469
[Serializable, StructLayout(LayoutKind.Sequential)]
470
public struct BITMAPINFO : IEquatable<BITMAPINFO>
473
/// Specifies a <see cref="FreeImageAPI.BITMAPINFOHEADER"/> structure that contains information
474
/// about the dimensions of color format.
476
public BITMAPINFOHEADER bmiHeader;
478
/// The <b>bmiColors</b> member contains one of the following:
479
/// <list type="bullets">
483
/// An array of <see cref="FreeImageAPI.RGBQUAD"/>. The elements of the array that make up the
490
/// An array of 16-bit unsigned integers that specifies indexes into the currently realized
491
/// logical palette. This use of <b>bmiColors</b> is allowed for functions that use DIBs.
492
/// When <b>bmiColors</b> elements contain indexes to a realized logical palette, they must
493
/// also call the following bitmap functions:
498
/// <b>CreateDIBitmap</b>
500
/// <b>CreateDIBPatternBrush</b>
502
/// <b>CreateDIBSection</b>
504
/// The <i>iUsage</i> parameter of CreateDIBSection must be set to DIB_PAL_COLORS.
506
/// The number of entries in the array depends on the values of the <b>biBitCount</b> and
507
/// <b>biClrUsed</b> members of the <see cref="FreeImageAPI.BITMAPINFOHEADER"/> structure.
509
/// The colors in the <b>bmiColors</b> table appear in order of importance. For more information,
510
/// see the Remarks section.
512
public RGBQUAD[] bmiColors;
515
/// Tests whether two specified <see cref="BITMAPINFO"/> structures are equivalent.
517
/// <param name="left">The <see cref="BITMAPINFO"/> that is to the left of the equality operator.</param>
518
/// <param name="right">The <see cref="BITMAPINFO"/> that is to the right of the equality operator.</param>
520
/// <b>true</b> if the two <see cref="BITMAPINFO"/> structures are equal; otherwise, <b>false</b>.
522
public static bool operator ==(BITMAPINFO left, BITMAPINFO right)
524
if (left.bmiHeader != right.bmiHeader)
528
if ((left.bmiColors == null) && (right.bmiColors == null))
532
if ((left.bmiColors == null) || (right.bmiColors == null))
536
if (left.bmiColors.Length != right.bmiColors.Length)
540
for (int i = 0; i < left.bmiColors.Length; i++)
542
if (left.bmiColors[i] != right.bmiColors[i])
551
/// Tests whether two specified <see cref="BITMAPINFO"/> structures are different.
553
/// <param name="left">The <see cref="BITMAPINFO"/> that is to the left of the inequality operator.</param>
554
/// <param name="right">The <see cref="BITMAPINFO"/> that is to the right of the inequality operator.</param>
556
/// <b>true</b> if the two <see cref="BITMAPINFO"/> structures are different; otherwise, <b>false</b>.
558
public static bool operator !=(BITMAPINFO left, BITMAPINFO right)
560
return !(left == right);
564
/// Tests whether the specified <see cref="BITMAPINFO"/> structure is equivalent to this <see cref="BITMAPINFO"/> structure.
566
/// <param name="other">A <see cref="BITMAPINFO"/> structure to compare to this instance.</param>
567
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="BITMAPINFO"/> structure
568
/// equivalent to this <see cref="BITMAPINFO"/> structure; otherwise, <b>false</b>.</returns>
569
public bool Equals(BITMAPINFO other)
571
return (this == other);
575
/// Tests whether the specified object is a <see cref="BITMAPINFO"/> structure
576
/// and is equivalent to this <see cref="BITMAPINFO"/> structure.
578
/// <param name="obj">The object to test.</param>
579
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="BITMAPINFO"/> structure
580
/// equivalent to this <see cref="BITMAPINFO"/> structure; otherwise, <b>false</b>.</returns>
581
public override bool Equals(object obj)
583
return ((obj is BITMAPINFO) && (this == ((BITMAPINFO)obj)));
587
/// Returns a hash code for this <see cref="BITMAPINFO"/> structure.
589
/// <returns>An integer value that specifies the hash code for this <see cref="BITMAPINFO"/>.</returns>
590
public override int GetHashCode()
592
int hash = bmiHeader.GetHashCode();
593
if (bmiColors != null)
595
for (int c = 0; c < bmiColors.Length; c++)
597
hash ^= bmiColors[c].GetHashCode();
611
namespace FreeImageAPI
614
/// The <b>FIBITMAP</b> structure is a handle to a FreeImage bimtap.
617
/// The handle represented by a <b>FIBITBAP</b> structure provides
618
/// access to either a singlepage bitmap or exactly one page of
619
/// a multipage bitmap.
621
[Serializable, StructLayout(LayoutKind.Sequential)]
622
public struct FIBITMAP : IComparable, IComparable<FIBITMAP>, IEquatable<FIBITMAP>
627
/// A read-only field that represents a handle that has been initialized to zero.
629
public static readonly FIBITMAP Zero;
632
/// Tests whether two specified <see cref="FIBITMAP"/> structures are equivalent.
634
/// <param name="left">The <see cref="FIBITMAP"/> that is to the left of the equality operator.</param>
635
/// <param name="right">The <see cref="FIBITMAP"/> that is to the right of the equality operator.</param>
637
/// <b>true</b> if the two <see cref="FIBITMAP"/> structures are equal; otherwise, <b>false</b>.
639
public static bool operator ==(FIBITMAP left, FIBITMAP right)
641
return (left.data == right.data);
645
/// Tests whether two specified <see cref="FIBITMAP"/> structures are different.
647
/// <param name="left">The <see cref="FIBITMAP"/> that is to the left of the inequality operator.</param>
648
/// <param name="right">The <see cref="FIBITMAP"/> that is to the right of the inequality operator.</param>
650
/// <b>true</b> if the two <see cref="FIBITMAP"/> structures are different; otherwise, <b>false</b>.
652
public static bool operator !=(FIBITMAP left, FIBITMAP right)
654
return (left.data != right.data);
658
/// Gets whether the handle is a null or not.
660
/// <value><b>true</b> if this <see cref="FIBITMAP"/> handle is a null;
661
/// otherwise, <b>false</b>.</value>
666
return (data == IntPtr.Zero);
671
/// Sets the handle to <i>null</i>.
673
public void SetNull()
679
/// Converts the numeric value of the <see cref="FIBITMAP"/> object
680
/// to its equivalent string representation.
682
/// <returns>The string representation of the value of this instance.</returns>
683
public override string ToString()
685
return data.ToString();
689
/// Returns a hash code for this <see cref="FIBITMAP"/> structure.
691
/// <returns>An integer value that specifies the hash code for this <see cref="FIBITMAP"/>.</returns>
692
public override int GetHashCode()
694
return data.GetHashCode();
698
/// Determines whether the specified <see cref="Object"/> is equal to the current <see cref="Object"/>.
700
/// <param name="obj">The <see cref="Object"/> to compare with the current <see cref="Object"/>.</param>
701
/// <returns><b>true</b> if the specified <see cref="Object"/> is equal to the current <see cref="Object"/>; otherwise, <b>false</b>.</returns>
702
public override bool Equals(object obj)
704
return ((obj is FIBITMAP) && (this == ((FIBITMAP)obj)));
708
/// Indicates whether the current object is equal to another object of the same type.
710
/// <param name="other">An object to compare with this object.</param>
711
/// <returns><b>true</b> if the current object is equal to the other parameter; otherwise, <b>false</b>.</returns>
712
public bool Equals(FIBITMAP other)
714
return (this == other);
718
/// Compares this instance with a specified <see cref="Object"/>.
720
/// <param name="obj">An object to compare with this instance.</param>
721
/// <returns>A 32-bit signed integer indicating the lexical relationship between the two comparands.</returns>
722
/// <exception cref="ArgumentException"><paramref name="obj"/> is not a <see cref="FIBITMAP"/>.</exception>
723
public int CompareTo(object obj)
729
if (!(obj is FIBITMAP))
731
throw new ArgumentException("obj");
733
return CompareTo((FIBITMAP)obj);
737
/// Compares this instance with a specified <see cref="FIBITMAP"/> object.
739
/// <param name="other">A <see cref="FIBITMAP"/> to compare.</param>
740
/// <returns>A signed number indicating the relative values of this instance
741
/// and <paramref name="other"/>.</returns>
742
public int CompareTo(FIBITMAP other)
744
return this.data.ToInt64().CompareTo(other.data.ToInt64());
749
namespace FreeImageAPI
752
/// The <b>FIMULTIBITMAP</b> structure is a handle to a FreeImage multipaged bimtap.
754
[Serializable, StructLayout(LayoutKind.Sequential)]
755
public struct FIMULTIBITMAP : IComparable, IComparable<FIMULTIBITMAP>, IEquatable<FIMULTIBITMAP>
760
/// A read-only field that represents a handle that has been initialized to zero.
762
public static readonly FIMULTIBITMAP Zero;
765
/// Tests whether two specified <see cref="FIMULTIBITMAP"/> structures are equivalent.
767
/// <param name="left">The <see cref="FIMULTIBITMAP"/> that is to the left of the equality operator.</param>
768
/// <param name="right">The <see cref="FIMULTIBITMAP"/> that is to the right of the equality operator.</param>
770
/// <b>true</b> if the two <see cref="FIMULTIBITMAP"/> structures are equal; otherwise, <b>false</b>.
772
public static bool operator ==(FIMULTIBITMAP left, FIMULTIBITMAP right)
774
return (left.data == right.data);
778
/// Tests whether two specified <see cref="FIMULTIBITMAP"/> structures are different.
780
/// <param name="left">The <see cref="FIMULTIBITMAP"/> that is to the left of the inequality operator.</param>
781
/// <param name="right">The <see cref="FIMULTIBITMAP"/> that is to the right of the inequality operator.</param>
783
/// <b>true</b> if the two <see cref="FIMULTIBITMAP"/> structures are different; otherwise, <b>false</b>.
785
public static bool operator !=(FIMULTIBITMAP left, FIMULTIBITMAP right)
787
return (left.data != right.data);
791
/// Gets whether the handle is a null or not.
793
/// <value><b>true</b> if this <see cref="FIMULTIBITMAP"/> handle is a null;
794
/// otherwise, <b>false</b>.</value>
799
return (data == IntPtr.Zero);
804
/// Sets the handle to <i>null</i>.
806
public void SetNull()
812
/// Converts the numeric value of the <see cref="FIMULTIBITMAP"/> object
813
/// to its equivalent string representation.
815
/// <returns>The string representation of the value of this instance.</returns>
816
public override string ToString()
818
return data.ToString();
822
/// Returns a hash code for this <see cref="FIMULTIBITMAP"/> structure.
824
/// <returns>An integer value that specifies the hash code for this <see cref="FIMULTIBITMAP"/>.</returns>
825
public override int GetHashCode()
827
return data.GetHashCode();
831
/// Determines whether the specified <see cref="Object"/> is equal to the current <see cref="Object"/>.
833
/// <param name="obj">The <see cref="Object"/> to compare with the current <see cref="Object"/>.</param>
834
/// <returns><b>true</b> if the specified <see cref="Object"/> is equal to the current <see cref="Object"/>; otherwise, <b>false</b>.</returns>
835
public override bool Equals(object obj)
837
return ((obj is FIMULTIBITMAP) && (this == ((FIMULTIBITMAP)obj)));
841
/// Indicates whether the current object is equal to another object of the same type.
843
/// <param name="other">An object to compare with this object.</param>
844
/// <returns><b>true</b> if the current object is equal to the other parameter; otherwise, <b>false</b>.</returns>
845
public bool Equals(FIMULTIBITMAP other)
847
return (this == other);
851
/// Compares this instance with a specified <see cref="Object"/>.
853
/// <param name="obj">An object to compare with this instance.</param>
854
/// <returns>A 32-bit signed integer indicating the lexical relationship between the two comparands.</returns>
855
/// <exception cref="ArgumentException"><paramref name="obj"/> is not a <see cref="FIMULTIBITMAP"/>.</exception>
856
public int CompareTo(object obj)
862
if (!(obj is FIMULTIBITMAP))
864
throw new ArgumentException("obj");
866
return CompareTo((FIMULTIBITMAP)obj);
870
/// Compares this instance with a specified <see cref="FIMULTIBITMAP"/> object.
872
/// <param name="other">A <see cref="FIMULTIBITMAP"/> to compare.</param>
873
/// <returns>A signed number indicating the relative values of this instance
874
/// and <paramref name="other"/>.</returns>
875
public int CompareTo(FIMULTIBITMAP other)
877
return this.data.ToInt64().CompareTo(other.data.ToInt64());
882
namespace FreeImageAPI
885
/// The <b>FIMEMORY</b> structure is a handle to an opened memory stream.
887
[Serializable, StructLayout(LayoutKind.Sequential)]
888
public struct FIMEMORY : IComparable, IComparable<FIMEMORY>, IEquatable<FIMEMORY>
893
/// A read-only field that represents a handle that has been initialized to zero.
895
public static readonly FIMEMORY Zero;
898
/// Tests whether two specified <see cref="FIMEMORY"/> structures are equivalent.
900
/// <param name="left">The <see cref="FIMEMORY"/> that is to the left of the equality operator.</param>
901
/// <param name="right">The <see cref="FIMEMORY"/> that is to the right of the equality operator.</param>
903
/// <b>true</b> if the two <see cref="FIMEMORY"/> structures are equal; otherwise, <b>false</b>.
905
public static bool operator ==(FIMEMORY left, FIMEMORY right)
907
return (left.data == right.data);
911
/// Tests whether two specified <see cref="FIMEMORY"/> structures are different.
913
/// <param name="left">The <see cref="FIMEMORY"/> that is to the left of the inequality operator.</param>
914
/// <param name="right">The <see cref="FIMEMORY"/> that is to the right of the inequality operator.</param>
916
/// <b>true</b> if the two <see cref="FIMEMORY"/> structures are different; otherwise, <b>false</b>.
918
public static bool operator !=(FIMEMORY left, FIMEMORY right)
920
return (left.data != right.data);
924
/// Gets whether the pointer is a null pointer or not.
926
/// <value><b>true</b> if this <see cref="FIMEMORY"/> is a null pointer;
927
/// otherwise, <b>false</b>.</value>
932
return (data == IntPtr.Zero);
937
/// Sets the handle to <i>null</i>.
939
public void SetNull()
945
/// Converts the numeric value of the <see cref="FIMEMORY"/> object
946
/// to its equivalent string representation.
948
/// <returns>The string representation of the value of this instance.</returns>
949
public override string ToString()
951
return data.ToString();
955
/// Returns a hash code for this <see cref="FIMEMORY"/> structure.
957
/// <returns>An integer value that specifies the hash code for this <see cref="FIMEMORY"/>.</returns>
958
public override int GetHashCode()
960
return data.GetHashCode();
964
/// Determines whether the specified <see cref="Object"/> is equal to the current <see cref="Object"/>.
966
/// <param name="obj">The <see cref="Object"/> to compare with the current <see cref="Object"/>.</param>
967
/// <returns><b>true</b> if the specified <see cref="Object"/> is equal to the current <see cref="Object"/>; otherwise, <b>false</b>.</returns>
968
public override bool Equals(object obj)
970
return ((obj is FIMEMORY) && (this == ((FIMEMORY)obj)));
974
/// Indicates whether the current object is equal to another object of the same type.
976
/// <param name="other">An object to compare with this object.</param>
977
/// <returns><b>true</b> if the current object is equal to the other parameter; otherwise, <b>false</b>.</returns>
978
public bool Equals(FIMEMORY other)
980
return (this == other);
984
/// Compares this instance with a specified <see cref="Object"/>.
986
/// <param name="obj">An object to compare with this instance.</param>
987
/// <returns>A 32-bit signed integer indicating the lexical relationship between the two comparands.</returns>
988
/// <exception cref="ArgumentException"><paramref name="obj"/> is not a <see cref="FIMEMORY"/>.</exception>
989
public int CompareTo(object obj)
995
if (!(obj is FIMEMORY))
997
throw new ArgumentException("obj");
999
return CompareTo((FIMEMORY)obj);
1003
/// Compares this instance with a specified <see cref="FIMEMORY"/> object.
1005
/// <param name="other">A <see cref="FIMEMORY"/> to compare.</param>
1006
/// <returns>A signed number indicating the relative values of this instance
1007
/// and <paramref name="other"/>.</returns>
1008
public int CompareTo(FIMEMORY other)
1010
return this.data.ToInt64().CompareTo(other.data.ToInt64());
1015
namespace FreeImageAPI
1018
/// The <b>FIMETADATA</b> structure is an unique search handle for metadata search operations.
1021
/// The <b>FIMETADATA</b> structure is usually returned by the
1022
/// <see cref="FreeImageAPI.FreeImage.FindFirstMetadata(FREE_IMAGE_MDMODEL, FIBITMAP, out FITAG)"/>
1023
/// function and then used on subsequent calls to
1024
/// <see cref="FreeImageAPI.FreeImage.FindNextMetadata(FIMETADATA, out FITAG)"/>.
1025
/// When the <b>FIMETADATA</b> handle is no longer used, it needs to be freed by the
1026
/// <see cref="FreeImageAPI.FreeImage.FindCloseMetadata(FIMETADATA)"/> function.
1028
[Serializable, StructLayout(LayoutKind.Sequential)]
1029
public struct FIMETADATA : IComparable, IComparable<FIMETADATA>, IEquatable<FIMETADATA>
1031
private IntPtr data;
1034
/// A read-only field that represents a handle that has been initialized to zero.
1036
public static readonly FIMETADATA Zero;
1039
/// Tests whether two specified <see cref="FIMETADATA"/> structures are equivalent.
1041
/// <param name="left">The <see cref="FIMETADATA"/> that is to the left of the equality operator.</param>
1042
/// <param name="right">The <see cref="FIMETADATA"/> that is to the right of the equality operator.</param>
1044
/// <b>true</b> if the two <see cref="FIMETADATA"/> structures are equal; otherwise, <b>false</b>.
1046
public static bool operator ==(FIMETADATA left, FIMETADATA right)
1048
return (left.data == right.data);
1052
/// Tests whether two specified <see cref="FIMETADATA"/> structures are different.
1054
/// <param name="left">The <see cref="FIMETADATA"/> that is to the left of the inequality operator.</param>
1055
/// <param name="right">The <see cref="FIMETADATA"/> that is to the right of the inequality operator.</param>
1057
/// <b>true</b> if the two <see cref="FIMETADATA"/> structures are different; otherwise, <b>false</b>.
1059
public static bool operator !=(FIMETADATA left, FIMETADATA right)
1061
return (left.data != right.data);
1065
/// Gets whether the pointer is a null pointer or not.
1067
/// <value><b>true</b> if this <see cref="FIMETADATA"/> is a null pointer;
1068
/// otherwise, <b>false</b>.</value>
1073
return (data == IntPtr.Zero);
1078
/// Sets the handle to <i>null</i>.
1080
public void SetNull()
1086
/// Converts the numeric value of the <see cref="FIMETADATA"/> object
1087
/// to its equivalent string representation.
1089
/// <returns>The string representation of the value of this instance.</returns>
1090
public override string ToString()
1092
return data.ToString();
1096
/// Returns a hash code for this <see cref="FIMETADATA"/> structure.
1098
/// <returns>An integer value that specifies the hash code for this <see cref="FIMETADATA"/>.</returns>
1099
public override int GetHashCode()
1101
return data.GetHashCode();
1105
/// Determines whether the specified <see cref="Object"/> is equal to the current <see cref="Object"/>.
1107
/// <param name="obj">The <see cref="Object"/> to compare with the current <see cref="Object"/>.</param>
1108
/// <returns><b>true</b> if the specified <see cref="Object"/> is equal to the current <see cref="Object"/>; otherwise, <b>false</b>.</returns>
1109
public override bool Equals(object obj)
1111
return ((obj is FIMETADATA) && (this == ((FIMETADATA)obj)));
1115
/// Indicates whether the current object is equal to another object of the same type.
1117
/// <param name="other">An object to compare with this object.</param>
1118
/// <returns><b>true</b> if the current object is equal to the other parameter; otherwise, <b>false</b>.</returns>
1119
public bool Equals(FIMETADATA other)
1121
return (this == other);
1125
/// Compares this instance with a specified <see cref="Object"/>.
1127
/// <param name="obj">An object to compare with this instance.</param>
1128
/// <returns>A 32-bit signed integer indicating the lexical relationship between the two comparands.</returns>
1129
/// <exception cref="ArgumentException"><paramref name="obj"/> is not a <see cref="FIMETADATA"/>.</exception>
1130
public int CompareTo(object obj)
1136
if (!(obj is FIMETADATA))
1138
throw new ArgumentException("obj");
1140
return CompareTo((FIMETADATA)obj);
1144
/// Compares this instance with a specified <see cref="FIMETADATA"/> object.
1146
/// <param name="other">A <see cref="FIMETADATA"/> to compare.</param>
1147
/// <returns>A signed number indicating the relative values of this instance
1148
/// and <paramref name="other"/>.</returns>
1149
public int CompareTo(FIMETADATA other)
1151
return this.data.ToInt64().CompareTo(other.data.ToInt64());
1156
namespace FreeImageAPI
1159
/// The <b>FITAG</b> structure is a handle to a FreeImage metadata tag.
1161
[Serializable, StructLayout(LayoutKind.Sequential)]
1162
public struct FITAG : IComparable, IComparable<FITAG>, IEquatable<FITAG>
1164
private IntPtr data;
1167
/// A read-only field that represents a handle that has been initialized to zero.
1169
public static readonly FITAG Zero;
1172
/// Tests whether two specified <see cref="FITAG"/> structures are equivalent.
1174
/// <param name="left">The <see cref="FITAG"/> that is to the left of the equality operator.</param>
1175
/// <param name="right">The <see cref="FITAG"/> that is to the right of the equality operator.</param>
1177
/// <b>true</b> if the two <see cref="FITAG"/> structures are equal; otherwise, <b>false</b>.
1179
public static bool operator ==(FITAG left, FITAG right)
1181
return (left.data == right.data);
1185
/// Tests whether two specified <see cref="FITAG"/> structures are different.
1187
/// <param name="left">The <see cref="FITAG"/> that is to the left of the inequality operator.</param>
1188
/// <param name="right">The <see cref="FITAG"/> that is to the right of the inequality operator.</param>
1190
/// <b>true</b> if the two <see cref="FITAG"/> structures are different; otherwise, <b>false</b>.
1192
public static bool operator !=(FITAG left, FITAG right)
1194
return (left.data != right.data);
1198
/// Gets whether the pointer is a null pointer or not.
1200
/// <value><b>true</b> if this <see cref="FITAG"/> is a null pointer;
1201
/// otherwise, <b>false</b>.</value>
1206
return (data == IntPtr.Zero);
1211
/// Sets the handle to <i>null</i>.
1213
public void SetNull()
1219
/// Converts the numeric value of the <see cref="FITAG"/> object
1220
/// to its equivalent string representation.
1222
/// <returns>The string representation of the value of this instance.</returns>
1223
public override string ToString()
1225
return data.ToString();
1229
/// Returns a hash code for this <see cref="FITAG"/> structure.
1231
/// <returns>An integer value that specifies the hash code for this <see cref="FITAG"/>.</returns>
1232
public override int GetHashCode()
1234
return data.GetHashCode();
1238
/// Determines whether the specified <see cref="Object"/> is equal to the current <see cref="Object"/>.
1240
/// <param name="obj">The <see cref="Object"/> to compare with the current <see cref="Object"/>.</param>
1241
/// <returns><b>true</b> if the specified <see cref="Object"/> is equal to the current <see cref="Object"/>; otherwise, <b>false</b>.</returns>
1242
public override bool Equals(object obj)
1244
return ((obj is FITAG) && (this == ((FITAG)obj)));
1248
/// Indicates whether the current object is equal to another object of the same type.
1250
/// <param name="other">An object to compare with this object.</param>
1251
/// <returns><b>true</b> if the current object is equal to the other parameter; otherwise, <b>false</b>.</returns>
1252
public bool Equals(FITAG other)
1254
return (this == other);
1258
/// Compares this instance with a specified <see cref="Object"/>.
1260
/// <param name="obj">An object to compare with this instance.</param>
1261
/// <returns>A 32-bit signed integer indicating the lexical relationship between the two comparands.</returns>
1262
/// <exception cref="ArgumentException"><paramref name="obj"/> is not a <see cref="FITAG"/>.</exception>
1263
public int CompareTo(object obj)
1269
if (!(obj is FITAG))
1271
throw new ArgumentException("obj");
1273
return CompareTo((FITAG)obj);
1277
/// Compares this instance with a specified <see cref="FITAG"/> object.
1279
/// <param name="other">A <see cref="FITAG"/> to compare.</param>
1280
/// <returns>A signed number indicating the relative values of this instance
1281
/// and <paramref name="other"/>.</returns>
1282
public int CompareTo(FITAG other)
1284
return this.data.ToInt64().CompareTo(other.data.ToInt64());
1289
namespace FreeImageAPI.IO
1292
/// Structure for implementing access to custom handles.
1294
[StructLayout(LayoutKind.Sequential)]
1295
public struct FreeImageIO
1298
/// Delegate to the C++ function <b>fread</b>.
1300
public ReadProc readProc;
1303
/// Delegate to the C++ function <b>fwrite</b>.
1305
public WriteProc writeProc;
1308
/// Delegate to the C++ function <b>fseek</b>.
1310
public SeekProc seekProc;
1313
/// Delegate to the C++ function <b>ftell</b>.
1315
public TellProc tellProc;
1319
namespace FreeImageAPI
1322
/// The <b>RGBQUAD</b> structure describes a color consisting of relative
1323
/// intensities of red, green, blue and alpha value. Each single color
1324
/// component consumes 8 bits and so, takes values in the range from 0 to 255.
1328
/// The <b>RGBQUAD</b> structure provides access to an underlying Win32 <b>RGBQUAD</b>
1329
/// structure. To determine the alpha, red, green or blue component of a color,
1330
/// use the rgbReserved, rgbRed, rgbGreen or rgbBlue fields, respectively.
1332
/// <para>For easy integration of the underlying structure into the .NET framework,
1333
/// the <b>RGBQUAD</b> structure implements implicit conversion operators to
1334
/// convert the represented color to and from the <see cref="System.Drawing.Color"/>
1335
/// type. This makes the <see cref="System.Drawing.Color"/> type a real replacement
1336
/// for the <b>RGBQUAD</b> structure and my be used in all situations which require
1337
/// an <b>RGBQUAD</b> type.
1340
/// Each color component rgbReserved, rgbRed, rgbGreen or rgbBlue of <b>RGBQUAD</b>
1341
/// is translated into it's corresponding color component A, R, G or B of
1342
/// <see cref="System.Drawing.Color"/> by an one-to-one manner and vice versa.
1345
/// <b>Conversion from System.Drawing.Color to RGBQUAD</b>
1347
/// <c>RGBQUAD.component = Color.component</c>
1349
/// <b>Conversion from RGBQUAD to System.Drawing.Color</b>
1351
/// <c>Color.component = RGBQUAD.component</c>
1353
/// The same conversion is also applied when the <see cref="FreeImageAPI.RGBQUAD.Color"/>
1354
/// property or the <see cref="FreeImageAPI.RGBQUAD(System.Drawing.Color)"/> constructor
1359
/// The following code example demonstrates the various conversions between the
1360
/// <b>RGBQUAD</b> structure and the <see cref="System.Drawing.Color"/> structure.
1363
/// // Initialize the structure using a native .NET Color structure.
1364
/// rgbq = new RGBQUAD(Color.Indigo);
1365
/// // Initialize the structure using the implicit operator.
1366
/// rgbq = Color.DarkSeaGreen;
1367
/// // Convert the RGBQUAD instance into a native .NET Color
1368
/// // using its implicit operator.
1369
/// Color color = rgbq;
1370
/// // Using the structure's Color property for converting it
1371
/// // into a native .NET Color.
1372
/// Color another = rgbq.Color;
1375
[Serializable, StructLayout(LayoutKind.Explicit)]
1376
public struct RGBQUAD : IComparable, IComparable<RGBQUAD>, IEquatable<RGBQUAD>
1379
/// The blue color component.
1382
public byte rgbBlue;
1385
/// The green color component.
1388
public byte rgbGreen;
1391
/// The red color component.
1397
/// The alpha color component.
1400
public byte rgbReserved;
1403
/// The color's value.
1406
public uint uintValue;
1409
/// Initializes a new instance based on the specified <see cref="System.Drawing.Color"/>.
1411
/// <param name="color"><see cref="System.Drawing.Color"/> to initialize with.</param>
1412
public RGBQUAD(Color color)
1418
rgbReserved = color.A;
1422
/// Tests whether two specified <see cref="RGBQUAD"/> structures are equivalent.
1424
/// <param name="left">The <see cref="RGBQUAD"/> that is to the left of the equality operator.</param>
1425
/// <param name="right">The <see cref="RGBQUAD"/> that is to the right of the equality operator.</param>
1427
/// <b>true</b> if the two <see cref="RGBQUAD"/> structures are equal; otherwise, <b>false</b>.
1429
public static bool operator ==(RGBQUAD left, RGBQUAD right)
1431
return (left.uintValue == right.uintValue);
1435
/// Tests whether two specified <see cref="RGBQUAD"/> structures are different.
1437
/// <param name="left">The <see cref="RGBQUAD"/> that is to the left of the inequality operator.</param>
1438
/// <param name="right">The <see cref="RGBQUAD"/> that is to the right of the inequality operator.</param>
1440
/// <b>true</b> if the two <see cref="RGBQUAD"/> structures are different; otherwise, <b>false</b>.
1442
public static bool operator !=(RGBQUAD left, RGBQUAD right)
1444
return (left.uintValue != right.uintValue);
1448
/// Converts the value of a <see cref="System.Drawing.Color"/> structure to a <see cref="RGBQUAD"/> structure.
1450
/// <param name="value">A <see cref="System.Drawing.Color"/> structure.</param>
1451
/// <returns>A new instance of <see cref="RGBQUAD"/> initialized to <paramref name="value"/>.</returns>
1452
public static implicit operator RGBQUAD(Color value)
1454
return new RGBQUAD(value);
1458
/// Converts the value of a <see cref="RGBQUAD"/> structure to a Color structure.
1460
/// <param name="value">A <see cref="RGBQUAD"/> structure.</param>
1461
/// <returns>A new instance of <see cref="System.Drawing.Color"/> initialized to <paramref name="value"/>.</returns>
1462
public static implicit operator Color(RGBQUAD value)
1468
/// Converts the value of an <see cref="UInt32"/> structure to a <see cref="RGBQUAD"/> structure.
1470
/// <param name="value">An <see cref="UInt32"/> structure.</param>
1471
/// <returns>A new instance of <see cref="RGBQUAD"/> initialized to <paramref name="value"/>.</returns>
1472
public static implicit operator RGBQUAD(uint value)
1474
RGBQUAD result = new RGBQUAD();
1475
result.uintValue = value;
1480
/// Converts the value of a <see cref="RGBQUAD"/> structure to an <see cref="UInt32"/> structure.
1482
/// <param name="value">A <see cref="RGBQUAD"/> structure.</param>
1483
/// <returns>A new instance of <see cref="RGBQUAD"/> initialized to <paramref name="value"/>.</returns>
1484
public static implicit operator uint(RGBQUAD value)
1486
return value.uintValue;
1490
/// Gets or sets the <see cref="System.Drawing.Color"/> of the structure.
1496
return Color.FromArgb(
1507
rgbReserved = value.A;
1512
/// Converts an array of <see cref="Color"/> into an array of
1513
/// <see cref="RGBQUAD"/>.
1515
/// <param name="array">The array to convert.</param>
1516
/// <returns>An array of <see cref="RGBQUAD"/>.</returns>
1517
public static RGBQUAD[] ToRGBQUAD(Color[] array)
1522
RGBQUAD[] result = new RGBQUAD[array.Length];
1523
for (int i = 0; i < array.Length; i++)
1525
result[i] = array[i];
1531
/// Converts an array of <see cref="RGBQUAD"/> into an array of
1532
/// <see cref="Color"/>.
1534
/// <param name="array">The array to convert.</param>
1535
/// <returns>An array of <see cref="RGBQUAD"/>.</returns>
1536
public static Color[] ToColor(RGBQUAD[] array)
1541
Color[] result = new Color[array.Length];
1542
for (int i = 0; i < array.Length; i++)
1544
result[i] = array[i].Color;
1550
/// Compares this instance with a specified <see cref="Object"/>.
1552
/// <param name="obj">An object to compare with this instance.</param>
1553
/// <returns>A 32-bit signed integer indicating the lexical relationship between the two comparands.</returns>
1554
/// <exception cref="ArgumentException"><paramref name="obj"/> is not a <see cref="RGBQUAD"/>.</exception>
1555
public int CompareTo(object obj)
1561
if (!(obj is RGBQUAD))
1563
throw new ArgumentException("obj");
1565
return CompareTo((RGBQUAD)obj);
1569
/// Compares this instance with a specified <see cref="RGBQUAD"/> object.
1571
/// <param name="other">A <see cref="RGBQUAD"/> to compare.</param>
1572
/// <returns>A signed number indicating the relative values of this instance
1573
/// and <paramref name="other"/>.</returns>
1574
public int CompareTo(RGBQUAD other)
1576
return this.Color.ToArgb().CompareTo(other.Color.ToArgb());
1580
/// Tests whether the specified object is a <see cref="RGBQUAD"/> structure
1581
/// and is equivalent to this <see cref="RGBQUAD"/> structure.
1583
/// <param name="obj">The object to test.</param>
1584
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="RGBQUAD"/> structure
1585
/// equivalent to this <see cref="RGBQUAD"/> structure; otherwise, <b>false</b>.</returns>
1586
public override bool Equals(object obj)
1588
return ((obj is RGBQUAD) && (this == ((RGBQUAD)obj)));
1592
/// Tests whether the specified <see cref="RGBQUAD"/> structure is equivalent to this <see cref="RGBQUAD"/> structure.
1594
/// <param name="other">A <see cref="RGBQUAD"/> structure to compare to this instance.</param>
1595
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="RGBQUAD"/> structure
1596
/// equivalent to this <see cref="RGBQUAD"/> structure; otherwise, <b>false</b>.</returns>
1597
public bool Equals(RGBQUAD other)
1599
return (this == other);
1603
/// Returns a hash code for this <see cref="RGBQUAD"/> structure.
1605
/// <returns>An integer value that specifies the hash code for this <see cref="RGBQUAD"/>.</returns>
1606
public override int GetHashCode()
1608
return base.GetHashCode();
1612
/// Converts the numeric value of the <see cref="RGBQUAD"/> object
1613
/// to its equivalent string representation.
1615
/// <returns>The string representation of the value of this instance.</returns>
1616
public override string ToString()
1618
return FreeImage.ColorToString(Color);
1623
namespace FreeImageAPI
1626
/// The <b>RGBTRIPLE</b> structure describes a color consisting of relative
1627
/// intensities of red, green and blue value. Each single color component
1628
/// consumes 8 bits and so, takes values in the range from 0 to 255.
1632
/// The <b>RGBTRIPLE</b> structure provides access to an underlying Win32 <b>RGBTRIPLE</b>
1633
/// structure. To determine the red, green or blue component of a color, use the
1634
/// rgbtRed, rgbtGreen or rgbtBlue fields, respectively.
1636
/// <para>For easy integration of the underlying structure into the .NET framework,
1637
/// the <b>RGBTRIPLE</b> structure implements implicit conversion operators to
1638
/// convert the represented color to and from the <see cref="System.Drawing.Color"/>
1639
/// type. This makes the <see cref="System.Drawing.Color"/> type a real replacement
1640
/// for the <b>RGBTRIPLE</b> structure and my be used in all situations which require
1641
/// an <b>RGBTRIPLE</b> type.
1644
/// Each of the color components rgbtRed, rgbtGreen or rgbtBlue of <b>RGBTRIPLE</b> is
1645
/// translated into it's corresponding color component R, G or B of
1646
/// <see cref="System.Drawing.Color"/> by an one-to-one manner and vice versa.
1647
/// When converting from <see cref="System.Drawing.Color"/> into <b>RGBTRIPLE</b>, the
1648
/// color's alpha value is ignored and assumed to be 255 when converting from
1649
/// <b>RGBTRIPLE</b> into <see cref="System.Drawing.Color"/>, creating a fully
1653
/// <b>Conversion from System.Drawing.Color to RGBTRIPLE</b>
1655
/// <c>RGBTRIPLE.component = Color.component</c>
1657
/// <b>Conversion from RGBTRIPLE to System.Drawing.Color</b>
1659
/// <c>Color.component = RGBTRIPLE.component</c>
1661
/// The same conversion is also applied when the <see cref="FreeImageAPI.RGBTRIPLE.Color"/>
1662
/// property or the <see cref="FreeImageAPI.RGBTRIPLE(System.Drawing.Color)"/> constructor
1667
/// The following code example demonstrates the various conversions between the
1668
/// <b>RGBTRIPLE</b> structure and the <see cref="System.Drawing.Color"/> structure.
1671
/// // Initialize the structure using a native .NET Color structure.
1672
/// rgbt = new RGBTRIPLE(Color.Indigo);
1673
/// // Initialize the structure using the implicit operator.
1674
/// rgbt = Color.DarkSeaGreen;
1675
/// // Convert the RGBTRIPLE instance into a native .NET Color
1676
/// // using its implicit operator.
1677
/// Color color = rgbt;
1678
/// // Using the structure's Color property for converting it
1679
/// // into a native .NET Color.
1680
/// Color another = rgbt.Color;
1683
[Serializable, StructLayout(LayoutKind.Sequential)]
1684
public struct RGBTRIPLE : IComparable, IComparable<RGBTRIPLE>, IEquatable<RGBTRIPLE>
1687
/// The blue color component.
1689
public byte rgbtBlue;
1692
/// The green color component.
1694
public byte rgbtGreen;
1697
/// The red color component.
1699
public byte rgbtRed;
1702
/// Initializes a new instance based on the specified <see cref="System.Drawing.Color"/>.
1704
/// <param name="color"><see cref="System.Drawing.Color"/> to initialize with.</param>
1705
public RGBTRIPLE(Color color)
1708
rgbtGreen = color.G;
1713
/// Tests whether two specified <see cref="RGBTRIPLE"/> structures are equivalent.
1715
/// <param name="left">The <see cref="RGBTRIPLE"/> that is to the left of the equality operator.</param>
1716
/// <param name="right">The <see cref="RGBTRIPLE"/> that is to the right of the equality operator.</param>
1718
/// <b>true</b> if the two <see cref="RGBTRIPLE"/> structures are equal; otherwise, <b>false</b>.
1720
public static bool operator ==(RGBTRIPLE left, RGBTRIPLE right)
1723
left.rgbtBlue == right.rgbtBlue &&
1724
left.rgbtGreen == right.rgbtGreen &&
1725
left.rgbtRed == right.rgbtRed;
1729
/// Tests whether two specified <see cref="RGBTRIPLE"/> structures are different.
1731
/// <param name="left">The <see cref="RGBTRIPLE"/> that is to the left of the inequality operator.</param>
1732
/// <param name="right">The <see cref="RGBTRIPLE"/> that is to the right of the inequality operator.</param>
1734
/// <b>true</b> if the two <see cref="RGBTRIPLE"/> structures are different; otherwise, <b>false</b>.
1736
public static bool operator !=(RGBTRIPLE left, RGBTRIPLE right)
1738
return !(left == right);
1742
/// Converts the value of a <see cref="System.Drawing.Color"/> structure to a <see cref="RGBTRIPLE"/> structure.
1744
/// <param name="value">A <see cref="System.Drawing.Color"/> structure.</param>
1745
/// <returns>A new instance of <see cref="RGBTRIPLE"/> initialized to <paramref name="value"/>.</returns>
1746
public static implicit operator RGBTRIPLE(Color value)
1748
return new RGBTRIPLE(value);
1752
/// Converts the value of a <see cref="RGBTRIPLE"/> structure to a <see cref="System.Drawing.Color"/> structure.
1754
/// <param name="value">A <see cref="RGBTRIPLE"/> structure.</param>
1755
/// <returns>A new instance of <see cref="System.Drawing.Color"/> initialized to <paramref name="value"/>.</returns>
1756
public static implicit operator Color(RGBTRIPLE value)
1762
/// Converts the value of an <see cref="UInt32"/> structure to a <see cref="RGBTRIPLE"/> structure.
1764
/// <param name="value">An <see cref="UInt32"/> structure.</param>
1765
/// <returns>A new instance of <see cref="RGBTRIPLE"/> initialized to <paramref name="value"/>.</returns>
1766
public static implicit operator RGBTRIPLE(uint value)
1768
RGBTRIPLE result = new RGBTRIPLE();
1769
result.rgbtBlue = (byte)(value & 0xFF);
1770
result.rgbtGreen = (byte)((value >> 8) & 0xFF);
1771
result.rgbtRed = (byte)((value >> 16) & 0xFF);
1776
/// Converts the value of a <see cref="RGBTRIPLE"/> structure to an <see cref="UInt32"/> structure.
1778
/// <param name="value">A <see cref="RGBTRIPLE"/> structure.</param>
1779
/// <returns>A new instance of <see cref="RGBTRIPLE"/> initialized to <paramref name="value"/>.</returns>
1780
public static implicit operator uint(RGBTRIPLE value)
1782
return (uint)((value.rgbtRed << 16) | (value.rgbtGreen << 8) | (value.rgbtBlue));
1786
/// Gets or sets the <see cref="System.Drawing.Color"/> of the structure.
1792
return Color.FromArgb(
1800
rgbtGreen = value.G;
1806
/// Compares this instance with a specified <see cref="Object"/>.
1808
/// <param name="obj">An object to compare with this instance.</param>
1809
/// <returns>A 32-bit signed integer indicating the lexical relationship between the two comparands.</returns>
1810
/// <exception cref="ArgumentException"><paramref name="obj"/> is not a <see cref="RGBTRIPLE"/>.</exception>
1811
public int CompareTo(object obj)
1817
if (!(obj is RGBTRIPLE))
1819
throw new ArgumentException("obj");
1821
return CompareTo((RGBTRIPLE)obj);
1825
/// Compares this instance with a specified <see cref="RGBTRIPLE"/> object.
1827
/// <param name="other">A <see cref="RGBTRIPLE"/> to compare.</param>
1828
/// <returns>A signed number indicating the relative values of this instance
1829
/// and <paramref name="other"/>.</returns>
1830
public int CompareTo(RGBTRIPLE other)
1832
return this.Color.ToArgb().CompareTo(other.Color.ToArgb());
1836
/// Tests whether the specified object is a <see cref="RGBTRIPLE"/> structure
1837
/// and is equivalent to this <see cref="RGBTRIPLE"/> structure.
1839
/// <param name="obj">The object to test.</param>
1840
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="RGBTRIPLE"/> structure
1841
/// equivalent to this <see cref="RGBTRIPLE"/> structure; otherwise, <b>false</b>.</returns>
1842
public override bool Equals(object obj)
1844
return ((obj is RGBTRIPLE) && (this == ((RGBTRIPLE)obj)));
1848
/// Tests whether the specified <see cref="RGBTRIPLE"/> structure is equivalent to this
1849
/// <see cref="RGBTRIPLE"/> structure.
1851
/// <param name="other">A <see cref="RGBTRIPLE"/> structure to compare to this instance.</param>
1852
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="RGBTRIPLE"/> structure
1853
/// equivalent to this <see cref="RGBTRIPLE"/> structure; otherwise, <b>false</b>.</returns>
1854
public bool Equals(RGBTRIPLE other)
1856
return (this == other);
1860
/// Returns a hash code for this <see cref="RGBTRIPLE"/> structure.
1862
/// <returns>An integer value that specifies the hash code for this <see cref="RGBTRIPLE"/>.</returns>
1863
public override int GetHashCode()
1865
return base.GetHashCode();
1869
/// Converts the numeric value of the <see cref="RGBTRIPLE"/> object
1870
/// to its equivalent string representation.
1872
/// <returns>The string representation of the value of this instance.</returns>
1873
public override string ToString()
1875
return FreeImage.ColorToString(Color);
1880
namespace FreeImageAPI
1883
/// The <b>FIRGBA16</b> structure describes a color consisting of relative
1884
/// intensities of red, green, blue and alpha value. Each single color
1885
/// component consumes 16 bits and so, takes values in the range from 0 to 65535.
1889
/// The <b>FIRGBA16</b> structure provides access to an underlying FreeImage <b>FIRGBA16</b>
1890
/// structure. To determine the alpha, red, green or blue component of a color,
1891
/// use the alpha, red, green or blue fields, respectively.
1893
/// <para>For easy integration of the underlying structure into the .NET framework,
1894
/// the <b>FIRGBA16</b> structure implements implicit conversion operators to
1895
/// convert the represented color to and from the <see cref="System.Drawing.Color"/>
1896
/// type. This makes the <see cref="System.Drawing.Color"/> type a real replacement
1897
/// for the <b>FIRGBA16</b> structure and my be used in all situations which require
1898
/// an <b>FIRGBA16</b> type.
1901
/// Each color component alpha, red, green or blue of <b>FIRGBA16</b>
1902
/// is translated into it's corresponding color component A, R, G or B of
1903
/// <see cref="System.Drawing.Color"/> by an 8 bit right shift and vice versa.
1906
/// <b>Conversion from System.Drawing.Color to FIRGBA16</b>
1908
/// <c>FIRGBA16.component = Color.component << 8</c>
1910
/// <b>Conversion from FIRGBA16 to System.Drawing.Color</b>
1912
/// <c>Color.component = FIRGBA16.component >> 8</c>
1914
/// The same conversion is also applied when the <see cref="FreeImageAPI.FIRGBA16.Color"/>
1915
/// property or the <see cref="FreeImageAPI.FIRGBA16(System.Drawing.Color)"/> constructor
1920
/// The following code example demonstrates the various conversions between the
1921
/// <b>FIRGBA16</b> structure and the <see cref="System.Drawing.Color"/> structure.
1923
/// FIRGBA16 firgba16;
1924
/// // Initialize the structure using a native .NET Color structure.
1925
/// firgba16 = new FIRGBA16(Color.Indigo);
1926
/// // Initialize the structure using the implicit operator.
1927
/// firgba16 = Color.DarkSeaGreen;
1928
/// // Convert the FIRGBA16 instance into a native .NET Color
1929
/// // using its implicit operator.
1930
/// Color color = firgba16;
1931
/// // Using the structure's Color property for converting it
1932
/// // into a native .NET Color.
1933
/// Color another = firgba16.Color;
1936
[Serializable, StructLayout(LayoutKind.Sequential)]
1937
public struct FIRGBA16 : IComparable, IComparable<FIRGBA16>, IEquatable<FIRGBA16>
1940
/// The red color component.
1945
/// The green color component.
1947
public ushort green;
1950
/// The blue color component.
1955
/// The alpha color component.
1957
public ushort alpha;
1960
/// Initializes a new instance based on the specified <see cref="System.Drawing.Color"/>.
1962
/// <param name="color"><see cref="System.Drawing.Color"/> to initialize with.</param>
1963
public FIRGBA16(Color color)
1965
red = (ushort)(color.R << 8);
1966
green = (ushort)(color.G << 8);
1967
blue = (ushort)(color.B << 8);
1968
alpha = (ushort)(color.A << 8);
1972
/// Tests whether two specified <see cref="FIRGBA16"/> structures are equivalent.
1974
/// <param name="left">The <see cref="FIRGBA16"/> that is to the left of the equality operator.</param>
1975
/// <param name="right">The <see cref="FIRGBA16"/> that is to the right of the equality operator.</param>
1977
/// <b>true</b> if the two <see cref="FIRGBA16"/> structures are equal; otherwise, <b>false</b>.
1979
public static bool operator ==(FIRGBA16 left, FIRGBA16 right)
1982
((left.alpha == right.alpha) &&
1983
(left.blue == right.blue) &&
1984
(left.green == right.green) &&
1985
(left.red == right.red));
1989
/// Tests whether two specified <see cref="FIRGBA16"/> structures are different.
1991
/// <param name="left">The <see cref="FIRGBA16"/> that is to the left of the inequality operator.</param>
1992
/// <param name="right">The <see cref="FIRGBA16"/> that is to the right of the inequality operator.</param>
1994
/// <b>true</b> if the two <see cref="FIRGBA16"/> structures are different; otherwise, <b>false</b>.
1996
public static bool operator !=(FIRGBA16 left, FIRGBA16 right)
1998
return !(left == right);
2002
/// Converts the value of a <see cref="System.Drawing.Color"/> structure to a <see cref="FIRGBA16"/> structure.
2004
/// <param name="value">A <see cref="System.Drawing.Color"/> structure.</param>
2005
/// <returns>A new instance of <see cref="FIRGBA16"/> initialized to <paramref name="value"/>.</returns>
2006
public static implicit operator FIRGBA16(Color value)
2008
return new FIRGBA16(value);
2012
/// Converts the value of a <see cref="FIRGBA16"/> structure to a <see cref="System.Drawing.Color"/> structure.
2014
/// <param name="value">A <see cref="FIRGBA16"/> structure.</param>
2015
/// <returns>A new instance of <see cref="System.Drawing.Color"/> initialized to <paramref name="value"/>.</returns>
2016
public static implicit operator Color(FIRGBA16 value)
2022
/// Gets or sets the <see cref="System.Drawing.Color"/> of the structure.
2028
return Color.FromArgb((alpha >> 8), (red >> 8), (green >> 8), (blue >> 8));
2032
red = (ushort)(value.R << 8);
2033
green = (ushort)(value.G << 8);
2034
blue = (ushort)(value.B << 8);
2035
alpha = (ushort)(value.A << 8);
2040
/// Compares this instance with a specified <see cref="Object"/>.
2042
/// <param name="obj">An object to compare with this instance.</param>
2043
/// <returns>A 32-bit signed integer indicating the lexical relationship between the two comparands.</returns>
2044
/// <exception cref="ArgumentException"><paramref name="obj"/> is not a <see cref="FIRGBA16"/>.</exception>
2045
public int CompareTo(object obj)
2051
if (!(obj is FIRGBA16))
2053
throw new ArgumentException("obj");
2055
return CompareTo((FIRGBA16)obj);
2059
/// Compares this instance with a specified <see cref="FIRGBA16"/> object.
2061
/// <param name="other">A <see cref="FIRGBA16"/> to compare.</param>
2062
/// <returns>A signed number indicating the relative values of this instance
2063
/// and <paramref name="other"/>.</returns>
2064
public int CompareTo(FIRGBA16 other)
2066
return this.Color.ToArgb().CompareTo(other.Color.ToArgb());
2070
/// Tests whether the specified object is a <see cref="FIRGBA16"/> structure
2071
/// and is equivalent to this <see cref="FIRGBA16"/> structure.
2073
/// <param name="obj">The object to test.</param>
2074
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="FIRGBA16"/> structure
2075
/// equivalent to this <see cref="FIRGBA16"/> structure; otherwise, <b>false</b>.</returns>
2076
public override bool Equals(object obj)
2078
return ((obj is FIRGBA16) && (this == ((FIRGBA16)obj)));
2082
/// Tests whether the specified <see cref="FIRGBA16"/> structure is equivalent to this <see cref="FIRGBA16"/> structure.
2084
/// <param name="other">A <see cref="FIRGBA16"/> structure to compare to this instance.</param>
2085
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="FIRGBA16"/> structure
2086
/// equivalent to this <see cref="FIRGBA16"/> structure; otherwise, <b>false</b>.</returns>
2087
public bool Equals(FIRGBA16 other)
2089
return (this == other);
2093
/// Returns a hash code for this <see cref="FIRGBA16"/> structure.
2095
/// <returns>An integer value that specifies the hash code for this <see cref="FIRGBA16"/>.</returns>
2096
public override int GetHashCode()
2098
return base.GetHashCode();
2102
/// Converts the numeric value of the <see cref="FIRGBA16"/> object
2103
/// to its equivalent string representation.
2105
/// <returns>The string representation of the value of this instance.</returns>
2106
public override string ToString()
2108
return FreeImage.ColorToString(Color);
2113
namespace FreeImageAPI
2116
/// The <b>FIRGB16</b> structure describes a color consisting of relative
2117
/// intensities of red, green, blue and alpha value. Each single color
2118
/// component consumes 16 bits and so, takes values in the range from 0 to 65535.
2122
/// The <b>FIRGB16</b> structure provides access to an underlying FreeImage <b>FIRGB16</b>
2123
/// structure. To determine the red, green or blue component of a color,
2124
/// use the red, green or blue fields, respectively.
2126
/// <para>For easy integration of the underlying structure into the .NET framework,
2127
/// the <b>FIRGB16</b> structure implements implicit conversion operators to
2128
/// convert the represented color to and from the <see cref="System.Drawing.Color"/>
2129
/// type. This makes the <see cref="System.Drawing.Color"/> type a real replacement
2130
/// for the <b>FIRGB16</b> structure and my be used in all situations which require
2131
/// an <b>FIRGB16</b> type.
2134
/// Each color component red, green or blue of <b>FIRGB16</b> is translated into
2135
/// it's corresponding color component R, G or B of
2136
/// <see cref="System.Drawing.Color"/> by right shifting 8 bits and shifting left 8 bits for the reverse conversion.
2137
/// When converting from <see cref="System.Drawing.Color"/> into <b>FIRGB16</b>, the
2138
/// color's alpha value is ignored and assumed to be 255 when converting from
2139
/// <b>FIRGB16</b> into <see cref="System.Drawing.Color"/>, creating a fully
2143
/// <b>Conversion from System.Drawing.Color to FIRGB16</b>
2145
/// <c>FIRGB16.component = Color.component << 8</c>
2147
/// <b>Conversion from FIRGB16 to System.Drawing.Color</b>
2149
/// <c>Color.component = FIRGB16.component >> 8</c>
2151
/// The same conversion is also applied when the <see cref="FreeImageAPI.FIRGB16.Color"/>
2152
/// property or the <see cref="FreeImageAPI.FIRGB16(System.Drawing.Color)"/> constructor
2157
/// The following code example demonstrates the various conversions between the
2158
/// <b>FIRGB16</b> structure and the <see cref="System.Drawing.Color"/> structure.
2160
/// FIRGB16 firgb16;
2161
/// // Initialize the structure using a native .NET Color structure.
2162
/// firgb16 = new FIRGBA16(Color.Indigo);
2163
/// // Initialize the structure using the implicit operator.
2164
/// firgb16 = Color.DarkSeaGreen;
2165
/// // Convert the FIRGB16 instance into a native .NET Color
2166
/// // using its implicit operator.
2167
/// Color color = firgb16;
2168
/// // Using the structure's Color property for converting it
2169
/// // into a native .NET Color.
2170
/// Color another = firgb16.Color;
2173
[Serializable, StructLayout(LayoutKind.Sequential)]
2174
public struct FIRGB16 : IComparable, IComparable<FIRGB16>, IEquatable<FIRGB16>
2177
/// The red color component.
2182
/// The green color component.
2184
public ushort green;
2187
/// The blue color component.
2192
/// Initializes a new instance based on the specified <see cref="System.Drawing.Color"/>.
2194
/// <param name="color"><see cref="System.Drawing.Color"/> to initialize with.</param>
2195
public FIRGB16(Color color)
2197
red = (ushort)(color.R << 8);
2198
green = (ushort)(color.G << 8);
2199
blue = (ushort)(color.B << 8);
2203
/// Tests whether two specified <see cref="FIRGB16"/> structures are equivalent.
2205
/// <param name="left">The <see cref="FIRGB16"/> that is to the left of the equality operator.</param>
2206
/// <param name="right">The <see cref="FIRGB16"/> that is to the right of the equality operator.</param>
2208
/// <b>true</b> if the two <see cref="FIRGB16"/> structures are equal; otherwise, <b>false</b>.
2210
public static bool operator ==(FIRGB16 left, FIRGB16 right)
2213
((left.blue == right.blue) &&
2214
(left.green == right.green) &&
2215
(left.red == right.red));
2219
/// Tests whether two specified <see cref="FIRGB16"/> structures are different.
2221
/// <param name="left">The <see cref="FIRGB16"/> that is to the left of the inequality operator.</param>
2222
/// <param name="right">The <see cref="FIRGB16"/> that is to the right of the inequality operator.</param>
2224
/// <b>true</b> if the two <see cref="FIRGB16"/> structures are different; otherwise, <b>false</b>.
2226
public static bool operator !=(FIRGB16 left, FIRGB16 right)
2228
return !(left == right);
2232
/// Converts the value of a <see cref="System.Drawing.Color"/> structure to a <see cref="FIRGB16"/> structure.
2234
/// <param name="value">A <see cref="System.Drawing.Color"/> structure.</param>
2235
/// <returns>A new instance of <see cref="FIRGB16"/> initialized to <paramref name="value"/>.</returns>
2236
public static implicit operator FIRGB16(Color value)
2238
return new FIRGB16(value);
2242
/// Converts the value of a <see cref="FIRGB16"/> structure to a <see cref="System.Drawing.Color"/> structure.
2244
/// <param name="value">A <see cref="FIRGB16"/> structure.</param>
2245
/// <returns>A new instance of <see cref="System.Drawing.Color"/> initialized to <paramref name="value"/>.</returns>
2246
public static implicit operator Color(FIRGB16 value)
2252
/// Gets or sets the <see cref="System.Drawing.Color"/> of the structure.
2258
return Color.FromArgb((red >> 8), (green >> 8), (blue >> 8));
2262
red = (ushort)(value.R << 8);
2263
green = (ushort)(value.G << 8);
2264
blue = (ushort)(value.B << 8);
2269
/// Compares this instance with a specified <see cref="Object"/>.
2271
/// <param name="obj">An object to compare with this instance.</param>
2272
/// <returns>A 32-bit signed integer indicating the lexical relationship between the two comparands.</returns>
2273
/// <exception cref="ArgumentException"><paramref name="obj"/> is not a <see cref="FIRGB16"/>.</exception>
2274
public int CompareTo(object obj)
2280
if (!(obj is FIRGB16))
2282
throw new ArgumentException("obj");
2284
return CompareTo((FIRGB16)obj);
2288
/// Compares this instance with a specified <see cref="FIRGB16"/> object.
2290
/// <param name="other">A <see cref="FIRGB16"/> to compare.</param>
2291
/// <returns>A signed number indicating the relative values of this instance
2292
/// and <paramref name="other"/>.</returns>
2293
public int CompareTo(FIRGB16 other)
2295
return this.Color.ToArgb().CompareTo(other.Color.ToArgb());
2299
/// Tests whether the specified object is a <see cref="FIRGB16"/> structure
2300
/// and is equivalent to this <see cref="FIRGB16"/> structure.
2302
/// <param name="obj">The object to test.</param>
2303
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="FIRGB16"/> structure
2304
/// equivalent to this <see cref="FIRGB16"/> structure; otherwise, <b>false</b>.</returns>
2305
public override bool Equals(object obj)
2307
return ((obj is FIRGB16) && (this == ((FIRGB16)obj)));
2311
/// Tests whether the specified <see cref="FIRGB16"/> structure is equivalent to this <see cref="FIRGB16"/> structure.
2313
/// <param name="other">A <see cref="FIRGB16"/> structure to compare to this instance.</param>
2314
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="FIRGB16"/> structure
2315
/// equivalent to this <see cref="FIRGB16"/> structure; otherwise, <b>false</b>.</returns>
2316
public bool Equals(FIRGB16 other)
2318
return (this == other);
2322
/// Returns a hash code for this <see cref="FIRGB16"/> structure.
2324
/// <returns>An integer value that specifies the hash code for this <see cref="FIRGB16"/>.</returns>
2325
public override int GetHashCode()
2327
return base.GetHashCode();
2331
/// Converts the numeric value of the <see cref="FIRGB16"/> object
2332
/// to its equivalent string representation.
2334
/// <returns>The string representation of the value of this instance.</returns>
2335
public override string ToString()
2337
return FreeImage.ColorToString(Color);
2342
namespace FreeImageAPI
2345
/// The <b>FIRGBAF</b> structure describes a color consisting of relative
2346
/// intensities of red, green, blue and alpha value. Each single color
2347
/// component consumes 32 bits and takes values in the range from 0 to 1.
2351
/// The <b>FIRGBAF</b> structure provides access to an underlying FreeImage <b>FIRGBAF</b>
2352
/// structure. To determine the alpha, red, green or blue component of a color,
2353
/// use the alpha, red, green or blue fields, respectively.
2355
/// <para>For easy integration of the underlying structure into the .NET framework,
2356
/// the <b>FIRGBAF</b> structure implements implicit conversion operators to
2357
/// convert the represented color to and from the <see cref="System.Drawing.Color"/>
2358
/// type. This makes the <see cref="System.Drawing.Color"/> type a real replacement
2359
/// for the <b>FIRGBAF</b> structure and my be used in all situations which require
2360
/// an <b>FIRGBAF</b> type.
2363
/// Each color component alpha, red, green or blue of <b>FIRGBAF</b> is translated
2364
/// into it's corresponding color component A, R, G or B of
2365
/// <see cref="System.Drawing.Color"/> by linearly mapping the values of one range
2366
/// into the other range and vice versa.
2369
/// <b>Conversion from System.Drawing.Color to FIRGBAF</b>
2371
/// <c>FIRGBAF.component = (float)Color.component / 255f</c>
2373
/// <b>Conversion from FIRGBAF to System.Drawing.Color</b>
2375
/// <c>Color.component = (int)(FIRGBAF.component * 255f)</c>
2377
/// The same conversion is also applied when the <see cref="FreeImageAPI.FIRGBAF.Color"/>
2378
/// property or the <see cref="FreeImageAPI.FIRGBAF(System.Drawing.Color)"/> constructor
2383
/// The following code example demonstrates the various conversions between the
2384
/// <b>FIRGBAF</b> structure and the <see cref="System.Drawing.Color"/> structure.
2386
/// FIRGBAF firgbaf;
2387
/// // Initialize the structure using a native .NET Color structure.
2388
/// firgbaf = new FIRGBAF(Color.Indigo);
2389
/// // Initialize the structure using the implicit operator.
2390
/// firgbaf = Color.DarkSeaGreen;
2391
/// // Convert the FIRGBAF instance into a native .NET Color
2392
/// // using its implicit operator.
2393
/// Color color = firgbaf;
2394
/// // Using the structure's Color property for converting it
2395
/// // into a native .NET Color.
2396
/// Color another = firgbaf.Color;
2399
[Serializable, StructLayout(LayoutKind.Sequential)]
2400
public struct FIRGBAF : IComparable, IComparable<FIRGBAF>, IEquatable<FIRGBAF>
2403
/// The red color component.
2408
/// The green color component.
2413
/// The blue color component.
2418
/// The alpha color component.
2423
/// Initializes a new instance based on the specified <see cref="System.Drawing.Color"/>.
2425
/// <param name="color"><see cref="System.Drawing.Color"/> to initialize with.</param>
2426
public FIRGBAF(Color color)
2428
red = (float)color.R / 255f;
2429
green = (float)color.G / 255f;
2430
blue = (float)color.B / 255f;
2431
alpha = (float)color.A / 255f;
2435
/// Tests whether two specified <see cref="FIRGBAF"/> structures are equivalent.
2437
/// <param name="left">The <see cref="FIRGBAF"/> that is to the left of the equality operator.</param>
2438
/// <param name="right">The <see cref="FIRGBAF"/> that is to the right of the equality operator.</param>
2440
/// <b>true</b> if the two <see cref="FIRGBAF"/> structures are equal; otherwise, <b>false</b>.
2442
public static bool operator ==(FIRGBAF left, FIRGBAF right)
2445
((left.alpha == right.alpha) &&
2446
(left.blue == right.blue) &&
2447
(left.green == right.green) &&
2448
(left.red == right.red));
2452
/// Tests whether two specified <see cref="FIRGBAF"/> structures are different.
2454
/// <param name="left">The <see cref="FIRGBAF"/> that is to the left of the inequality operator.</param>
2455
/// <param name="right">The <see cref="FIRGBAF"/> that is to the right of the inequality operator.</param>
2457
/// <b>true</b> if the two <see cref="FIRGBAF"/> structures are different; otherwise, <b>false</b>.
2459
public static bool operator !=(FIRGBAF left, FIRGBAF right)
2461
return !(left == right);
2465
/// Converts the value of a <see cref="System.Drawing.Color"/> structure to a <see cref="FIRGBAF"/> structure.
2467
/// <param name="value">A <see cref="System.Drawing.Color"/> structure.</param>
2468
/// <returns>A new instance of <see cref="FIRGBAF"/> initialized to <paramref name="value"/>.</returns>
2469
public static implicit operator FIRGBAF(Color value)
2471
return new FIRGBAF(value);
2475
/// Converts the value of a <see cref="FIRGBAF"/> structure to a <see cref="System.Drawing.Color"/> structure.
2477
/// <param name="value">A <see cref="FIRGBAF"/> structure.</param>
2478
/// <returns>A new instance of <see cref="System.Drawing.Color"/> initialized to <paramref name="value"/>.</returns>
2479
public static implicit operator Color(FIRGBAF value)
2485
/// Gets or sets the <see cref="System.Drawing.Color"/> of the structure.
2491
return Color.FromArgb(
2492
(int)(alpha * 255f),
2494
(int)(green * 255f),
2495
(int)(blue * 255f));
2499
red = (float)value.R / 255f;
2500
green = (float)value.G / 255f;
2501
blue = (float)value.B / 255f;
2502
alpha = (float)value.A / 255f;
2507
/// Compares this instance with a specified <see cref="Object"/>.
2509
/// <param name="obj">An object to compare with this instance.</param>
2510
/// <returns>A 32-bit signed integer indicating the lexical relationship between the two comparands.</returns>
2511
/// <exception cref="ArgumentException"><paramref name="obj"/> is not a <see cref="FIRGBAF"/>.</exception>
2512
public int CompareTo(object obj)
2518
if (!(obj is FIRGBAF))
2520
throw new ArgumentException("obj");
2522
return CompareTo((FIRGBAF)obj);
2526
/// Compares this instance with a specified <see cref="FIRGBAF"/> object.
2528
/// <param name="other">A <see cref="FIRGBAF"/> to compare.</param>
2529
/// <returns>A signed number indicating the relative values of this instance
2530
/// and <paramref name="other"/>.</returns>
2531
public int CompareTo(FIRGBAF other)
2533
return this.Color.ToArgb().CompareTo(other.Color.ToArgb());
2537
/// Tests whether the specified object is a <see cref="FIRGBAF"/> structure
2538
/// and is equivalent to this <see cref="FIRGBAF"/> structure.
2540
/// <param name="obj">The object to test.</param>
2541
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="FIRGBAF"/> structure
2542
/// equivalent to this <see cref="FIRGBAF"/> structure; otherwise, <b>false</b>.</returns>
2543
public override bool Equals(object obj)
2545
return ((obj is FIRGBAF) && (this == ((FIRGBAF)obj)));
2549
/// Tests whether the specified <see cref="FIRGBAF"/> structure is equivalent to this <see cref="FIRGBAF"/> structure.
2551
/// <param name="other">A <see cref="FIRGBAF"/> structure to compare to this instance.</param>
2552
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="FIRGBAF"/> structure
2553
/// equivalent to this <see cref="FIRGBAF"/> structure; otherwise, <b>false</b>.</returns>
2554
public bool Equals(FIRGBAF other)
2556
return (this == other);
2560
/// Returns a hash code for this <see cref="FIRGBAF"/> structure.
2562
/// <returns>An integer value that specifies the hash code for this <see cref="FIRGBAF"/>.</returns>
2563
public override int GetHashCode()
2565
return base.GetHashCode();
2569
/// Converts the numeric value of the <see cref="FIRGBAF"/> object
2570
/// to its equivalent string representation.
2572
/// <returns>The string representation of the value of this instance.</returns>
2573
public override string ToString()
2575
return FreeImage.ColorToString(Color);
2580
namespace FreeImageAPI
2583
/// The <b>FIRGBF</b> structure describes a color consisting of relative
2584
/// intensities of red, green, blue and alpha value. Each single color
2585
/// component consumes 32 bits and takes values in the range from 0 to 1.
2589
/// The <b>FIRGBF</b> structure provides access to an underlying FreeImage <b>FIRGBF</b>
2590
/// structure. To determine the red, green or blue component of a color, use the
2591
/// red, green or blue fields, respectively.
2593
/// <para>For easy integration of the underlying structure into the .NET framework,
2594
/// the <b>FIRGBF</b> structure implements implicit conversion operators to
2595
/// convert the represented color to and from the <see cref="System.Drawing.Color"/>
2596
/// type. This makes the <see cref="System.Drawing.Color"/> type a real replacement
2597
/// for the <b>FIRGBF</b> structure and my be used in all situations which require
2598
/// an <b>FIRGBF</b> type.
2601
/// Each color component alpha, red, green or blue of <b>FIRGBF</b> is translated
2602
/// into it's corresponding color component A, R, G or B of
2603
/// <see cref="System.Drawing.Color"/> by linearly mapping the values of one range
2604
/// into the other range and vice versa.
2605
/// When converting from <see cref="System.Drawing.Color"/> into <b>FIRGBF</b>, the
2606
/// color's alpha value is ignored and assumed to be 255 when converting from
2607
/// <b>FIRGBF</b> into <see cref="System.Drawing.Color"/>, creating a fully
2611
/// <b>Conversion from System.Drawing.Color to FIRGBF</b>
2613
/// <c>FIRGBF.component = (float)Color.component / 255f</c>
2615
/// <b>Conversion from FIRGBF to System.Drawing.Color</b>
2617
/// <c>Color.component = (int)(FIRGBF.component * 255f)</c>
2619
/// The same conversion is also applied when the <see cref="FreeImageAPI.FIRGBF.Color"/>
2620
/// property or the <see cref="FreeImageAPI.FIRGBF(System.Drawing.Color)"/> constructor
2625
/// The following code example demonstrates the various conversions between the
2626
/// <b>FIRGBF</b> structure and the <see cref="System.Drawing.Color"/> structure.
2629
/// // Initialize the structure using a native .NET Color structure.
2630
/// firgbf = new FIRGBF(Color.Indigo);
2631
/// // Initialize the structure using the implicit operator.
2632
/// firgbf = Color.DarkSeaGreen;
2633
/// // Convert the FIRGBF instance into a native .NET Color
2634
/// // using its implicit operator.
2635
/// Color color = firgbf;
2636
/// // Using the structure's Color property for converting it
2637
/// // into a native .NET Color.
2638
/// Color another = firgbf.Color;
2641
[Serializable, StructLayout(LayoutKind.Sequential)]
2642
public struct FIRGBF : IComparable, IComparable<FIRGBF>, IEquatable<FIRGBF>
2645
/// The red color component.
2650
/// The green color component.
2655
/// The blue color component.
2660
/// Initializes a new instance based on the specified <see cref="System.Drawing.Color"/>.
2662
/// <param name="color"><see cref="System.Drawing.Color"/> to initialize with.</param>
2663
public FIRGBF(Color color)
2665
red = (float)color.R / 255f;
2666
green = (float)color.G / 255f;
2667
blue = (float)color.B / 255f;
2671
/// Tests whether two specified <see cref="FIRGBF"/> structures are equivalent.
2673
/// <param name="left">The <see cref="FIRGBF"/> that is to the left of the equality operator.</param>
2674
/// <param name="right">The <see cref="FIRGBF"/> that is to the right of the equality operator.</param>
2676
/// <b>true</b> if the two <see cref="FIRGBF"/> structures are equal; otherwise, <b>false</b>.
2678
public static bool operator ==(FIRGBF left, FIRGBF right)
2681
((left.blue == right.blue) &&
2682
(left.green == right.green) &&
2683
(left.red == right.red));
2687
/// Tests whether two specified <see cref="FIRGBF"/> structures are different.
2689
/// <param name="left">The <see cref="FIRGBF"/> that is to the left of the inequality operator.</param>
2690
/// <param name="right">The <see cref="FIRGBF"/> that is to the right of the inequality operator.</param>
2692
/// <b>true</b> if the two <see cref="FIRGBF"/> structures are different; otherwise, <b>false</b>.
2694
public static bool operator !=(FIRGBF left, FIRGBF right)
2696
return !(left == right);
2700
/// Converts the value of a <see cref="System.Drawing.Color"/> structure to a <see cref="FIRGBF"/> structure.
2702
/// <param name="value">A <see cref="System.Drawing.Color"/> structure.</param>
2703
/// <returns>A new instance of <see cref="FIRGBF"/> initialized to <paramref name="value"/>.</returns>
2704
public static implicit operator FIRGBF(Color value)
2706
return new FIRGBF(value);
2710
/// Converts the value of a <see cref="FIRGBF"/> structure to a <see cref="System.Drawing.Color"/> structure.
2712
/// <param name="value">A <see cref="FIRGBF"/> structure.</param>
2713
/// <returns>A new instance of <see cref="System.Drawing.Color"/> initialized to <paramref name="value"/>.</returns>
2714
public static implicit operator Color(FIRGBF value)
2720
/// Gets or sets the <see cref="System.Drawing.Color"/> of the structure.
2726
return Color.FromArgb(
2728
(int)(green * 255f),
2729
(int)(blue * 255f));
2733
red = (float)value.R / 255f;
2734
green = (float)value.G / 255f;
2735
blue = (float)value.B / 255f;
2740
/// Compares this instance with a specified <see cref="Object"/>.
2742
/// <param name="obj">An object to compare with this instance.</param>
2743
/// <returns>A 32-bit signed integer indicating the lexical relationship between the two comparands.</returns>
2744
/// <exception cref="ArgumentException"><paramref name="obj"/> is not a <see cref="FIRGBF"/>.</exception>
2745
public int CompareTo(object obj)
2751
if (!(obj is FIRGBF))
2753
throw new ArgumentException("obj");
2755
return CompareTo((FIRGBF)obj);
2759
/// Compares this instance with a specified <see cref="FIRGBF"/> object.
2761
/// <param name="other">A <see cref="FIRGBF"/> to compare.</param>
2762
/// <returns>A signed number indicating the relative values of this instance
2763
/// and <paramref name="other"/>.</returns>
2764
public int CompareTo(FIRGBF other)
2766
return this.Color.ToArgb().CompareTo(other.Color.ToArgb());
2770
/// Tests whether the specified object is a <see cref="FIRGBF"/> structure
2771
/// and is equivalent to this <see cref="FIRGBF"/> structure.
2773
/// <param name="obj">The object to test.</param>
2774
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="FIRGBF"/> structure
2775
/// equivalent to this <see cref="FIRGBF"/> structure; otherwise, <b>false</b>.</returns>
2776
public override bool Equals(object obj)
2778
return ((obj is FIRGBF) && (this == ((FIRGBF)obj)));
2782
/// Tests whether the specified <see cref="FIRGBF"/> structure is equivalent to this <see cref="FIRGBF"/> structure.
2784
/// <param name="other">A <see cref="FIRGBF"/> structure to compare to this instance.</param>
2785
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="FIRGBF"/> structure
2786
/// equivalent to this <see cref="FIRGBF"/> structure; otherwise, <b>false</b>.</returns>
2787
public bool Equals(FIRGBF other)
2789
return (this == other);
2793
/// Returns a hash code for this <see cref="FIRGBF"/> structure.
2795
/// <returns>An integer value that specifies the hash code for this <see cref="FIRGBF"/>.</returns>
2796
public override int GetHashCode()
2798
return base.GetHashCode();
2803
/// Converts the numeric value of the <see cref="FIRGBF"/> object
2804
/// to its equivalent string representation.
2806
/// <returns>The string representation of the value of this instance.</returns>
2807
public override string ToString()
2809
return FreeImage.ColorToString(Color);
2814
namespace FreeImageAPI
2817
/// The <b>FICOMPLEX</b> structure describes a color consisting of a real and an imaginary part.
2818
/// Each part is using 4 bytes of data.
2820
[Serializable, StructLayout(LayoutKind.Sequential)]
2821
public struct FICOMPLEX : IComparable, IComparable<FICOMPLEX>, IEquatable<FICOMPLEX>
2824
/// Real part of the color.
2829
/// Imaginary part of the color.
2834
/// Tests whether two specified <see cref="FICOMPLEX"/> structures are equivalent.
2836
/// <param name="left">The <see cref="FICOMPLEX"/> that is to the left of the equality operator.</param>
2837
/// <param name="right">The <see cref="FICOMPLEX"/> that is to the right of the equality operator.</param>
2839
/// <b>true</b> if the two <see cref="FICOMPLEX"/> structures are equal; otherwise, <b>false</b>.
2841
public static bool operator ==(FICOMPLEX left, FICOMPLEX right)
2843
return ((left.real == right.real) && (left.imag == right.imag));
2847
/// Tests whether two specified <see cref="FICOMPLEX"/> structures are different.
2849
/// <param name="left">The <see cref="FICOMPLEX"/> that is to the left of the inequality operator.</param>
2850
/// <param name="right">The <see cref="FICOMPLEX"/> that is to the right of the inequality operator.</param>
2852
/// <b>true</b> if the two <see cref="FICOMPLEX"/> structures are different; otherwise, <b>false</b>.
2854
public static bool operator !=(FICOMPLEX left, FICOMPLEX right)
2856
return ((left.real != right.real) || (left.imag == right.imag));
2860
/// Compares this instance with a specified <see cref="Object"/>.
2862
/// <param name="obj">An object to compare with this instance.</param>
2863
/// <returns>A 32-bit signed integer indicating the lexical relationship between the two comparands.</returns>
2864
/// <exception cref="ArgumentException"><paramref name="obj"/> is not a <see cref="FICOMPLEX"/>.</exception>
2865
public int CompareTo(object obj)
2871
if (!(obj is FICOMPLEX))
2873
throw new ArgumentException("obj");
2875
return CompareTo((FICOMPLEX)obj);
2879
/// Compares this instance with a specified <see cref="FICOMPLEX"/> object.
2881
/// <param name="other">A <see cref="FICOMPLEX"/> to compare.</param>
2882
/// <returns>A signed number indicating the relative values of this instance
2883
/// and <paramref name="other"/>.</returns>
2884
public int CompareTo(FICOMPLEX other)
2886
return base.GetHashCode();
2890
/// Tests whether the specified object is a <see cref="FICOMPLEX"/> structure
2891
/// and is equivalent to this <see cref="FICOMPLEX"/> structure.
2893
/// <param name="obj">The object to test.</param>
2894
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="FICOMPLEX"/> structure
2895
/// equivalent to this <see cref="FICOMPLEX"/> structure; otherwise, <b>false</b>.</returns>
2896
public override bool Equals(object obj)
2898
return ((obj is FICOMPLEX) && (this == ((FICOMPLEX)obj)));
2902
/// Tests whether the specified <see cref="FICOMPLEX"/> structure is equivalent to this <see cref="FICOMPLEX"/> structure.
2904
/// <param name="other">A <see cref="FICOMPLEX"/> structure to compare to this instance.</param>
2905
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="FICOMPLEX"/> structure
2906
/// equivalent to this <see cref="FICOMPLEX"/> structure; otherwise, <b>false</b>.</returns>
2907
public bool Equals(FICOMPLEX other)
2909
return (this == other);
2913
/// Returns a hash code for this <see cref="FICOMPLEX"/> structure.
2915
/// <returns>An integer value that specifies the hash code for this <see cref="FICOMPLEX"/>.</returns>
2916
public override int GetHashCode()
2918
return base.GetHashCode();
2923
namespace FreeImageAPI
2926
/// This Structure contains ICC-Profile data.
2928
[Serializable, StructLayout(LayoutKind.Sequential)]
2929
public struct FIICCPROFILE
2931
private ICC_FLAGS flags;
2933
private IntPtr data;
2936
/// Creates a new ICC-Profile for <paramref name="dib"/>.
2938
/// <param name="dib">Handle to a FreeImage bitmap.</param>
2939
/// <param name="data">The ICC-Profile data.</param>
2940
/// <exception cref="ArgumentNullException">
2941
/// <paramref name="dib"/> is null.</exception>
2942
public FIICCPROFILE(FIBITMAP dib, byte[] data)
2943
: this(dib, data, (int)data.Length)
2948
/// Creates a new ICC-Profile for <paramref name="dib"/>.
2950
/// <param name="dib">Handle to a FreeImage bitmap.</param>
2951
/// <param name="data">The ICC-Profile data.</param>
2952
/// <param name="size">Number of bytes to use from data.</param>
2953
/// <exception cref="ArgumentNullException">
2954
/// <paramref name="dib"/> is null.</exception>
2955
public unsafe FIICCPROFILE(FIBITMAP dib, byte[] data, int size)
2959
throw new ArgumentNullException("dib");
2962
size = Math.Min(size, (int)data.Length);
2963
prof = *(FIICCPROFILE*)FreeImage.CreateICCProfile(dib, data, size);
2964
this.flags = prof.flags;
2965
this.size = prof.size;
2966
this.data = prof.data;
2970
/// Info flag of the profile.
2972
public ICC_FLAGS Flags
2974
get { return flags; }
2978
/// Profile's size measured in bytes.
2982
get { return size; }
2986
/// Points to a block of contiguous memory containing the profile.
2988
public IntPtr DataPointer
2990
get { return data; }
2994
/// Copy of the ICC-Profiles data.
2996
public unsafe byte[] Data
3001
FreeImage.CopyMemory(result = new byte[size], data.ToPointer(), size);
3007
/// Indicates whether the profile is CMYK.
3013
return ((flags & ICC_FLAGS.FIICC_COLOR_IS_CMYK) != 0);
3019
namespace FreeImageAPI.Plugins
3022
/// The structure contains functionpointers that make up a FreeImage plugin.
3024
[Serializable, StructLayout(LayoutKind.Sequential)]
3025
public struct Plugin
3028
/// Delegate to a function that returns a string which describes
3029
/// the plugins format.
3031
public FormatProc formatProc;
3034
/// Delegate to a function that returns a string which contains
3035
/// a more detailed description.
3037
public DescriptionProc descriptionProc;
3040
/// Delegate to a function that returns a comma seperated list
3041
/// of file extensions the plugin can read or write.
3043
public ExtensionListProc extensionListProc;
3046
/// Delegate to a function that returns a regular expression that
3047
/// can be used to idientify whether a file can be handled by the plugin.
3049
public RegExprProc regExprProc;
3052
/// Delegate to a function that opens a file.
3054
public OpenProc openProc;
3057
/// Delegate to a function that closes a previosly opened file.
3059
public CloseProc closeProc;
3062
/// Delegate to a function that returns the number of pages of a multipage
3063
/// bitmap if the plugin is capable of handling multipage bitmaps.
3065
public PageCountProc pageCountProc;
3070
public PageCapabilityProc pageCapabilityProc;
3073
/// Delegate to a function that loads and decodes a bitmap into memory.
3075
public LoadProc loadProc;
3078
/// Delegate to a function that saves a bitmap.
3080
public SaveProc saveProc;
3083
/// Delegate to a function that determines whether the source is a valid image.
3085
public ValidateProc validateProc;
3088
/// Delegate to a function that returns a string which contains
3089
/// the plugin's mime type.
3091
public MimeProc mimeProc;
3094
/// Delegate to a function that returns whether the plugin can handle the
3095
/// specified color depth.
3097
public SupportsExportBPPProc supportsExportBPPProc;
3100
/// Delegate to a function that returns whether the plugin can handle the
3101
/// specified image type.
3103
public SupportsExportTypeProc supportsExportTypeProc;
3106
/// Delegate to a function that returns whether the plugin can handle
3109
public SupportsICCProfilesProc supportsICCProfilesProc;
3117
namespace FreeImageAPI.Metadata
3120
/// Specifies how a single frame will be handled after being displayed.
3122
public enum DisposalMethodType : byte
3125
/// Same behavior as <see cref="DisposalMethodType.Leave"/> but should not be used.
3130
/// The image is left in place and will be overdrawn by the next image.
3135
/// The area of the image will be blanked out by its background.
3140
/// Restores the the area of the image to the state it was before it
3147
namespace FreeImageAPI
3150
/// I/O image format identifiers.
3152
public enum FREE_IMAGE_FORMAT
3155
/// Unknown format (returned value only, never use it as input value)
3159
/// Windows or OS/2 Bitmap File (*.BMP)
3163
/// Windows Icon (*.ICO)
3167
/// Independent JPEG Group (*.JPG, *.JIF, *.JPEG, *.JPE)
3171
/// JPEG Network Graphics (*.JNG)
3175
/// Commodore 64 Koala format (*.KOA)
3179
/// Amiga IFF (*.IFF, *.LBM)
3183
/// Amiga IFF (*.IFF, *.LBM)
3187
/// Multiple Network Graphics (*.MNG)
3191
/// Portable Bitmap (ASCII) (*.PBM)
3195
/// Portable Bitmap (BINARY) (*.PBM)
3199
/// Kodak PhotoCD (*.PCD)
3203
/// Zsoft Paintbrush PCX bitmap format (*.PCX)
3207
/// Portable Graymap (ASCII) (*.PGM)
3211
/// Portable Graymap (BINARY) (*.PGM)
3215
/// Portable Network Graphics (*.PNG)
3219
/// Portable Pixelmap (ASCII) (*.PPM)
3223
/// Portable Pixelmap (BINARY) (*.PPM)
3227
/// Sun Rasterfile (*.RAS)
3231
/// truevision Targa files (*.TGA, *.TARGA)
3235
/// Tagged Image File Format (*.TIF, *.TIFF)
3239
/// Wireless Bitmap (*.WBMP)
3243
/// Adobe Photoshop (*.PSD)
3247
/// Dr. Halo (*.CUT)
3251
/// X11 Bitmap Format (*.XBM)
3255
/// X11 Pixmap Format (*.XPM)
3259
/// DirectDraw Surface (*.DDS)
3263
/// Graphics Interchange Format (*.GIF)
3267
/// High Dynamic Range (*.HDR)
3271
/// Raw Fax format CCITT G3 (*.G3)
3275
/// Silicon Graphics SGI image format (*.SGI)
3279
/// OpenEXR format (*.EXR)
3283
/// JPEG-2000 format (*.J2K, *.J2C)
3287
/// JPEG-2000 format (*.JP2)
3291
/// Portable FloatMap (*.PFM)
3295
/// Macintosh PICT (*.PICT)
3299
/// RAW camera image (*.*)
3305
namespace FreeImageAPI
3308
/// Image types used in FreeImage.
3310
public enum FREE_IMAGE_TYPE
3317
/// standard image : 1-, 4-, 8-, 16-, 24-, 32-bit
3321
/// array of unsigned short : unsigned 16-bit
3325
/// array of short : signed 16-bit
3329
/// array of unsigned long : unsigned 32-bit
3333
/// array of long : signed 32-bit
3337
/// array of float : 32-bit IEEE floating point
3341
/// array of double : 64-bit IEEE floating point
3345
/// array of FICOMPLEX : 2 x 64-bit IEEE floating point
3349
/// 48-bit RGB image : 3 x 16-bit
3353
/// 64-bit RGBA image : 4 x 16-bit
3357
/// 96-bit RGB float image : 3 x 32-bit IEEE floating point
3361
/// 128-bit RGBA float image : 4 x 32-bit IEEE floating point
3367
namespace FreeImageAPI
3370
/// Constants used in color filling routines.
3372
public enum FREE_IMAGE_COLOR_OPTIONS
3379
/// <see cref="RGBQUAD"/> color is RGB color (contains no valid alpha channel).
3383
/// <see cref="RGBQUAD"/> color is RGBA color (contains a valid alpha channel).
3387
/// Lookup nearest RGB color from palette.
3389
FICO_NEAREST_COLOR = 0x0,
3391
/// Lookup equal RGB color from palette.
3393
FICO_EQUAL_COLOR = 0x2,
3395
/// <see cref="RGBQUAD.rgbReserved"/> contains the palette index to be used.
3397
FICO_ALPHA_IS_INDEX = 0x4,
3401
namespace FreeImageAPI
3404
/// Image color types used in FreeImage.
3406
public enum FREE_IMAGE_COLOR_TYPE
3409
/// min value is white
3413
/// min value is black
3421
/// color map indexed
3425
/// RGB color model with alpha channel
3429
/// CMYK color model
3435
namespace FreeImageAPI
3438
/// Color quantization algorithms.
3439
/// Constants used in FreeImage_ColorQuantize.
3441
public enum FREE_IMAGE_QUANTIZE
3444
/// Xiaolin Wu color quantization algorithm
3448
/// NeuQuant neural-net quantization algorithm by Anthony Dekker
3454
namespace FreeImageAPI
3457
/// Dithering algorithms.
3458
/// Constants used in FreeImage_Dither.
3460
public enum FREE_IMAGE_DITHER
3463
/// Floyd and Steinberg error diffusion
3467
/// Bayer ordered dispersed dot dithering (order 2 dithering matrix)
3471
/// Bayer ordered dispersed dot dithering (order 3 dithering matrix)
3475
/// Ordered clustered dot dithering (order 3 - 6x6 matrix)
3479
/// Ordered clustered dot dithering (order 4 - 8x8 matrix)
3483
/// Ordered clustered dot dithering (order 8 - 16x16 matrix)
3485
FID_CLUSTER16x16 = 5,
3487
/// Bayer ordered dispersed dot dithering (order 4 dithering matrix)
3493
namespace FreeImageAPI
3496
/// Lossless JPEG transformations constants used in FreeImage_JPEGTransform.
3498
public enum FREE_IMAGE_JPEG_OPERATION
3501
/// no transformation
3507
FIJPEG_OP_FLIP_H = 1,
3511
FIJPEG_OP_FLIP_V = 2,
3513
/// transpose across UL-to-LR axis
3515
FIJPEG_OP_TRANSPOSE = 3,
3517
/// transpose across UR-to-LL axis
3519
FIJPEG_OP_TRANSVERSE = 4,
3521
/// 90-degree clockwise rotation
3523
FIJPEG_OP_ROTATE_90 = 5,
3525
/// 180-degree rotation
3527
FIJPEG_OP_ROTATE_180 = 6,
3529
/// 270-degree clockwise (or 90 ccw)
3531
FIJPEG_OP_ROTATE_270 = 7
3535
namespace FreeImageAPI
3538
/// Tone mapping operators. Constants used in FreeImage_ToneMapping.
3540
public enum FREE_IMAGE_TMO
3543
/// Adaptive logarithmic mapping (F. Drago, 2003)
3547
/// Dynamic range reduction inspired by photoreceptor physiology (E. Reinhard, 2005)
3549
FITMO_REINHARD05 = 1,
3551
/// Gradient domain high dynamic range compression (R. Fattal, 2002)
3557
namespace FreeImageAPI
3560
/// Upsampling / downsampling filters. Constants used in FreeImage_Rescale.
3562
public enum FREE_IMAGE_FILTER
3565
/// Box, pulse, Fourier window, 1st order (constant) b-spline
3569
/// Mitchell and Netravali's two-param cubic filter
3575
FILTER_BILINEAR = 2,
3577
/// 4th order (cubic) b-spline
3581
/// Catmull-Rom spline, Overhauser spline
3583
FILTER_CATMULLROM = 4,
3591
namespace FreeImageAPI
3594
/// Color channels. Constants used in color manipulation routines.
3596
public enum FREE_IMAGE_COLOR_CHANNEL
3599
/// Use red, green and blue channels
3607
/// Use green channel
3611
/// Use blue channel
3615
/// Use alpha channel
3619
/// Use black channel
3623
/// Complex images: use real part
3627
/// Complex images: use imaginary part
3631
/// Complex images: use magnitude
3635
/// Complex images: use phase
3641
namespace FreeImageAPI
3644
/// Tag data type information (based on TIFF specifications)
3645
/// Note: RATIONALs are the ratio of two 32-bit integer values.
3647
public enum FREE_IMAGE_MDTYPE
3654
/// 8-bit unsigned integer
3658
/// 8-bit bytes w/ last byte null
3662
/// 16-bit unsigned integer
3666
/// 32-bit unsigned integer
3670
/// 64-bit unsigned fraction
3674
/// 8-bit signed integer
3678
/// 8-bit untyped data
3682
/// 16-bit signed integer
3686
/// 32-bit signed integer
3690
/// 64-bit signed fraction
3692
FIDT_SRATIONAL = 10,
3694
/// 32-bit IEEE floating point
3698
/// 64-bit IEEE floating point
3702
/// 32-bit unsigned integer (offset)
3712
namespace FreeImageAPI
3715
/// Metadata models supported by FreeImage.
3717
public enum FREE_IMAGE_MDMODEL
3724
/// single comment or keywords
3728
/// Exif-TIFF metadata
3732
/// Exif-specific metadata
3736
/// Exif GPS metadata
3740
/// Exif maker note metadata
3742
FIMD_EXIF_MAKERNOTE = 4,
3744
/// Exif interoperability metadata
3746
FIMD_EXIF_INTEROP = 5,
3748
/// IPTC/NAA metadata
3752
/// Abobe XMP metadata
3756
/// GeoTIFF metadata
3760
/// Animation metadata
3764
/// Used to attach other metadata types to a dib
3770
namespace FreeImageAPI
3773
/// Flags used in load functions.
3776
public enum FREE_IMAGE_LOAD_FLAGS
3779
/// Default option for all types.
3783
/// Load the image as a 256 color image with ununsed palette entries, if it's 16 or 2 color.
3787
/// 'Play' the GIF to generate each frame (as 32bpp) instead of returning raw frame data when loading.
3791
/// Convert to 32bpp and create an alpha channel from the AND-mask when loading.
3795
/// Load the file as fast as possible, sacrificing some quality.
3799
/// Load the file with the best quality, sacrificing some speed.
3801
JPEG_ACCURATE = 0x0002,
3803
/// Load separated CMYK "as is" (use | to combine with other load flags).
3807
/// Load and rotate according to Exif 'Orientation' tag if available.
3809
JPEG_EXIFROTATE = 0x0008,
3811
/// Load the bitmap sized 768 x 512.
3815
/// Load the bitmap sized 384 x 256.
3819
/// Load the bitmap sized 192 x 128.
3823
/// Avoid gamma correction.
3825
PNG_IGNOREGAMMA = 1,
3827
/// If set the loader converts RGB555 and ARGB8888 -> RGB888.
3829
TARGA_LOAD_RGB888 = 1,
3831
/// Reads tags for separated CMYK.
3835
/// Tries to load the JPEG preview image, embedded in
3836
/// Exif Metadata or load the image as RGB 24-bit if no
3837
/// preview image is available.
3841
/// Loads the image as RGB 24-bit.
3847
namespace FreeImageAPI
3850
/// Flags used in save functions.
3853
public enum FREE_IMAGE_SAVE_FLAGS
3856
/// Default option for all types.
3860
/// Save with run length encoding.
3864
/// Save data as float instead of as half (not recommended).
3868
/// Save with no compression.
3872
/// Save with zlib compression, in blocks of 16 scan lines.
3876
/// Save with piz-based wavelet compression.
3880
/// Save with lossy 24-bit float compression.
3884
/// Save with lossy 44% float compression - goes to 22% when combined with EXR_LC.
3888
/// Save images with one luminance and two chroma channels, rather than as RGB (lossy compression).
3892
/// Save with superb quality (100:1).
3894
JPEG_QUALITYSUPERB = 0x80,
3896
/// Save with good quality (75:1).
3898
JPEG_QUALITYGOOD = 0x0100,
3900
/// Save with normal quality (50:1).
3902
JPEG_QUALITYNORMAL = 0x0200,
3904
/// Save with average quality (25:1).
3906
JPEG_QUALITYAVERAGE = 0x0400,
3908
/// Save with bad quality (10:1).
3910
JPEG_QUALITYBAD = 0x0800,
3912
/// Save as a progressive-JPEG (use | to combine with other save flags).
3914
JPEG_PROGRESSIVE = 0x2000,
3916
/// Save with high 4x1 chroma subsampling (4:1:1).
3918
JPEG_SUBSAMPLING_411 = 0x1000,
3920
/// Save with medium 2x2 medium chroma (4:2:0).
3922
JPEG_SUBSAMPLING_420 = 0x4000,
3924
/// Save with low 2x1 chroma subsampling (4:2:2).
3926
JPEG_SUBSAMPLING_422 = 0x8000,
3928
/// Save with no chroma subsampling (4:4:4).
3930
JPEG_SUBSAMPLING_444 = 0x10000,
3932
/// Save using ZLib level 1 compression flag
3933
/// (default value is <see cref="PNG_Z_DEFAULT_COMPRESSION"/>).
3935
PNG_Z_BEST_SPEED = 0x0001,
3937
/// Save using ZLib level 6 compression flag (default recommended value).
3939
PNG_Z_DEFAULT_COMPRESSION = 0x0006,
3941
/// save using ZLib level 9 compression flag
3942
/// (default value is <see cref="PNG_Z_DEFAULT_COMPRESSION"/>).
3944
PNG_Z_BEST_COMPRESSION = 0x0009,
3946
/// Save without ZLib compression.
3948
PNG_Z_NO_COMPRESSION = 0x0100,
3950
/// Save using Adam7 interlacing (use | to combine with other save flags).
3952
PNG_INTERLACED = 0x0200,
3954
/// If set the writer saves in ASCII format (i.e. P1, P2 or P3).
3958
/// Stores tags for separated CMYK (use | to combine with compression flags).
3962
/// Save using PACKBITS compression.
3964
TIFF_PACKBITS = 0x0100,
3966
/// Save using DEFLATE compression (a.k.a. ZLIB compression).
3968
TIFF_DEFLATE = 0x0200,
3970
/// Save using ADOBE DEFLATE compression.
3972
TIFF_ADOBE_DEFLATE = 0x0400,
3974
/// Save without any compression.
3978
/// Save using CCITT Group 3 fax encoding.
3980
TIFF_CCITTFAX3 = 0x1000,
3982
/// Save using CCITT Group 4 fax encoding.
3984
TIFF_CCITTFAX4 = 0x2000,
3986
/// Save using LZW compression.
3990
/// Save using JPEG compression.
3996
namespace FreeImageAPI
3999
/// Flags for ICC profiles.
4002
public enum ICC_FLAGS : ushort
4007
FIICC_DEFAULT = 0x00,
4009
/// The color is CMYK.
4011
FIICC_COLOR_IS_CMYK = 0x01
4019
namespace FreeImageAPI
4021
// Delegates used by the FreeImageIO structure
4024
/// Delegate for capturing FreeImage error messages.
4026
/// <param name="fif">The format of the image.</param>
4027
/// <param name="message">The errormessage.</param>
4028
// DLL_API is missing in the definition of the callbackfuntion.
4029
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi, ThrowOnUnmappableChar = false)]
4030
public delegate void OutputMessageFunction(FREE_IMAGE_FORMAT fif, string message);
4033
namespace FreeImageAPI.IO
4036
/// Delegate to the C++ function <b>fread</b>.
4038
/// <param name="buffer">Pointer to read from.</param>
4039
/// <param name="size">Item size in bytes.</param>
4040
/// <param name="count">Maximum number of items to be read.</param>
4041
/// <param name="handle">Handle/stream to read from.</param>
4042
/// <returns>Number of full items actually read,
4043
/// which may be less than count if an error occurs or
4044
/// if the end of the file is encountered before reaching count.</returns>
4045
public delegate uint ReadProc(IntPtr buffer, uint size, uint count, fi_handle handle);
4048
/// Delegate to the C++ function <b>fwrite</b>.
4050
/// <param name="buffer">Pointer to data to be written.</param>
4051
/// <param name="size">Item size in bytes.</param>
4052
/// <param name="count">Maximum number of items to be written.</param>
4053
/// <param name="handle">Handle/stream to write to.</param>
4054
/// <returns>Number of full items actually written,
4055
/// which may be less than count if an error occurs.
4056
/// Also, if an error occurs, the file-position indicator cannot be determined.</returns>
4057
public delegate uint WriteProc(IntPtr buffer, uint size, uint count, fi_handle handle);
4060
/// Delegate to the C++ function <b>fseek</b>.
4062
/// <param name="handle">Handle/stream to seek in.</param>
4063
/// <param name="offset">Number of bytes from origin.</param>
4064
/// <param name="origin">Initial position.</param>
4065
/// <returns>If successful 0 is returned; otherwise a nonzero value. </returns>
4066
public delegate int SeekProc(fi_handle handle, int offset, SeekOrigin origin);
4069
/// Delegate to the C++ function <b>ftell</b>.
4071
/// <param name="handle">Handle/stream to retrieve its currents position from.</param>
4072
/// <returns>The current position.</returns>
4073
public delegate int TellProc(fi_handle handle);
4075
// Delegates used by 'Plugin' structure
4078
namespace FreeImageAPI.Plugins
4081
/// Delegate to a function that returns a string which describes
4082
/// the plugins format.
4084
public delegate string FormatProc();
4087
/// Delegate to a function that returns a string which contains
4088
/// a more detailed description.
4090
public delegate string DescriptionProc();
4093
/// Delegate to a function that returns a comma seperated list
4094
/// of file extensions the plugin can read or write.
4096
public delegate string ExtensionListProc();
4099
/// Delegate to a function that returns a regular expression that
4100
/// can be used to idientify whether a file can be handled by the plugin.
4102
public delegate string RegExprProc();
4105
/// Delegate to a function that opens a file.
4107
public delegate IntPtr OpenProc(ref FreeImageIO io, fi_handle handle, bool read);
4110
/// Delegate to a function that closes a previosly opened file.
4112
public delegate void CloseProc(ref FreeImageIO io, fi_handle handle, IntPtr data);
4115
/// Delegate to a function that returns the number of pages of a multipage
4116
/// bitmap if the plugin is capable of handling multipage bitmaps.
4118
public delegate int PageCountProc(ref FreeImageIO io, fi_handle handle, IntPtr data);
4123
public delegate int PageCapabilityProc(ref FreeImageIO io, fi_handle handle, IntPtr data);
4126
/// Delegate to a function that loads and decodes a bitmap into memory.
4128
public delegate FIBITMAP LoadProc(ref FreeImageIO io, fi_handle handle, int page, int flags, IntPtr data);
4131
/// Delegate to a function that saves a bitmap.
4133
public delegate bool SaveProc(ref FreeImageIO io, FIBITMAP dib, fi_handle handle, int page, int flags, IntPtr data);
4136
/// Delegate to a function that determines whether the source defined
4137
/// by <param name="io"/> and <param name="handle"/> is a valid image.
4139
public delegate bool ValidateProc(ref FreeImageIO io, fi_handle handle);
4142
/// Delegate to a function that returns a string which contains
4143
/// the plugin's mime type.
4145
public delegate string MimeProc();
4148
/// Delegate to a function that returns whether the plugin can handle the
4149
/// specified color depth.
4151
public delegate bool SupportsExportBPPProc(int bpp);
4154
/// Delegate to a function that returns whether the plugin can handle the
4155
/// specified image type.
4157
public delegate bool SupportsExportTypeProc(FREE_IMAGE_TYPE type);
4160
/// Delegate to a function that returns whether the plugin can handle
4163
public delegate bool SupportsICCProfilesProc();
4166
/// Callback function used by FreeImage to register plugins.
4168
public delegate void InitProc(ref Plugin plugin, int format_id);
4173
namespace FreeImageAPI
4175
public static partial class FreeImage
4180
/// Filename of the FreeImage library.
4182
private const string FreeImageLibrary = "FreeImage";
4185
/// Number of bytes to shift left within a 4 byte block.
4187
public const int FI_RGBA_RED = 2;
4190
/// Number of bytes to shift left within a 4 byte block.
4192
public const int FI_RGBA_GREEN = 1;
4195
/// Number of bytes to shift left within a 4 byte block.
4197
public const int FI_RGBA_BLUE = 0;
4200
/// Number of bytes to shift left within a 4 byte block.
4202
public const int FI_RGBA_ALPHA = 3;
4205
/// Mask indicating the position of the given color.
4207
public const uint FI_RGBA_RED_MASK = 0x00FF0000;
4210
/// Mask indicating the position of the given color.
4212
public const uint FI_RGBA_GREEN_MASK = 0x0000FF00;
4215
/// Mask indicating the position of the given color.
4217
public const uint FI_RGBA_BLUE_MASK = 0x000000FF;
4220
/// Mask indicating the position of the given color.
4222
public const uint FI_RGBA_ALPHA_MASK = 0xFF000000;
4225
/// Number of bits to shift left within a 32 bit block.
4227
public const int FI_RGBA_RED_SHIFT = 16;
4230
/// Number of bits to shift left within a 32 bit block.
4232
public const int FI_RGBA_GREEN_SHIFT = 8;
4235
/// Number of bits to shift left within a 32 bit block.
4237
public const int FI_RGBA_BLUE_SHIFT = 0;
4240
/// Number of bits to shift left within a 32 bit block.
4242
public const int FI_RGBA_ALPHA_SHIFT = 24;
4245
/// Mask indicating the position of color components of a 32 bit color.
4247
public const uint FI_RGBA_RGB_MASK = (FI_RGBA_RED_MASK | FI_RGBA_GREEN_MASK | FI_RGBA_BLUE_MASK);
4250
/// Mask indicating the position of the given color.
4252
public const int FI16_555_RED_MASK = 0x7C00;
4255
/// Mask indicating the position of the given color.
4257
public const int FI16_555_GREEN_MASK = 0x03E0;
4260
/// Mask indicating the position of the given color.
4262
public const int FI16_555_BLUE_MASK = 0x001F;
4265
/// Number of bits to shift left within a 16 bit block.
4267
public const int FI16_555_RED_SHIFT = 10;
4270
/// Number of bits to shift left within a 16 bit block.
4272
public const int FI16_555_GREEN_SHIFT = 5;
4275
/// Number of bits to shift left within a 16 bit block.
4277
public const int FI16_555_BLUE_SHIFT = 0;
4280
/// Mask indicating the position of the given color.
4282
public const int FI16_565_RED_MASK = 0xF800;
4285
/// Mask indicating the position of the given color.
4287
public const int FI16_565_GREEN_MASK = 0x07E0;
4290
/// Mask indicating the position of the given color.
4292
public const int FI16_565_BLUE_MASK = 0x001F;
4295
/// Number of bits to shift left within a 16 bit block.
4297
public const int FI16_565_RED_SHIFT = 11;
4300
/// Number of bits to shift left within a 16 bit block.
4302
public const int FI16_565_GREEN_SHIFT = 5;
4305
/// Number of bits to shift left within a 16 bit block.
4307
public const int FI16_565_BLUE_SHIFT = 0;
4311
#region General functions
4314
/// Initialises the library.
4316
/// <param name="load_local_plugins_only">
4317
/// When the <paramref name="load_local_plugins_only"/> is true, FreeImage won't make use of external plugins.
4319
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Initialise")]
4320
private static extern void Initialise(bool load_local_plugins_only);
4323
/// Deinitialises the library.
4325
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_DeInitialise")]
4326
private static extern void DeInitialise();
4329
/// Returns a string containing the current version of the library.
4331
/// <returns>The current version of the library.</returns>
4332
public static unsafe string GetVersion() { return PtrToStr(GetVersion_()); }
4333
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetVersion")]
4334
private static unsafe extern byte* GetVersion_();
4337
/// Returns a string containing a standard copyright message.
4339
/// <returns>A standard copyright message.</returns>
4340
public static unsafe string GetCopyrightMessage() { return PtrToStr(GetCopyrightMessage_()); }
4341
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetCopyrightMessage")]
4342
private static unsafe extern byte* GetCopyrightMessage_();
4345
/// Calls the set error message function in FreeImage.
4347
/// <param name="fif">Format of the bitmaps.</param>
4348
/// <param name="message">The error message.</param>
4349
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_OutputMessageProc")]
4350
public static extern void OutputMessageProc(FREE_IMAGE_FORMAT fif, string message);
4353
/// You use the function FreeImage_SetOutputMessage to capture the log string
4354
/// so that you can show it to the user of the program.
4355
/// The callback is implemented in the <see cref="FreeImageEngine.Message"/> event of this class.
4357
/// <remarks>The function is private because FreeImage can only have a single
4358
/// callback function. To use the callback use the <see cref="FreeImageEngine.Message"/>
4359
/// event of this class.</remarks>
4360
/// <param name="omf">Handler to the callback function.</param>
4361
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetOutputMessage")]
4362
internal static extern void SetOutputMessage(OutputMessageFunction omf);
4366
#region Bitmap management functions
4369
/// Creates a new bitmap in memory.
4371
/// <param name="width">Width of the new bitmap.</param>
4372
/// <param name="height">Height of the new bitmap.</param>
4373
/// <param name="bpp">Bit depth of the new Bitmap.
4374
/// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap</param>
4375
/// <param name="red_mask">Red part of the color layout.
4376
/// eg: 0xFF0000</param>
4377
/// <param name="green_mask">Green part of the color layout.
4378
/// eg: 0x00FF00</param>
4379
/// <param name="blue_mask">Blue part of the color layout.
4380
/// eg: 0x0000FF</param>
4381
/// <returns>Handle to a FreeImage bitmap.</returns>
4382
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Allocate")]
4383
public static extern FIBITMAP Allocate(int width, int height, int bpp,
4384
uint red_mask, uint green_mask, uint blue_mask);
4387
/// Creates a new bitmap in memory.
4389
/// <param name="type">Type of the image.</param>
4390
/// <param name="width">Width of the new bitmap.</param>
4391
/// <param name="height">Height of the new bitmap.</param>
4392
/// <param name="bpp">Bit depth of the new Bitmap.
4393
/// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap</param>
4394
/// <param name="red_mask">Red part of the color layout.
4395
/// eg: 0xFF0000</param>
4396
/// <param name="green_mask">Green part of the color layout.
4397
/// eg: 0x00FF00</param>
4398
/// <param name="blue_mask">Blue part of the color layout.
4399
/// eg: 0x0000FF</param>
4400
/// <returns>Handle to a FreeImage bitmap.</returns>
4401
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AllocateT")]
4402
public static extern FIBITMAP AllocateT(FREE_IMAGE_TYPE type, int width, int height, int bpp,
4403
uint red_mask, uint green_mask, uint blue_mask);
4405
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AllocateEx")]
4406
internal static extern FIBITMAP AllocateEx(int width, int height, int bpp,
4407
IntPtr color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette,
4408
uint red_mask, uint green_mask, uint blue_mask);
4410
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AllocateExT")]
4411
internal static extern FIBITMAP AllocateExT(FREE_IMAGE_TYPE type, int width, int height, int bpp,
4412
IntPtr color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette,
4413
uint red_mask, uint green_mask, uint blue_mask);
4416
/// Makes an exact reproduction of an existing bitmap, including metadata and attached profile if any.
4418
/// <param name="dib">Handle to a FreeImage bitmap.</param>
4419
/// <returns>Handle to a FreeImage bitmap.</returns>
4420
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Clone")]
4421
public static extern FIBITMAP Clone(FIBITMAP dib);
4424
/// Deletes a previously loaded FIBITMAP from memory.
4426
/// <param name="dib">Handle to a FreeImage bitmap.</param>
4427
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Unload")]
4428
public static extern void Unload(FIBITMAP dib);
4431
/// Decodes a bitmap, allocates memory for it and returns it as a FIBITMAP.
4433
/// <param name="fif">Type of the bitmap.</param>
4434
/// <param name="filename">Name of the file to decode.</param>
4435
/// <param name="flags">Flags to enable or disable plugin-features.</param>
4436
/// <returns>Handle to a FreeImage bitmap.</returns>
4437
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_LoadU")]
4438
public static extern FIBITMAP Load(FREE_IMAGE_FORMAT fif, string filename, FREE_IMAGE_LOAD_FLAGS flags);
4441
/// Decodes a bitmap, allocates memory for it and returns it as a FIBITMAP.
4442
/// The filename supports UNICODE.
4444
/// <param name="fif">Type of the bitmap.</param>
4445
/// <param name="filename">Name of the file to decode.</param>
4446
/// <param name="flags">Flags to enable or disable plugin-features.</param>
4447
/// <returns>Handle to a FreeImage bitmap.</returns>
4448
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_LoadU")]
4449
private static extern FIBITMAP LoadU(FREE_IMAGE_FORMAT fif, string filename, FREE_IMAGE_LOAD_FLAGS flags);
4452
/// Loads a bitmap from an arbitrary source.
4454
/// <param name="fif">Type of the bitmap.</param>
4455
/// <param name="io">A FreeImageIO structure with functionpointers to handle the source.</param>
4456
/// <param name="handle">A handle to the source.</param>
4457
/// <param name="flags">Flags to enable or disable plugin-features.</param>
4458
/// <returns>Handle to a FreeImage bitmap.</returns>
4459
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_LoadFromHandle")]
4460
public static extern FIBITMAP LoadFromHandle(FREE_IMAGE_FORMAT fif, ref FreeImageIO io, fi_handle handle, FREE_IMAGE_LOAD_FLAGS flags);
4463
/// Saves a previosly loaded FIBITMAP to a file.
4465
/// <param name="fif">Type of the bitmap.</param>
4466
/// <param name="dib">Handle to a FreeImage bitmap.</param>
4467
/// <param name="filename">Name of the file to save to.</param>
4468
/// <param name="flags">Flags to enable or disable plugin-features.</param>
4469
/// <returns>Returns true on success, false on failure.</returns>
4470
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_SaveU")]
4471
public static extern bool Save(FREE_IMAGE_FORMAT fif, FIBITMAP dib, string filename, FREE_IMAGE_SAVE_FLAGS flags);
4474
/// Saves a previosly loaded FIBITMAP to a file.
4475
/// The filename supports UNICODE.
4477
/// <param name="fif">Type of the bitmap.</param>
4478
/// <param name="dib">Handle to a FreeImage bitmap.</param>
4479
/// <param name="filename">Name of the file to save to.</param>
4480
/// <param name="flags">Flags to enable or disable plugin-features.</param>
4481
/// <returns>Returns true on success, false on failure.</returns>
4482
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_SaveU")]
4483
private static extern bool SaveU(FREE_IMAGE_FORMAT fif, FIBITMAP dib, string filename, FREE_IMAGE_SAVE_FLAGS flags);
4486
/// Saves a bitmap to an arbitrary source.
4488
/// <param name="fif">Type of the bitmap.</param>
4489
/// <param name="dib">Handle to a FreeImage bitmap.</param>
4490
/// <param name="io">A FreeImageIO structure with functionpointers to handle the source.</param>
4491
/// <param name="handle">A handle to the source.</param>
4492
/// <param name="flags">Flags to enable or disable plugin-features.</param>
4493
/// <returns>Returns true on success, false on failure.</returns>
4494
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SaveToHandle")]
4495
public static extern bool SaveToHandle(FREE_IMAGE_FORMAT fif, FIBITMAP dib, ref FreeImageIO io, fi_handle handle,
4496
FREE_IMAGE_SAVE_FLAGS flags);
4500
#region Memory I/O streams
4503
/// Open a memory stream.
4505
/// <param name="data">Pointer to the data in memory.</param>
4506
/// <param name="size_in_bytes">Length of the data in byte.</param>
4507
/// <returns>Handle to a memory stream.</returns>
4508
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_OpenMemory")]
4509
public static extern FIMEMORY OpenMemory(IntPtr data, uint size_in_bytes);
4511
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_OpenMemory")]
4512
internal static extern FIMEMORY OpenMemoryEx(byte[] data, uint size_in_bytes);
4515
/// Close and free a memory stream.
4517
/// <param name="stream">Handle to a memory stream.</param>
4518
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CloseMemory")]
4519
public static extern void CloseMemory(FIMEMORY stream);
4522
/// Decodes a bitmap from a stream, allocates memory for it and returns it as a FIBITMAP.
4524
/// <param name="fif">Type of the bitmap.</param>
4525
/// <param name="stream">Handle to a memory stream.</param>
4526
/// <param name="flags">Flags to enable or disable plugin-features.</param>
4527
/// <returns>Handle to a FreeImage bitmap.</returns>
4528
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_LoadFromMemory")]
4529
public static extern FIBITMAP LoadFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY stream, FREE_IMAGE_LOAD_FLAGS flags);
4532
/// Saves a previosly loaded FIBITMAP to a stream.
4534
/// <param name="fif">Type of the bitmap.</param>
4535
/// <param name="dib">Handle to a FreeImage bitmap.</param>
4536
/// <param name="stream">Handle to a memory stream.</param>
4537
/// <param name="flags">Flags to enable or disable plugin-features.</param>
4538
/// <returns>Returns true on success, false on failure.</returns>
4539
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SaveToMemory")]
4540
public static extern bool SaveToMemory(FREE_IMAGE_FORMAT fif, FIBITMAP dib, FIMEMORY stream, FREE_IMAGE_SAVE_FLAGS flags);
4543
/// Gets the current position of a memory handle.
4545
/// <param name="stream">Handle to a memory stream.</param>
4546
/// <returns>The current file position if successful, -1 otherwise.</returns>
4547
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_TellMemory")]
4548
public static extern int TellMemory(FIMEMORY stream);
4551
/// Moves the memory handle to a specified location.
4553
/// <param name="stream">Handle to a memory stream.</param>
4554
/// <param name="offset">Number of bytes from origin.</param>
4555
/// <param name="origin">Initial position.</param>
4556
/// <returns>Returns true on success, false on failure.</returns>
4557
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SeekMemory")]
4558
public static extern bool SeekMemory(FIMEMORY stream, int offset, System.IO.SeekOrigin origin);
4561
/// Provides a direct buffer access to a memory stream.
4563
/// <param name="stream">The target memory stream.</param>
4564
/// <param name="data">Pointer to the data in memory.</param>
4565
/// <param name="size_in_bytes">Size of the data in bytes.</param>
4566
/// <returns>Returns true on success, false on failure.</returns>
4567
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AcquireMemory")]
4568
public static extern bool AcquireMemory(FIMEMORY stream, ref IntPtr data, ref uint size_in_bytes);
4571
/// Reads data from a memory stream.
4573
/// <param name="buffer">The buffer to store the data in.</param>
4574
/// <param name="size">Size in bytes of the items.</param>
4575
/// <param name="count">Number of items to read.</param>
4576
/// <param name="stream">The stream to read from.
4577
/// The memory pointer associated with stream is increased by the number of bytes actually read.</param>
4578
/// <returns>The number of full items actually read.
4579
/// May be less than count on error or stream-end.</returns>
4580
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ReadMemory")]
4581
public static extern uint ReadMemory(byte[] buffer, uint size, uint count, FIMEMORY stream);
4584
/// Writes data to a memory stream.
4586
/// <param name="buffer">The buffer to read the data from.</param>
4587
/// <param name="size">Size in bytes of the items.</param>
4588
/// <param name="count">Number of items to write.</param>
4589
/// <param name="stream">The stream to write to.
4590
/// The memory pointer associated with stream is increased by the number of bytes actually written.</param>
4591
/// <returns>The number of full items actually written.
4592
/// May be less than count on error or stream-end.</returns>
4593
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_WriteMemory")]
4594
public static extern uint WriteMemory(byte[] buffer, uint size, uint count, FIMEMORY stream);
4597
/// Open a multi-page bitmap from a memory stream.
4599
/// <param name="fif">Type of the bitmap.</param>
4600
/// <param name="stream">The stream to decode.</param>
4601
/// <param name="flags">Flags to enable or disable plugin-features.</param>
4602
/// <returns>Handle to a FreeImage multi-paged bitmap.</returns>
4603
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_LoadMultiBitmapFromMemory")]
4604
public static extern FIMULTIBITMAP LoadMultiBitmapFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY stream, FREE_IMAGE_LOAD_FLAGS flags);
4608
#region Plugin functions
4611
/// Registers a new plugin to be used in FreeImage.
4613
/// <param name="proc_address">Pointer to the function that initialises the plugin.</param>
4614
/// <param name="format">A string describing the format of the plugin.</param>
4615
/// <param name="description">A string describing the plugin.</param>
4616
/// <param name="extension">A string witha comma sperated list of extensions. f.e: "pl,pl2,pl4"</param>
4617
/// <param name="regexpr">A regular expression used to identify the bitmap.</param>
4618
/// <returns>The format idientifier assigned by FreeImage.</returns>
4619
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_RegisterLocalPlugin")]
4620
public static extern FREE_IMAGE_FORMAT RegisterLocalPlugin(InitProc proc_address,
4621
string format, string description, string extension, string regexpr);
4624
/// Registers a new plugin to be used in FreeImage. The plugin is residing in a DLL.
4625
/// The Init function must be called �Init� and must use the stdcall calling convention.
4627
/// <param name="path">Complete path to the dll file hosting the plugin.</param>
4628
/// <param name="format">A string describing the format of the plugin.</param>
4629
/// <param name="description">A string describing the plugin.</param>
4630
/// <param name="extension">A string witha comma sperated list of extensions. f.e: "pl,pl2,pl4"</param>
4631
/// <param name="regexpr">A regular expression used to identify the bitmap.</param>
4632
/// <returns>The format idientifier assigned by FreeImage.</returns>
4633
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_RegisterExternalPlugin")]
4634
public static extern FREE_IMAGE_FORMAT RegisterExternalPlugin(string path,
4635
string format, string description, string extension, string regexpr);
4638
/// Retrieves the number of FREE_IMAGE_FORMAT identifiers being currently registered.
4640
/// <returns>The number of registered formats.</returns>
4641
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFCount")]
4642
public static extern int GetFIFCount();
4645
/// Enables or disables a plugin.
4647
/// <param name="fif">The plugin to enable or disable.</param>
4648
/// <param name="enable">True: enable the plugin. false: disable the plugin.</param>
4649
/// <returns>The previous state of the plugin.
4650
/// 1 - enabled. 0 - disables. -1 plugin does not exist.</returns>
4651
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetPluginEnabled")]
4652
public static extern int SetPluginEnabled(FREE_IMAGE_FORMAT fif, bool enable);
4655
/// Retrieves the state of a plugin.
4657
/// <param name="fif">The plugin to check.</param>
4658
/// <returns>1 - enabled. 0 - disables. -1 plugin does not exist.</returns>
4659
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_IsPluginEnabled")]
4660
public static extern int IsPluginEnabled(FREE_IMAGE_FORMAT fif);
4663
/// Returns a <see cref="FREE_IMAGE_FORMAT"/> identifier from the format string that was used to register the FIF.
4665
/// <param name="format">The string that was used to register the plugin.</param>
4666
/// <returns>A <see cref="FREE_IMAGE_FORMAT"/> identifier from the format.</returns>
4667
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetFIFFromFormat")]
4668
public static extern FREE_IMAGE_FORMAT GetFIFFromFormat(string format);
4671
/// Returns a <see cref="FREE_IMAGE_FORMAT"/> identifier from a MIME content type string
4672
/// (MIME stands for Multipurpose Internet Mail Extension).
4674
/// <param name="mime">A MIME content type.</param>
4675
/// <returns>A <see cref="FREE_IMAGE_FORMAT"/> identifier from the MIME.</returns>
4676
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetFIFFromMime")]
4677
public static extern FREE_IMAGE_FORMAT GetFIFFromMime(string mime);
4680
/// Returns the string that was used to register a plugin from the system assigned <see cref="FREE_IMAGE_FORMAT"/>.
4682
/// <param name="fif">The assigned <see cref="FREE_IMAGE_FORMAT"/>.</param>
4683
/// <returns>The string that was used to register the plugin.</returns>
4684
public static unsafe string GetFormatFromFIF(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFormatFromFIF_(fif)); }
4685
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFormatFromFIF")]
4686
private static unsafe extern byte* GetFormatFromFIF_(FREE_IMAGE_FORMAT fif);
4689
/// Returns a comma-delimited file extension list describing the bitmap formats the given plugin can read and/or write.
4691
/// <param name="fif">The desired <see cref="FREE_IMAGE_FORMAT"/>.</param>
4692
/// <returns>A comma-delimited file extension list.</returns>
4693
public static unsafe string GetFIFExtensionList(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFIFExtensionList_(fif)); }
4694
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFExtensionList")]
4695
private static unsafe extern byte* GetFIFExtensionList_(FREE_IMAGE_FORMAT fif);
4698
/// Returns a descriptive string that describes the bitmap formats the given plugin can read and/or write.
4700
/// <param name="fif">The desired <see cref="FREE_IMAGE_FORMAT"/>.</param>
4701
/// <returns>A descriptive string that describes the bitmap formats.</returns>
4702
public static unsafe string GetFIFDescription(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFIFDescription_(fif)); }
4703
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFDescription")]
4704
private static unsafe extern byte* GetFIFDescription_(FREE_IMAGE_FORMAT fif);
4707
/// Returns a regular expression string that can be used by a regular expression engine to identify the bitmap.
4708
/// FreeImageQt makes use of this function.
4710
/// <param name="fif">The desired <see cref="FREE_IMAGE_FORMAT"/>.</param>
4711
/// <returns>A regular expression string.</returns>
4712
public static unsafe string GetFIFRegExpr(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFIFRegExpr_(fif)); }
4713
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFRegExpr")]
4714
private static unsafe extern byte* GetFIFRegExpr_(FREE_IMAGE_FORMAT fif);
4717
/// Given a <see cref="FREE_IMAGE_FORMAT"/> identifier, returns a MIME content type string (MIME stands for Multipurpose Internet Mail Extension).
4719
/// <param name="fif">The desired <see cref="FREE_IMAGE_FORMAT"/>.</param>
4720
/// <returns>A MIME content type string.</returns>
4721
public static unsafe string GetFIFMimeType(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFIFMimeType_(fif)); }
4722
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFMimeType")]
4723
private static unsafe extern byte* GetFIFMimeType_(FREE_IMAGE_FORMAT fif);
4726
/// This function takes a filename or a file-extension and returns the plugin that can
4727
/// read/write files with that extension in the form of a <see cref="FREE_IMAGE_FORMAT"/> identifier.
4729
/// <param name="filename">The filename or -extension.</param>
4730
/// <returns>The <see cref="FREE_IMAGE_FORMAT"/> of the plugin.</returns>
4731
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFIFFromFilenameU")]
4732
public static extern FREE_IMAGE_FORMAT GetFIFFromFilename(string filename);
4735
/// This function takes a filename or a file-extension and returns the plugin that can
4736
/// read/write files with that extension in the form of a <see cref="FREE_IMAGE_FORMAT"/> identifier.
4737
/// Supports UNICODE filenames.
4739
/// <param name="filename">The filename or -extension.</param>
4740
/// <returns>The <see cref="FREE_IMAGE_FORMAT"/> of the plugin.</returns>
4741
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFIFFromFilenameU")]
4742
private static extern FREE_IMAGE_FORMAT GetFIFFromFilenameU(string filename);
4745
/// Checks if a plugin can load bitmaps.
4747
/// <param name="fif">The <see cref="FREE_IMAGE_FORMAT"/> of the plugin.</param>
4748
/// <returns>True if the plugin can load bitmaps, else false.</returns>
4749
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsReading")]
4750
public static extern bool FIFSupportsReading(FREE_IMAGE_FORMAT fif);
4753
/// Checks if a plugin can save bitmaps.
4755
/// <param name="fif">The <see cref="FREE_IMAGE_FORMAT"/> of the plugin.</param>
4756
/// <returns>True if the plugin can save bitmaps, else false.</returns>
4757
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsWriting")]
4758
public static extern bool FIFSupportsWriting(FREE_IMAGE_FORMAT fif);
4761
/// Checks if a plugin can save bitmaps in the desired bit depth.
4763
/// <param name="fif">The <see cref="FREE_IMAGE_FORMAT"/> of the plugin.</param>
4764
/// <param name="bpp">The desired bit depth.</param>
4765
/// <returns>True if the plugin can save bitmaps in the desired bit depth, else false.</returns>
4766
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsExportBPP")]
4767
public static extern bool FIFSupportsExportBPP(FREE_IMAGE_FORMAT fif, int bpp);
4770
/// Checks if a plugin can save a bitmap in the desired data type.
4772
/// <param name="fif">The <see cref="FREE_IMAGE_FORMAT"/> of the plugin.</param>
4773
/// <param name="type">The desired image type.</param>
4774
/// <returns>True if the plugin can save bitmaps as the desired type, else false.</returns>
4775
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsExportType")]
4776
public static extern bool FIFSupportsExportType(FREE_IMAGE_FORMAT fif, FREE_IMAGE_TYPE type);
4779
/// Checks if a plugin can load or save an ICC profile.
4781
/// <param name="fif">The <see cref="FREE_IMAGE_FORMAT"/> of the plugin.</param>
4782
/// <returns>True if the plugin can load or save an ICC profile, else false.</returns>
4783
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsICCProfiles")]
4784
public static extern bool FIFSupportsICCProfiles(FREE_IMAGE_FORMAT fif);
4788
#region Multipage functions
4791
/// Loads a FreeImage multi-paged bitmap.
4792
/// Load flags can be provided by the flags parameter.
4794
/// <param name="fif">Format of the image.</param>
4795
/// <param name="filename">The complete name of the file to load.</param>
4796
/// <param name="create_new">When true a new bitmap is created.</param>
4797
/// <param name="read_only">When true the bitmap will be loaded read only.</param>
4798
/// <param name="keep_cache_in_memory">When true performance is increased at the cost of memory.</param>
4799
/// <param name="flags">Flags to enable or disable plugin-features.</param>
4800
/// <returns>Handle to a FreeImage multi-paged bitmap.</returns>
4801
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_OpenMultiBitmap")]
4802
public static extern FIMULTIBITMAP OpenMultiBitmap(FREE_IMAGE_FORMAT fif, string filename, bool create_new,
4803
bool read_only, bool keep_cache_in_memory, FREE_IMAGE_LOAD_FLAGS flags);
4806
/// Loads a FreeImage multi-pages bitmap from the specified handle
4807
/// using the specified functions.
4808
/// Load flags can be provided by the flags parameter.
4810
/// <param name="fif">Format of the image.</param>
4811
/// <param name="io">IO functions used to read from the specified handle.</param>
4812
/// <param name="handle">The handle to load the bitmap from.</param>
4813
/// <param name="flags">Flags to enable or disable plugin-features.</param>
4814
/// <returns>Handle to a FreeImage multi-paged bitmap.</returns>
4815
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_OpenMultiBitmapFromHandle")]
4816
public static extern FIMULTIBITMAP OpenMultiBitmapFromHandle(FREE_IMAGE_FORMAT fif, ref FreeImageIO io,
4817
fi_handle handle, FREE_IMAGE_LOAD_FLAGS flags);
4820
/// Closes a previously opened multi-page bitmap and, when the bitmap was not opened read-only, applies any changes made to it.
4822
/// <param name="bitmap">Handle to a FreeImage multi-paged bitmap.</param>
4823
/// <param name="flags">Flags to enable or disable plugin-features.</param>
4824
/// <returns>Returns true on success, false on failure.</returns>
4825
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CloseMultiBitmap")]
4826
private static extern bool CloseMultiBitmap_(FIMULTIBITMAP bitmap, FREE_IMAGE_SAVE_FLAGS flags);
4829
/// Returns the number of pages currently available in the multi-paged bitmap.
4831
/// <param name="bitmap">Handle to a FreeImage multi-paged bitmap.</param>
4832
/// <returns>Number of pages.</returns>
4833
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPageCount")]
4834
public static extern int GetPageCount(FIMULTIBITMAP bitmap);
4837
/// Appends a new page to the end of the bitmap.
4839
/// <param name="bitmap">Handle to a FreeImage multi-paged bitmap.</param>
4840
/// <param name="data">Handle to a FreeImage bitmap.</param>
4841
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AppendPage")]
4842
public static extern void AppendPage(FIMULTIBITMAP bitmap, FIBITMAP data);
4845
/// Inserts a new page before the given position in the bitmap.
4847
/// <param name="bitmap">Handle to a FreeImage multi-paged bitmap.</param>
4848
/// <param name="page">Page has to be a number smaller than the current number of pages available in the bitmap.</param>
4849
/// <param name="data">Handle to a FreeImage bitmap.</param>
4850
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_InsertPage")]
4851
public static extern void InsertPage(FIMULTIBITMAP bitmap, int page, FIBITMAP data);
4854
/// Deletes the page on the given position.
4856
/// <param name="bitmap">Handle to a FreeImage multi-paged bitmap.</param>
4857
/// <param name="page">Number of the page to delete.</param>
4858
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_DeletePage")]
4859
public static extern void DeletePage(FIMULTIBITMAP bitmap, int page);
4862
/// Locks a page in memory for editing.
4864
/// <param name="bitmap">Handle to a FreeImage multi-paged bitmap.</param>
4865
/// <param name="page">Number of the page to lock.</param>
4866
/// <returns>Handle to a FreeImage bitmap.</returns>
4867
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_LockPage")]
4868
public static extern FIBITMAP LockPage(FIMULTIBITMAP bitmap, int page);
4871
/// Unlocks a previously locked page and gives it back to the multi-page engine.
4873
/// <param name="bitmap">Handle to a FreeImage multi-paged bitmap.</param>
4874
/// <param name="data">Handle to a FreeImage bitmap.</param>
4875
/// <param name="changed">If true, the page is applied to the multi-page bitmap.</param>
4876
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_UnlockPage")]
4877
public static extern void UnlockPage(FIMULTIBITMAP bitmap, FIBITMAP data, bool changed);
4880
/// Moves the source page to the position of the target page.
4882
/// <param name="bitmap">Handle to a FreeImage multi-paged bitmap.</param>
4883
/// <param name="target">New position of the page.</param>
4884
/// <param name="source">Old position of the page.</param>
4885
/// <returns>Returns true on success, false on failure.</returns>
4886
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_MovePage")]
4887
public static extern bool MovePage(FIMULTIBITMAP bitmap, int target, int source);
4890
/// Returns an array of page-numbers that are currently locked in memory.
4891
/// When the pages parameter is null, the size of the array is returned in the count variable.
4895
/// int[] lockedPages = null;
4897
/// GetLockedPageNumbers(dib, lockedPages, ref count);
4898
/// lockedPages = new int[count];
4899
/// GetLockedPageNumbers(dib, lockedPages, ref count);
4902
/// <param name="bitmap">Handle to a FreeImage multi-paged bitmap.</param>
4903
/// <param name="pages">The list of locked pages in the multi-pages bitmap.
4904
/// If set to null, count will contain the number of pages.</param>
4905
/// <param name="count">If <paramref name="pages"/> is set to null count will contain the number of locked pages.</param>
4906
/// <returns>Returns true on success, false on failure.</returns>
4907
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetLockedPageNumbers")]
4908
public static extern bool GetLockedPageNumbers(FIMULTIBITMAP bitmap, int[] pages, ref int count);
4912
#region Filetype functions
4915
/// Orders FreeImage to analyze the bitmap signature.
4917
/// <param name="filename">Name of the file to analyze.</param>
4918
/// <param name="size">Reserved parameter - use 0.</param>
4919
/// <returns>Type of the bitmap.</returns>
4920
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFileTypeU")]
4921
public static extern FREE_IMAGE_FORMAT GetFileType(string filename, int size);
4925
/// Orders FreeImage to analyze the bitmap signature.
4926
/// Supports UNICODE filenames.
4928
/// <param name="filename">Name of the file to analyze.</param>
4929
/// <param name="size">Reserved parameter - use 0.</param>
4930
/// <returns>Type of the bitmap.</returns>
4931
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFileTypeU")]
4932
private static extern FREE_IMAGE_FORMAT GetFileTypeU(string filename, int size);
4935
/// Uses the <see cref="FreeImageIO"/> structure as described in the topic bitmap management functions
4936
/// to identify a bitmap type.
4938
/// <param name="io">A <see cref="FreeImageIO"/> structure with functionpointers to handle the source.</param>
4939
/// <param name="handle">A handle to the source.</param>
4940
/// <param name="size">Size in bytes of the source.</param>
4941
/// <returns>Type of the bitmap.</returns>
4942
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFileTypeFromHandle")]
4943
public static extern FREE_IMAGE_FORMAT GetFileTypeFromHandle(ref FreeImageIO io, fi_handle handle, int size);
4946
/// Uses a memory handle to identify a bitmap type.
4948
/// <param name="stream">Pointer to the stream.</param>
4949
/// <param name="size">Size in bytes of the source.</param>
4950
/// <returns>Type of the bitmap.</returns>
4951
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFileTypeFromMemory")]
4952
public static extern FREE_IMAGE_FORMAT GetFileTypeFromMemory(FIMEMORY stream, int size);
4956
#region Helper functions
4959
/// Returns whether the platform is using Little Endian.
4961
/// <returns>Returns true if the platform is using Litte Endian, else false.</returns>
4962
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_IsLittleEndian")]
4963
public static extern bool IsLittleEndian();
4966
/// Converts a X11 color name into a corresponding RGB value.
4968
/// <param name="szColor">Name of the color to convert.</param>
4969
/// <param name="nRed">Red component.</param>
4970
/// <param name="nGreen">Green component.</param>
4971
/// <param name="nBlue">Blue component.</param>
4972
/// <returns>Returns true on success, false on failure.</returns>
4973
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_LookupX11Color")]
4974
public static extern bool LookupX11Color(string szColor, out byte nRed, out byte nGreen, out byte nBlue);
4977
/// Converts a SVG color name into a corresponding RGB value.
4979
/// <param name="szColor">Name of the color to convert.</param>
4980
/// <param name="nRed">Red component.</param>
4981
/// <param name="nGreen">Green component.</param>
4982
/// <param name="nBlue">Blue component.</param>
4983
/// <returns>Returns true on success, false on failure.</returns>
4984
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_LookupSVGColor")]
4985
public static extern bool LookupSVGColor(string szColor, out byte nRed, out byte nGreen, out byte nBlue);
4989
#region Pixel access functions
4992
/// Returns a pointer to the data-bits of the bitmap.
4994
/// <param name="dib">Handle to a FreeImage bitmap.</param>
4995
/// <returns>Pointer to the data-bits.</returns>
4996
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetBits")]
4997
public static extern IntPtr GetBits(FIBITMAP dib);
5000
/// Returns a pointer to the start of the given scanline in the bitmap's data-bits.
5002
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5003
/// <param name="scanline">Number of the scanline.</param>
5004
/// <returns>Pointer to the scanline.</returns>
5005
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetScanLine")]
5006
public static extern IntPtr GetScanLine(FIBITMAP dib, int scanline);
5009
/// Get the pixel index of a palettized image at position (x, y), including range check (slow access).
5011
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5012
/// <param name="x">Pixel position in horizontal direction.</param>
5013
/// <param name="y">Pixel position in vertical direction.</param>
5014
/// <param name="value">The pixel index.</param>
5015
/// <returns>Returns true on success, false on failure.</returns>
5016
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPixelIndex")]
5017
public static extern bool GetPixelIndex(FIBITMAP dib, uint x, uint y, out byte value);
5020
/// Get the pixel color of a 16-, 24- or 32-bit image at position (x, y), including range check (slow access).
5022
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5023
/// <param name="x">Pixel position in horizontal direction.</param>
5024
/// <param name="y">Pixel position in vertical direction.</param>
5025
/// <param name="value">The pixel color.</param>
5026
/// <returns>Returns true on success, false on failure.</returns>
5027
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPixelColor")]
5028
public static extern bool GetPixelColor(FIBITMAP dib, uint x, uint y, out RGBQUAD value);
5031
/// Set the pixel index of a palettized image at position (x, y), including range check (slow access).
5033
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5034
/// <param name="x">Pixel position in horizontal direction.</param>
5035
/// <param name="y">Pixel position in vertical direction.</param>
5036
/// <param name="value">The new pixel index.</param>
5037
/// <returns>Returns true on success, false on failure.</returns>
5038
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetPixelIndex")]
5039
public static extern bool SetPixelIndex(FIBITMAP dib, uint x, uint y, ref byte value);
5042
/// Set the pixel color of a 16-, 24- or 32-bit image at position (x, y), including range check (slow access).
5044
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5045
/// <param name="x">Pixel position in horizontal direction.</param>
5046
/// <param name="y">Pixel position in vertical direction.</param>
5047
/// <param name="value">The new pixel color.</param>
5048
/// <returns>Returns true on success, false on failure.</returns>
5049
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetPixelColor")]
5050
public static extern bool SetPixelColor(FIBITMAP dib, uint x, uint y, ref RGBQUAD value);
5054
#region Bitmap information functions
5057
/// Retrieves the type of the bitmap.
5059
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5060
/// <returns>Type of the bitmap.</returns>
5061
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetImageType")]
5062
public static extern FREE_IMAGE_TYPE GetImageType(FIBITMAP dib);
5065
/// Returns the number of colors used in a bitmap.
5067
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5068
/// <returns>Palette-size for palletised bitmaps, and 0 for high-colour bitmaps.</returns>
5069
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetColorsUsed")]
5070
public static extern uint GetColorsUsed(FIBITMAP dib);
5073
/// Returns the size of one pixel in the bitmap in bits.
5075
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5076
/// <returns>Size of one pixel in the bitmap in bits.</returns>
5077
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetBPP")]
5078
public static extern uint GetBPP(FIBITMAP dib);
5081
/// Returns the width of the bitmap in pixel units.
5083
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5084
/// <returns>With of the bitmap.</returns>
5085
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetWidth")]
5086
public static extern uint GetWidth(FIBITMAP dib);
5089
/// Returns the height of the bitmap in pixel units.
5091
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5092
/// <returns>Height of the bitmap.</returns>
5093
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetHeight")]
5094
public static extern uint GetHeight(FIBITMAP dib);
5097
/// Returns the width of the bitmap in bytes.
5099
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5100
/// <returns>With of the bitmap in bytes.</returns>
5101
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetLine")]
5102
public static extern uint GetLine(FIBITMAP dib);
5105
/// Returns the width of the bitmap in bytes, rounded to the next 32-bit boundary,
5106
/// also known as pitch or stride or scan width.
5108
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5109
/// <returns>With of the bitmap in bytes.</returns>
5110
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPitch")]
5111
public static extern uint GetPitch(FIBITMAP dib);
5114
/// Returns the size of the DIB-element of a FIBITMAP in memory.
5116
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5117
/// <returns>Size of the DIB-element</returns>
5118
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetDIBSize")]
5119
public static extern uint GetDIBSize(FIBITMAP dib);
5122
/// Returns a pointer to the bitmap's palette.
5124
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5125
/// <returns>Pointer to the bitmap's palette.</returns>
5126
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPalette")]
5127
public static extern IntPtr GetPalette(FIBITMAP dib);
5130
/// Returns the horizontal resolution, in pixels-per-meter, of the target device for the bitmap.
5132
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5133
/// <returns>The horizontal resolution, in pixels-per-meter.</returns>
5134
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetDotsPerMeterX")]
5135
public static extern uint GetDotsPerMeterX(FIBITMAP dib);
5138
/// Returns the vertical resolution, in pixels-per-meter, of the target device for the bitmap.
5140
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5141
/// <returns>The vertical resolution, in pixels-per-meter.</returns>
5142
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetDotsPerMeterY")]
5143
public static extern uint GetDotsPerMeterY(FIBITMAP dib);
5146
/// Set the horizontal resolution, in pixels-per-meter, of the target device for the bitmap.
5148
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5149
/// <param name="res">The new horizontal resolution.</param>
5150
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetDotsPerMeterX")]
5151
public static extern void SetDotsPerMeterX(FIBITMAP dib, uint res);
5154
/// Set the vertical resolution, in pixels-per-meter, of the target device for the bitmap.
5156
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5157
/// <param name="res">The new vertical resolution.</param>
5158
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetDotsPerMeterY")]
5159
public static extern void SetDotsPerMeterY(FIBITMAP dib, uint res);
5162
/// Returns a pointer to the <see cref="BITMAPINFOHEADER"/> of the DIB-element in a FIBITMAP.
5164
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5165
/// <returns>Poiter to the header of the bitmap.</returns>
5166
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetInfoHeader")]
5167
public static extern IntPtr GetInfoHeader(FIBITMAP dib);
5170
/// Alias for FreeImage_GetInfoHeader that returns a pointer to a <see cref="BITMAPINFO"/>
5171
/// rather than to a <see cref="BITMAPINFOHEADER"/>.
5173
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5174
/// <returns>Pointer to the <see cref="BITMAPINFO"/> structure for the bitmap.</returns>
5175
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetInfo")]
5176
public static extern IntPtr GetInfo(FIBITMAP dib);
5179
/// Investigates the color type of the bitmap by reading the bitmap's pixel bits and analysing them.
5181
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5182
/// <returns>The color type of the bitmap.</returns>
5183
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetColorType")]
5184
public static extern FREE_IMAGE_COLOR_TYPE GetColorType(FIBITMAP dib);
5187
/// Returns a bit pattern describing the red color component of a pixel in a FreeImage bitmap.
5189
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5190
/// <returns>The bit pattern for RED.</returns>
5191
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetRedMask")]
5192
public static extern uint GetRedMask(FIBITMAP dib);
5195
/// Returns a bit pattern describing the green color component of a pixel in a FreeImage bitmap.
5197
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5198
/// <returns>The bit pattern for green.</returns>
5199
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetGreenMask")]
5200
public static extern uint GetGreenMask(FIBITMAP dib);
5203
/// Returns a bit pattern describing the blue color component of a pixel in a FreeImage bitmap.
5205
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5206
/// <returns>The bit pattern for blue.</returns>
5207
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetBlueMask")]
5208
public static extern uint GetBlueMask(FIBITMAP dib);
5211
/// Returns the number of transparent colors in a palletised bitmap.
5213
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5214
/// <returns>The number of transparent colors in a palletised bitmap.</returns>
5215
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTransparencyCount")]
5216
public static extern uint GetTransparencyCount(FIBITMAP dib);
5219
/// Returns a pointer to the bitmap's transparency table.
5221
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5222
/// <returns>Pointer to the bitmap's transparency table.</returns>
5223
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTransparencyTable")]
5224
public static extern IntPtr GetTransparencyTable(FIBITMAP dib);
5227
/// Tells FreeImage if it should make use of the transparency table
5228
/// or the alpha channel that may accompany a bitmap.
5230
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5231
/// <param name="enabled">True to enable the transparency, false to disable.</param>
5232
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTransparent")]
5233
public static extern void SetTransparent(FIBITMAP dib, bool enabled);
5236
/// Set the bitmap's transparency table. Only affects palletised bitmaps.
5238
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5239
/// <param name="table">Pointer to the bitmap's new transparency table.</param>
5240
/// <param name="count">The number of transparent colors in the new transparency table.</param>
5241
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTransparencyTable")]
5242
internal static extern void SetTransparencyTable(FIBITMAP dib, byte[] table, int count);
5245
/// Returns whether the transparency table is enabled.
5247
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5248
/// <returns>Returns true when the transparency table is enabled (1-, 4- or 8-bit images)
5249
/// or when the input dib contains alpha values (32-bit images). Returns false otherwise.</returns>
5250
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_IsTransparent")]
5251
public static extern bool IsTransparent(FIBITMAP dib);
5254
/// Returns whether the bitmap has a file background color.
5256
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5257
/// <returns>Returns true when the image has a file background color, false otherwise.</returns>
5258
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_HasBackgroundColor")]
5259
public static extern bool HasBackgroundColor(FIBITMAP dib);
5262
/// Returns the file background color of an image.
5263
/// For 8-bit images, the color index in the palette is returned in the
5264
/// rgbReserved member of the bkcolor parameter.
5266
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5267
/// <param name="bkcolor">The background color.</param>
5268
/// <returns>Returns true on success, false on failure.</returns>
5269
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetBackgroundColor")]
5270
public static extern bool GetBackgroundColor(FIBITMAP dib, out RGBQUAD bkcolor);
5273
/// Set the file background color of an image.
5274
/// When saving an image to PNG, this background color is transparently saved to the PNG file.
5276
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5277
/// <param name="bkcolor">The new background color.</param>
5278
/// <returns>Returns true on success, false on failure.</returns>
5279
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetBackgroundColor")]
5280
public static unsafe extern bool SetBackgroundColor(FIBITMAP dib, ref RGBQUAD bkcolor);
5283
/// Set the file background color of an image.
5284
/// When saving an image to PNG, this background color is transparently saved to the PNG file.
5285
/// When the bkcolor parameter is null, the background color is removed from the image.
5287
/// This overloaded version of the function with an array parameter is provided to allow
5288
/// passing <c>null</c> in the <paramref name="bkcolor"/> parameter. This is similar to the
5289
/// original C/C++ function. Passing <c>null</c> as <paramref name="bkcolor"/> parameter will
5290
/// unset the dib's previously set background color.
5293
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5294
/// <param name="bkcolor">The new background color.
5295
/// The first entry in the array is used.</param>
5296
/// <returns>Returns true on success, false on failure.</returns>
5299
/// // create a RGBQUAD color
5300
/// RGBQUAD color = new RGBQUAD(Color.Green);
5302
/// // set the dib's background color (using the other version of the function)
5303
/// FreeImage.SetBackgroundColor(dib, ref color);
5305
/// // remove it again (this only works due to the array parameter RGBQUAD[])
5306
/// FreeImage.SetBackgroundColor(dib, null);
5309
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetBackgroundColor")]
5310
public static unsafe extern bool SetBackgroundColor(FIBITMAP dib, RGBQUAD[] bkcolor);
5313
/// Sets the index of the palette entry to be used as transparent color
5314
/// for the image specified. Does nothing on high color images.
5316
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5317
/// <param name="index">The index of the palette entry to be set as transparent color.</param>
5318
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTransparentIndex")]
5319
public static extern void SetTransparentIndex(FIBITMAP dib, int index);
5322
/// Returns the palette entry used as transparent color for the image specified.
5323
/// Works for palletised images only and returns -1 for high color
5324
/// images or if the image has no color set to be transparent.
5326
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5327
/// <returns>the index of the palette entry used as transparent color for
5328
/// the image specified or -1 if there is no transparent color found
5329
/// (e.g. the image is a high color image).</returns>
5330
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTransparentIndex")]
5331
public static extern int GetTransparentIndex(FIBITMAP dib);
5335
#region ICC profile functions
5338
/// Retrieves the <see cref="FIICCPROFILE"/> data of the bitmap.
5339
/// This function can also be called safely, when the original format does not support profiles.
5341
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5342
/// <returns>The <see cref="FIICCPROFILE"/> data of the bitmap.</returns>
5343
public static FIICCPROFILE GetICCProfileEx(FIBITMAP dib) { unsafe { return *(FIICCPROFILE*)FreeImage.GetICCProfile(dib); } }
5346
/// Retrieves a pointer to the <see cref="FIICCPROFILE"/> data of the bitmap.
5347
/// This function can also be called safely, when the original format does not support profiles.
5349
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5350
/// <returns>Pointer to the <see cref="FIICCPROFILE"/> data of the bitmap.</returns>
5351
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetICCProfile")]
5352
public static extern IntPtr GetICCProfile(FIBITMAP dib);
5355
/// Creates a new <see cref="FIICCPROFILE"/> block from ICC profile data previously read from a file
5356
/// or built by a color management system. The profile data is attached to the bitmap.
5358
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5359
/// <param name="data">Pointer to the new <see cref="FIICCPROFILE"/> data.</param>
5360
/// <param name="size">Size of the <see cref="FIICCPROFILE"/> data.</param>
5361
/// <returns>Pointer to the created <see cref="FIICCPROFILE"/> structure.</returns>
5362
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CreateICCProfile")]
5363
public static extern IntPtr CreateICCProfile(FIBITMAP dib, byte[] data, int size);
5366
/// This function destroys an <see cref="FIICCPROFILE"/> previously created by <see cref="CreateICCProfile(FIBITMAP,byte[],int)"/>.
5367
/// After this call the bitmap will contain no profile information.
5368
/// This function should be called to ensure that a stored bitmap will not contain any profile information.
5370
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5371
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_DestroyICCProfile")]
5372
public static extern void DestroyICCProfile(FIBITMAP dib);
5376
#region Conversion functions
5379
/// Converts a bitmap to 4 bits.
5380
/// If the bitmap was a high-color bitmap (16, 24 or 32-bit) or if it was a
5381
/// monochrome or greyscale bitmap (1 or 8-bit), the end result will be a
5382
/// greyscale bitmap, otherwise (1-bit palletised bitmaps) it will be a palletised bitmap.
5384
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5385
/// <returns>Handle to a FreeImage bitmap.</returns>
5386
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo4Bits")]
5387
public static extern FIBITMAP ConvertTo4Bits(FIBITMAP dib);
5390
/// Converts a bitmap to 8 bits. If the bitmap was a high-color bitmap (16, 24 or 32-bit)
5391
/// or if it was a monochrome or greyscale bitmap (1 or 4-bit), the end result will be a
5392
/// greyscale bitmap, otherwise (1 or 4-bit palletised bitmaps) it will be a palletised bitmap.
5394
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5395
/// <returns>Handle to a FreeImage bitmap.</returns>
5396
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo8Bits")]
5397
public static extern FIBITMAP ConvertTo8Bits(FIBITMAP dib);
5400
/// Converts a bitmap to a 8-bit greyscale image with a linear ramp.
5402
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5403
/// <returns>Handle to a FreeImage bitmap.</returns>
5404
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToGreyscale")]
5405
public static extern FIBITMAP ConvertToGreyscale(FIBITMAP dib);
5408
/// Converts a bitmap to 16 bits, where each pixel has a color pattern of
5409
/// 5 bits red, 5 bits green and 5 bits blue. One bit in each pixel is unused.
5411
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5412
/// <returns>Handle to a FreeImage bitmap.</returns>
5413
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo16Bits555")]
5414
public static extern FIBITMAP ConvertTo16Bits555(FIBITMAP dib);
5417
/// Converts a bitmap to 16 bits, where each pixel has a color pattern of
5418
/// 5 bits red, 6 bits green and 5 bits blue.
5420
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5421
/// <returns>Handle to a FreeImage bitmap.</returns>
5422
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo16Bits565")]
5423
public static extern FIBITMAP ConvertTo16Bits565(FIBITMAP dib);
5426
/// Converts a bitmap to 24 bits. A clone of the input bitmap is returned for 24-bit bitmaps.
5428
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5429
/// <returns>Handle to a FreeImage bitmap.</returns>
5430
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo24Bits")]
5431
public static extern FIBITMAP ConvertTo24Bits(FIBITMAP dib);
5434
/// Converts a bitmap to 32 bits. A clone of the input bitmap is returned for 32-bit bitmaps.
5436
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5437
/// <returns>Handle to a FreeImage bitmap.</returns>
5438
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertTo32Bits")]
5439
public static extern FIBITMAP ConvertTo32Bits(FIBITMAP dib);
5442
/// Quantizes a high-color 24-bit bitmap to an 8-bit palette color bitmap.
5444
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5445
/// <param name="quantize">Specifies the color reduction algorithm to be used.</param>
5446
/// <returns>Handle to a FreeImage bitmap.</returns>
5447
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ColorQuantize")]
5448
public static extern FIBITMAP ColorQuantize(FIBITMAP dib, FREE_IMAGE_QUANTIZE quantize);
5451
/// ColorQuantizeEx is an extension to the <see cref="ColorQuantize(FIBITMAP, FREE_IMAGE_QUANTIZE)"/> method that
5452
/// provides additional options used to quantize a 24-bit image to any
5453
/// number of colors (up to 256), as well as quantize a 24-bit image using a
5454
/// partial or full provided palette.
5456
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5457
/// <param name="quantize">Specifies the color reduction algorithm to be used.</param>
5458
/// <param name="PaletteSize">Size of the desired output palette.</param>
5459
/// <param name="ReserveSize">Size of the provided palette of ReservePalette.</param>
5460
/// <param name="ReservePalette">The provided palette.</param>
5461
/// <returns>Handle to a FreeImage bitmap.</returns>
5462
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ColorQuantizeEx")]
5463
public static extern FIBITMAP ColorQuantizeEx(FIBITMAP dib, FREE_IMAGE_QUANTIZE quantize, int PaletteSize, int ReserveSize, RGBQUAD[] ReservePalette);
5466
/// Converts a bitmap to 1-bit monochrome bitmap using a threshold T between [0..255].
5467
/// The function first converts the bitmap to a 8-bit greyscale bitmap.
5468
/// Then, any brightness level that is less than T is set to zero, otherwise to 1.
5469
/// For 1-bit input bitmaps, the function clones the input bitmap and builds a monochrome palette.
5471
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5472
/// <param name="t">The threshold.</param>
5473
/// <returns>Handle to a FreeImage bitmap.</returns>
5474
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Threshold")]
5475
public static extern FIBITMAP Threshold(FIBITMAP dib, byte t);
5478
/// Converts a bitmap to 1-bit monochrome bitmap using a dithering algorithm.
5479
/// For 1-bit input bitmaps, the function clones the input bitmap and builds a monochrome palette.
5481
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5482
/// <param name="algorithm">The dithering algorithm to use.</param>
5483
/// <returns>Handle to a FreeImage bitmap.</returns>
5484
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Dither")]
5485
public static extern FIBITMAP Dither(FIBITMAP dib, FREE_IMAGE_DITHER algorithm);
5488
/// Converts a raw bitmap to a FreeImage bitmap.
5490
/// <param name="bits">Pointer to the memory block containing the raw bitmap.</param>
5491
/// <param name="width">The width in pixels of the raw bitmap.</param>
5492
/// <param name="height">The height in pixels of the raw bitmap.</param>
5493
/// <param name="pitch">Defines the total width of a scanline in the raw bitmap,
5494
/// including padding bytes.</param>
5495
/// <param name="bpp">The bit depth (bits per pixel) of the raw bitmap.</param>
5496
/// <param name="red_mask">The bit mask describing the bits used to store a single
5497
/// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.</param>
5498
/// <param name="green_mask">The bit mask describing the bits used to store a single
5499
/// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.</param>
5500
/// <param name="blue_mask">The bit mask describing the bits used to store a single
5501
/// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.</param>
5502
/// <param name="topdown">If true, the raw bitmap is stored in top-down order (top-left pixel first)
5503
/// and in bottom-up order (bottom-left pixel first) otherwise.</param>
5504
/// <returns>Handle to a FreeImage bitmap.</returns>
5505
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertFromRawBits")]
5506
public static extern FIBITMAP ConvertFromRawBits(IntPtr bits, int width, int height, int pitch,
5507
uint bpp, uint red_mask, uint green_mask, uint blue_mask, bool topdown);
5510
/// Converts a raw bitmap to a FreeImage bitmap.
5512
/// <param name="bits">Array of bytes containing the raw bitmap.</param>
5513
/// <param name="width">The width in pixels of the raw bitmap.</param>
5514
/// <param name="height">The height in pixels of the raw bitmap.</param>
5515
/// <param name="pitch">Defines the total width of a scanline in the raw bitmap,
5516
/// including padding bytes.</param>
5517
/// <param name="bpp">The bit depth (bits per pixel) of the raw bitmap.</param>
5518
/// <param name="red_mask">The bit mask describing the bits used to store a single
5519
/// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.</param>
5520
/// <param name="green_mask">The bit mask describing the bits used to store a single
5521
/// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.</param>
5522
/// <param name="blue_mask">The bit mask describing the bits used to store a single
5523
/// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.</param>
5524
/// <param name="topdown">If true, the raw bitmap is stored in top-down order (top-left pixel first)
5525
/// and in bottom-up order (bottom-left pixel first) otherwise.</param>
5526
/// <returns>Handle to a FreeImage bitmap.</returns>
5527
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertFromRawBits")]
5528
public static extern FIBITMAP ConvertFromRawBits(byte[] bits, int width, int height, int pitch,
5529
uint bpp, uint red_mask, uint green_mask, uint blue_mask, bool topdown);
5532
/// Converts a FreeImage bitmap to a raw bitmap, that is a raw piece of memory.
5534
/// <param name="bits">Pointer to the memory block receiving the raw bitmap.</param>
5535
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5536
/// <param name="pitch">The desired total width in bytes of a scanline in the raw bitmap,
5537
/// including any padding bytes.</param>
5538
/// <param name="bpp">The desired bit depth (bits per pixel) of the raw bitmap.</param>
5539
/// <param name="red_mask">The desired bit mask describing the bits used to store a single
5540
/// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.</param>
5541
/// <param name="green_mask">The desired bit mask describing the bits used to store a single
5542
/// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.</param>
5543
/// <param name="blue_mask">The desired bit mask describing the bits used to store a single
5544
/// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.</param>
5545
/// <param name="topdown">If true, the raw bitmap will be stored in top-down order (top-left pixel first)
5546
/// and in bottom-up order (bottom-left pixel first) otherwise.</param>
5547
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToRawBits")]
5548
public static extern void ConvertToRawBits(IntPtr bits, FIBITMAP dib, int pitch, uint bpp,
5549
uint red_mask, uint green_mask, uint blue_mask, bool topdown);
5552
/// Converts a FreeImage bitmap to a raw bitmap, that is a raw piece of memory.
5554
/// <param name="bits">Array of bytes receiving the raw bitmap.</param>
5555
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5556
/// <param name="pitch">The desired total width in bytes of a scanline in the raw bitmap,
5557
/// including any padding bytes.</param>
5558
/// <param name="bpp">The desired bit depth (bits per pixel) of the raw bitmap.</param>
5559
/// <param name="red_mask">The desired bit mask describing the bits used to store a single
5560
/// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.</param>
5561
/// <param name="green_mask">The desired bit mask describing the bits used to store a single
5562
/// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.</param>
5563
/// <param name="blue_mask">The desired bit mask describing the bits used to store a single
5564
/// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.</param>
5565
/// <param name="topdown">If true, the raw bitmap will be stored in top-down order (top-left pixel first)
5566
/// and in bottom-up order (bottom-left pixel first) otherwise.</param>
5567
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToRawBits")]
5568
public static extern void ConvertToRawBits(byte[] bits, FIBITMAP dib, int pitch, uint bpp,
5569
uint red_mask, uint green_mask, uint blue_mask, bool topdown);
5572
/// Converts a 24- or 32-bit RGB(A) standard image or a 48-bit RGB image to a FIT_RGBF type image.
5574
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5575
/// <returns>Handle to a FreeImage bitmap.</returns>
5576
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToRGBF")]
5577
public static extern FIBITMAP ConvertToRGBF(FIBITMAP dib);
5580
/// Converts a non standard image whose color type is FIC_MINISBLACK
5581
/// to a standard 8-bit greyscale image.
5583
/// <param name="src">Handle to a FreeImage bitmap.</param>
5584
/// <param name="scale_linear">When true the conversion is done by scaling linearly
5585
/// each pixel value from [min, max] to an integer value between [0..255],
5586
/// where min and max are the minimum and maximum pixel values in the image.
5587
/// When false the conversion is done by rounding each pixel value to an integer between [0..255].
5589
/// Rounding is done using the following formula:
5591
/// dst_pixel = (BYTE) MIN(255, MAX(0, q)) where int q = int(src_pixel + 0.5);</param>
5592
/// <returns>Handle to a FreeImage bitmap.</returns>
5593
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToStandardType")]
5594
public static extern FIBITMAP ConvertToStandardType(FIBITMAP src, bool scale_linear);
5597
/// Converts an image of any type to type dst_type.
5599
/// <param name="src">Handle to a FreeImage bitmap.</param>
5600
/// <param name="dst_type">Destination type.</param>
5601
/// <param name="scale_linear">True to scale linear, else false.</param>
5602
/// <returns>Handle to a FreeImage bitmap.</returns>
5603
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ConvertToType")]
5604
public static extern FIBITMAP ConvertToType(FIBITMAP src, FREE_IMAGE_TYPE dst_type, bool scale_linear);
5608
#region Tone mapping operators
5611
/// Converts a High Dynamic Range image (48-bit RGB or 96-bit RGBF) to a 24-bit RGB image, suitable for display.
5613
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5614
/// <param name="tmo">The tone mapping operator to be used.</param>
5615
/// <param name="first_param">Parmeter depending on the used algorithm</param>
5616
/// <param name="second_param">Parmeter depending on the used algorithm</param>
5617
/// <returns>Handle to a FreeImage bitmap.</returns>
5618
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ToneMapping")]
5619
public static extern FIBITMAP ToneMapping(FIBITMAP dib, FREE_IMAGE_TMO tmo, double first_param, double second_param);
5622
/// Converts a High Dynamic Range image to a 24-bit RGB image using a global
5623
/// operator based on logarithmic compression of luminance values, imitating the human response to light.
5625
/// <param name="src">Handle to a FreeImage bitmap.</param>
5626
/// <param name="gamma">A gamma correction that is applied after the tone mapping.
5627
/// A value of 1 means no correction.</param>
5628
/// <param name="exposure">Scale factor allowing to adjust the brightness of the output image.</param>
5629
/// <returns>Handle to a FreeImage bitmap.</returns>
5630
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_TmoDrago03")]
5631
public static extern FIBITMAP TmoDrago03(FIBITMAP src, double gamma, double exposure);
5634
/// Converts a High Dynamic Range image to a 24-bit RGB image using a global operator inspired
5635
/// by photoreceptor physiology of the human visual system.
5637
/// <param name="src">Handle to a FreeImage bitmap.</param>
5638
/// <param name="intensity">Controls the overall image intensity in the range [-8, 8].</param>
5639
/// <param name="contrast">Controls the overall image contrast in the range [0.3, 1.0[.</param>
5640
/// <returns>Handle to a FreeImage bitmap.</returns>
5641
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_TmoReinhard05")]
5642
public static extern FIBITMAP TmoReinhard05(FIBITMAP src, double intensity, double contrast);
5645
/// Apply the Gradient Domain High Dynamic Range Compression to a RGBF image and convert to 24-bit RGB.
5647
/// <param name="src">Handle to a FreeImage bitmap.</param>
5648
/// <param name="color_saturation">Color saturation (s parameter in the paper) in [0.4..0.6]</param>
5649
/// <param name="attenuation">Atenuation factor (beta parameter in the paper) in [0.8..0.9]</param>
5650
/// <returns>Handle to a FreeImage bitmap.</returns>
5651
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_TmoFattal02")]
5652
public static extern FIBITMAP TmoFattal02(FIBITMAP src, double color_saturation, double attenuation);
5656
#region Compression functions
5659
/// Compresses a source buffer into a target buffer, using the ZLib library.
5661
/// <param name="target">Pointer to the target buffer.</param>
5662
/// <param name="target_size">Size of the target buffer.
5663
/// Must be at least 0.1% larger than source_size plus 12 bytes.</param>
5664
/// <param name="source">Pointer to the source buffer.</param>
5665
/// <param name="source_size">Size of the source buffer.</param>
5666
/// <returns>The actual size of the compressed buffer, or 0 if an error occurred.</returns>
5667
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibCompress")]
5668
public static extern uint ZLibCompress(byte[] target, uint target_size, byte[] source, uint source_size);
5671
/// Decompresses a source buffer into a target buffer, using the ZLib library.
5673
/// <param name="target">Pointer to the target buffer.</param>
5674
/// <param name="target_size">Size of the target buffer.
5675
/// Must have been saved outlide of zlib.</param>
5676
/// <param name="source">Pointer to the source buffer.</param>
5677
/// <param name="source_size">Size of the source buffer.</param>
5678
/// <returns>The actual size of the uncompressed buffer, or 0 if an error occurred.</returns>
5679
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibUncompress")]
5680
public static extern uint ZLibUncompress(byte[] target, uint target_size, byte[] source, uint source_size);
5683
/// Compresses a source buffer into a target buffer, using the ZLib library.
5685
/// <param name="target">Pointer to the target buffer.</param>
5686
/// <param name="target_size">Size of the target buffer.
5687
/// Must be at least 0.1% larger than source_size plus 24 bytes.</param>
5688
/// <param name="source">Pointer to the source buffer.</param>
5689
/// <param name="source_size">Size of the source buffer.</param>
5690
/// <returns>The actual size of the compressed buffer, or 0 if an error occurred.</returns>
5691
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibGZip")]
5692
public static extern uint ZLibGZip(byte[] target, uint target_size, byte[] source, uint source_size);
5695
/// Decompresses a source buffer into a target buffer, using the ZLib library.
5697
/// <param name="target">Pointer to the target buffer.</param>
5698
/// <param name="target_size">Size of the target buffer.
5699
/// Must have been saved outlide of zlib.</param>
5700
/// <param name="source">Pointer to the source buffer.</param>
5701
/// <param name="source_size">Size of the source buffer.</param>
5702
/// <returns>The actual size of the uncompressed buffer, or 0 if an error occurred.</returns>
5703
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibGUnzip")]
5704
public static extern uint ZLibGUnzip(byte[] target, uint target_size, byte[] source, uint source_size);
5707
/// Generates a CRC32 checksum.
5709
/// <param name="crc">The CRC32 checksum to begin with.</param>
5710
/// <param name="source">Pointer to the source buffer.
5711
/// If the value is 0, the function returns the required initial value for the crc.</param>
5712
/// <param name="source_size">Size of the source buffer.</param>
5713
/// <returns></returns>
5714
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ZLibCRC32")]
5715
public static extern uint ZLibCRC32(uint crc, byte[] source, uint source_size);
5719
#region Tag creation and destruction
5722
/// Allocates a new <see cref="FITAG"/> object.
5723
/// This object must be destroyed with a call to
5724
/// <see cref="FreeImageAPI.FreeImage.DeleteTag(FITAG)"/> when no longer in use.
5726
/// <returns>The new <see cref="FITAG"/>.</returns>
5727
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CreateTag")]
5728
public static extern FITAG CreateTag();
5731
/// Delete a previously allocated <see cref="FITAG"/> object.
5733
/// <param name="tag">The <see cref="FITAG"/> to destroy.</param>
5734
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_DeleteTag")]
5735
public static extern void DeleteTag(FITAG tag);
5738
/// Creates and returns a copy of a <see cref="FITAG"/> object.
5740
/// <param name="tag">The <see cref="FITAG"/> to clone.</param>
5741
/// <returns>The new <see cref="FITAG"/>.</returns>
5742
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CloneTag")]
5743
public static extern FITAG CloneTag(FITAG tag);
5747
#region Tag accessors
5750
/// Returns the tag field name (unique inside a metadata model).
5752
/// <param name="tag">The tag field.</param>
5753
/// <returns>The field name.</returns>
5754
public static unsafe string GetTagKey(FITAG tag) { return PtrToStr(GetTagKey_(tag)); }
5755
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetTagKey")]
5756
private static unsafe extern byte* GetTagKey_(FITAG tag);
5759
/// Returns the tag description.
5761
/// <param name="tag">The tag field.</param>
5762
/// <returns>The description or NULL if unavailable.</returns>
5763
public static unsafe string GetTagDescription(FITAG tag) { return PtrToStr(GetTagDescription_(tag)); }
5764
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetTagDescription")]
5765
private static unsafe extern byte* GetTagDescription_(FITAG tag);
5768
/// Returns the tag ID.
5770
/// <param name="tag">The tag field.</param>
5771
/// <returns>The ID or 0 if unavailable.</returns>
5772
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagID")]
5773
public static extern ushort GetTagID(FITAG tag);
5776
/// Returns the tag data type.
5778
/// <param name="tag">The tag field.</param>
5779
/// <returns>The tag type.</returns>
5780
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagType")]
5781
public static extern FREE_IMAGE_MDTYPE GetTagType(FITAG tag);
5784
/// Returns the number of components in the tag (in tag type units).
5786
/// <param name="tag">The tag field.</param>
5787
/// <returns>The number of components.</returns>
5788
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagCount")]
5789
public static extern uint GetTagCount(FITAG tag);
5792
/// Returns the length of the tag value in bytes.
5794
/// <param name="tag">The tag field.</param>
5795
/// <returns>The length of the tag value.</returns>
5796
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagLength")]
5797
public static extern uint GetTagLength(FITAG tag);
5800
/// Returns the tag value.
5801
/// It is up to the programmer to interpret the returned pointer correctly,
5802
/// according to the results of GetTagType and GetTagCount.
5804
/// <param name="tag">The tag field.</param>
5805
/// <returns>Pointer to the value.</returns>
5806
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetTagValue")]
5807
public static extern IntPtr GetTagValue(FITAG tag);
5810
/// Sets the tag field name.
5812
/// <param name="tag">The tag field.</param>
5813
/// <param name="key">The new name.</param>
5814
/// <returns>Returns true on success, false on failure.</returns>
5815
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_SetTagKey")]
5816
public static extern bool SetTagKey(FITAG tag, string key);
5819
/// Sets the tag description.
5821
/// <param name="tag">The tag field.</param>
5822
/// <param name="description">The new description.</param>
5823
/// <returns>Returns true on success, false on failure.</returns>
5824
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_SetTagDescription")]
5825
public static extern bool SetTagDescription(FITAG tag, string description);
5828
/// Sets the tag ID.
5830
/// <param name="tag">The tag field.</param>
5831
/// <param name="id">The new ID.</param>
5832
/// <returns>Returns true on success, false on failure.</returns>
5833
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagID")]
5834
public static extern bool SetTagID(FITAG tag, ushort id);
5837
/// Sets the tag data type.
5839
/// <param name="tag">The tag field.</param>
5840
/// <param name="type">The new type.</param>
5841
/// <returns>Returns true on success, false on failure.</returns>
5842
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagType")]
5843
public static extern bool SetTagType(FITAG tag, FREE_IMAGE_MDTYPE type);
5846
/// Sets the number of data in the tag.
5848
/// <param name="tag">The tag field.</param>
5849
/// <param name="count">New number of data.</param>
5850
/// <returns>Returns true on success, false on failure.</returns>
5851
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagCount")]
5852
public static extern bool SetTagCount(FITAG tag, uint count);
5855
/// Sets the length of the tag value in bytes.
5857
/// <param name="tag">The tag field.</param>
5858
/// <param name="length">The new length.</param>
5859
/// <returns>Returns true on success, false on failure.</returns>
5860
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagLength")]
5861
public static extern bool SetTagLength(FITAG tag, uint length);
5864
/// Sets the tag value.
5866
/// <param name="tag">The tag field.</param>
5867
/// <param name="value">Pointer to the new value.</param>
5868
/// <returns>Returns true on success, false on failure.</returns>
5869
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetTagValue")]
5870
public static extern bool SetTagValue(FITAG tag, byte[] value);
5874
#region Metadata iterator
5877
/// Provides information about the first instance of a tag that matches the metadata model.
5879
/// <param name="model">The model to match.</param>
5880
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5881
/// <param name="tag">Tag that matches the metadata model.</param>
5882
/// <returns>Unique search handle that can be used to call FindNextMetadata or FindCloseMetadata.
5883
/// Null if the metadata model does not exist.</returns>
5884
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FindFirstMetadata")]
5885
public static extern FIMETADATA FindFirstMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP dib, out FITAG tag);
5888
/// Find the next tag, if any, that matches the metadata model argument in a previous call
5889
/// to FindFirstMetadata, and then alters the tag object contents accordingly.
5891
/// <param name="mdhandle">Unique search handle provided by FindFirstMetadata.</param>
5892
/// <param name="tag">Tag that matches the metadata model.</param>
5893
/// <returns>Returns true on success, false on failure.</returns>
5894
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FindNextMetadata")]
5895
public static extern bool FindNextMetadata(FIMETADATA mdhandle, out FITAG tag);
5898
/// Closes the specified metadata search handle and releases associated resources.
5900
/// <param name="mdhandle">The handle to close.</param>
5901
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FindCloseMetadata")]
5902
private static extern void FindCloseMetadata_(FIMETADATA mdhandle);
5906
#region Metadata setter and getter
5909
/// Retrieve a metadata attached to a dib.
5911
/// <param name="model">The metadata model to look for.</param>
5912
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5913
/// <param name="key">The metadata field name.</param>
5914
/// <param name="tag">A FITAG structure returned by the function.</param>
5915
/// <returns>Returns true on success, false on failure.</returns>
5916
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetMetadata")]
5917
public static extern bool GetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP dib, string key, out FITAG tag);
5920
/// Attach a new FreeImage tag to a dib.
5922
/// <param name="model">The metadata model used to store the tag.</param>
5923
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5924
/// <param name="key">The tag field name.</param>
5925
/// <param name="tag">The FreeImage tag to be attached.</param>
5926
/// <returns>Returns true on success, false on failure.</returns>
5927
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_SetMetadata")]
5928
public static extern bool SetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP dib, string key, FITAG tag);
5932
#region Metadata helper functions
5935
/// Returns the number of tags contained in the model metadata model attached to the input dib.
5937
/// <param name="model">The metadata model.</param>
5938
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5939
/// <returns>Number of tags contained in the metadata model.</returns>
5940
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetMetadataCount")]
5941
public static extern uint GetMetadataCount(FREE_IMAGE_MDMODEL model, FIBITMAP dib);
5944
/// Copies the metadata of FreeImage bitmap to another.
5946
/// <param name="dst">The FreeImage bitmap to copy the metadata to.</param>
5947
/// <param name="src">The FreeImage bitmap to copy the metadata from.</param>
5948
/// <returns>Returns true on success, false on failure.</returns>
5949
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CloneMetadata")]
5950
public static extern bool CloneMetadata(FIBITMAP dst, FIBITMAP src);
5953
/// Converts a FreeImage tag structure to a string that represents the interpreted tag value.
5954
/// The function is not thread safe.
5956
/// <param name="model">The metadata model.</param>
5957
/// <param name="tag">The interpreted tag value.</param>
5958
/// <param name="Make">Reserved.</param>
5959
/// <returns>The representing string.</returns>
5960
public static unsafe string TagToString(FREE_IMAGE_MDMODEL model, FITAG tag, uint Make) { return PtrToStr(TagToString_(model, tag, Make)); }
5961
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_TagToString")]
5962
private static unsafe extern byte* TagToString_(FREE_IMAGE_MDMODEL model, FITAG tag, uint Make);
5966
#region Rotation and flipping
5969
/// This function rotates a 1-, 8-bit greyscale or a 24-, 32-bit color image by means of 3 shears.
5970
/// 1-bit images rotation is limited to integer multiple of 90�.
5971
/// <c>null</c> is returned for other values.
5973
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5974
/// <param name="angle">The angle of rotation.</param>
5975
/// <returns>Handle to a FreeImage bitmap.</returns>
5976
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_RotateClassic")]
5977
[Obsolete("RotateClassic is deprecated (use Rotate instead).")]
5978
public static extern FIBITMAP RotateClassic(FIBITMAP dib, double angle);
5980
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Rotate")]
5981
internal static extern FIBITMAP Rotate(FIBITMAP dib, double angle, IntPtr backgroundColor);
5984
/// This function performs a rotation and / or translation of an 8-bit greyscale,
5985
/// 24- or 32-bit image, using a 3rd order (cubic) B-Spline.
5987
/// <param name="dib">Handle to a FreeImage bitmap.</param>
5988
/// <param name="angle">The angle of rotation.</param>
5989
/// <param name="x_shift">Horizontal image translation.</param>
5990
/// <param name="y_shift">Vertical image translation.</param>
5991
/// <param name="x_origin">Rotation center x-coordinate.</param>
5992
/// <param name="y_origin">Rotation center y-coordinate.</param>
5993
/// <param name="use_mask">When true the irrelevant part of the image is set to a black color,
5994
/// otherwise, a mirroring technique is used to fill irrelevant pixels.</param>
5995
/// <returns>Handle to a FreeImage bitmap.</returns>
5996
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_RotateEx")]
5997
public static extern FIBITMAP RotateEx(FIBITMAP dib, double angle,
5998
double x_shift, double y_shift, double x_origin, double y_origin, bool use_mask);
6001
/// Flip the input dib horizontally along the vertical axis.
6003
/// <param name="dib">Handle to a FreeImage bitmap.</param>
6004
/// <returns>Returns true on success, false on failure.</returns>
6005
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FlipHorizontal")]
6006
public static extern bool FlipHorizontal(FIBITMAP dib);
6009
/// Flip the input dib vertically along the horizontal axis.
6011
/// <param name="dib">Handle to a FreeImage bitmap.</param>
6012
/// <returns>Returns true on success, false on failure.</returns>
6013
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FlipVertical")]
6014
public static extern bool FlipVertical(FIBITMAP dib);
6017
/// Performs a lossless rotation or flipping on a JPEG file.
6019
/// <param name="src_file">Source file.</param>
6020
/// <param name="dst_file">Destination file; can be the source file; will be overwritten.</param>
6021
/// <param name="operation">The operation to apply.</param>
6022
/// <param name="perfect">To avoid lossy transformation, you can set the perfect parameter to true.</param>
6023
/// <returns>Returns true on success, false on failure.</returns>
6024
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_JPEGTransformU")]
6025
public static extern bool JPEGTransform(string src_file, string dst_file,
6026
FREE_IMAGE_JPEG_OPERATION operation, bool perfect);
6030
#region Upsampling / downsampling
6033
/// Performs resampling (or scaling, zooming) of a greyscale or RGB(A) image
6034
/// to the desired destination width and height.
6036
/// <param name="dib">Handle to a FreeImage bitmap.</param>
6037
/// <param name="dst_width">Destination width.</param>
6038
/// <param name="dst_height">Destination height.</param>
6039
/// <param name="filter">The filter to apply.</param>
6040
/// <returns>Handle to a FreeImage bitmap.</returns>
6041
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Rescale")]
6042
public static extern FIBITMAP Rescale(FIBITMAP dib, int dst_width, int dst_height, FREE_IMAGE_FILTER filter);
6045
/// Creates a thumbnail from a greyscale or RGB(A) image, keeping aspect ratio.
6047
/// <param name="dib">Handle to a FreeImage bitmap.</param>
6048
/// <param name="max_pixel_size">Thumbnail square size.</param>
6049
/// <param name="convert">When true HDR images are transperantly converted to standard images.</param>
6050
/// <returns>Handle to a FreeImage bitmap.</returns>
6051
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_MakeThumbnail")]
6052
public static extern FIBITMAP MakeThumbnail(FIBITMAP dib, int max_pixel_size, bool convert);
6054
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_EnlargeCanvas")]
6055
internal static extern FIBITMAP EnlargeCanvas(FIBITMAP dib,
6056
int left, int top, int right, int bottom, IntPtr color, FREE_IMAGE_COLOR_OPTIONS options);
6060
#region Color manipulation
6063
/// Perfoms an histogram transformation on a 8-, 24- or 32-bit image.
6065
/// <param name="dib">Handle to a FreeImage bitmap.</param>
6066
/// <param name="lookUpTable">The lookup table.
6067
/// It's size is assumed to be 256 in length.</param>
6068
/// <param name="channel">The color channel to be transformed.</param>
6069
/// <returns>Returns true on success, false on failure.</returns>
6070
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustCurve")]
6071
public static extern bool AdjustCurve(FIBITMAP dib, byte[] lookUpTable, FREE_IMAGE_COLOR_CHANNEL channel);
6074
/// Performs gamma correction on a 8-, 24- or 32-bit image.
6076
/// <param name="dib">Handle to a FreeImage bitmap.</param>
6077
/// <param name="gamma">The parameter represents the gamma value to use (gamma > 0).
6078
/// A value of 1.0 leaves the image alone, less than one darkens it, and greater than one lightens it.</param>
6079
/// <returns>Returns true on success, false on failure.</returns>
6080
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustGamma")]
6081
public static extern bool AdjustGamma(FIBITMAP dib, double gamma);
6084
/// Adjusts the brightness of a 8-, 24- or 32-bit image by a certain amount.
6086
/// <param name="dib">Handle to a FreeImage bitmap.</param>
6087
/// <param name="percentage">A value 0 means no change,
6088
/// less than 0 will make the image darker and greater than 0 will make the image brighter.</param>
6089
/// <returns>Returns true on success, false on failure.</returns>
6090
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustBrightness")]
6091
public static extern bool AdjustBrightness(FIBITMAP dib, double percentage);
6094
/// Adjusts the contrast of a 8-, 24- or 32-bit image by a certain amount.
6096
/// <param name="dib">Handle to a FreeImage bitmap.</param>
6097
/// <param name="percentage">A value 0 means no change,
6098
/// less than 0 will decrease the contrast and greater than 0 will increase the contrast of the image.</param>
6099
/// <returns>Returns true on success, false on failure.</returns>
6100
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustContrast")]
6101
public static extern bool AdjustContrast(FIBITMAP dib, double percentage);
6104
/// Inverts each pixel data.
6106
/// <param name="dib">Handle to a FreeImage bitmap.</param>
6107
/// <returns>Returns true on success, false on failure.</returns>
6108
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Invert")]
6109
public static extern bool Invert(FIBITMAP dib);
6112
/// Computes the image histogram.
6114
/// <param name="dib">Handle to a FreeImage bitmap.</param>
6115
/// <param name="histo">Array of integers with a size of 256.</param>
6116
/// <param name="channel">Channel to compute from.</param>
6117
/// <returns>Returns true on success, false on failure.</returns>
6118
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetHistogram")]
6119
public static extern bool GetHistogram(FIBITMAP dib, int[] histo, FREE_IMAGE_COLOR_CHANNEL channel);
6123
#region Channel processing
6126
/// Retrieves the red, green, blue or alpha channel of a 24- or 32-bit image.
6128
/// <param name="dib">Handle to a FreeImage bitmap.</param>
6129
/// <param name="channel">The color channel to extract.</param>
6130
/// <returns>Handle to a FreeImage bitmap.</returns>
6131
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetChannel")]
6132
public static extern FIBITMAP GetChannel(FIBITMAP dib, FREE_IMAGE_COLOR_CHANNEL channel);
6135
/// Insert a 8-bit dib into a 24- or 32-bit image.
6136
/// Both images must have to same width and height.
6138
/// <param name="dib">Handle to a FreeImage bitmap.</param>
6139
/// <param name="dib8">Handle to the bitmap to insert.</param>
6140
/// <param name="channel">The color channel to replace.</param>
6141
/// <returns>Returns true on success, false on failure.</returns>
6142
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetChannel")]
6143
public static extern bool SetChannel(FIBITMAP dib, FIBITMAP dib8, FREE_IMAGE_COLOR_CHANNEL channel);
6146
/// Retrieves the real part, imaginary part, magnitude or phase of a complex image.
6148
/// <param name="src">Handle to a FreeImage bitmap.</param>
6149
/// <param name="channel">The color channel to extract.</param>
6150
/// <returns>Handle to a FreeImage bitmap.</returns>
6151
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetComplexChannel")]
6152
public static extern FIBITMAP GetComplexChannel(FIBITMAP src, FREE_IMAGE_COLOR_CHANNEL channel);
6155
/// Set the real or imaginary part of a complex image.
6156
/// Both images must have to same width and height.
6158
/// <param name="dst">Handle to a FreeImage bitmap.</param>
6159
/// <param name="src">Handle to a FreeImage bitmap.</param>
6160
/// <param name="channel">The color channel to replace.</param>
6161
/// <returns>Returns true on success, false on failure.</returns>
6162
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetComplexChannel")]
6163
public static extern bool SetComplexChannel(FIBITMAP dst, FIBITMAP src, FREE_IMAGE_COLOR_CHANNEL channel);
6167
#region Copy / Paste / Composite routines
6170
/// Copy a sub part of the current dib image.
6172
/// <param name="dib">Handle to a FreeImage bitmap.</param>
6173
/// <param name="left">Specifies the left position of the cropped rectangle.</param>
6174
/// <param name="top">Specifies the top position of the cropped rectangle.</param>
6175
/// <param name="right">Specifies the right position of the cropped rectangle.</param>
6176
/// <param name="bottom">Specifies the bottom position of the cropped rectangle.</param>
6177
/// <returns>Handle to a FreeImage bitmap.</returns>
6178
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Copy")]
6179
public static extern FIBITMAP Copy(FIBITMAP dib, int left, int top, int right, int bottom);
6182
/// Alpha blend or combine a sub part image with the current dib image.
6183
/// The bit depth of the dst bitmap must be greater than or equal to the bit depth of the src.
6185
/// <param name="dst">Handle to a FreeImage bitmap.</param>
6186
/// <param name="src">Handle to a FreeImage bitmap.</param>
6187
/// <param name="left">Specifies the left position of the sub image.</param>
6188
/// <param name="top">Specifies the top position of the sub image.</param>
6189
/// <param name="alpha">alpha blend factor.
6190
/// The source and destination images are alpha blended if alpha=0..255.
6191
/// If alpha > 255, then the source image is combined to the destination image.</param>
6192
/// <returns>Returns true on success, false on failure.</returns>
6193
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Paste")]
6194
public static extern bool Paste(FIBITMAP dst, FIBITMAP src, int left, int top, int alpha);
6197
/// This function composite a transparent foreground image against a single background color or
6198
/// against a background image.
6200
/// <param name="fg">Handle to a FreeImage bitmap.</param>
6201
/// <param name="useFileBkg">When true the background of fg is used if it contains one.</param>
6202
/// <param name="appBkColor">The application background is used if useFileBkg is false.</param>
6203
/// <param name="bg">Image used as background when useFileBkg is false or fg has no background
6204
/// and appBkColor is null.</param>
6205
/// <returns>Handle to a FreeImage bitmap.</returns>
6206
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Composite")]
6207
public static extern FIBITMAP Composite(FIBITMAP fg, bool useFileBkg, ref RGBQUAD appBkColor, FIBITMAP bg);
6210
/// This function composite a transparent foreground image against a single background color or
6211
/// against a background image.
6213
/// <param name="fg">Handle to a FreeImage bitmap.</param>
6214
/// <param name="useFileBkg">When true the background of fg is used if it contains one.</param>
6215
/// <param name="appBkColor">The application background is used if useFileBkg is false
6216
/// and 'appBkColor' is not null.</param>
6217
/// <param name="bg">Image used as background when useFileBkg is false or fg has no background
6218
/// and appBkColor is null.</param>
6219
/// <returns>Handle to a FreeImage bitmap.</returns>
6220
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Composite")]
6221
public static extern FIBITMAP Composite(FIBITMAP fg, bool useFileBkg, RGBQUAD[] appBkColor, FIBITMAP bg);
6224
/// Performs a lossless crop on a JPEG file.
6226
/// <param name="src_file">Source filename.</param>
6227
/// <param name="dst_file">Destination filename.</param>
6228
/// <param name="left">Specifies the left position of the cropped rectangle.</param>
6229
/// <param name="top">Specifies the top position of the cropped rectangle.</param>
6230
/// <param name="right">Specifies the right position of the cropped rectangle.</param>
6231
/// <param name="bottom">Specifies the bottom position of the cropped rectangle.</param>
6232
/// <returns>Returns true on success, false on failure.</returns>
6233
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_JPEGCropU")]
6234
public static extern bool JPEGCrop(string src_file, string dst_file, int left, int top, int right, int bottom);
6237
/// Applies the alpha value of each pixel to its color components.
6238
/// The aplha value stays unchanged.
6239
/// Only works with 32-bits color depth.
6241
/// <param name="dib">Handle to a FreeImage bitmap.</param>
6242
/// <returns>Returns true on success, false on failure.</returns>
6243
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_PreMultiplyWithAlpha")]
6244
public static extern bool PreMultiplyWithAlpha(FIBITMAP dib);
6248
#region Miscellaneous algorithms
6251
/// Solves a Poisson equation, remap result pixels to [0..1] and returns the solution.
6253
/// <param name="Laplacian">Handle to a FreeImage bitmap.</param>
6254
/// <param name="ncycle">Number of cycles in the multigrid algorithm (usually 2 or 3)</param>
6255
/// <returns>Handle to a FreeImage bitmap.</returns>
6256
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_MultigridPoissonSolver")]
6257
public static extern FIBITMAP MultigridPoissonSolver(FIBITMAP Laplacian, int ncycle);
6264
/// Creates a lookup table to be used with <see cref="AdjustCurve"/> which may adjusts brightness and
6265
/// contrast, correct gamma and invert the image with a single call to <see cref="AdjustCurve"/>.
6267
/// <param name="lookUpTable">Output lookup table to be used with <see cref="AdjustCurve"/>.
6268
/// The size of 'lookUpTable' is assumed to be 256.</param>
6269
/// <param name="brightness">Percentage brightness value where -100 <= brightness <= 100.
6270
/// <para>A value of 0 means no change, less than 0 will make the image darker and greater
6271
/// than 0 will make the image brighter.</para></param>
6272
/// <param name="contrast">Percentage contrast value where -100 <= contrast <= 100.
6273
/// <para>A value of 0 means no change, less than 0 will decrease the contrast
6274
/// and greater than 0 will increase the contrast of the image.</para></param>
6275
/// <param name="gamma">Gamma value to be used for gamma correction.
6276
/// <para>A value of 1.0 leaves the image alone, less than one darkens it,
6277
/// and greater than one lightens it.</para></param>
6278
/// <param name="invert">If set to true, the image will be inverted.</param>
6279
/// <returns>The number of adjustments applied to the resulting lookup table
6280
/// compared to a blind lookup table.</returns>
6282
/// This function creates a lookup table to be used with <see cref="AdjustCurve"/> which may adjust
6283
/// brightness and contrast, correct gamma and invert the image with a single call to
6284
/// <see cref="AdjustCurve"/>. If more than one of these image display properties need to be adjusted,
6285
/// using a combined lookup table should be preferred over calling each adjustment function
6286
/// separately. That's particularly true for huge images or if performance is an issue. Then,
6287
/// the expensive process of iterating over all pixels of an image is performed only once and
6288
/// not up to four times.
6290
/// Furthermore, the lookup table created does not depend on the order, in which each single
6291
/// adjustment operation is performed. Due to rounding and byte casting issues, it actually
6292
/// matters in which order individual adjustment operations are performed. Both of the following
6293
/// snippets most likely produce different results:
6296
/// // snippet 1: contrast, brightness
6297
/// AdjustContrast(dib, 15.0);
6298
/// AdjustBrightness(dib, 50.0);
6302
/// // snippet 2: brightness, contrast
6303
/// AdjustBrightness(dib, 50.0);
6304
/// AdjustContrast(dib, 15.0);
6307
/// Better and even faster would be snippet 3:
6311
/// byte[] lut = new byte[256];
6312
/// GetAdjustColorsLookupTable(lut, 50.0, 15.0, 1.0, false);
6313
/// AdjustCurve(dib, lut, FREE_IMAGE_COLOR_CHANNEL.FICC_RGB);
6316
/// This function is also used internally by <see cref="AdjustColors"/>, which does not return the
6317
/// lookup table, but uses it to call <see cref="AdjustCurve"/> on the passed image.
6319
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetAdjustColorsLookupTable")]
6320
public static extern int GetAdjustColorsLookupTable(byte[] lookUpTable, double brightness, double contrast, double gamma, bool invert);
6323
/// Adjusts an image's brightness, contrast and gamma as well as it may
6324
/// optionally invert the image within a single operation.
6326
/// <param name="dib">Handle to a FreeImage bitmap.</param>
6327
/// <param name="brightness">Percentage brightness value where -100 <= brightness <= 100.
6328
/// <para>A value of 0 means no change, less than 0 will make the image darker and greater
6329
/// than 0 will make the image brighter.</para></param>
6330
/// <param name="contrast">Percentage contrast value where -100 <= contrast <= 100.
6331
/// <para>A value of 0 means no change, less than 0 will decrease the contrast
6332
/// and greater than 0 will increase the contrast of the image.</para></param>
6333
/// <param name="gamma">Gamma value to be used for gamma correction.
6334
/// <para>A value of 1.0 leaves the image alone, less than one darkens it,
6335
/// and greater than one lightens it.</para>
6336
/// This parameter must not be zero or smaller than zero.
6337
/// If so, it will be ignored and no gamma correction will be performed on the image.</param>
6338
/// <param name="invert">If set to true, the image will be inverted.</param>
6339
/// <returns>Returns true on success, false on failure.</returns>
6341
/// This function adjusts an image's brightness, contrast and gamma as well as it
6342
/// may optionally invert the image within a single operation. If more than one of
6343
/// these image display properties need to be adjusted, using this function should
6344
/// be preferred over calling each adjustment function separately. That's particularly
6345
/// true for huge images or if performance is an issue.
6347
/// This function relies on <see cref="GetAdjustColorsLookupTable"/>,
6348
/// which creates a single lookup table, that combines all adjustment operations requested.
6350
/// Furthermore, the lookup table created by <see cref="GetAdjustColorsLookupTable"/> does
6351
/// not depend on the order, in which each single adjustment operation is performed.
6352
/// Due to rounding and byte casting issues, it actually matters in which order individual
6353
/// adjustment operations are performed. Both of the following snippets most likely produce
6354
/// different results:
6357
/// // snippet 1: contrast, brightness
6358
/// AdjustContrast(dib, 15.0);
6359
/// AdjustBrightness(dib, 50.0);
6363
/// // snippet 2: brightness, contrast
6364
/// AdjustBrightness(dib, 50.0);
6365
/// AdjustContrast(dib, 15.0);
6368
/// Better and even faster would be snippet 3:
6372
/// AdjustColors(dib, 50.0, 15.0, 1.0, false);
6375
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AdjustColors")]
6376
public static extern bool AdjustColors(FIBITMAP dib, double brightness, double contrast, double gamma, bool invert);
6379
/// Applies color mapping for one or several colors on a 1-, 4- or 8-bit
6380
/// palletized or a 16-, 24- or 32-bit high color image.
6382
/// <param name="dib">Handle to a FreeImage bitmap.</param>
6383
/// <param name="srccolors">Array of colors to be used as the mapping source.</param>
6384
/// <param name="dstcolors">Array of colors to be used as the mapping destination.</param>
6385
/// <param name="count">The number of colors to be mapped. This is the size of both
6386
/// srccolors and dstcolors.</param>
6387
/// <param name="ignore_alpha">If true, 32-bit images and colors are treated as 24-bit.</param>
6388
/// <param name="swap">If true, source and destination colors are swapped, that is,
6389
/// each destination color is also mapped to the corresponding source color.</param>
6390
/// <returns>The total number of pixels changed.</returns>
6392
/// This function maps up to <paramref name="count"/> colors specified in
6393
/// <paramref name="srccolors"/> to these specified in <paramref name="dstcolors"/>.
6394
/// Thereby, color <i>srccolors[N]</i>, if found in the image, will be replaced by color
6395
/// <i>dstcolors[N]</i>. If <paramref name="swap"/> is <b>true</b>, additionally all colors
6396
/// specified in <paramref name="dstcolors"/> are also mapped to these specified
6397
/// in <paramref name="srccolors"/>. For high color images, the actual image data will be
6398
/// modified whereas, for palletized images only the palette will be changed.
6400
/// The function returns the number of pixels changed or zero, if no pixels were changed.
6402
/// Both arrays <paramref name="srccolors"/> and <paramref name="dstcolors"/> are assumed
6403
/// not to hold less than <paramref name="count"/> colors.
6405
/// For 16-bit images, all colors specified are transparently converted to their
6406
/// proper 16-bit representation (either in RGB555 or RGB565 format, which is determined
6407
/// by the image's red- green- and blue-mask).
6409
/// <b>Note, that this behaviour is different from what <see cref="ApplyPaletteIndexMapping"/> does,
6410
/// which modifies the actual image data on palletized images.</b>
6412
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ApplyColorMapping")]
6413
public static extern uint ApplyColorMapping(FIBITMAP dib, RGBQUAD[] srccolors, RGBQUAD[] dstcolors, uint count, bool ignore_alpha, bool swap);
6416
/// Swaps two specified colors on a 1-, 4- or 8-bit palletized
6417
/// or a 16-, 24- or 32-bit high color image.
6419
/// <param name="dib">Handle to a FreeImage bitmap.</param>
6420
/// <param name="color_a">One of the two colors to be swapped.</param>
6421
/// <param name="color_b">The other of the two colors to be swapped.</param>
6422
/// <param name="ignore_alpha">If true, 32-bit images and colors are treated as 24-bit.</param>
6423
/// <returns>The total number of pixels changed.</returns>
6425
/// This function swaps the two specified colors <paramref name="color_a"/> and
6426
/// <paramref name="color_b"/> on a palletized or high color image.
6427
/// For high color images, the actual image data will be modified whereas, for palletized
6428
/// images only the palette will be changed.
6430
/// <b>Note, that this behaviour is different from what <see cref="SwapPaletteIndices"/> does,
6431
/// which modifies the actual image data on palletized images.</b>
6433
/// This is just a thin wrapper for <see cref="ApplyColorMapping"/> and resolves to:
6436
/// return ApplyColorMapping(dib, color_a, color_b, 1, ignore_alpha, true);
6439
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SwapColors")]
6440
public static extern uint SwapColors(FIBITMAP dib, ref RGBQUAD color_a, ref RGBQUAD color_b, bool ignore_alpha);
6443
/// Applies palette index mapping for one or several indices
6444
/// on a 1-, 4- or 8-bit palletized image.
6446
/// <param name="dib">Handle to a FreeImage bitmap.</param>
6447
/// <param name="srcindices">Array of palette indices to be used as the mapping source.</param>
6448
/// <param name="dstindices">Array of palette indices to be used as the mapping destination.</param>
6449
/// <param name="count">The number of palette indices to be mapped. This is the size of both
6450
/// srcindices and dstindices</param>
6451
/// <param name="swap">If true, source and destination palette indices are swapped, that is,
6452
/// each destination index is also mapped to the corresponding source index.</param>
6453
/// <returns>The total number of pixels changed.</returns>
6455
/// This function maps up to <paramref name="count"/> palette indices specified in
6456
/// <paramref name="srcindices"/> to these specified in <paramref name="dstindices"/>.
6457
/// Thereby, index <i>srcindices[N]</i>, if present in the image, will be replaced by index
6458
/// <i>dstindices[N]</i>. If <paramref name="swap"/> is <b>true</b>, additionally all indices
6459
/// specified in <paramref name="dstindices"/> are also mapped to these specified in
6460
/// <paramref name="srcindices"/>.
6462
/// The function returns the number of pixels changed or zero, if no pixels were changed.
6463
/// Both arrays <paramref name="srcindices"/> and <paramref name="dstindices"/> are assumed not to
6464
/// hold less than <paramref name="count"/> indices.
6466
/// <b>Note, that this behaviour is different from what <see cref="ApplyColorMapping"/> does, which
6467
/// modifies the actual image data on palletized images.</b>
6469
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ApplyPaletteIndexMapping")]
6470
public static extern uint ApplyPaletteIndexMapping(FIBITMAP dib, byte[] srcindices, byte[] dstindices, uint count, bool swap);
6473
/// Swaps two specified palette indices on a 1-, 4- or 8-bit palletized image.
6475
/// <param name="dib">Handle to a FreeImage bitmap.</param>
6476
/// <param name="index_a">One of the two palette indices to be swapped.</param>
6477
/// <param name="index_b">The other of the two palette indices to be swapped.</param>
6478
/// <returns>The total number of pixels changed.</returns>
6480
/// This function swaps the two specified palette indices <i>index_a</i> and
6481
/// <i>index_b</i> on a palletized image. Therefore, not the palette, but the
6482
/// actual image data will be modified.
6484
/// <b>Note, that this behaviour is different from what <see cref="SwapColors"/> does on palletized images,
6485
/// which only swaps the colors in the palette.</b>
6487
/// This is just a thin wrapper for <see cref="ApplyColorMapping"/> and resolves to:
6490
/// return ApplyPaletteIndexMapping(dib, index_a, index_b, 1, true);
6493
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SwapPaletteIndices")]
6494
public static extern uint SwapPaletteIndices(FIBITMAP dib, ref byte index_a, ref byte index_b);
6496
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FillBackground")]
6497
internal static extern bool FillBackground(FIBITMAP dib, IntPtr color, FREE_IMAGE_COLOR_OPTIONS options);
6503
/////////////////////////////////////////////////////
6505
// Wrapper functions //
6507
/////////////////////////////////////////////////////
6511
namespace FreeImageAPI.IO
6514
/// Wrapper for a custom handle.
6517
/// The <b>fi_handle</b> of FreeImage in C++ is a simple pointer, but in .NET
6518
/// it's not that simple. This wrapper uses fi_handle in two different ways.
6520
/// We implement a new plugin and FreeImage gives us a handle (pointer) that
6521
/// we can simply pass through to the given functions in a 'FreeImageIO'
6523
/// But when we want to use LoadFromhandle or SaveToHandle we need
6524
/// a fi_handle (that we receive again in our own functions).
6525
/// This handle is for example a stream (see LoadFromStream / SaveToStream)
6526
/// that we want to work with. To know which stream a read/write is meant for
6527
/// we could use a hash value that the wrapper itself handles or we can
6528
/// go the unmanaged way of using a handle.
6529
/// Therefor we use a <see cref="GCHandle"/> to receive a unique pointer that we can
6530
/// convert back into a .NET object.
6531
/// When the <b>fi_handle</b> instance is no longer needed the instance must be disposed
6532
/// by the creater manually! It is recommended to use the <c>using</c> statement to
6533
/// be sure the instance is always disposed:
6536
/// using (fi_handle handle = new fi_handle(object))
6538
/// callSomeFunctions(handle);
6542
/// What does that mean?
6543
/// If we get a <b>fi_handle</b> from unmanaged code we get a pointer to unmanaged
6544
/// memory that we do not have to care about, and just pass ist back to FreeImage.
6545
/// If we have to create a handle our own we use the standard constructur
6546
/// that fills the <see cref="IntPtr"/> with an pointer that represents the given object.
6547
/// With calling <see cref="GetObject"/> the <see cref="IntPtr"/> is used to retrieve the original
6548
/// object we passed through the constructor.
6550
/// This way we can implement a <b>fi_handle</b> that works with managed an unmanaged
6553
[Serializable, StructLayout(LayoutKind.Sequential)]
6554
public struct fi_handle : IComparable, IComparable<fi_handle>, IEquatable<fi_handle>, IDisposable
6557
/// The handle to wrap.
6559
public IntPtr handle;
6562
/// Initializes a new instance wrapping a managed object.
6564
/// <param name="obj">The object to wrap.</param>
6565
/// <exception cref="ArgumentNullException">
6566
/// <paramref name="obj"/> is null.</exception>
6567
public fi_handle(object obj)
6571
throw new ArgumentNullException("obj");
6573
GCHandle gch = GCHandle.Alloc(obj, GCHandleType.Normal);
6574
handle = GCHandle.ToIntPtr(gch);
6578
/// Tests whether two specified <see cref="fi_handle"/> structures are equivalent.
6580
/// <param name="left">The <see cref="fi_handle"/> that is to the left of the equality operator.</param>
6581
/// <param name="right">The <see cref="fi_handle"/> that is to the right of the equality operator.</param>
6583
/// <b>true</b> if the two <see cref="fi_handle"/> structures are equal; otherwise, <b>false</b>.
6585
public static bool operator ==(fi_handle left, fi_handle right)
6587
return (left.handle == right.handle);
6591
/// Tests whether two specified <see cref="fi_handle"/> structures are different.
6593
/// <param name="left">The <see cref="fi_handle"/> that is to the left of the inequality operator.</param>
6594
/// <param name="right">The <see cref="fi_handle"/> that is to the right of the inequality operator.</param>
6596
/// <b>true</b> if the two <see cref="fi_handle"/> structures are different; otherwise, <b>false</b>.
6598
public static bool operator !=(fi_handle left, fi_handle right)
6600
return (left.handle != right.handle);
6604
/// Gets whether the pointer is a null pointer.
6610
return (handle == IntPtr.Zero);
6615
/// Returns the object assigned to the handle in case this instance
6616
/// was created by managed code.
6618
/// <returns><see cref="Object"/> assigned to this handle or null on failure.</returns>
6619
internal object GetObject()
6621
object result = null;
6622
if (handle != IntPtr.Zero)
6626
result = GCHandle.FromIntPtr(handle).Target;
6636
/// Converts the numeric value of the <see cref="fi_handle"/> object
6637
/// to its equivalent string representation.
6639
/// <returns>The string representation of the value of this instance.</returns>
6640
public override string ToString()
6642
return handle.ToString();
6646
/// Returns a hash code for this <see cref="fi_handle"/> structure.
6648
/// <returns>An integer value that specifies the hash code for this <see cref="fi_handle"/>.</returns>
6649
public override int GetHashCode()
6651
return handle.GetHashCode();
6655
/// Tests whether the specified object is a <see cref="fi_handle"/> structure
6656
/// and is equivalent to this <see cref="fi_handle"/> structure.
6658
/// <param name="obj">The object to test.</param>
6659
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="fi_handle"/> structure
6660
/// equivalent to this <see cref="fi_handle"/> structure; otherwise, <b>false</b>.</returns>
6661
public override bool Equals(object obj)
6663
return ((obj is fi_handle) && (this == ((fi_handle)obj)));
6667
/// Indicates whether the current object is equal to another object of the same type.
6669
/// <param name="other">An object to compare with this object.</param>
6670
/// <returns>True if the current object is equal to the other parameter; otherwise, <b>false</b>.</returns>
6671
public bool Equals(fi_handle other)
6673
return (this == other);
6677
/// Compares this instance with a specified <see cref="Object"/>.
6679
/// <param name="obj">An object to compare with this instance.</param>
6680
/// <returns>A 32-bit signed integer indicating the lexical relationship between the two comparands.</returns>
6681
/// <exception cref="ArgumentException"><paramref name="obj"/> is not a <see cref="fi_handle"/>.</exception>
6682
public int CompareTo(object obj)
6688
if (!(obj is fi_handle))
6690
throw new ArgumentException("obj");
6692
return CompareTo((fi_handle)obj);
6696
/// Compares this instance with a specified <see cref="fi_handle"/> object.
6698
/// <param name="other">A <see cref="fi_handle"/> to compare.</param>
6699
/// <returns>A signed number indicating the relative values of this instance
6700
/// and <paramref name="other"/>.</returns>
6701
public int CompareTo(fi_handle other)
6703
return handle.ToInt64().CompareTo(other.handle.ToInt64());
6707
/// Releases all resources used by the instance.
6709
public void Dispose()
6711
if (this.handle != IntPtr.Zero)
6715
GCHandle.FromIntPtr(handle).Free();
6722
this.handle = IntPtr.Zero;
6729
namespace FreeImageAPI
6732
/// The <b>FI1BIT</b> structure represents a single bit.
6733
/// It's value can be <i>0</i> or <i>1</i>.
6735
[DebuggerDisplay("{value}"),
6737
public struct FI1BIT
6740
/// Represents the largest possible value of <see cref="FI1BIT"/>. This field is constant.
6742
public const byte MaxValue = 0x01;
6745
/// Represents the smallest possible value of <see cref="FI1BIT"/>. This field is constant.
6747
public const byte MinValue = 0x00;
6750
/// The value of the structure.
6755
/// Initializes a new instance based on the specified value.
6757
/// <param name="value">The value to initialize with.</param>
6758
private FI1BIT(byte value)
6760
this.value = (byte)(value & MaxValue);
6764
/// Converts the value of a <see cref="FI1BIT"/> structure to a <see cref="Byte"/> structure.
6766
/// <param name="value">A <see cref="FI1BIT"/> structure.</param>
6767
/// <returns>A new instance of <see cref="FI1BIT"/> initialized to <paramref name="value"/>.</returns>
6768
public static implicit operator byte(FI1BIT value)
6774
/// Converts the value of a <see cref="Byte"/> structure to a <see cref="FI1BIT"/> structure.
6776
/// <param name="value">A <see cref="Byte"/> structure.</param>
6777
/// <returns>A new instance of <see cref="FI1BIT"/> initialized to <paramref name="value"/>.</returns>
6778
public static implicit operator FI1BIT(byte value)
6780
return new FI1BIT(value);
6784
/// Converts the numeric value of the <see cref="FI1BIT"/> object
6785
/// to its equivalent string representation.
6787
/// <returns>The string representation of the value of this instance.</returns>
6788
public override string ToString()
6790
return value.ToString();
6795
namespace FreeImageAPI
6798
/// The <b>FI4BIT</b> structure represents the half of a <see cref="Byte"/>.
6799
/// It's valuerange is between <i>0</i> and <i>15</i>.
6801
[DebuggerDisplay("{value}"),
6803
public struct FI4BIT
6806
/// Represents the largest possible value of <see cref="FI4BIT"/>. This field is constant.
6808
public const byte MaxValue = 0x0F;
6811
/// Represents the smallest possible value of <see cref="FI4BIT"/>. This field is constant.
6813
public const byte MinValue = 0x00;
6816
/// The value of the structure.
6821
/// Initializes a new instance based on the specified value.
6823
/// <param name="value">The value to initialize with.</param>
6824
private FI4BIT(byte value)
6826
this.value = (byte)(value & MaxValue);
6830
/// Converts the value of a <see cref="FI4BIT"/> structure to a <see cref="Byte"/> structure.
6832
/// <param name="value">A <see cref="FI4BIT"/> structure.</param>
6833
/// <returns>A new instance of <see cref="FI4BIT"/> initialized to <paramref name="value"/>.</returns>
6834
public static implicit operator byte(FI4BIT value)
6840
/// Converts the value of a <see cref="Byte"/> structure to a <see cref="FI4BIT"/> structure.
6842
/// <param name="value">A <see cref="Byte"/> structure.</param>
6843
/// <returns>A new instance of <see cref="FI4BIT"/> initialized to <paramref name="value"/>.</returns>
6844
public static implicit operator FI4BIT(byte value)
6846
return new FI4BIT(value);
6850
/// Converts the numeric value of the <see cref="FI4BIT"/> object
6851
/// to its equivalent string representation.
6853
/// <returns>The string representation of the value of this instance.</returns>
6854
public override string ToString()
6856
return value.ToString();
6861
namespace FreeImageAPI
6864
/// The <b>FI16RGB555</b> structure describes a color consisting of relative
6865
/// intensities of red, green, blue and alpha value. Each single color
6866
/// component consumes 5 bits and so, takes values in the range from 0 to 31.
6869
/// <para>For easy integration of the underlying structure into the .NET framework,
6870
/// the <b>FI16RGB555</b> structure implements implicit conversion operators to
6871
/// convert the represented color to and from the <see cref="System.Drawing.Color"/>
6872
/// type. This makes the <see cref="System.Drawing.Color"/> type a real replacement
6873
/// for the <b>FI16RGB555</b> structure and my be used in all situations which require
6874
/// an <b>FI16RGB555</b> type.
6878
/// The following code example demonstrates the various conversions between the
6879
/// <b>FI16RGB555</b> structure and the <see cref="System.Drawing.Color"/> structure.
6881
/// FI16RGB555 fi16rgb;
6882
/// // Initialize the structure using a native .NET Color structure.
6883
/// fi16rgb = new FI16RGB555(Color.Indigo);
6884
/// // Initialize the structure using the implicit operator.
6885
/// fi16rgb = Color.DarkSeaGreen;
6886
/// // Convert the FI16RGB555 instance into a native .NET Color
6887
/// // using its implicit operator.
6888
/// Color color = fi16rgb;
6889
/// // Using the structure's Color property for converting it
6890
/// // into a native .NET Color.
6891
/// Color another = fi16rgb.Color;
6894
[Serializable, StructLayout(LayoutKind.Sequential)]
6895
public struct FI16RGB555 : IComparable, IComparable<FI16RGB555>, IEquatable<FI16RGB555>
6898
/// The value of the color.
6900
private ushort value;
6903
/// Initializes a new instance based on the specified <see cref="System.Drawing.Color"/>.
6905
/// <param name="color"><see cref="System.Drawing.Color"/> to initialize with.</param>
6906
public FI16RGB555(Color color)
6909
(((color.R * 31) / 255) << FreeImage.FI16_555_RED_SHIFT) +
6910
(((color.G * 31) / 255) << FreeImage.FI16_555_GREEN_SHIFT) +
6911
(((color.B * 31) / 255) << FreeImage.FI16_555_BLUE_SHIFT));
6915
/// Tests whether two specified <see cref="FI16RGB555"/> structures are equivalent.
6917
/// <param name="left">The <see cref="FI16RGB555"/> that is to the left of the equality operator.</param>
6918
/// <param name="right">The <see cref="FI16RGB555"/> that is to the right of the equality operator.</param>
6920
/// <b>true</b> if the two <see cref="FI16RGB555"/> structures are equal; otherwise, <b>false</b>.
6922
public static bool operator ==(FI16RGB555 left, FI16RGB555 right)
6924
return (left.value == right.value);
6928
/// Tests whether two specified <see cref="FI16RGB555"/> structures are different.
6930
/// <param name="left">The <see cref="FI16RGB555"/> that is to the left of the inequality operator.</param>
6931
/// <param name="right">The <see cref="FI16RGB555"/> that is to the right of the inequality operator.</param>
6933
/// <b>true</b> if the two <see cref="FI16RGB555"/> structures are different; otherwise, <b>false</b>.
6935
public static bool operator !=(FI16RGB555 left, FI16RGB555 right)
6937
return (!(left == right));
6941
/// Converts the value of a <see cref="System.Drawing.Color"/> structure to a <see cref="FI16RGB555"/> structure.
6943
/// <param name="value">A <see cref="System.Drawing.Color"/> structure.</param>
6944
/// <returns>A new instance of <see cref="FI16RGB555"/> initialized to <paramref name="value"/>.</returns>
6945
public static implicit operator FI16RGB555(Color value)
6947
return new FI16RGB555(value);
6951
/// Converts the value of a <see cref="FI16RGB555"/> structure to a <see cref="System.Drawing.Color"/> structure.
6953
/// <param name="value">A <see cref="FI16RGB555"/> structure.</param>
6954
/// <returns>A new instance of <see cref="System.Drawing.Color"/> initialized to <paramref name="value"/>.</returns>
6955
public static implicit operator Color(FI16RGB555 value)
6961
/// Gets or sets the <see cref="System.Drawing.Color"/> of the structure.
6967
return Color.FromArgb(
6968
((value & FreeImage.FI16_555_RED_MASK) >> FreeImage.FI16_555_RED_SHIFT) * 255 / 31,
6969
((value & FreeImage.FI16_555_GREEN_MASK) >> FreeImage.FI16_555_GREEN_SHIFT) * 255 / 31,
6970
((value & FreeImage.FI16_555_BLUE_MASK) >> FreeImage.FI16_555_BLUE_SHIFT) * 255 / 31);
6974
this.value = (ushort)(
6975
(((value.R * 31) / 255) << FreeImage.FI16_555_RED_SHIFT) +
6976
(((value.G * 31) / 255) << FreeImage.FI16_555_GREEN_SHIFT) +
6977
(((value.B * 31) / 255) << FreeImage.FI16_555_BLUE_SHIFT));
6982
/// Gets or sets the red color component.
6988
return (byte)(((value & FreeImage.FI16_555_RED_MASK) >> FreeImage.FI16_555_RED_SHIFT) * 255 / 31);
6992
this.value = (ushort)((this.value & (~FreeImage.FI16_555_RED_MASK)) | (((value * 31) / 255) << FreeImage.FI16_555_RED_SHIFT));
6997
/// Gets or sets the green color component.
7003
return (byte)(((value & FreeImage.FI16_555_GREEN_MASK) >> FreeImage.FI16_555_GREEN_SHIFT) * 255 / 31);
7007
this.value = (ushort)((this.value & (~FreeImage.FI16_555_GREEN_MASK)) | (((value * 31) / 255) << FreeImage.FI16_555_GREEN_SHIFT));
7012
/// Gets or sets the blue color component.
7018
return (byte)(((value & FreeImage.FI16_555_BLUE_MASK) >> FreeImage.FI16_555_BLUE_SHIFT) * 255 / 31);
7022
this.value = (ushort)((this.value & (~FreeImage.FI16_555_BLUE_MASK)) | (((value * 31) / 255) << FreeImage.FI16_555_BLUE_SHIFT));
7027
/// Compares this instance with a specified <see cref="Object"/>.
7029
/// <param name="obj">An object to compare with this instance.</param>
7030
/// <returns>A 32-bit signed integer indicating the lexical relationship between the two comparands.</returns>
7031
/// <exception cref="ArgumentException"><paramref name="obj"/> is not a <see cref="FI16RGB555"/>.</exception>
7032
public int CompareTo(object obj)
7038
if (!(obj is FI16RGB555))
7040
throw new ArgumentException("obj");
7042
return CompareTo((FI16RGB555)obj);
7046
/// Compares this instance with a specified <see cref="FI16RGB555"/> object.
7048
/// <param name="other">A <see cref="FI16RGB555"/> to compare.</param>
7049
/// <returns>A signed number indicating the relative values of this instance
7050
/// and <paramref name="other"/>.</returns>
7051
public int CompareTo(FI16RGB555 other)
7053
return this.Color.ToArgb().CompareTo(other.Color.ToArgb());
7057
/// Tests whether the specified object is a <see cref="FI16RGB555"/> structure
7058
/// and is equivalent to this <see cref="FI16RGB555"/> structure.
7060
/// <param name="obj">The object to test.</param>
7061
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="FI16RGB555"/> structure
7062
/// equivalent to this <see cref="FI16RGB555"/> structure; otherwise, <b>false</b>.</returns>
7063
public override bool Equals(object obj)
7065
return base.Equals(obj);
7069
/// Tests whether the specified <see cref="FI16RGB555"/> structure is equivalent to this <see cref="FI16RGB555"/> structure.
7071
/// <param name="other">A <see cref="FI16RGB555"/> structure to compare to this instance.</param>
7072
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="FI16RGB555"/> structure
7073
/// equivalent to this <see cref="FI16RGB555"/> structure; otherwise, <b>false</b>.</returns>
7074
public bool Equals(FI16RGB555 other)
7076
return (this == other);
7080
/// Returns a hash code for this <see cref="FI16RGB555"/> structure.
7082
/// <returns>An integer value that specifies the hash code for this <see cref="FI16RGB555"/>.</returns>
7083
public override int GetHashCode()
7085
return base.GetHashCode();
7089
/// Converts the numeric value of the <see cref="FI16RGB555"/> object
7090
/// to its equivalent string representation.
7092
/// <returns>The string representation of the value of this instance.</returns>
7093
public override string ToString()
7095
return FreeImage.ColorToString(Color);
7100
namespace FreeImageAPI
7103
/// The <b>FI16RGB565</b> structure describes a color consisting of relative
7104
/// intensities of red, green, blue and alpha value. Each single color
7105
/// component consumes 5 bits and so, takes values in the range from 0 to 31.
7108
/// <para>For easy integration of the underlying structure into the .NET framework,
7109
/// the <b>FI16RGB565</b> structure implements implicit conversion operators to
7110
/// convert the represented color to and from the <see cref="System.Drawing.Color"/>
7111
/// type. This makes the <see cref="System.Drawing.Color"/> type a real replacement
7112
/// for the <b>FI16RGB565</b> structure and my be used in all situations which require
7113
/// an <b>FI16RGB565</b> type.
7117
/// The following code example demonstrates the various conversions between the
7118
/// <b>FI16RGB565</b> structure and the <see cref="System.Drawing.Color"/> structure.
7120
/// FI16RGB565 fi16rgb;
7121
/// // Initialize the structure using a native .NET Color structure.
7122
/// fi16rgb = new FI16RGB565(Color.Indigo);
7123
/// // Initialize the structure using the implicit operator.
7124
/// fi16rgb = Color.DarkSeaGreen;
7125
/// // Convert the FI16RGB565 instance into a native .NET Color
7126
/// // using its implicit operator.
7127
/// Color color = fi16rgb;
7128
/// // Using the structure's Color property for converting it
7129
/// // into a native .NET Color.
7130
/// Color another = fi16rgb.Color;
7133
[Serializable, StructLayout(LayoutKind.Sequential)]
7134
public struct FI16RGB565 : IComparable, IComparable<FI16RGB565>, IEquatable<FI16RGB565>
7137
/// The value of the color.
7139
private ushort value;
7142
/// Initializes a new instance based on the specified <see cref="System.Drawing.Color"/>.
7144
/// <param name="color"><see cref="System.Drawing.Color"/> to initialize with.</param>
7145
public FI16RGB565(Color color)
7148
(((color.R * 31) / 255) << FreeImage.FI16_565_RED_SHIFT) +
7149
(((color.G * 63) / 255) << FreeImage.FI16_565_GREEN_SHIFT) +
7150
(((color.B * 31) / 255) << FreeImage.FI16_565_BLUE_SHIFT));
7154
/// Tests whether two specified <see cref="FI16RGB565"/> structures are equivalent.
7156
/// <param name="left">The <see cref="FI16RGB565"/> that is to the left of the equality operator.</param>
7157
/// <param name="right">The <see cref="FI16RGB565"/> that is to the right of the equality operator.</param>
7159
/// <b>true</b> if the two <see cref="FI16RGB565"/> structures are equal; otherwise, <b>false</b>.
7161
public static bool operator ==(FI16RGB565 left, FI16RGB565 right)
7163
return (left.value == right.value);
7167
/// Tests whether two specified <see cref="FI16RGB565"/> structures are different.
7169
/// <param name="left">The <see cref="FI16RGB565"/> that is to the left of the inequality operator.</param>
7170
/// <param name="right">The <see cref="FI16RGB565"/> that is to the right of the inequality operator.</param>
7172
/// <b>true</b> if the two <see cref="FI16RGB565"/> structures are different; otherwise, <b>false</b>.
7174
public static bool operator !=(FI16RGB565 left, FI16RGB565 right)
7176
return (!(left == right));
7180
/// Converts the value of a <see cref="System.Drawing.Color"/> structure to a <see cref="FI16RGB565"/> structure.
7182
/// <param name="value">A <see cref="System.Drawing.Color"/> structure.</param>
7183
/// <returns>A new instance of <see cref="FI16RGB565"/> initialized to <paramref name="value"/>.</returns>
7184
public static implicit operator FI16RGB565(Color value)
7186
return new FI16RGB565(value);
7190
/// Converts the value of a <see cref="FI16RGB565"/> structure to a <see cref="System.Drawing.Color"/> structure.
7192
/// <param name="value">A <see cref="FI16RGB565"/> structure.</param>
7193
/// <returns>A new instance of <see cref="System.Drawing.Color"/> initialized to <paramref name="value"/>.</returns>
7194
public static implicit operator Color(FI16RGB565 value)
7200
/// Gets or sets the <see cref="System.Drawing.Color"/> of the structure.
7206
return Color.FromArgb(
7207
((value & FreeImage.FI16_565_RED_MASK) >> FreeImage.FI16_565_RED_SHIFT) * 255 / 31,
7208
((value & FreeImage.FI16_565_GREEN_MASK) >> FreeImage.FI16_565_GREEN_SHIFT) * 255 / 63,
7209
((value & FreeImage.FI16_565_BLUE_MASK) >> FreeImage.FI16_565_BLUE_SHIFT) * 255 / 31);
7213
this.value = (ushort)(
7214
(((value.R * 31) / 255) << FreeImage.FI16_565_RED_SHIFT) +
7215
(((value.G * 63) / 255) << FreeImage.FI16_565_GREEN_SHIFT) +
7216
(((value.B * 31) / 255) << FreeImage.FI16_565_BLUE_SHIFT));
7221
/// Gets or sets the red color component.
7227
return (byte)(((value & FreeImage.FI16_565_RED_MASK) >> FreeImage.FI16_565_RED_SHIFT) * 255 / 31);
7231
this.value = (ushort)((this.value & (~FreeImage.FI16_565_RED_MASK)) | (((value * 31) / 255) << FreeImage.FI16_565_RED_SHIFT));
7236
/// Gets or sets the green color component.
7242
return (byte)(((value & FreeImage.FI16_565_GREEN_MASK) >> FreeImage.FI16_565_GREEN_SHIFT) * 255 / 63);
7246
this.value = (ushort)((this.value & (~FreeImage.FI16_565_GREEN_MASK)) | (((value * 63) / 255) << FreeImage.FI16_565_GREEN_SHIFT));
7251
/// Gets or sets the blue color component.
7257
return (byte)(((value & FreeImage.FI16_565_BLUE_MASK) >> FreeImage.FI16_565_BLUE_SHIFT) * 255 / 31);
7261
this.value = (ushort)((this.value & (~FreeImage.FI16_565_BLUE_MASK)) | (((value * 31) / 255) << FreeImage.FI16_565_BLUE_SHIFT));
7266
/// Compares this instance with a specified <see cref="Object"/>.
7268
/// <param name="obj">An object to compare with this instance.</param>
7269
/// <returns>A 32-bit signed integer indicating the lexical relationship between the two comparands.</returns>
7270
/// <exception cref="ArgumentException"><paramref name="obj"/> is not a <see cref="FI16RGB565"/>.</exception>
7271
public int CompareTo(object obj)
7277
if (!(obj is FI16RGB565))
7279
throw new ArgumentException("obj");
7281
return CompareTo((FI16RGB565)obj);
7285
/// Compares this instance with a specified <see cref="FI16RGB565"/> object.
7287
/// <param name="other">A <see cref="FI16RGB565"/> to compare.</param>
7288
/// <returns>A signed number indicating the relative values of this instance
7289
/// and <paramref name="other"/>.</returns>
7290
public int CompareTo(FI16RGB565 other)
7292
return this.Color.ToArgb().CompareTo(other.Color.ToArgb());
7296
/// Tests whether the specified object is a <see cref="FI16RGB565"/> structure
7297
/// and is equivalent to this <see cref="FI16RGB565"/> structure.
7299
/// <param name="obj">The object to test.</param>
7300
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="FI16RGB565"/> structure
7301
/// equivalent to this <see cref="FI16RGB565"/> structure; otherwise, <b>false</b>.</returns>
7302
public override bool Equals(object obj)
7304
return base.Equals(obj);
7308
/// Tests whether the specified <see cref="FI16RGB565"/> structure is equivalent to this <see cref="FI16RGB565"/> structure.
7310
/// <param name="other">A <see cref="FI16RGB565"/> structure to compare to this instance.</param>
7311
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="FI16RGB565"/> structure
7312
/// equivalent to this <see cref="FI16RGB565"/> structure; otherwise, <b>false</b>.</returns>
7313
public bool Equals(FI16RGB565 other)
7315
return (this == other);
7319
/// Returns a hash code for this <see cref="FI16RGB565"/> structure.
7321
/// <returns>An integer value that specifies the hash code for this <see cref="FI16RGB565"/>.</returns>
7322
public override int GetHashCode()
7324
return base.GetHashCode();
7328
/// Converts the numeric value of the <see cref="FI16RGB565"/> object
7329
/// to its equivalent string representation.
7331
/// <returns>The string representation of the value of this instance.</returns>
7332
public override string ToString()
7334
return FreeImage.ColorToString(Color);
7339
namespace FreeImageAPI
7342
/// The <b>FIRational</b> structure represents a fraction via two <see cref="Int32"/>
7343
/// instances which are interpreted as numerator and denominator.
7346
/// The structure tries to approximate the value of <see cref="FreeImageAPI.FIRational(decimal)"/>
7347
/// when creating a new instance by using a better algorithm than FreeImage does.
7349
/// The structure implements the following operators:
7350
/// +, -, ++, --, ==, != , >, >==, <, <== and ~ (which switches nominator and denomiator).
7352
/// The structure can be converted into all .NET standard types either implicit or
7355
[Serializable, StructLayout(LayoutKind.Sequential), ComVisible(true)]
7356
public struct FIRational : IConvertible, IComparable, IFormattable, IComparable<FIRational>, IEquatable<FIRational>
7358
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
7359
private int numerator;
7361
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
7362
private int denominator;
7365
/// Represents the largest possible value of <see cref="FIRational"/>. This field is constant.
7367
public static readonly FIRational MaxValue = new FIRational(Int32.MaxValue, 1);
7370
/// Represents the smallest possible value of <see cref="FIRational"/>. This field is constant.
7372
public static readonly FIRational MinValue = new FIRational(Int32.MinValue, 1);
7375
/// Represents the smallest positive <see cref="FIRational"/> value greater than zero. This field is constant.
7377
public static readonly FIRational Epsilon = new FIRational(1, Int32.MaxValue);
7380
/// Initializes a new instance based on the specified parameters.
7382
/// <param name="n">The numerator.</param>
7383
/// <param name="d">The denominator.</param>
7384
public FIRational(int n, int d)
7392
/// Initializes a new instance based on the specified parameters.
7394
/// <param name="tag">The tag to read the data from.</param>
7395
public unsafe FIRational(FITAG tag)
7397
switch (FreeImage.GetTagType(tag))
7399
case FREE_IMAGE_MDTYPE.FIDT_SRATIONAL:
7400
int* value = (int*)FreeImage.GetTagValue(tag);
7401
numerator = (int)value[0];
7402
denominator = (int)value[1];
7406
throw new ArgumentException("tag");
7411
/// Initializes a new instance based on the specified parameters.
7413
/// <param name="value">The value to convert into a fraction.</param>
7414
/// <exception cref="OverflowException">
7415
/// <paramref name="value"/> cannot be converted into a fraction
7416
/// represented by two integer values.</exception>
7417
public FIRational(decimal value)
7421
int sign = value < 0 ? -1 : 1;
7422
value = Math.Abs(value);
7425
int[] contFract = CreateContinuedFraction(value);
7426
CreateFraction(contFract, out numerator, out denominator);
7434
if (Math.Abs(((decimal)numerator / (decimal)denominator) - value) > 0.0001m)
7436
int maxDen = (Int32.MaxValue / (int)value) - 2;
7437
maxDen = maxDen < 10000 ? maxDen : 10000;
7438
ApproximateFraction(value, maxDen, out numerator, out denominator);
7440
if (Math.Abs(((decimal)numerator / (decimal)denominator) - value) > 0.0001m)
7442
throw new OverflowException("Unable to convert value into a fraction");
7448
catch (Exception ex)
7450
throw new OverflowException("Unable to calculate fraction.", ex);
7455
/// The numerator of the fraction.
7457
public int Numerator
7459
get { return numerator; }
7463
/// The denominator of the fraction.
7465
public int Denominator
7467
get { return denominator; }
7471
/// Returns the truncated value of the fraction.
7473
/// <returns></returns>
7474
public int Truncate()
7476
return denominator > 0 ? (int)(numerator / denominator) : 0;
7480
/// Returns whether the fraction is representing an integer value.
7482
public bool IsInteger
7486
return (denominator == 1 ||
7487
(denominator != 0 && (numerator % denominator == 0)) ||
7488
(denominator == 0 && numerator == 0));
7493
/// Calculated the greatest common divisor of 'a' and 'b'.
7495
private static long Gcd(long a, long b)
7510
/// Calculated the smallest common multiple of 'a' and 'b'.
7512
private static long Scm(int n, int m)
7514
return Math.Abs((long)n * (long)m) / Gcd(n, m);
7518
/// Normalizes the fraction.
7520
private void Normalize()
7522
if (denominator == 0)
7529
if (numerator != 1 && denominator != 1)
7531
int common = (int)Gcd(numerator, denominator);
7532
if (common != 1 && common != 0)
7534
numerator /= common;
7535
denominator /= common;
7539
if (denominator < 0)
7547
/// Normalizes a fraction.
7549
private static void Normalize(ref long numerator, ref long denominator)
7551
if (denominator == 0)
7556
else if (numerator != 1 && denominator != 1)
7558
long common = Gcd(numerator, denominator);
7561
numerator /= common;
7562
denominator /= common;
7565
if (denominator < 0)
7573
/// Returns the digits after the point.
7575
private static int GetDigits(decimal value)
7578
value -= decimal.Truncate(value);
7582
value -= decimal.Truncate(value);
7589
/// Creates a continued fraction of a decimal value.
7591
private static int[] CreateContinuedFraction(decimal value)
7593
int precision = GetDigits(value);
7594
decimal epsilon = 0.0000001m;
7595
List<int> list = new List<int>();
7596
value = Math.Abs(value);
7600
list.Add((int)value);
7601
value -= ((int)value);
7605
if (++b == byte.MaxValue || value < epsilon)
7610
if (Math.Abs((Math.Round(value, precision - 1) - value)) < epsilon)
7612
value = Math.Round(value, precision - 1);
7614
list.Add((int)value);
7615
value -= ((int)value);
7617
return list.ToArray();
7621
/// Creates a fraction from a continued fraction.
7623
private static void CreateFraction(int[] continuedFraction, out int numerator, out int denominator)
7629
for (int i = continuedFraction.Length - 1; i > -1; i--)
7632
numerator = continuedFraction[i] * numerator + denominator;
7638
/// Tries 'brute force' to approximate <paramref name="value"/> with a fraction.
7640
private static void ApproximateFraction(decimal value, int maxDen, out int num, out int den)
7644
decimal bestDifference = 1m;
7645
decimal currentDifference = -1m;
7646
int digits = GetDigits(value);
7651
for (int i = 1; i <= digits; i++)
7657
num = (int)(value * mul);
7663
for (int i = 1; i <= maxDen; i++)
7665
int numerator = (int)Math.Floor(value * (decimal)i + 0.5m);
7666
currentDifference = Math.Abs(value - (decimal)numerator / (decimal)i);
7667
if (currentDifference < bestDifference)
7671
bestDifference = currentDifference;
7677
/// Converts the numeric value of the <see cref="FIRational"/> object
7678
/// to its equivalent string representation.
7680
/// <returns>The string representation of the value of this instance.</returns>
7681
public override string ToString()
7683
return ((IConvertible)this).ToDouble(null).ToString();
7687
/// Tests whether the specified object is a <see cref="FIRational"/> structure
7688
/// and is equivalent to this <see cref="FIRational"/> structure.
7690
/// <param name="obj">The object to test.</param>
7691
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="FIRational"/> structure
7692
/// equivalent to this <see cref="FIRational"/> structure; otherwise, <b>false</b>.</returns>
7693
public override bool Equals(object obj)
7695
return ((obj is FIRational) && (this == ((FIRational)obj)));
7699
/// Returns a hash code for this <see cref="FIRational"/> structure.
7701
/// <returns>An integer value that specifies the hash code for this <see cref="FIRational"/>.</returns>
7702
public override int GetHashCode()
7704
return base.GetHashCode();
7710
/// Standard implementation of the operator.
7712
public static FIRational operator +(FIRational r1)
7718
/// Standard implementation of the operator.
7720
public static FIRational operator -(FIRational r1)
7727
/// Returns the reciprocal value of this instance.
7729
public static FIRational operator ~(FIRational r1)
7731
int temp = r1.denominator;
7732
r1.denominator = r1.numerator;
7733
r1.numerator = temp;
7739
/// Standard implementation of the operator.
7741
public static FIRational operator ++(FIRational r1)
7745
r1.numerator += r1.denominator;
7751
/// Standard implementation of the operator.
7753
public static FIRational operator --(FIRational r1)
7757
r1.numerator -= r1.denominator;
7763
/// Standard implementation of the operator.
7765
public static FIRational operator +(FIRational r1, FIRational r2)
7768
long denominator = Scm(r1.denominator, r2.denominator);
7769
numerator = (r1.numerator * (denominator / r1.denominator)) + (r2.numerator * (denominator / r2.denominator));
7770
Normalize(ref numerator, ref denominator);
7773
return new FIRational((int)numerator, (int)denominator);
7778
/// Standard implementation of the operator.
7780
public static FIRational operator -(FIRational r1, FIRational r2)
7786
/// Standard implementation of the operator.
7788
public static FIRational operator *(FIRational r1, FIRational r2)
7790
long numerator = r1.numerator * r2.numerator;
7791
long denominator = r1.denominator * r2.denominator;
7792
Normalize(ref numerator, ref denominator);
7795
return new FIRational((int)numerator, (int)denominator);
7800
/// Standard implementation of the operator.
7802
public static FIRational operator /(FIRational r1, FIRational r2)
7804
int temp = r2.denominator;
7805
r2.denominator = r2.numerator;
7806
r2.numerator = temp;
7811
/// Standard implementation of the operator.
7813
public static FIRational operator %(FIRational r1, FIRational r2)
7816
if (Math.Abs(r2.numerator) < r2.denominator)
7817
return new FIRational(0, 0);
7818
int div = (int)(r1 / r2);
7819
return r1 - (r2 * div);
7823
/// Standard implementation of the operator.
7825
public static bool operator ==(FIRational r1, FIRational r2)
7829
return (r1.numerator == r2.numerator) && (r1.denominator == r2.denominator);
7833
/// Standard implementation of the operator.
7835
public static bool operator !=(FIRational r1, FIRational r2)
7841
/// Standard implementation of the operator.
7843
public static bool operator >(FIRational r1, FIRational r2)
7845
long denominator = Scm(r1.denominator, r2.denominator);
7846
return (r1.numerator * (denominator / r1.denominator)) > (r2.numerator * (denominator / r2.denominator));
7850
/// Standard implementation of the operator.
7852
public static bool operator <(FIRational r1, FIRational r2)
7854
long denominator = Scm(r1.denominator, r2.denominator);
7855
return (r1.numerator * (denominator / r1.denominator)) < (r2.numerator * (denominator / r2.denominator));
7859
/// Standard implementation of the operator.
7861
public static bool operator >=(FIRational r1, FIRational r2)
7863
long denominator = Scm(r1.denominator, r2.denominator);
7864
return (r1.numerator * (denominator / r1.denominator)) >= (r2.numerator * (denominator / r2.denominator));
7868
/// Standard implementation of the operator.
7870
public static bool operator <=(FIRational r1, FIRational r2)
7872
long denominator = Scm(r1.denominator, r2.denominator);
7873
return (r1.numerator * (denominator / r1.denominator)) <= (r2.numerator * (denominator / r2.denominator));
7881
/// Converts the value of a <see cref="FIRational"/> structure to a <see cref="Boolean"/> structure.
7883
/// <param name="value">A <see cref="FIRational"/> structure.</param>
7884
/// <returns>A new instance of <see cref="Boolean"/> initialized to <paramref name="value"/>.</returns>
7885
public static explicit operator bool(FIRational value)
7887
return (value.numerator != 0);
7891
/// Converts the value of a <see cref="FIRational"/> structure to a <see cref="Byte"/> structure.
7893
/// <param name="value">A <see cref="FIRational"/> structure.</param>
7894
/// <returns>A new instance of <see cref="Byte"/> initialized to <paramref name="value"/>.</returns>
7895
public static explicit operator byte(FIRational value)
7897
return (byte)(double)value;
7901
/// Converts the value of a <see cref="FIRational"/> structure to a <see cref="Char"/> structure.
7903
/// <param name="value">A <see cref="FIRational"/> structure.</param>
7904
/// <returns>A new instance of <see cref="Char"/> initialized to <paramref name="value"/>.</returns>
7905
public static explicit operator char(FIRational value)
7907
return (char)(double)value;
7911
/// Converts the value of a <see cref="FIRational"/> structure to a <see cref="Decimal"/> structure.
7913
/// <param name="value">A <see cref="FIRational"/> structure.</param>
7914
/// <returns>A new instance of <see cref="Decimal"/> initialized to <paramref name="value"/>.</returns>
7915
public static implicit operator decimal(FIRational value)
7917
return value.denominator == 0 ? 0m : (decimal)value.numerator / (decimal)value.denominator;
7921
/// Converts the value of a <see cref="FIRational"/> structure to a <see cref="Double"/> structure.
7923
/// <param name="value">A <see cref="FIRational"/> structure.</param>
7924
/// <returns>A new instance of <see cref="Double"/> initialized to <paramref name="value"/>.</returns>
7925
public static implicit operator double(FIRational value)
7927
return value.denominator == 0 ? 0d : (double)value.numerator / (double)value.denominator;
7931
/// Converts the value of a <see cref="FIRational"/> structure to an <see cref="Int16"/> structure.
7933
/// <param name="value">A <see cref="FIRational"/> structure.</param>
7934
/// <returns>A new instance of <see cref="Int16"/> initialized to <paramref name="value"/>.</returns>
7935
public static explicit operator short(FIRational value)
7937
return (short)(double)value;
7941
/// Converts the value of a <see cref="FIRational"/> structure to an <see cref="Int32"/> structure.
7943
/// <param name="value">A <see cref="FIRational"/> structure.</param>
7944
/// <returns>A new instance of <see cref="Int32"/> initialized to <paramref name="value"/>.</returns>
7945
public static explicit operator int(FIRational value)
7947
return (int)(double)value;
7951
/// Converts the value of a <see cref="FIRational"/> structure to an <see cref="Int64"/> structure.
7953
/// <param name="value">A <see cref="FIRational"/> structure.</param>
7954
/// <returns>A new instance of <see cref="Int64"/> initialized to <paramref name="value"/>.</returns>
7955
public static explicit operator long(FIRational value)
7957
return (byte)(double)value;
7961
/// Converts the value of a <see cref="FIRational"/> structure to a <see cref="Single"/> structure.
7963
/// <param name="value">A <see cref="FIRational"/> structure.</param>
7964
/// <returns>A new instance of <see cref="Single"/> initialized to <paramref name="value"/>.</returns>
7965
public static implicit operator float(FIRational value)
7967
return value.denominator == 0 ? 0f : (float)value.numerator / (float)value.denominator;
7971
/// Converts the value of a <see cref="FIRational"/> structure to a <see cref="SByte"/> structure.
7973
/// <param name="value">A <see cref="FIRational"/> structure.</param>
7974
/// <returns>A new instance of <see cref="SByte"/> initialized to <paramref name="value"/>.</returns>
7975
public static explicit operator sbyte(FIRational value)
7977
return (sbyte)(double)value;
7981
/// Converts the value of a <see cref="FIRational"/> structure to an <see cref="UInt16"/> structure.
7983
/// <param name="value">A <see cref="FIRational"/> structure.</param>
7984
/// <returns>A new instance of <see cref="UInt16"/> initialized to <paramref name="value"/>.</returns>
7985
public static explicit operator ushort(FIRational value)
7987
return (ushort)(double)value;
7991
/// Converts the value of a <see cref="FIRational"/> structure to an <see cref="UInt32"/> structure.
7993
/// <param name="value">A <see cref="FIRational"/> structure.</param>
7994
/// <returns>A new instance of <see cref="UInt32"/> initialized to <paramref name="value"/>.</returns>
7995
public static explicit operator uint(FIRational value)
7997
return (uint)(double)value;
8001
/// Converts the value of a <see cref="FIRational"/> structure to an <see cref="UInt64"/> structure.
8003
/// <param name="value">A <see cref="FIRational"/> structure.</param>
8004
/// <returns>A new instance of <see cref="UInt64"/> initialized to <paramref name="value"/>.</returns>
8005
public static explicit operator ulong(FIRational value)
8007
return (ulong)(double)value;
8013
/// Converts the value of a <see cref="Boolean"/> structure to a <see cref="FIRational"/> structure.
8015
/// <param name="value">A <see cref="Boolean"/> structure.</param>
8016
/// <returns>A new instance of <see cref="FIRational"/> initialized to <paramref name="value"/>.</returns>
8017
public static explicit operator FIRational(bool value)
8019
return new FIRational(value ? 1 : 0, 1);
8023
/// Converts the value of a <see cref="Byte"/> structure to a <see cref="FIRational"/> structure.
8025
/// <param name="value">A <see cref="Byte"/> structure.</param>
8026
/// <returns>A new instance of <see cref="FIRational"/> initialized to <paramref name="value"/>.</returns>
8027
public static implicit operator FIRational(byte value)
8029
return new FIRational(value, 1);
8033
/// Converts the value of a <see cref="Char"/> structure to a <see cref="FIRational"/> structure.
8035
/// <param name="value">A <see cref="Char"/> structure.</param>
8036
/// <returns>A new instance of <see cref="FIRational"/> initialized to <paramref name="value"/>.</returns>
8037
public static implicit operator FIRational(char value)
8039
return new FIRational(value, 1);
8043
/// Converts the value of a <see cref="Decimal"/> structure to a <see cref="FIRational"/> structure.
8045
/// <param name="value">A <see cref="Decimal"/> structure.</param>
8046
/// <returns>A new instance of <see cref="FIRational"/> initialized to <paramref name="value"/>.</returns>
8047
public static explicit operator FIRational(decimal value)
8049
return new FIRational(value);
8053
/// Converts the value of a <see cref="Double"/> structure to a <see cref="FIRational"/> structure.
8055
/// <param name="value">A <see cref="Double"/> structure.</param>
8056
/// <returns>A new instance of <see cref="FIRational"/> initialized to <paramref name="value"/>.</returns>
8057
public static explicit operator FIRational(double value)
8059
return new FIRational((decimal)value);
8063
/// Converts the value of an <see cref="Int16"/> structure to a <see cref="FIRational"/> structure.
8065
/// <param name="value">An <see cref="Int16"/> structure.</param>
8066
/// <returns>A new instance of <see cref="FIRational"/> initialized to <paramref name="value"/>.</returns>
8067
public static implicit operator FIRational(short value)
8069
return new FIRational(value, 1);
8073
/// Converts the value of an <see cref="Int32"/> structure to a <see cref="FIRational"/> structure.
8075
/// <param name="value">An <see cref="Int32"/> structure.</param>
8076
/// <returns>A new instance of <see cref="FIRational"/> initialized to <paramref name="value"/>.</returns>
8077
public static implicit operator FIRational(int value)
8079
return new FIRational(value, 1);
8083
/// Converts the value of an <see cref="Int64"/> structure to a <see cref="FIRational"/> structure.
8085
/// <param name="value">An <see cref="Int64"/> structure.</param>
8086
/// <returns>A new instance of <see cref="FIRational"/> initialized to <paramref name="value"/>.</returns>
8087
public static explicit operator FIRational(long value)
8089
return new FIRational((int)value, 1);
8093
/// Converts the value of a <see cref="SByte"/> structure to a <see cref="FIRational"/> structure.
8095
/// <param name="value">A <see cref="SByte"/> structure.</param>
8096
/// <returns>A new instance of <see cref="FIRational"/> initialized to <paramref name="value"/>.</returns>
8097
public static implicit operator FIRational(sbyte value)
8099
return new FIRational(value, 1);
8103
/// Converts the value of a <see cref="Single"/> structure to a <see cref="FIRational"/> structure.
8105
/// <param name="value">A <see cref="Single"/> structure.</param>
8106
/// <returns>A new instance of <see cref="FIRational"/> initialized to <paramref name="value"/>.</returns>
8107
public static explicit operator FIRational(float value)
8109
return new FIRational((decimal)value);
8113
/// Converts the value of an <see cref="UInt16"/> structure to a <see cref="FIRational"/> structure.
8115
/// <param name="value">An <see cref="UInt16"/> structure.</param>
8116
/// <returns>A new instance of <see cref="FIRational"/> initialized to <paramref name="value"/>.</returns>
8117
public static implicit operator FIRational(ushort value)
8119
return new FIRational(value, 1);
8123
/// Converts the value of an <see cref="UInt32"/> structure to a <see cref="FIRational"/> structure.
8125
/// <param name="value">An <see cref="UInt32"/> structure.</param>
8126
/// <returns>A new instance of <see cref="FIRational"/> initialized to <paramref name="value"/>.</returns>
8127
public static explicit operator FIRational(uint value)
8129
return new FIRational((int)value, 1);
8133
/// Converts the value of an <see cref="UInt64"/> structure to a <see cref="FIRational"/> structure.
8135
/// <param name="value">An <see cref="UInt64"/> structure.</param>
8136
/// <returns>A new instance of <see cref="FIRational"/> initialized to <paramref name="value"/>.</returns>
8137
public static explicit operator FIRational(ulong value)
8139
return new FIRational((int)value, 1);
8144
#region IConvertible Member
8146
TypeCode IConvertible.GetTypeCode()
8148
return TypeCode.Double;
8151
bool IConvertible.ToBoolean(IFormatProvider provider)
8156
byte IConvertible.ToByte(IFormatProvider provider)
8161
char IConvertible.ToChar(IFormatProvider provider)
8166
DateTime IConvertible.ToDateTime(IFormatProvider provider)
8168
return Convert.ToDateTime(((IConvertible)this).ToDouble(provider));
8171
decimal IConvertible.ToDecimal(IFormatProvider provider)
8176
double IConvertible.ToDouble(IFormatProvider provider)
8181
short IConvertible.ToInt16(IFormatProvider provider)
8186
int IConvertible.ToInt32(IFormatProvider provider)
8191
long IConvertible.ToInt64(IFormatProvider provider)
8196
sbyte IConvertible.ToSByte(IFormatProvider provider)
8201
float IConvertible.ToSingle(IFormatProvider provider)
8206
string IConvertible.ToString(IFormatProvider provider)
8208
return ToString(((double)this).ToString(), provider);
8211
object IConvertible.ToType(Type conversionType, IFormatProvider provider)
8213
return Convert.ChangeType(((IConvertible)this).ToDouble(provider), conversionType, provider);
8216
ushort IConvertible.ToUInt16(IFormatProvider provider)
8218
return (ushort)this;
8221
uint IConvertible.ToUInt32(IFormatProvider provider)
8226
ulong IConvertible.ToUInt64(IFormatProvider provider)
8233
#region IComparable Member
8236
/// Compares this instance with a specified <see cref="Object"/>.
8238
/// <param name="obj">An object to compare with this instance.</param>
8239
/// <returns>A 32-bit signed integer indicating the lexical relationship between the two comparands.</returns>
8240
/// <exception cref="ArgumentException"><paramref name="obj"/> is not a <see cref="FIRational"/>.</exception>
8241
public int CompareTo(object obj)
8247
if (!(obj is FIRational))
8249
throw new ArgumentException();
8251
return CompareTo((FIRational)obj);
8256
#region IFormattable Member
8259
/// Formats the value of the current instance using the specified format.
8261
/// <param name="format">The String specifying the format to use.</param>
8262
/// <param name="formatProvider">The IFormatProvider to use to format the value.</param>
8263
/// <returns>A String containing the value of the current instance in the specified format.</returns>
8264
public string ToString(string format, IFormatProvider formatProvider)
8270
return String.Format(formatProvider, format, ((IConvertible)this).ToDouble(formatProvider));
8275
#region IEquatable<FIRational> Member
8278
/// Tests whether the specified <see cref="FIRational"/> structure is equivalent to this <see cref="FIRational"/> structure.
8280
/// <param name="other">A <see cref="FIRational"/> structure to compare to this instance.</param>
8281
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="FIRational"/> structure
8282
/// equivalent to this <see cref="FIRational"/> structure; otherwise, <b>false</b>.</returns>
8283
public bool Equals(FIRational other)
8285
return (this == other);
8290
#region IComparable<FIRational> Member
8293
/// Compares this instance with a specified <see cref="FIRational"/> object.
8295
/// <param name="other">A <see cref="FIRational"/> to compare.</param>
8296
/// <returns>A signed number indicating the relative values of this instance
8297
/// and <paramref name="other"/>.</returns>
8298
public int CompareTo(FIRational other)
8300
FIRational difference = this - other;
8301
difference.Normalize();
8302
if (difference.numerator > 0) return 1;
8303
if (difference.numerator < 0) return -1;
8311
namespace FreeImageAPI
8314
/// The <b>FIURational</b> structure represents a fraction via two <see cref="UInt32"/>
8315
/// instances which are interpreted as numerator and denominator.
8318
/// The structure tries to approximate the value of <see cref="FreeImageAPI.FIURational(decimal)"/>
8319
/// when creating a new instance by using a better algorithm than FreeImage does.
8321
/// The structure implements the following operators:
8322
/// +, ++, --, ==, != , >, >==, <, <== and ~ (which switches nominator and denomiator).
8324
/// The structure can be converted into all .NET standard types either implicit or
8327
[Serializable, StructLayout(LayoutKind.Sequential), ComVisible(true)]
8328
public struct FIURational : IConvertible, IComparable, IFormattable, IComparable<FIURational>, IEquatable<FIURational>
8330
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
8331
private uint numerator;
8333
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
8334
private uint denominator;
8337
/// Represents the largest possible value of <see cref="FIURational"/>. This field is constant.
8339
public static readonly FIURational MaxValue = new FIURational(UInt32.MaxValue, 1u);
8342
/// Represents the smallest possible value of <see cref="FIURational"/>. This field is constant.
8344
public static readonly FIURational MinValue = new FIURational(0u, 1u);
8347
/// Represents the smallest positive <see cref="FIURational"/> value greater than zero. This field is constant.
8349
public static readonly FIURational Epsilon = new FIURational(1u, UInt32.MaxValue);
8352
/// Initializes a new instance based on the specified parameters.
8354
/// <param name="n">The numerator.</param>
8355
/// <param name="d">The denominator.</param>
8356
public FIURational(uint n, uint d)
8364
/// Initializes a new instance based on the specified parameters.
8366
/// <param name="tag">The tag to read the data from.</param>
8367
public unsafe FIURational(FITAG tag)
8369
switch (FreeImage.GetTagType(tag))
8371
case FREE_IMAGE_MDTYPE.FIDT_RATIONAL:
8372
uint* pvalue = (uint*)FreeImage.GetTagValue(tag);
8373
numerator = pvalue[0];
8374
denominator = pvalue[1];
8378
throw new ArgumentException("tag");
8383
///Initializes a new instance based on the specified parameters.
8385
/// <param name="value">The value to convert into a fraction.</param>
8386
/// <exception cref="OverflowException">
8387
/// <paramref name="value"/> cannot be converted into a fraction
8388
/// represented by two unsigned integer values.</exception>
8389
public FIURational(decimal value)
8395
throw new OverflowException("value");
8399
int[] contFract = CreateContinuedFraction(value);
8400
CreateFraction(contFract, out numerator, out denominator);
8408
if (Math.Abs(((decimal)numerator / (decimal)denominator) - value) > 0.0001m)
8410
int maxDen = (Int32.MaxValue / (int)value) - 2;
8411
maxDen = maxDen < 10000 ? maxDen : 10000;
8412
ApproximateFraction(value, maxDen, out numerator, out denominator);
8414
if (Math.Abs(((decimal)numerator / (decimal)denominator) - value) > 0.0001m)
8416
throw new OverflowException("Unable to convert value into a fraction");
8421
catch (Exception ex)
8423
throw new OverflowException("Unable to calculate fraction.", ex);
8428
/// The numerator of the fraction.
8430
public uint Numerator
8432
get { return numerator; }
8436
/// The denominator of the fraction.
8438
public uint Denominator
8440
get { return denominator; }
8444
/// Returns the truncated value of the fraction.
8446
/// <returns></returns>
8447
public int Truncate()
8449
return denominator > 0 ? (int)(numerator / denominator) : 0;
8453
/// Returns whether the fraction is representing an integer value.
8455
public bool IsInteger
8459
return (denominator == 1 ||
8460
(denominator != 0 && (numerator % denominator == 0)) ||
8461
(denominator == 0 && numerator == 0));
8466
/// Calculated the greatest common divisor of 'a' and 'b'.
8468
private static ulong Gcd(ulong a, ulong b)
8481
/// Calculated the smallest common multiple of 'a' and 'b'.
8483
private static ulong Scm(uint n, uint m)
8485
return (ulong)n * (ulong)m / Gcd(n, m);
8489
/// Normalizes the fraction.
8491
private void Normalize()
8493
if (denominator == 0)
8500
if (numerator != 1 && denominator != 1)
8502
uint common = (uint)Gcd(numerator, denominator);
8503
if (common != 1 && common != 0)
8505
numerator /= common;
8506
denominator /= common;
8512
/// Normalizes a fraction.
8514
private static void Normalize(ref ulong numerator, ref ulong denominator)
8516
if (denominator == 0)
8521
else if (numerator != 1 && denominator != 1)
8523
ulong common = Gcd(numerator, denominator);
8526
numerator /= common;
8527
denominator /= common;
8533
/// Returns the digits after the point.
8535
private static int GetDigits(decimal value)
8538
value -= decimal.Truncate(value);
8542
value -= decimal.Truncate(value);
8549
/// Creates a continued fraction of a decimal value.
8551
private static int[] CreateContinuedFraction(decimal value)
8553
int precision = GetDigits(value);
8554
decimal epsilon = 0.0000001m;
8555
List<int> list = new List<int>();
8556
value = Math.Abs(value);
8560
list.Add((int)value);
8561
value -= ((int)value);
8565
if (++b == byte.MaxValue || value < epsilon)
8570
if (Math.Abs((Math.Round(value, precision - 1) - value)) < epsilon)
8572
value = Math.Round(value, precision - 1);
8574
list.Add((int)value);
8575
value -= ((int)value);
8577
return list.ToArray();
8581
/// Creates a fraction from a continued fraction.
8583
private static void CreateFraction(int[] continuedFraction, out uint numerator, out uint denominator)
8589
for (int i = continuedFraction.Length - 1; i > -1; i--)
8592
numerator = (uint)(continuedFraction[i] * numerator + denominator);
8598
/// Tries 'brute force' to approximate <paramref name="value"/> with a fraction.
8600
private static void ApproximateFraction(decimal value, int maxDen, out uint num, out uint den)
8604
decimal bestDifference = 1m;
8605
decimal currentDifference = -1m;
8606
int digits = GetDigits(value);
8611
for (int i = 1; i <= digits; i++)
8617
num = (uint)(value * mul);
8623
for (uint u = 1; u <= maxDen; u++)
8625
uint numerator = (uint)Math.Floor(value * (decimal)u + 0.5m);
8626
currentDifference = Math.Abs(value - (decimal)numerator / (decimal)u);
8627
if (currentDifference < bestDifference)
8631
bestDifference = currentDifference;
8637
/// Converts the numeric value of the <see cref="FIURational"/> object
8638
/// to its equivalent string representation.
8640
/// <returns>The string representation of the value of this instance.</returns>
8641
public override string ToString()
8643
return ((IConvertible)this).ToDouble(null).ToString();
8647
/// Tests whether the specified object is a <see cref="FIURational"/> structure
8648
/// and is equivalent to this <see cref="FIURational"/> structure.
8650
/// <param name="obj">The object to test.</param>
8651
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="FIURational"/> structure
8652
/// equivalent to this <see cref="FIURational"/> structure; otherwise, <b>false</b>.</returns>
8653
public override bool Equals(object obj)
8655
return ((obj is FIURational) && (this == ((FIURational)obj)));
8659
/// Returns a hash code for this <see cref="FIURational"/> structure.
8661
/// <returns>An integer value that specifies the hash code for this <see cref="FIURational"/>.</returns>
8662
public override int GetHashCode()
8664
return base.GetHashCode();
8670
/// Standard implementation of the operator.
8672
public static FIURational operator +(FIURational value)
8678
/// Returns the reciprocal value of this instance.
8680
public static FIURational operator ~(FIURational value)
8682
uint temp = value.denominator;
8683
value.denominator = value.numerator;
8684
value.numerator = temp;
8690
/// Standard implementation of the operator.
8692
public static FIURational operator ++(FIURational value)
8696
value.numerator += value.denominator;
8702
/// Standard implementation of the operator.
8704
public static FIURational operator --(FIURational value)
8708
value.numerator -= value.denominator;
8714
/// Standard implementation of the operator.
8716
public static FIURational operator +(FIURational left, FIURational right)
8718
ulong numerator = 0;
8719
ulong denominator = Scm(left.denominator, right.denominator);
8720
numerator = (left.numerator * (denominator / left.denominator)) +
8721
(right.numerator * (denominator / right.denominator));
8722
Normalize(ref numerator, ref denominator);
8725
return new FIURational((uint)numerator, (uint)denominator);
8730
/// Standard implementation of the operator.
8732
public static FIURational operator -(FIURational left, FIURational right)
8736
if (left.denominator != right.denominator)
8738
uint denom = left.denominator;
8739
left.numerator *= right.denominator;
8740
left.denominator *= right.denominator;
8741
right.numerator *= denom;
8742
right.denominator *= denom;
8744
left.numerator -= right.numerator;
8751
/// Standard implementation of the operator.
8753
public static FIURational operator *(FIURational left, FIURational r2)
8755
ulong numerator = left.numerator * r2.numerator;
8756
ulong denominator = left.denominator * r2.denominator;
8757
Normalize(ref numerator, ref denominator);
8760
return new FIURational((uint)numerator, (uint)denominator);
8765
/// Standard implementation of the operator.
8767
public static FIURational operator /(FIURational left, FIURational right)
8769
uint temp = right.denominator;
8770
right.denominator = right.numerator;
8771
right.numerator = temp;
8772
return left * right;
8776
/// Standard implementation of the operator.
8778
public static FIURational operator %(FIURational left, FIURational right)
8781
if (Math.Abs(right.numerator) < right.denominator)
8782
return new FIURational(0, 0);
8783
int div = (int)(left / right);
8784
return left - (right * div);
8788
/// Standard implementation of the operator.
8790
public static bool operator ==(FIURational left, FIURational right)
8794
return (left.numerator == right.numerator) && (left.denominator == right.denominator);
8798
/// Standard implementation of the operator.
8800
public static bool operator !=(FIURational left, FIURational right)
8804
return (left.numerator != right.numerator) || (left.denominator != right.denominator);
8808
/// Standard implementation of the operator.
8810
public static bool operator >(FIURational left, FIURational right)
8812
ulong denominator = Scm(left.denominator, right.denominator);
8813
return (left.numerator * (denominator / left.denominator)) >
8814
(right.numerator * (denominator / right.denominator));
8818
/// Standard implementation of the operator.
8820
public static bool operator <(FIURational left, FIURational right)
8822
ulong denominator = Scm(left.denominator, right.denominator);
8823
return (left.numerator * (denominator / left.denominator)) <
8824
(right.numerator * (denominator / right.denominator));
8828
/// Standard implementation of the operator.
8830
public static bool operator >=(FIURational left, FIURational right)
8832
ulong denominator = Scm(left.denominator, right.denominator);
8833
return (left.numerator * (denominator / left.denominator)) >=
8834
(right.numerator * (denominator / right.denominator));
8838
/// Standard implementation of the operator.
8840
public static bool operator <=(FIURational left, FIURational right)
8842
ulong denominator = Scm(left.denominator, right.denominator);
8843
return (left.numerator * (denominator / left.denominator)) <=
8844
(right.numerator * (denominator / right.denominator));
8852
/// Converts the value of a <see cref="FIURational"/> structure to a <see cref="Boolean"/> structure.
8854
/// <param name="value">A <see cref="FIURational"/> structure.</param>
8855
/// <returns>A new instance of <see cref="Boolean"/> initialized to <paramref name="value"/>.</returns>
8856
public static explicit operator bool(FIURational value)
8858
return (value.numerator != 0);
8862
/// Converts the value of a <see cref="FIURational"/> structure to a <see cref="Byte"/> structure.
8864
/// <param name="value">A <see cref="FIURational"/> structure.</param>
8865
/// <returns>A new instance of <see cref="Byte"/> initialized to <paramref name="value"/>.</returns>
8866
public static explicit operator byte(FIURational value)
8868
return (byte)(double)value;
8872
/// Converts the value of a <see cref="FIURational"/> structure to a <see cref="Char"/> structure.
8874
/// <param name="value">A <see cref="FIURational"/> structure.</param>
8875
/// <returns>A new instance of <see cref="Char"/> initialized to <paramref name="value"/>.</returns>
8876
public static explicit operator char(FIURational value)
8878
return (char)(double)value;
8882
/// Converts the value of a <see cref="FIURational"/> structure to a <see cref="Decimal"/> structure.
8884
/// <param name="value">A <see cref="FIURational"/> structure.</param>
8885
/// <returns>A new instance of <see cref="Decimal"/> initialized to <paramref name="value"/>.</returns>
8886
public static implicit operator decimal(FIURational value)
8888
return value.denominator == 0 ? 0m : (decimal)value.numerator / (decimal)value.denominator;
8892
/// Converts the value of a <see cref="FIURational"/> structure to a <see cref="Double"/> structure.
8894
/// <param name="value">A <see cref="FIURational"/> structure.</param>
8895
/// <returns>A new instance of <see cref="Double"/> initialized to <paramref name="value"/>.</returns>
8896
public static implicit operator double(FIURational value)
8898
return value.denominator == 0 ? 0d : (double)value.numerator / (double)value.denominator;
8902
/// Converts the value of a <see cref="FIURational"/> structure to an <see cref="Int16"/> structure.
8904
/// <param name="value">A <see cref="FIURational"/> structure.</param>
8905
/// <returns>A new instance of <see cref="Int16"/> initialized to <paramref name="value"/>.</returns>
8906
public static explicit operator short(FIURational value)
8908
return (short)(double)value;
8912
/// Converts the value of a <see cref="FIURational"/> structure to an <see cref="Int32"/> structure.
8914
/// <param name="value">A <see cref="FIURational"/> structure.</param>
8915
/// <returns>A new instance of <see cref="Int32"/> initialized to <paramref name="value"/>.</returns>
8916
public static explicit operator int(FIURational value)
8918
return (int)(double)value;
8922
/// Converts the value of a <see cref="FIURational"/> structure to an <see cref="Int64"/> structure.
8924
/// <param name="value">A <see cref="FIURational"/> structure.</param>
8925
/// <returns>A new instance of <see cref="Int64"/> initialized to <paramref name="value"/>.</returns>
8926
public static explicit operator long(FIURational value)
8928
return (byte)(double)value;
8932
/// Converts the value of a <see cref="FIURational"/> structure to a <see cref="Single"/> structure.
8934
/// <param name="value">A <see cref="FIURational"/> structure.</param>
8935
/// <returns>A new instance of <see cref="Single"/> initialized to <paramref name="value"/>.</returns>
8936
public static implicit operator float(FIURational value)
8938
return value.denominator == 0 ? 0f : (float)value.numerator / (float)value.denominator;
8942
/// Converts the value of a <see cref="FIURational"/> structure to a <see cref="SByte"/> structure.
8944
/// <param name="value">A <see cref="FIURational"/> structure.</param>
8945
/// <returns>A new instance of <see cref="SByte"/> initialized to <paramref name="value"/>.</returns>
8946
public static explicit operator sbyte(FIURational value)
8948
return (sbyte)(double)value;
8952
/// Converts the value of a <see cref="FIURational"/> structure to an <see cref="UInt16"/> structure.
8954
/// <param name="value">A <see cref="FIURational"/> structure.</param>
8955
/// <returns>A new instance of <see cref="UInt16"/> initialized to <paramref name="value"/>.</returns>
8956
public static explicit operator ushort(FIURational value)
8958
return (ushort)(double)value;
8962
/// Converts the value of a <see cref="FIURational"/> structure to an <see cref="UInt32"/> structure.
8964
/// <param name="value">A <see cref="FIURational"/> structure.</param>
8965
/// <returns>A new instance of <see cref="UInt32"/> initialized to <paramref name="value"/>.</returns>
8966
public static explicit operator uint(FIURational value)
8968
return (uint)(double)value;
8972
/// Converts the value of a <see cref="FIURational"/> structure to an <see cref="UInt32"/> structure.
8974
/// <param name="value">A <see cref="FIURational"/> structure.</param>
8975
/// <returns>A new instance of <see cref="UInt32"/> initialized to <paramref name="value"/>.</returns>
8976
public static explicit operator ulong(FIURational value)
8978
return (ulong)(double)value;
8984
/// Converts the value of a <see cref="Boolean"/> structure to a <see cref="FIURational"/> structure.
8986
/// <param name="value">A <see cref="Boolean"/> structure.</param>
8987
/// <returns>A new instance of <see cref="FIURational"/> initialized to <paramref name="value"/>.</returns>
8988
public static explicit operator FIURational(bool value)
8990
return new FIURational(value ? 1u : 0u, 1u);
8994
/// Converts the value of a <see cref="Byte"/> structure to a <see cref="FIURational"/> structure.
8996
/// <param name="value">A <see cref="Byte"/> structure.</param>
8997
/// <returns>A new instance of <see cref="FIURational"/> initialized to <paramref name="value"/>.</returns>
8998
public static implicit operator FIURational(byte value)
9000
return new FIURational(value, 1);
9004
/// Converts the value of a <see cref="Char"/> structure to a <see cref="FIURational"/> structure.
9006
/// <param name="value">A <see cref="Char"/> structure.</param>
9007
/// <returns>A new instance of <see cref="FIURational"/> initialized to <paramref name="value"/>.</returns>
9008
public static implicit operator FIURational(char value)
9010
return new FIURational(value, 1);
9014
/// Converts the value of a <see cref="Decimal"/> structure to a <see cref="FIURational"/> structure.
9016
/// <param name="value">A <see cref="Decimal"/> structure.</param>
9017
/// <returns>A new instance of <see cref="FIURational"/> initialized to <paramref name="value"/>.</returns>
9018
public static explicit operator FIURational(decimal value)
9020
return new FIURational(value);
9024
/// Converts the value of a <see cref="Double"/> structure to a <see cref="FIURational"/> structure.
9026
/// <param name="value">A <see cref="Double"/> structure.</param>
9027
/// <returns>A new instance of <see cref="FIURational"/> initialized to <paramref name="value"/>.</returns>
9028
public static explicit operator FIURational(double value)
9030
return new FIURational((decimal)value);
9034
/// Converts the value of an <see cref="Int16"/> structure to a <see cref="FIURational"/> structure.
9036
/// <param name="value">An <see cref="Int16"/> structure.</param>
9037
/// <returns>A new instance of <see cref="FIURational"/> initialized to <paramref name="value"/>.</returns>
9038
public static implicit operator FIURational(short value)
9040
return new FIURational((uint)value, 1u);
9044
/// Converts the value of an <see cref="Int32"/> structure to a <see cref="FIURational"/> structure.
9046
/// <param name="value">An <see cref="Int32"/> structure.</param>
9047
/// <returns>A new instance of <see cref="FIURational"/> initialized to <paramref name="value"/>.</returns>
9048
public static implicit operator FIURational(int value)
9050
return new FIURational((uint)value, 1u);
9054
/// Converts the value of an <see cref="Int64"/> structure to a <see cref="FIURational"/> structure.
9056
/// <param name="value">An <see cref="Int64"/> structure.</param>
9057
/// <returns>A new instance of <see cref="FIURational"/> initialized to <paramref name="value"/>.</returns>
9058
public static explicit operator FIURational(long value)
9060
return new FIURational((uint)value, 1u);
9064
/// Converts the value of a <see cref="SByte"/> structure to a <see cref="FIURational"/> structure.
9066
/// <param name="value">A <see cref="SByte"/> structure.</param>
9067
/// <returns>A new instance of <see cref="FIURational"/> initialized to <paramref name="value"/>.</returns>
9068
public static implicit operator FIURational(sbyte value)
9070
return new FIURational((uint)value, 1u);
9074
/// Converts the value of a <see cref="Single"/> structure to a <see cref="FIURational"/> structure.
9076
/// <param name="value">A <see cref="Single"/> structure.</param>
9077
/// <returns>A new instance of <see cref="FIURational"/> initialized to <paramref name="value"/>.</returns>
9078
public static explicit operator FIURational(float value)
9080
return new FIURational((decimal)value);
9084
/// Converts the value of an <see cref="UInt16"/> structure to a <see cref="FIURational"/> structure.
9086
/// <param name="value">An <see cref="UInt16"/> structure.</param>
9087
/// <returns>A new instance of <see cref="FIURational"/> initialized to <paramref name="value"/>.</returns>
9088
public static implicit operator FIURational(ushort value)
9090
return new FIURational(value, 1);
9094
/// Converts the value of an <see cref="UInt32"/> structure to a <see cref="FIURational"/> structure.
9096
/// <param name="value">An <see cref="UInt32"/> structure.</param>
9097
/// <returns>A new instance of <see cref="FIURational"/> initialized to <paramref name="value"/>.</returns>
9098
public static explicit operator FIURational(uint value)
9100
return new FIURational(value, 1u);
9104
/// Converts the value of an <see cref="UInt64"/> structure to a <see cref="FIURational"/> structure.
9106
/// <param name="value">An <see cref="UInt64"/> structure.</param>
9107
/// <returns>A new instance of <see cref="FIURational"/> initialized to <paramref name="value"/>.</returns>
9108
public static explicit operator FIURational(ulong value)
9110
return new FIURational((uint)value, 1u);
9115
#region IConvertible Member
9117
TypeCode IConvertible.GetTypeCode()
9119
return TypeCode.Double;
9122
bool IConvertible.ToBoolean(IFormatProvider provider)
9127
byte IConvertible.ToByte(IFormatProvider provider)
9132
char IConvertible.ToChar(IFormatProvider provider)
9137
DateTime IConvertible.ToDateTime(IFormatProvider provider)
9139
return Convert.ToDateTime(((IConvertible)this).ToDouble(provider));
9142
decimal IConvertible.ToDecimal(IFormatProvider provider)
9147
double IConvertible.ToDouble(IFormatProvider provider)
9152
short IConvertible.ToInt16(IFormatProvider provider)
9157
int IConvertible.ToInt32(IFormatProvider provider)
9162
long IConvertible.ToInt64(IFormatProvider provider)
9167
sbyte IConvertible.ToSByte(IFormatProvider provider)
9172
float IConvertible.ToSingle(IFormatProvider provider)
9177
string IConvertible.ToString(IFormatProvider provider)
9179
return ToString(((double)this).ToString(), provider);
9182
object IConvertible.ToType(Type conversionType, IFormatProvider provider)
9184
return Convert.ChangeType(((IConvertible)this).ToDouble(provider), conversionType, provider);
9187
ushort IConvertible.ToUInt16(IFormatProvider provider)
9189
return (ushort)this;
9192
uint IConvertible.ToUInt32(IFormatProvider provider)
9197
ulong IConvertible.ToUInt64(IFormatProvider provider)
9204
#region IComparable Member
9207
/// Compares this instance with a specified <see cref="Object"/>.
9209
/// <param name="obj">An object to compare with this instance.</param>
9210
/// <returns>A 32-bit signed integer indicating the lexical relationship between the two comparands.</returns>
9211
/// <exception cref="ArgumentException"><paramref name="obj"/> is not a <see cref="FIURational"/>.</exception>
9212
public int CompareTo(object obj)
9218
if (!(obj is FIURational))
9220
throw new ArgumentException();
9222
return CompareTo((FIURational)obj);
9227
#region IFormattable Member
9230
/// Formats the value of the current instance using the specified format.
9232
/// <param name="format">The String specifying the format to use.</param>
9233
/// <param name="formatProvider">The IFormatProvider to use to format the value.</param>
9234
/// <returns>A String containing the value of the current instance in the specified format.</returns>
9235
public string ToString(string format, IFormatProvider formatProvider)
9241
return String.Format(formatProvider, format, ((IConvertible)this).ToDouble(formatProvider));
9246
#region IEquatable<FIURational> Member
9249
/// Tests whether the specified <see cref="FIURational"/> structure is equivalent to this <see cref="FIURational"/> structure.
9251
/// <param name="other">A <see cref="FIURational"/> structure to compare to this instance.</param>
9252
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="FIURational"/> structure
9253
/// equivalent to this <see cref="FIURational"/> structure; otherwise, <b>false</b>.</returns>
9254
public bool Equals(FIURational other)
9256
return (this == other);
9261
#region IComparable<FIURational> Member
9264
/// Compares this instance with a specified <see cref="FIURational"/> object.
9266
/// <param name="other">A <see cref="FIURational"/> to compare.</param>
9267
/// <returns>A signed number indicating the relative values of this instance
9268
/// and <paramref name="other"/>.</returns>
9269
public int CompareTo(FIURational other)
9271
FIURational difference = this - other;
9272
difference.Normalize();
9273
if (difference.numerator > 0) return 1;
9274
if (difference.numerator < 0) return -1;
9286
namespace FreeImageAPI
9289
/// Encapsulates a FreeImage-bitmap.
9291
[Serializable, Guid("64a4c935-b757-499c-ab8c-6110316a9e51")]
9292
public class FreeImageBitmap : MarshalByRefObject, ICloneable, IDisposable, IEnumerable, ISerializable
9297
/// Indicates whether this instance is disposed.
9299
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
9300
private bool disposed;
9305
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
9309
/// Object used to syncronize lock methods.
9311
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
9312
private object lockObject = new object();
9315
/// Holds information used by SaveAdd() methods.
9317
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
9318
private SaveInformation saveInformation = new SaveInformation();
9321
/// The stream that this instance was loaded from or
9322
/// null if it has been cloned or deserialized.
9324
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
9325
private Stream stream;
9328
/// True if the stream must be disposed with this
9331
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
9332
private bool disposeStream;
9335
/// The number of frames contained by a mutlipage bitmap.
9336
/// Default value is 1 and only changed if needed.
9338
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
9339
private int frameCount = 1;
9342
/// The index of the loaded frame.
9343
/// Default value is 0 and only changed if needed.
9345
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
9346
private int frameIndex = 0;
9349
/// Format of the sourceimage.
9351
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
9352
private FREE_IMAGE_FORMAT originalFormat = FREE_IMAGE_FORMAT.FIF_UNKNOWN;
9355
/// Handle to the encapsulated FreeImage-bitmap.
9357
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
9358
private FIBITMAP dib;
9360
private const string ErrorLoadingBitmap = "Unable to load bitmap.";
9361
private const string ErrorLoadingFrame = "Unable to load frame.";
9362
private const string ErrorCreatingBitmap = "Unable to create bitmap.";
9363
private const string ErrorUnloadBitmap = "Unable to unload bitmap.";
9367
#region Constructors and Destructor
9370
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class.
9372
protected FreeImageBitmap()
9377
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class.
9378
/// For internal use only.
9380
/// <exception cref="Exception">The operation failed.</exception>
9381
internal protected FreeImageBitmap(FIBITMAP dib)
9385
throw new Exception(ErrorLoadingBitmap);
9388
AddMemoryPressure();
9392
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class
9393
/// bases on the specified image.
9395
/// <param name="original">The original to clone from.</param>
9396
/// <exception cref="Exception">The operation failed.</exception>
9397
/// <exception cref="ArgumentNullException"><paramref name="original"/> is a null reference.</exception>
9398
public FreeImageBitmap(FreeImageBitmap original)
9400
if (original == null)
9402
throw new ArgumentNullException("original");
9404
original.EnsureNotDisposed();
9405
dib = FreeImage.Clone(original.dib);
9408
throw new Exception(ErrorLoadingBitmap);
9410
originalFormat = original.originalFormat;
9411
AddMemoryPressure();
9415
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class
9416
/// bases on the specified image with the specified size.
9418
/// <param name="original">The original to clone from.</param>
9419
/// <param name="newSize">The Size structure that represent the
9420
/// size of the new <see cref="FreeImageBitmap"/>.</param>
9421
/// <exception cref="Exception">The operation failed.</exception>
9422
/// <exception cref="ArgumentNullException"><paramref name="original"/> is a null reference.</exception>
9423
/// <exception cref="ArgumentOutOfRangeException">
9424
/// <paramref name="newSize.Width"/> or <paramref name="newSize.Height"/> are less or equal zero.
9426
public FreeImageBitmap(FreeImageBitmap original, Size newSize)
9427
: this(original, newSize.Width, newSize.Height)
9432
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class
9433
/// bases on the specified image with the specified size.
9435
/// <param name="original">The original to clone from.</param>
9436
/// <param name="width">Width of the new <see cref="FreeImageBitmap"/>.</param>
9437
/// <param name="height">Height of the new <see cref="FreeImageBitmap"/>.</param>
9438
/// <exception cref="Exception">The operation failed.</exception>
9439
/// <exception cref="ArgumentNullException"><paramref name="original"/> is a null reference.</exception>
9440
/// <exception cref="ArgumentOutOfRangeException">
9441
/// <paramref name="width"/> or <paramref name="height"/> are less or equal zero.</exception>
9442
public FreeImageBitmap(FreeImageBitmap original, int width, int height)
9444
if (original == null)
9446
throw new ArgumentNullException("original");
9450
throw new ArgumentOutOfRangeException("width");
9454
throw new ArgumentOutOfRangeException("height");
9456
original.EnsureNotDisposed();
9457
dib = FreeImage.Rescale(original.dib, width, height, FREE_IMAGE_FILTER.FILTER_BICUBIC);
9460
throw new Exception(ErrorLoadingBitmap);
9462
originalFormat = original.originalFormat;
9463
AddMemoryPressure();
9467
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class
9468
/// bases on the specified image.
9470
/// <param name="original">The original to clone from.</param>
9472
/// Although this constructor supports creating images in both formats
9473
/// <see cref="System.Drawing.Imaging.PixelFormat.Format32bppPArgb"/>
9474
/// and <see cref="System.Drawing.Imaging.PixelFormat.Format64bppPArgb"/>, bitmaps
9475
/// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA
9476
/// images respectively. Currently, there is no support for automatic premultiplying images in
9477
/// <see cref="FreeImageBitmap"/>.
9479
/// <exception cref="Exception">The operation failed.</exception>
9480
public FreeImageBitmap(Image original)
9481
: this(original as Bitmap)
9486
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class
9487
/// bases on the specified image with the specified size.
9489
/// <param name="original">The original to clone from.</param>
9490
/// <param name="newSize">The Size structure that represent the
9491
/// size of the new <see cref="FreeImageBitmap"/>.</param>
9493
/// Although this constructor supports creating images in both formats
9494
/// <see cref="System.Drawing.Imaging.PixelFormat.Format32bppPArgb"/>
9495
/// and <see cref="System.Drawing.Imaging.PixelFormat.Format64bppPArgb"/>, bitmaps
9496
/// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA
9497
/// images respectively. Currently, there is no support for automatic premultiplying images in
9498
/// <see cref="FreeImageBitmap"/>.
9500
/// <exception cref="Exception">The operation failed.</exception>
9501
/// <exception cref="ArgumentNullException"><paramref name="original"/> is a null reference.</exception>
9502
/// <exception cref="ArgumentOutOfRangeException">
9503
/// <paramref name="newSize.Width"/> or <paramref name="newSize.Height"/> are less or equal zero.
9505
public FreeImageBitmap(Image original, Size newSize)
9506
: this(original as Bitmap, newSize.Width, newSize.Height)
9511
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class
9512
/// bases on the specified image with the specified size.
9514
/// <param name="original">The original to clone from.</param>
9515
/// <param name="width">The width, in pixels, of the new <see cref="FreeImageBitmap"/>.</param>
9516
/// <param name="height">The height, in pixels, of the new <see cref="FreeImageBitmap"/>.</param>
9518
/// Although this constructor supports creating images in both formats
9519
/// <see cref="System.Drawing.Imaging.PixelFormat.Format32bppPArgb"/>
9520
/// and <see cref="System.Drawing.Imaging.PixelFormat.Format64bppPArgb"/>, bitmaps
9521
/// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA
9522
/// images respectively. Currently, there is no support for automatic premultiplying images in
9523
/// <see cref="FreeImageBitmap"/>.
9525
/// <exception cref="Exception">The operation failed.</exception>
9526
/// <exception cref="ArgumentNullException"><paramref name="original"/> is a null reference.</exception>
9527
/// <exception cref="ArgumentOutOfRangeException">
9528
/// <paramref name="width"/> or <paramref name="height"/> are less or equal zero.</exception>
9529
public FreeImageBitmap(Image original, int width, int height)
9530
: this(original as Bitmap, width, height)
9535
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class
9536
/// bases on the specified image.
9538
/// <param name="original">The original to clone from.</param>
9540
/// Although this constructor supports creating images in both formats
9541
/// <see cref="System.Drawing.Imaging.PixelFormat.Format32bppPArgb"/>
9542
/// and <see cref="System.Drawing.Imaging.PixelFormat.Format64bppPArgb"/>, bitmaps
9543
/// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA
9544
/// images respectively. Currently, there is no support for automatic premultiplying images in
9545
/// <see cref="FreeImageBitmap"/>.
9547
/// <exception cref="ArgumentNullException"><paramref name="original"/> is a null reference.</exception>
9548
/// <exception cref="Exception">The operation failed.</exception>
9549
public FreeImageBitmap(Bitmap original)
9551
if (original == null)
9553
throw new ArgumentNullException("original");
9555
dib = FreeImage.CreateFromBitmap(original, true);
9558
throw new Exception(ErrorLoadingBitmap);
9560
originalFormat = FreeImage.GetFormat(original.RawFormat);
9561
AddMemoryPressure();
9565
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class
9566
/// bases on the specified image with the specified size.
9568
/// <param name="original">The original to clone from.</param>
9569
/// <param name="newSize">The Size structure that represent the
9570
/// size of the new <see cref="FreeImageBitmap"/>.</param>
9572
/// Although this constructor supports creating images in both formats
9573
/// <see cref="System.Drawing.Imaging.PixelFormat.Format32bppPArgb"/>
9574
/// and <see cref="System.Drawing.Imaging.PixelFormat.Format64bppPArgb"/>, bitmaps
9575
/// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA
9576
/// images respectively. Currently, there is no support for automatic premultiplying images in
9577
/// <see cref="FreeImageBitmap"/>.
9579
/// <exception cref="Exception">The operation failed.</exception>
9580
/// <exception cref="ArgumentNullException"><paramref name="original"/> is a null reference.</exception>
9581
/// <exception cref="ArgumentOutOfRangeException">
9582
/// <paramref name="newSize.Width"/> or <paramref name="newSize.Height"/> are less or equal zero.
9584
public FreeImageBitmap(Bitmap original, Size newSize)
9585
: this(original, newSize.Width, newSize.Height)
9590
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class
9591
/// bases on the specified image with the specified size.
9593
/// <param name="original">The original to clone from.</param>
9594
/// <param name="width">The width, in pixels, of the new <see cref="FreeImageBitmap"/>.</param>
9595
/// <param name="height">The height, in pixels, of the new <see cref="FreeImageBitmap"/>.</param>
9597
/// Although this constructor supports creating images in both formats
9598
/// <see cref="System.Drawing.Imaging.PixelFormat.Format32bppPArgb"/>
9599
/// and <see cref="System.Drawing.Imaging.PixelFormat.Format64bppPArgb"/>, bitmaps
9600
/// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA
9601
/// images respectively. Currently, there is no support for automatic premultiplying images in
9602
/// <see cref="FreeImageBitmap"/>.
9604
/// <exception cref="Exception">The operation failed.</exception>
9605
/// <exception cref="ArgumentNullException"><paramref name="original"/> is a null reference.</exception>
9606
/// <exception cref="ArgumentOutOfRangeException">
9607
/// <paramref name="width"/> or <paramref name="height"/> are less or equal zero.</exception>
9608
public FreeImageBitmap(Bitmap original, int width, int height)
9610
if (original == null)
9612
throw new ArgumentNullException("original");
9616
throw new ArgumentOutOfRangeException("width");
9620
throw new ArgumentOutOfRangeException("height");
9622
FIBITMAP temp = FreeImage.CreateFromBitmap(original, true);
9625
throw new Exception(ErrorLoadingBitmap);
9627
dib = FreeImage.Rescale(temp, width, height, FREE_IMAGE_FILTER.FILTER_BICUBIC);
9628
FreeImage.Unload(temp);
9631
throw new Exception(ErrorLoadingBitmap);
9633
originalFormat = FreeImage.GetFormat(original.RawFormat);
9634
AddMemoryPressure();
9638
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class
9639
/// bases on the specified stream.
9641
/// <param name="stream">Stream to read from.</param>
9642
/// <param name="useIcm">Ignored.</param>
9643
/// <exception cref="Exception">The operation failed.</exception>
9644
/// <exception cref="ArgumentNullException"><paramref name="stream"/> is a null reference.</exception>
9646
/// You must keep the stream open for the lifetime of the <see cref="FreeImageBitmap"/>.
9648
public FreeImageBitmap(Stream stream, bool useIcm)
9654
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class
9655
/// bases on the specified stream.
9657
/// <param name="stream">Stream to read from.</param>
9658
/// <exception cref="Exception">The operation failed.</exception>
9659
/// <exception cref="ArgumentNullException"><paramref name="stream"/> is a null reference.</exception>
9661
/// You must keep the stream open for the lifetime of the <see cref="FreeImageBitmap"/>.
9663
public FreeImageBitmap(Stream stream)
9664
: this(stream, FREE_IMAGE_FORMAT.FIF_UNKNOWN, FREE_IMAGE_LOAD_FLAGS.DEFAULT)
9669
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class
9670
/// bases on the specified stream in the specified format.
9672
/// <param name="stream">Stream to read from.</param>
9673
/// <param name="format">Format of the image.</param>
9674
/// <exception cref="Exception">The operation failed.</exception>
9675
/// <exception cref="ArgumentNullException"><paramref name="stream"/> is a null reference.</exception>
9677
/// You must keep the stream open for the lifetime of the <see cref="FreeImageBitmap"/>.
9679
public FreeImageBitmap(Stream stream, FREE_IMAGE_FORMAT format)
9680
: this(stream, format, FREE_IMAGE_LOAD_FLAGS.DEFAULT)
9685
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class
9686
/// bases on the specified stream with the specified loading flags.
9688
/// <param name="stream">Stream to read from.</param>
9689
/// <param name="flags">Flags to enable or disable plugin-features.</param>
9690
/// <exception cref="Exception">The operation failed.</exception>
9691
/// <exception cref="ArgumentNullException"><paramref name="stream"/> is a null reference.</exception>
9693
/// You must keep the stream open for the lifetime of the <see cref="FreeImageBitmap"/>.
9695
public FreeImageBitmap(Stream stream, FREE_IMAGE_LOAD_FLAGS flags)
9696
: this(stream, FREE_IMAGE_FORMAT.FIF_UNKNOWN, flags)
9701
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class
9702
/// bases on the specified stream in the specified format
9703
/// with the specified loading flags.
9705
/// <param name="stream">Stream to read from.</param>
9706
/// <param name="format">Format of the image.</param>
9707
/// <param name="flags">Flags to enable or disable plugin-features.</param>
9708
/// <exception cref="Exception">The operation failed.</exception>
9709
/// <exception cref="ArgumentNullException"><paramref name="stream"/> is a null reference.</exception>
9711
/// You must keep the stream open for the lifetime of the <see cref="FreeImageBitmap"/>.
9713
public FreeImageBitmap(Stream stream, FREE_IMAGE_FORMAT format, FREE_IMAGE_LOAD_FLAGS flags)
9717
throw new ArgumentNullException("stream");
9719
this.stream = stream;
9720
disposeStream = false;
9721
LoadFromStream(stream, format, flags);
9725
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class bases on the specified file.
9727
/// <param name="filename">The complete name of the file to load.</param>
9728
/// <exception cref="Exception">The operation failed.</exception>
9729
/// <exception cref="ArgumentNullException"><paramref name="filename"/> is a null reference.</exception>
9730
/// <exception cref="FileNotFoundException"><paramref name="filename"/> does not exist.</exception>
9731
public FreeImageBitmap(string filename)
9732
: this(filename, FREE_IMAGE_LOAD_FLAGS.DEFAULT)
9737
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class bases on the specified file.
9739
/// <param name="filename">The complete name of the file to load.</param>
9740
/// <param name="useIcm">Ignored.</param>
9741
/// <exception cref="Exception">The operation failed.</exception>
9742
/// <exception cref="ArgumentNullException"><paramref name="filename"/> is a null reference.</exception>
9743
/// <exception cref="FileNotFoundException"><paramref name="filename"/> does not exist.</exception>
9744
public FreeImageBitmap(string filename, bool useIcm)
9750
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class bases on the specified file
9751
/// with the specified loading flags.
9753
/// <param name="filename">The complete name of the file to load.</param>
9754
/// <param name="flags">Flags to enable or disable plugin-features.</param>
9755
/// <exception cref="Exception">The operation failed.</exception>
9756
/// <exception cref="ArgumentNullException"><paramref name="filename"/> is a null reference.</exception>
9757
/// <exception cref="FileNotFoundException"><paramref name="filename"/> does not exist.</exception>
9758
public FreeImageBitmap(string filename, FREE_IMAGE_LOAD_FLAGS flags)
9759
: this(filename, FREE_IMAGE_FORMAT.FIF_UNKNOWN, flags)
9764
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class bases on the specified file
9765
/// in the specified format.
9767
/// <param name="filename">The complete name of the file to load.</param>
9768
/// <param name="format">Format of the image.</param>
9769
/// <exception cref="Exception">The operation failed.</exception>
9770
/// <exception cref="ArgumentNullException"><paramref name="filename"/> is a null reference.</exception>
9771
/// <exception cref="FileNotFoundException"><paramref name="filename"/> does not exist.</exception>
9772
public FreeImageBitmap(string filename, FREE_IMAGE_FORMAT format)
9773
: this(filename, format, FREE_IMAGE_LOAD_FLAGS.DEFAULT)
9778
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class bases on the specified file
9779
/// in the specified format with the specified loading flags.
9781
/// <param name="filename">The complete name of the file to load.</param>
9782
/// <param name="format">Format of the image.</param>
9783
/// <param name="flags">Flags to enable or disable plugin-features.</param>
9784
/// <exception cref="Exception">The operation failed.</exception>
9785
/// <exception cref="ArgumentNullException"><paramref name="filename"/> is a null reference.</exception>
9786
/// <exception cref="FileNotFoundException"><paramref name="filename"/> does not exist.</exception>
9787
public FreeImageBitmap(string filename, FREE_IMAGE_FORMAT format, FREE_IMAGE_LOAD_FLAGS flags)
9789
if (filename == null)
9791
throw new ArgumentNullException("filename");
9793
if (!File.Exists(filename))
9795
throw new FileNotFoundException("filename");
9798
saveInformation.filename = filename;
9799
stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
9800
disposeStream = true;
9801
LoadFromStream(stream, format, flags);
9805
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class
9806
/// bases on the specified size.
9808
/// <param name="width">The width, in pixels, of the new <see cref="FreeImageBitmap"/>.</param>
9809
/// <param name="height">The height, in pixels, of the new <see cref="FreeImageBitmap"/>.</param>
9810
/// <exception cref="Exception">The operation failed.</exception>
9811
public FreeImageBitmap(int width, int height)
9813
dib = FreeImage.Allocate(
9817
FreeImage.FI_RGBA_RED_MASK,
9818
FreeImage.FI_RGBA_GREEN_MASK,
9819
FreeImage.FI_RGBA_BLUE_MASK);
9822
throw new Exception(ErrorCreatingBitmap);
9824
AddMemoryPressure();
9828
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class bases on the specified resource.
9830
/// <param name="type">The class used to extract the resource.</param>
9831
/// <param name="resource">The name of the resource.</param>
9832
/// <exception cref="Exception">The operation failed.</exception>
9833
public FreeImageBitmap(Type type, string resource)
9834
: this(type.Module.Assembly.GetManifestResourceStream(type, resource))
9839
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class bases on the specified size
9840
/// and with the resolution of the specified <see cref="System.Drawing.Graphics"/> object.
9842
/// <param name="width">The width, in pixels, of the new <see cref="FreeImageBitmap"/>.</param>
9843
/// <param name="height">The height, in pixels, of the new <see cref="FreeImageBitmap"/>.</param>
9844
/// <param name="g">The Graphics object that specifies the resolution for the new <see cref="FreeImageBitmap"/>.</param>
9845
/// <exception cref="Exception">The operation failed.</exception>
9846
/// <exception cref="ArgumentNullException"><paramref name="g"/> is a null reference.</exception>
9847
public FreeImageBitmap(int width, int height, Graphics g)
9848
: this(width, height)
9850
FreeImage.SetResolutionX(dib, (uint)g.DpiX);
9851
FreeImage.SetResolutionX(dib, (uint)g.DpiY);
9855
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class bases on the specified size and format.
9857
/// <param name="width">The width, in pixels, of the new <see cref="FreeImageBitmap"/>.</param>
9858
/// <param name="height">The height, in pixels, of the new <see cref="FreeImageBitmap"/>.</param>
9859
/// <param name="format">The PixelFormat enumeration for the new <see cref="FreeImageBitmap"/>.</param>
9861
/// Although this constructor supports creating images in both formats
9862
/// <see cref="System.Drawing.Imaging.PixelFormat.Format32bppPArgb"/>
9863
/// and <see cref="System.Drawing.Imaging.PixelFormat.Format64bppPArgb"/>, bitmaps
9864
/// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA
9865
/// images respectively. Currently, there is no support for automatic premultiplying images in
9866
/// <see cref="FreeImageBitmap"/>.
9868
/// <exception cref="Exception">The operation failed.</exception>
9869
/// <exception cref="ArgumentException"><paramref name="format"/> is invalid.</exception>
9870
/// <exception cref="ArgumentOutOfRangeException">
9871
/// <paramref name="width"/> or <paramref name="height"/> are less or equal zero.</exception>
9872
public FreeImageBitmap(int width, int height, PixelFormat format)
9876
throw new ArgumentOutOfRangeException("width");
9880
throw new ArgumentOutOfRangeException("height");
9882
uint bpp, redMask, greenMask, blueMask;
9883
FREE_IMAGE_TYPE type;
9884
if (!FreeImage.GetFormatParameters(format, out type, out bpp, out redMask, out greenMask, out blueMask))
9886
throw new ArgumentException("format is invalid");
9888
dib = FreeImage.AllocateT(type, width, height, (int)bpp, redMask, greenMask, blueMask);
9891
throw new Exception(ErrorCreatingBitmap);
9893
AddMemoryPressure();
9897
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class bases on the specified size and type.
9898
/// Only non standard bitmaps are supported.
9900
/// <param name="width">The width, in pixels, of the new <see cref="FreeImageBitmap"/>.</param>
9901
/// <param name="height">The height, in pixels, of the new <see cref="FreeImageBitmap"/>.</param>
9902
/// <param name="type">The type of the bitmap.</param>
9903
/// <exception cref="Exception">The operation failed.</exception>
9904
/// <exception cref="ArgumentOutOfRangeException">
9905
/// <paramref name="type"/> is FIT_BITMAP or FIT_UNKNOWN.</exception>
9906
/// <exception cref="ArgumentException"><paramref name="type"/> is invalid.</exception>
9907
/// <exception cref="ArgumentOutOfRangeException">
9908
/// <paramref name="width"/> or <paramref name="height"/> are less or equal zero.</exception>
9909
public FreeImageBitmap(int width, int height, FREE_IMAGE_TYPE type)
9913
throw new ArgumentOutOfRangeException("width");
9917
throw new ArgumentOutOfRangeException("height");
9919
if ((type == FREE_IMAGE_TYPE.FIT_BITMAP) || (type == FREE_IMAGE_TYPE.FIT_UNKNOWN))
9921
throw new ArgumentException("type is invalid.");
9923
dib = FreeImage.AllocateT(type, width, height, 0, 0u, 0u, 0u);
9926
throw new Exception(ErrorCreatingBitmap);
9928
AddMemoryPressure();
9932
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class bases on the specified size,
9933
/// pixel format and pixel data.
9935
/// <param name="width">The width, in pixels, of the new <see cref="FreeImageBitmap"/>.</param>
9936
/// <param name="height">The height, in pixels, of the new <see cref="FreeImageBitmap"/>.</param>
9937
/// <param name="stride">Integer that specifies the byte offset between the beginning
9938
/// of one scan line and the next. This is usually (but not necessarily)
9939
/// the number of bytes in the pixel format (for example, 2 for 16 bits per pixel)
9940
/// multiplied by the width of the bitmap. The value passed to this parameter must
9941
/// be a multiple of four..</param>
9942
/// <param name="format">The PixelFormat enumeration for the new <see cref="FreeImageBitmap"/>.</param>
9943
/// <param name="scan0">Pointer to an array of bytes that contains the pixel data.</param>
9945
/// Although this constructor supports creating images in both formats
9946
/// <see cref="System.Drawing.Imaging.PixelFormat.Format32bppPArgb"/>
9947
/// and <see cref="System.Drawing.Imaging.PixelFormat.Format64bppPArgb"/>, bitmaps
9948
/// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA
9949
/// images respectively. Currently, there is no support for automatic premultiplying images in
9950
/// <see cref="FreeImageBitmap"/>.
9952
/// <exception cref="Exception">The operation failed.</exception>
9953
/// <exception cref="ArgumentException"><paramref name="format"/> is invalid.</exception>
9954
/// <exception cref="ArgumentOutOfRangeException">
9955
/// <paramref name="width"/> or <paramref name="height"/> are less or equal zero.</exception>
9956
public FreeImageBitmap(int width, int height, int stride, PixelFormat format, IntPtr scan0)
9960
throw new ArgumentOutOfRangeException("width");
9964
throw new ArgumentOutOfRangeException("height");
9966
uint bpp, redMask, greenMask, blueMask;
9967
FREE_IMAGE_TYPE type;
9968
bool topDown = (stride > 0);
9969
stride = (stride > 0) ? stride : (stride * -1);
9971
if (!FreeImage.GetFormatParameters(format, out type, out bpp, out redMask, out greenMask, out blueMask))
9973
throw new ArgumentException("format is invalid.");
9976
dib = FreeImage.ConvertFromRawBits(
9977
scan0, type, width, height, stride, bpp, redMask, greenMask, blueMask, topDown);
9981
throw new Exception(ErrorCreatingBitmap);
9983
AddMemoryPressure();
9987
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class bases on the specified size,
9988
/// pixel format and pixel data.
9990
/// <param name="width">The width, in pixels, of the new <see cref="FreeImageBitmap"/>.</param>
9991
/// <param name="height">The height, in pixels, of the new <see cref="FreeImageBitmap"/>.</param>
9992
/// <param name="stride">Integer that specifies the byte offset between the beginning
9993
/// of one scan line and the next. This is usually (but not necessarily)
9994
/// the number of bytes in the pixel format (for example, 2 for 16 bits per pixel)
9995
/// multiplied by the width of the bitmap. The value passed to this parameter must
9996
/// be a multiple of four..</param>
9997
/// <param name="format">The PixelFormat enumeration for the new <see cref="FreeImageBitmap"/>.</param>
9998
/// <param name="bits">Array of bytes containing the bitmap data.</param>
10000
/// Although this constructor supports creating images in both formats
10001
/// <see cref="System.Drawing.Imaging.PixelFormat.Format32bppPArgb"/>
10002
/// and <see cref="System.Drawing.Imaging.PixelFormat.Format64bppPArgb"/>, bitmaps
10003
/// created in these formats are treated like any normal 32-bit RGBA and 64-bit RGBA
10004
/// images respectively. Currently, there is no support for automatic premultiplying images in
10005
/// <see cref="FreeImageBitmap"/>.
10007
/// <exception cref="Exception">The operation failed.</exception>
10008
/// <exception cref="ArgumentException"><paramref name="format"/> is invalid.</exception>
10009
/// <exception cref="ArgumentOutOfRangeException">
10010
/// <paramref name="width"/> or <paramref name="height"/> are less or equal zero.</exception>
10011
/// <exception cref="ArgumentNullException"><paramref name="bits"/> is null</exception>
10012
public FreeImageBitmap(int width, int height, int stride, PixelFormat format, byte[] bits)
10016
throw new ArgumentOutOfRangeException("width");
10020
throw new ArgumentOutOfRangeException("height");
10024
throw new ArgumentNullException("bits");
10026
uint bpp, redMask, greenMask, blueMask;
10027
FREE_IMAGE_TYPE type;
10028
bool topDown = (stride > 0);
10029
stride = (stride > 0) ? stride : (stride * -1);
10031
if (!FreeImage.GetFormatParameters(format, out type, out bpp, out redMask, out greenMask, out blueMask))
10033
throw new ArgumentException("format is invalid.");
10036
dib = FreeImage.ConvertFromRawBits(
10037
bits, type, width, height, stride, bpp, redMask, greenMask, blueMask, topDown);
10041
throw new Exception(ErrorCreatingBitmap);
10043
AddMemoryPressure();
10047
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class bases on the specified size,
10048
/// pixel format and pixel data.
10050
/// <param name="width">The width, in pixels, of the new <see cref="FreeImageBitmap"/>.</param>
10051
/// <param name="height">The height, in pixels, of the new <see cref="FreeImageBitmap"/>.</param>
10052
/// <param name="stride">Integer that specifies the byte offset between the beginning
10053
/// of one scan line and the next. This is usually (but not necessarily)
10054
/// the number of bytes in the pixel format (for example, 2 for 16 bits per pixel)
10055
/// multiplied by the width of the bitmap. The value passed to this parameter must
10056
/// be a multiple of four..</param>
10057
/// <param name="bpp">The color depth of the new <see cref="FreeImageBitmap"/></param>
10058
/// <param name="type">The type for the new <see cref="FreeImageBitmap"/>.</param>
10059
/// <param name="scan0">Pointer to an array of bytes that contains the pixel data.</param>
10060
/// <exception cref="Exception">The operation failed.</exception>
10061
/// <exception cref="ArgumentException"><paramref name="format"/> is invalid.</exception>
10062
/// <exception cref="ArgumentOutOfRangeException">
10063
/// <paramref name="width"/> or <paramref name="height"/> are less or equal zero.</exception>
10064
public FreeImageBitmap(int width, int height, int stride, int bpp, FREE_IMAGE_TYPE type, IntPtr scan0)
10068
throw new ArgumentOutOfRangeException("width");
10072
throw new ArgumentOutOfRangeException("height");
10074
uint redMask, greenMask, blueMask;
10075
bool topDown = (stride > 0);
10076
stride = (stride > 0) ? stride : (stride * -1);
10078
if (!FreeImage.GetTypeParameters(type, bpp, out redMask, out greenMask, out blueMask))
10080
throw new ArgumentException("bpp and type are invalid or not supported.");
10083
dib = FreeImage.ConvertFromRawBits(
10084
scan0, type, width, height, stride, (uint)bpp, redMask, greenMask, blueMask, topDown);
10088
throw new Exception(ErrorCreatingBitmap);
10090
AddMemoryPressure();
10094
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class bases on the specified size,
10095
/// pixel format and pixel data.
10097
/// <param name="width">The width, in pixels, of the new <see cref="FreeImageBitmap"/>.</param>
10098
/// <param name="height">The height, in pixels, of the new <see cref="FreeImageBitmap"/>.</param>
10099
/// <param name="stride">Integer that specifies the byte offset between the beginning
10100
/// of one scan line and the next. This is usually (but not necessarily)
10101
/// the number of bytes in the pixel format (for example, 2 for 16 bits per pixel)
10102
/// multiplied by the width of the bitmap. The value passed to this parameter must
10103
/// be a multiple of four..</param>
10104
/// <param name="bpp">The color depth of the new <see cref="FreeImageBitmap"/></param>
10105
/// <param name="type">The type for the new <see cref="FreeImageBitmap"/>.</param>
10106
/// <param name="bits">Array of bytes containing the bitmap data.</param>
10107
/// <exception cref="Exception">The operation failed.</exception>
10108
/// <exception cref="ArgumentException"><paramref name="format"/> is invalid.</exception>
10109
/// <exception cref="ArgumentOutOfRangeException">
10110
/// <paramref name="width"/> or <paramref name="height"/> are less or equal zero.</exception>
10111
/// <exception cref="ArgumentNullException"><paramref name="bits"/> is null</exception>
10112
public FreeImageBitmap(int width, int height, int stride, int bpp, FREE_IMAGE_TYPE type, byte[] bits)
10116
throw new ArgumentOutOfRangeException("width");
10120
throw new ArgumentOutOfRangeException("height");
10124
throw new ArgumentNullException("bits");
10126
uint redMask, greenMask, blueMask;
10127
bool topDown = (stride > 0);
10128
stride = (stride > 0) ? stride : (stride * -1);
10130
if (!FreeImage.GetTypeParameters(type, bpp, out redMask, out greenMask, out blueMask))
10132
throw new ArgumentException("bpp and type are invalid or not supported.");
10135
dib = FreeImage.ConvertFromRawBits(
10136
bits, type, width, height, stride, (uint)bpp, redMask, greenMask, blueMask, topDown);
10140
throw new Exception(ErrorCreatingBitmap);
10142
AddMemoryPressure();
10146
/// Initializes a new instance of the <see cref="FreeImageBitmap"/> class.
10148
/// <exception cref="Exception">The operation failed.</exception>
10149
/// <exception cref="SerializationException">The operation failed.</exception>
10150
public FreeImageBitmap(SerializationInfo info, StreamingContext context)
10154
byte[] data = (byte[])info.GetValue("Bitmap Data", typeof(byte[]));
10155
if ((data != null) && (data.Length > 0))
10157
MemoryStream memory = new MemoryStream(data);
10158
FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_TIFF;
10159
dib = FreeImage.LoadFromStream(memory, ref format);
10163
throw new Exception(ErrorLoadingBitmap);
10166
AddMemoryPressure();
10169
catch (Exception ex)
10171
throw new SerializationException("Deserialization failed.", ex);
10176
/// Frees all managed and unmanaged ressources.
10188
/// Converts a <see cref="FreeImageBitmap"/> instance to a <see cref="Bitmap"/> instance.
10190
/// <param name="value">A <see cref="FreeImageBitmap"/> instance.</param>
10191
/// <returns>A new instance of <see cref="Bitmap"/> initialized to <paramref name="value"/>.</returns>
10193
/// The explicit conversion from <see cref="FreeImageBitmap"/> into Bitmap
10194
/// allows to create an instance on the fly and use it as if
10195
/// was a Bitmap. This way it can be directly used with a
10196
/// PixtureBox for example without having to call any
10197
/// conversion operations.
10199
public static explicit operator Bitmap(FreeImageBitmap value)
10201
return value.ToBitmap();
10205
/// Converts a <see cref="Bitmap"/> instance to a <see cref="FreeImageBitmap"/> instance.
10207
/// <param name="value">A <see cref="Bitmap"/> instance.</param>
10208
/// <returns>A new instance of <see cref="FreeImageBitmap"/> initialized to <paramref name="value"/>.</returns>
10210
/// The explicit conversion from <see cref="Bitmap"/> into <see cref="FreeImageBitmap"/>
10211
/// allows to create an instance on the fly to perform
10212
/// image processing operations and converting it back.
10214
public static explicit operator FreeImageBitmap(Bitmap value)
10216
return new FreeImageBitmap(value);
10220
/// Determines whether two specified <see cref="FreeImageBitmap"/> objects have the same value.
10222
/// <param name="left">A <see cref="FreeImageBitmap"/> or a null reference (<b>Nothing</b> in Visual Basic).</param>
10223
/// <param name="right">A <see cref="FreeImageBitmap"/> or a null reference (<b>Nothing</b> in Visual Basic).</param>
10225
/// <b>true</b> if the value of left is the same as the value of right; otherwise, <b>false</b>.
10227
public static bool operator ==(FreeImageBitmap left, FreeImageBitmap right)
10229
if (object.ReferenceEquals(left, right))
10233
else if (object.ReferenceEquals(left, null) || object.ReferenceEquals(right, null))
10239
left.EnsureNotDisposed();
10240
right.EnsureNotDisposed();
10241
return FreeImage.Compare(left.dib, right.dib, FREE_IMAGE_COMPARE_FLAGS.COMPLETE);
10246
/// Determines whether two specified <see cref="FreeImageBitmap"/> objects have different values.
10248
/// <param name="left">A <see cref="FreeImageBitmap"/> or a null reference (<b>Nothing</b> in Visual Basic).</param>
10249
/// <param name="right">A <see cref="FreeImageBitmap"/> or a null reference (<b>Nothing</b> in Visual Basic).</param>
10251
/// true if the value of left is different from the value of right; otherwise, <b>false</b>.
10253
public static bool operator !=(FreeImageBitmap left, FreeImageBitmap right)
10255
return (!(left == right));
10263
/// Type of the bitmap.
10265
public FREE_IMAGE_TYPE ImageType
10269
EnsureNotDisposed();
10270
return FreeImage.GetImageType(dib);
10275
/// Number of palette entries.
10277
public int ColorsUsed
10281
EnsureNotDisposed();
10282
return (int)FreeImage.GetColorsUsed(dib);
10287
/// The number of unique colors actually used by the bitmap. This might be different from
10288
/// what ColorsUsed returns, which actually returns the palette size for palletised images.
10289
/// Works for FIT_BITMAP type bitmaps only.
10291
public int UniqueColors
10295
EnsureNotDisposed();
10296
return FreeImage.GetUniqueColors(dib);
10301
/// The size of one pixel in the bitmap in bits.
10303
public int ColorDepth
10307
EnsureNotDisposed();
10308
return (int)FreeImage.GetBPP(dib);
10313
/// Width of the bitmap in pixel units.
10319
EnsureNotDisposed();
10320
return (int)FreeImage.GetWidth(dib);
10325
/// Height of the bitmap in pixel units.
10331
EnsureNotDisposed();
10332
return (int)FreeImage.GetHeight(dib);
10337
/// Returns the width of the bitmap in bytes, rounded to the next 32-bit boundary.
10343
EnsureNotDisposed();
10344
return (int)FreeImage.GetPitch(dib);
10349
/// Size of the bitmap in memory.
10351
public int DataSize
10355
EnsureNotDisposed();
10356
return (int)FreeImage.GetDIBSize(dib);
10361
/// Returns a structure that represents the palette of a FreeImage bitmap.
10363
/// <exception cref="InvalidOperationException"><see cref="HasPalette"/> is false.</exception>
10364
public Palette Palette
10368
EnsureNotDisposed();
10371
return new Palette(dib);
10373
throw new InvalidOperationException("This bitmap does not have a palette.");
10378
/// Gets whether the bitmap is RGB 555.
10380
public bool IsRGB555
10384
EnsureNotDisposed();
10385
return FreeImage.IsRGB555(dib);
10390
/// Gets whether the bitmap is RGB 565.
10392
public bool IsRGB565
10396
EnsureNotDisposed();
10397
return FreeImage.IsRGB565(dib);
10402
/// Gets the horizontal resolution, in pixels per inch, of this <see cref="FreeImageBitmap"/>.
10404
public float HorizontalResolution
10408
EnsureNotDisposed();
10409
return (float)FreeImage.GetResolutionX(dib);
10413
EnsureNotDisposed();
10414
FreeImage.SetResolutionX(dib, (uint)value);
10419
/// Gets the vertical resolution, in pixels per inch, of this <see cref="FreeImageBitmap"/>.
10421
public float VerticalResolution
10425
EnsureNotDisposed();
10426
return (float)FreeImage.GetResolutionY(dib);
10430
EnsureNotDisposed();
10431
FreeImage.SetResolutionY(dib, (uint)value);
10436
/// Returns the <see cref="BITMAPINFOHEADER"/> structure of this <see cref="FreeImageBitmap"/>.
10438
public BITMAPINFOHEADER InfoHeader
10442
EnsureNotDisposed();
10443
return FreeImage.GetInfoHeaderEx(dib);
10448
/// Returns the <see cref="BITMAPINFO"/> structure of a this <see cref="FreeImageBitmap"/>.
10450
public BITMAPINFO Info
10454
EnsureNotDisposed();
10455
return FreeImage.GetInfoEx(dib);
10460
/// Investigates the color type of this <see cref="FreeImageBitmap"/>
10461
/// by reading the bitmaps pixel bits and analysing them.
10463
public FREE_IMAGE_COLOR_TYPE ColorType
10467
EnsureNotDisposed();
10468
return FreeImage.GetColorType(dib);
10473
/// Bit pattern describing the red color component of a pixel in this <see cref="FreeImageBitmap"/>.
10475
public uint RedMask
10479
EnsureNotDisposed();
10480
return FreeImage.GetRedMask(dib);
10485
/// Bit pattern describing the green color component of a pixel in this <see cref="FreeImageBitmap"/>.
10487
public uint GreenMask
10491
EnsureNotDisposed();
10492
return FreeImage.GetGreenMask(dib);
10497
/// Bit pattern describing the blue color component of a pixel in this <see cref="FreeImageBitmap"/>.
10499
public uint BlueMask
10503
EnsureNotDisposed();
10504
return FreeImage.GetBlueMask(dib);
10509
/// Number of transparent colors in a palletised <see cref="FreeImageBitmap"/>.
10511
public int TransparencyCount
10515
EnsureNotDisposed();
10516
return (int)FreeImage.GetTransparencyCount(dib);
10521
/// Get or sets transparency table of this <see cref="FreeImageBitmap"/>.
10523
public byte[] TransparencyTable
10527
EnsureNotDisposed();
10528
return FreeImage.GetTransparencyTableEx(dib);
10532
EnsureNotDisposed();
10533
FreeImage.SetTransparencyTable(dib, value);
10538
/// Gets or sets whether this <see cref="FreeImageBitmap"/> is transparent.
10540
public bool IsTransparent
10544
EnsureNotDisposed();
10545
return FreeImage.IsTransparent(dib);
10549
EnsureNotDisposed();
10550
FreeImage.SetTransparent(dib, value);
10555
/// Gets whether this <see cref="FreeImageBitmap"/> has a file background color.
10557
public bool HasBackgroundColor
10561
EnsureNotDisposed();
10562
return FreeImage.HasBackgroundColor(dib);
10567
/// Gets or sets the background color of this <see cref="FreeImageBitmap"/>.
10568
/// In case the value is null, the background color is removed.
10570
/// <exception cref="InvalidOperationException">Get: There is no background color available.</exception>
10571
/// <exception cref="Exception">Set: Setting background color failed.</exception>
10572
public Color? BackgroundColor
10576
EnsureNotDisposed();
10577
if (!FreeImage.HasBackgroundColor(dib))
10579
throw new InvalidOperationException("No background color available.");
10582
FreeImage.GetBackgroundColor(dib, out rgbq);
10587
EnsureNotDisposed();
10588
if (!FreeImage.SetBackgroundColor(dib, (value.HasValue ? new RGBQUAD[] { value.Value } : null)))
10590
throw new Exception("Setting background color failed.");
10596
/// Pointer to the data-bits of this <see cref="FreeImageBitmap"/>.
10602
EnsureNotDisposed();
10603
return FreeImage.GetBits(dib);
10608
/// Width, in bytes, of this <see cref="FreeImageBitmap"/>.
10614
EnsureNotDisposed();
10615
return (int)FreeImage.GetLine(dib);
10620
/// Pointer to the scanline of the top most pixel row of this <see cref="FreeImageBitmap"/>.
10622
public IntPtr Scan0
10626
EnsureNotDisposed();
10627
return FreeImage.GetScanLine(dib, (int)(FreeImage.GetHeight(dib) - 1));
10632
/// Width, in bytes, of this <see cref="FreeImageBitmap"/>.
10633
/// In case this <see cref="FreeImageBitmap"/> is top down <b>Stride</b> will be positive, else negative.
10644
/// Gets attribute flags for the pixel data of this <see cref="FreeImageBitmap"/>.
10646
public unsafe int Flags
10650
EnsureNotDisposed();
10653
int cd = ColorDepth;
10655
if ((cd == 32) || (FreeImage.GetTransparencyCount(dib) != 0))
10657
result += (int)ImageFlags.HasAlpha;
10662
uint width = FreeImage.GetWidth(dib);
10663
uint height = FreeImage.GetHeight(dib);
10664
for (int y = 0; y < height; y++)
10666
RGBQUAD* scanline = (RGBQUAD*)FreeImage.GetScanLine(dib, y);
10667
for (int x = 0; x < width; x++)
10669
alpha = scanline[x].Color.A;
10670
if (alpha != byte.MinValue && alpha != byte.MaxValue)
10672
result += (int)ImageFlags.HasTranslucent;
10679
else if (FreeImage.GetTransparencyCount(dib) != 0)
10681
byte[] transTable = FreeImage.GetTransparencyTableEx(dib);
10682
for (int i = 0; i < transTable.Length; i++)
10684
if (transTable[i] != byte.MinValue && transTable[i] != byte.MaxValue)
10686
result += (int)ImageFlags.HasTranslucent;
10692
if (FreeImage.GetICCProfileEx(dib).IsCMYK)
10694
result += (int)ImageFlags.ColorSpaceCmyk;
10698
result += (int)ImageFlags.ColorSpaceRgb;
10701
if (FreeImage.GetColorType(dib) == FREE_IMAGE_COLOR_TYPE.FIC_MINISBLACK ||
10702
FreeImage.GetColorType(dib) == FREE_IMAGE_COLOR_TYPE.FIC_MINISWHITE)
10704
result += (int)ImageFlags.ColorSpaceGray;
10707
if (originalFormat == FREE_IMAGE_FORMAT.FIF_BMP ||
10708
originalFormat == FREE_IMAGE_FORMAT.FIF_FAXG3 ||
10709
originalFormat == FREE_IMAGE_FORMAT.FIF_ICO ||
10710
originalFormat == FREE_IMAGE_FORMAT.FIF_JPEG ||
10711
originalFormat == FREE_IMAGE_FORMAT.FIF_PCX ||
10712
originalFormat == FREE_IMAGE_FORMAT.FIF_PNG ||
10713
originalFormat == FREE_IMAGE_FORMAT.FIF_PSD ||
10714
originalFormat == FREE_IMAGE_FORMAT.FIF_TIFF)
10716
result += (int)ImageFlags.HasRealDpi;
10724
/// Gets the width and height of this <see cref="FreeImageBitmap"/>.
10726
public SizeF PhysicalDimension
10730
EnsureNotDisposed();
10731
return new SizeF((float)FreeImage.GetWidth(dib), (float)FreeImage.GetHeight(dib));
10736
/// Gets the pixel format for this <see cref="FreeImageBitmap"/>.
10738
public PixelFormat PixelFormat
10742
EnsureNotDisposed();
10743
return FreeImage.GetPixelFormat(dib);
10748
/// Gets IDs of the property items stored in this <see cref="FreeImageBitmap"/>.
10750
public int[] PropertyIdList
10754
EnsureNotDisposed();
10755
List<int> list = new List<int>();
10756
ImageMetadata metaData = new ImageMetadata(dib, true);
10758
foreach (MetadataModel metadataModel in metaData)
10760
foreach (MetadataTag metadataTag in metadataModel)
10762
list.Add(metadataTag.ID);
10766
return list.ToArray();
10771
/// Gets all the property items (pieces of metadata) stored in this <see cref="FreeImageBitmap"/>.
10773
public PropertyItem[] PropertyItems
10777
EnsureNotDisposed();
10778
List<PropertyItem> list = new List<PropertyItem>();
10779
ImageMetadata metaData = new ImageMetadata(dib, true);
10781
foreach (MetadataModel metadataModel in metaData)
10783
foreach (MetadataTag metadataTag in metadataModel)
10785
list.Add(metadataTag.GetPropertyItem());
10789
return list.ToArray();
10794
/// Gets the format of this <see cref="FreeImageBitmap"/>.
10796
public ImageFormat RawFormat
10800
EnsureNotDisposed();
10801
Attribute guidAttribute =
10802
Attribute.GetCustomAttribute(
10803
typeof(FreeImageBitmap), typeof(System.Runtime.InteropServices.GuidAttribute)
10805
return (guidAttribute == null) ?
10807
new ImageFormat(new Guid(((GuidAttribute)guidAttribute).Value));
10812
/// Gets the width and height, in pixels, of this <see cref="FreeImageBitmap"/>.
10818
EnsureNotDisposed();
10819
return new Size(Width, Height);
10824
/// Gets or sets an object that provides additional data about the <see cref="FreeImageBitmap"/>.
10830
EnsureNotDisposed();
10835
EnsureNotDisposed();
10841
/// Gets whether this <see cref="FreeImageBitmap"/> has been disposed.
10843
public bool IsDisposed
10852
/// Gets a new instance of a metadata representing class.
10854
public ImageMetadata Metadata
10858
EnsureNotDisposed();
10859
return new ImageMetadata(dib, true);
10864
/// Gets or sets the comment of this <see cref="FreeImageBitmap"/>.
10865
/// Supported formats are JPEG, PNG and GIF.
10867
public string Comment
10871
EnsureNotDisposed();
10872
return FreeImage.GetImageComment(dib);
10876
EnsureNotDisposed();
10877
FreeImage.SetImageComment(dib, value);
10882
/// Returns whether this <see cref="FreeImageBitmap"/> has a palette.
10884
public bool HasPalette
10888
EnsureNotDisposed();
10889
return (FreeImage.GetPalette(dib) != IntPtr.Zero);
10894
/// Gets or sets the entry used as transparent color in this <see cref="FreeImageBitmap"/>.
10895
/// Only works for 1-, 4- and 8-bpp.
10897
public int TransparentIndex
10901
EnsureNotDisposed();
10902
return FreeImage.GetTransparentIndex(dib);
10906
EnsureNotDisposed();
10907
FreeImage.SetTransparentIndex(dib, value);
10912
/// Gets the number of frames in this <see cref="FreeImageBitmap"/>.
10914
public int FrameCount
10918
EnsureNotDisposed();
10924
/// Gets the ICCProfile structure of this <see cref="FreeImageBitmap"/>.
10926
public FIICCPROFILE ICCProfile
10930
EnsureNotDisposed();
10931
return FreeImage.GetICCProfileEx(dib);
10936
/// Gets the format of the original image in case
10937
/// this <see cref="FreeImageBitmap"/> was loaded from a file or stream.
10939
public FREE_IMAGE_FORMAT ImageFormat
10943
EnsureNotDisposed();
10944
return originalFormat;
10949
/// Gets the encapsulated FIBITMAP.
10951
internal FIBITMAP Dib
10953
get { EnsureNotDisposed(); return dib; }
10961
/// Gets the bounds of this <see cref="FreeImageBitmap"/> in the specified unit.
10963
/// <param name="pageUnit">One of the <see cref="System.Drawing.GraphicsUnit"/> values indicating
10964
/// the unit of measure for the bounding rectangle.</param>
10965
/// <returns>The <see cref="System.Drawing.RectangleF"/> that represents the bounds of this
10966
/// <see cref="FreeImageBitmap"/>, in the specified unit.</returns>
10967
public RectangleF GetBounds(ref GraphicsUnit pageUnit)
10969
EnsureNotDisposed();
10970
pageUnit = GraphicsUnit.Pixel;
10971
return new RectangleF(
10974
(float)FreeImage.GetWidth(dib),
10975
(float)FreeImage.GetHeight(dib));
10979
/// Gets the specified property item from this <see cref="FreeImageBitmap"/>.
10981
/// <param name="propid">The ID of the property item to get.</param>
10982
/// <returns>The <see cref="PropertyItem"/> this method gets.</returns>
10983
public PropertyItem GetPropertyItem(int propid)
10985
EnsureNotDisposed();
10986
ImageMetadata metadata = new ImageMetadata(dib, true);
10987
foreach (MetadataModel metadataModel in metadata)
10989
foreach (MetadataTag tag in metadataModel)
10991
if (tag.ID == propid)
10993
return tag.GetPropertyItem();
11001
/// Returns a thumbnail for this <see cref="FreeImageBitmap"/>.
11003
/// <param name="thumbWidth">The width, in pixels, of the requested thumbnail image.</param>
11004
/// <param name="thumbHeight">The height, in pixels, of the requested thumbnail image.</param>
11005
/// <param name="callback">Ignored.</param>
11006
/// <param name="callBackData">Ignored.</param>
11007
/// <returns>A <see cref="FreeImageBitmap"/> that represents the thumbnail.</returns>
11008
public FreeImageBitmap GetThumbnailImage(int thumbWidth, int thumbHeight,
11009
Image.GetThumbnailImageAbort callback, IntPtr callBackData)
11011
EnsureNotDisposed();
11012
FreeImageBitmap result = null;
11013
FIBITMAP newDib = FreeImage.Rescale(
11014
dib, thumbWidth, thumbHeight, FREE_IMAGE_FILTER.FILTER_BICUBIC);
11015
if (!newDib.IsNull)
11017
result = new FreeImageBitmap(newDib);
11023
/// Returns a thumbnail for this <see cref="FreeImageBitmap"/>, keeping aspect ratio.
11024
/// <paramref name="maxPixelSize"/> defines the maximum width or height
11025
/// of the thumbnail.
11027
/// <param name="maxPixelSize">Thumbnail square size.</param>
11028
/// <param name="convert">When true HDR images are transperantly
11029
/// converted to standard images.</param>
11030
/// <returns>The thumbnail in a new instance.</returns>
11031
public FreeImageBitmap GetThumbnailImage(int maxPixelSize, bool convert)
11033
EnsureNotDisposed();
11034
FreeImageBitmap result = null;
11035
FIBITMAP newDib = FreeImage.MakeThumbnail(dib, maxPixelSize, convert);
11036
if (!newDib.IsNull)
11038
result = new FreeImageBitmap(newDib);
11044
/// Converts this <see cref="FreeImageBitmap"/> instance to a <see cref="Bitmap"/> instance.
11046
/// <returns>A new instance of <see cref="Bitmap"/> initialized this instance.</returns>
11047
public Bitmap ToBitmap()
11049
EnsureNotDisposed();
11050
return FreeImage.GetBitmap(dib, true);
11054
/// Returns an instance of <see cref="Scanline<T>"/>, representing the scanline
11055
/// specified by <paramref name="scanline"/> of this <see cref="FreeImageBitmap"/>.
11056
/// Since FreeImage bitmaps are always bottum up aligned, keep in mind that scanline 0 is the
11057
/// bottom-most line of the image.
11059
/// <param name="scanline">Number of the scanline to retrieve.</param>
11060
/// <returns>An instance of <see cref="Scanline<T>"/> representing the
11061
/// <paramref name="scanline"/>th scanline.</returns>
11063
/// List of return-types of <b>T</b>:<para/>
11064
/// <list type="table">
11065
/// <listheader><term>Color Depth / Type</term><description><see cref="Type">Result Type</see></description></listheader>
11066
/// <item><term>1 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="FI1BIT"/></description></item>
11067
/// <item><term>4 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="FI4BIT"/></description></item>
11068
/// <item><term>8 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="Byte"/></description></item>
11069
/// <item><term>16 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="UInt16"/></description></item>
11070
/// <item><term>16 - 555 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="FI16RGB555"/></description></item>
11071
/// <item><term>16 - 565 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="FI16RGB565"/></description></item>
11072
/// <item><term>24 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="RGBTRIPLE"/></description></item>
11073
/// <item><term>32 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="RGBQUAD"/></description></item>
11074
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_COMPLEX"/></term><description><see cref="FICOMPLEX"/></description></item>
11075
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_DOUBLE"/></term><description><see cref="Double"/></description></item>
11076
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_FLOAT"/></term><description><see cref="Single"/></description></item>
11077
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_INT16"/></term><description><see cref="Int16"/></description></item>
11078
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_INT32"/></term><description><see cref="Int32"/></description></item>
11079
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_RGB16"/></term><description><see cref="FIRGB16"/></description></item>
11080
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_RGBA16"/></term><description><see cref="FIRGBA16"/></description></item>
11081
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_RGBAF"/></term><description><see cref="FIRGBAF"/></description></item>
11082
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_RGBF"/></term><description><see cref="FIRGBF"/></description></item>
11083
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_UINT16"/></term><description><see cref="UInt16"/></description></item>
11084
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_UINT32"/></term><description><see cref="UInt32"/></description></item>
11089
/// FreeImageBitmap bitmap = new FreeImageBitmap(@"C:\Pictures\picture.bmp");
11090
/// if (bitmap.ColorDepth == 32)
11092
/// Scanline<RGBQUAD> scanline = bitmap.GetScanline<RGBQUAD>(0);
11093
/// foreach (RGBQUAD pixel in scanline)
11095
/// Console.WriteLine(pixel);
11100
/// <exception cref="ArgumentException">
11101
/// The bitmap's type or color depth are not supported.
11103
/// <exception cref="ArgumentOutOfRangeException">
11104
/// <paramref name="scanline"/> is no valid value.
11106
public Scanline<T> GetScanline<T>(int scanline) where T : struct
11108
EnsureNotDisposed();
11109
return new Scanline<T>(dib, scanline);
11113
/// Returns an instance of <see cref="Scanline<T>"/>, representing the scanline
11114
/// specified by <paramref name="scanline"/> of this <see cref="FreeImageBitmap"/>.
11115
/// Since FreeImage bitmaps are always bottum up aligned, keep in mind that scanline 0 is the
11116
/// bottom-most line of the image.
11118
/// <param name="scanline">Number of the scanline to retrieve.</param>
11119
/// <returns>An instance of <see cref="Scanline<T>"/> representing the
11120
/// <paramref name="scanline"/>th scanline.</returns>
11122
/// List of return-types of <b>T</b>:<para/>
11123
/// <list type="table">
11124
/// <listheader><term>Color Depth / Type</term><description><see cref="Type">Result Type</see></description></listheader>
11125
/// <item><term>1 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="FI1BIT"/></description></item>
11126
/// <item><term>4 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="FI4BIT"/></description></item>
11127
/// <item><term>8 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="Byte"/></description></item>
11128
/// <item><term>16 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="UInt16"/></description></item>
11129
/// <item><term>16 - 555 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="FI16RGB555"/></description></item>
11130
/// <item><term>16 - 565 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="FI16RGB565"/></description></item>
11131
/// <item><term>24 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="RGBTRIPLE"/></description></item>
11132
/// <item><term>32 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="RGBQUAD"/></description></item>
11133
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_COMPLEX"/></term><description><see cref="FICOMPLEX"/></description></item>
11134
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_DOUBLE"/></term><description><see cref="Double"/></description></item>
11135
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_FLOAT"/></term><description><see cref="Single"/></description></item>
11136
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_INT16"/></term><description><see cref="Int16"/></description></item>
11137
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_INT32"/></term><description><see cref="Int32"/></description></item>
11138
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_RGB16"/></term><description><see cref="FIRGB16"/></description></item>
11139
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_RGBA16"/></term><description><see cref="FIRGBA16"/></description></item>
11140
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_RGBAF"/></term><description><see cref="FIRGBAF"/></description></item>
11141
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_RGBF"/></term><description><see cref="FIRGBF"/></description></item>
11142
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_UINT16"/></term><description><see cref="UInt16"/></description></item>
11143
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_UINT32"/></term><description><see cref="UInt32"/></description></item>
11148
/// FreeImageBitmap bitmap = new FreeImageBitmap(@"C:\Pictures\picture.bmp");
11149
/// if (bitmap.ColorDepth == 32)
11151
/// Scanline<RGBQUAD> scanline = (Scanline<RGBQUAD>)bitmap.GetScanline(0);
11152
/// foreach (RGBQUAD pixel in scanline)
11154
/// Console.WriteLine(pixel);
11159
/// <exception cref="ArgumentException">
11160
/// The type of the bitmap or color depth are not supported.
11162
/// <exception cref="ArgumentOutOfRangeException">
11163
/// <paramref name="scanline"/> is no valid value.
11165
public object GetScanline(int scanline)
11167
EnsureNotDisposed();
11168
object result = null;
11169
int width = (int)FreeImage.GetWidth(dib);
11171
switch (FreeImage.GetImageType(dib))
11173
case FREE_IMAGE_TYPE.FIT_BITMAP:
11175
switch (FreeImage.GetBPP(dib))
11177
case 1u: result = new Scanline<FI1BIT>(dib, scanline, width); break;
11178
case 4u: result = new Scanline<FI4BIT>(dib, scanline, width); break;
11179
case 8u: result = new Scanline<Byte>(dib, scanline, width); break;
11181
if ((RedMask == FreeImage.FI16_555_RED_MASK) &&
11182
(GreenMask == FreeImage.FI16_555_GREEN_MASK) &&
11183
(BlueMask == FreeImage.FI16_555_BLUE_MASK))
11185
result = new Scanline<FI16RGB555>(dib, scanline, width);
11187
else if ((RedMask == FreeImage.FI16_565_RED_MASK) &&
11188
(GreenMask == FreeImage.FI16_565_GREEN_MASK) &&
11189
(BlueMask == FreeImage.FI16_565_BLUE_MASK))
11191
result = new Scanline<FI16RGB565>(dib, scanline, width);
11195
result = new Scanline<UInt16>(dib, scanline, width);
11198
case 24u: result = new Scanline<RGBTRIPLE>(dib, scanline, width); break;
11199
case 32u: result = new Scanline<RGBQUAD>(dib, scanline, width); break;
11200
default: throw new ArgumentException("Color depth is not supported.");
11204
case FREE_IMAGE_TYPE.FIT_COMPLEX: result = new Scanline<FICOMPLEX>(dib, scanline, width); break;
11205
case FREE_IMAGE_TYPE.FIT_DOUBLE: result = new Scanline<Double>(dib, scanline, width); break;
11206
case FREE_IMAGE_TYPE.FIT_FLOAT: result = new Scanline<Single>(dib, scanline, width); break;
11207
case FREE_IMAGE_TYPE.FIT_INT16: result = new Scanline<Int16>(dib, scanline, width); break;
11208
case FREE_IMAGE_TYPE.FIT_INT32: result = new Scanline<Int32>(dib, scanline, width); break;
11209
case FREE_IMAGE_TYPE.FIT_RGB16: result = new Scanline<FIRGB16>(dib, scanline, width); break;
11210
case FREE_IMAGE_TYPE.FIT_RGBA16: result = new Scanline<FIRGBA16>(dib, scanline, width); break;
11211
case FREE_IMAGE_TYPE.FIT_RGBAF: result = new Scanline<FIRGBAF>(dib, scanline, width); break;
11212
case FREE_IMAGE_TYPE.FIT_RGBF: result = new Scanline<FIRGBF>(dib, scanline, width); break;
11213
case FREE_IMAGE_TYPE.FIT_UINT16: result = new Scanline<UInt16>(dib, scanline, width); break;
11214
case FREE_IMAGE_TYPE.FIT_UINT32: result = new Scanline<UInt32>(dib, scanline, width); break;
11215
case FREE_IMAGE_TYPE.FIT_UNKNOWN:
11216
default: throw new ArgumentException("Type is not supported.");
11223
/// Returns a pointer to the specified scanline.
11224
/// Due to FreeImage bitmaps are bottum up,
11225
/// scanline 0 is the most bottom line of the image.
11227
/// <param name="scanline">Number of the scanline.</param>
11228
/// <returns>Pointer to the scanline.</returns>
11229
public IntPtr GetScanlinePointer(int scanline)
11231
EnsureNotDisposed();
11232
return FreeImage.GetScanLine(dib, scanline);
11236
/// Returns a list of structures, representing the scanlines of this <see cref="FreeImageBitmap"/>.
11237
/// Due to FreeImage bitmaps are bottum up, scanline 0 is the
11238
/// bottom-most line of the image.
11239
/// Each color depth has a different representing structure due to different memory layouts.
11242
/// List of return-types of <b>T</b>:<para/>
11243
/// <list type="table">
11244
/// <listheader><term>Color Depth / Type</term><description><see cref="Type">Result Type of IEnmuerable<Scanline<T>></see></description></listheader>
11245
/// <item><term>1 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="FI1BIT"/></description></item>
11246
/// <item><term>4 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="FI4BIT"/></description></item>
11247
/// <item><term>8 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="Byte"/></description></item>
11248
/// <item><term>16 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="UInt16"/></description></item>
11249
/// <item><term>16 - 555 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="FI16RGB555"/></description></item>
11250
/// <item><term>16 - 565 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="FI16RGB565"/></description></item>
11251
/// <item><term>24 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="RGBTRIPLE"/></description></item>
11252
/// <item><term>32 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="RGBQUAD"/></description></item>
11253
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_COMPLEX"/></term><description><see cref="FICOMPLEX"/></description></item>
11254
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_DOUBLE"/></term><description><see cref="Double"/></description></item>
11255
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_FLOAT"/></term><description><see cref="Single"/></description></item>
11256
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_INT16"/></term><description><see cref="Int16"/></description></item>
11257
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_INT32"/></term><description><see cref="Int32"/></description></item>
11258
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_RGB16"/></term><description><see cref="FIRGB16"/></description></item>
11259
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_RGBA16"/></term><description><see cref="FIRGBA16"/></description></item>
11260
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_RGBAF"/></term><description><see cref="FIRGBAF"/></description></item>
11261
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_RGBF"/></term><description><see cref="FIRGBF"/></description></item>
11262
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_UINT16"/></term><description><see cref="UInt16"/></description></item>
11263
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_UINT32"/></term><description><see cref="UInt32"/></description></item>
11266
public IList GetScanlines()
11268
EnsureNotDisposed();
11270
int height = (int)FreeImage.GetHeight(dib);
11273
switch (FreeImage.GetImageType(dib))
11275
case FREE_IMAGE_TYPE.FIT_BITMAP:
11277
switch (FreeImage.GetBPP(dib))
11279
case 1u: list = new List<Scanline<FI1BIT>>(height); break;
11280
case 4u: list = new List<Scanline<FI4BIT>>(height); break;
11281
case 8u: list = new List<Scanline<Byte>>(height); break;
11283
if (FreeImage.IsRGB555(dib))
11285
list = new List<Scanline<FI16RGB555>>(height);
11287
else if (FreeImage.IsRGB565(dib))
11289
list = new List<Scanline<FI16RGB565>>(height);
11293
list = new List<Scanline<UInt16>>(height);
11296
case 24u: list = new List<Scanline<RGBTRIPLE>>(height); break;
11297
case 32u: list = new List<Scanline<RGBQUAD>>(height); break;
11298
default: throw new ArgumentException("Color depth is not supported.");
11302
case FREE_IMAGE_TYPE.FIT_COMPLEX: list = new List<Scanline<FICOMPLEX>>(height); break;
11303
case FREE_IMAGE_TYPE.FIT_DOUBLE: list = new List<Scanline<Double>>(height); break;
11304
case FREE_IMAGE_TYPE.FIT_FLOAT: list = new List<Scanline<Single>>(height); break;
11305
case FREE_IMAGE_TYPE.FIT_INT16: list = new List<Scanline<Int16>>(height); break;
11306
case FREE_IMAGE_TYPE.FIT_INT32: list = new List<Scanline<Int32>>(height); break;
11307
case FREE_IMAGE_TYPE.FIT_RGB16: list = new List<Scanline<FIRGB16>>(height); break;
11308
case FREE_IMAGE_TYPE.FIT_RGBA16: list = new List<Scanline<FIRGBA16>>(height); break;
11309
case FREE_IMAGE_TYPE.FIT_RGBAF: list = new List<Scanline<FIRGBAF>>(height); break;
11310
case FREE_IMAGE_TYPE.FIT_RGBF: list = new List<Scanline<FIRGBF>>(height); break;
11311
case FREE_IMAGE_TYPE.FIT_UINT16: list = new List<Scanline<UInt16>>(height); break;
11312
case FREE_IMAGE_TYPE.FIT_UINT32: list = new List<Scanline<UInt32>>(height); break;
11313
case FREE_IMAGE_TYPE.FIT_UNKNOWN:
11314
default: throw new ArgumentException("Type is not supported.");
11317
for (int i = 0; i < height; i++)
11319
list.Add(GetScanline(i));
11326
/// Removes the specified property item from this <see cref="FreeImageBitmap"/>.
11328
/// <param name="propid">The ID of the property item to remove.</param>
11329
public void RemovePropertyItem(int propid)
11331
EnsureNotDisposed();
11332
ImageMetadata mdata = new ImageMetadata(dib, true);
11333
foreach (MetadataModel model in mdata)
11335
foreach (MetadataTag tag in model)
11337
if (tag.ID == propid)
11339
model.RemoveTag(tag.Key);
11347
/// This method rotates, flips, or rotates and flips this <see cref="FreeImageBitmap"/>.
11349
/// <param name="rotateFlipType">A RotateFlipType member
11350
/// that specifies the type of rotation and flip to apply to this <see cref="FreeImageBitmap"/>.</param>
11351
public void RotateFlip(RotateFlipType rotateFlipType)
11353
EnsureNotDisposed();
11355
FIBITMAP newDib = new FIBITMAP();
11356
uint bpp = FreeImage.GetBPP(dib);
11358
switch (rotateFlipType)
11360
case RotateFlipType.RotateNoneFlipX:
11362
FreeImage.FlipHorizontal(dib);
11365
case RotateFlipType.RotateNoneFlipY:
11367
FreeImage.FlipVertical(dib);
11370
case RotateFlipType.RotateNoneFlipXY:
11372
FreeImage.FlipHorizontal(dib);
11373
FreeImage.FlipVertical(dib);
11376
case RotateFlipType.Rotate90FlipNone:
11378
newDib = (bpp == 4u) ? FreeImage.Rotate4bit(dib, 90d) : FreeImage.Rotate(dib, 90d);
11381
case RotateFlipType.Rotate90FlipX:
11383
newDib = (bpp == 4u) ? FreeImage.Rotate4bit(dib, 90d) : FreeImage.Rotate(dib, 90d);
11384
FreeImage.FlipHorizontal(newDib);
11387
case RotateFlipType.Rotate90FlipY:
11389
newDib = (bpp == 4u) ? FreeImage.Rotate4bit(dib, 90d) : FreeImage.Rotate(dib, 90d);
11390
FreeImage.FlipVertical(newDib);
11393
case RotateFlipType.Rotate90FlipXY:
11395
newDib = (bpp == 4u) ? FreeImage.Rotate4bit(dib, 90d) : FreeImage.Rotate(dib, 90d);
11396
FreeImage.FlipHorizontal(newDib);
11397
FreeImage.FlipVertical(newDib);
11400
case RotateFlipType.Rotate180FlipXY:
11401
newDib = FreeImage.Clone(dib);
11404
ReplaceDib(newDib);
11408
/// Copies the metadata from another <see cref="FreeImageBitmap"/>.
11410
/// <param name="bitmap">The bitmap to read the metadata from.</param>
11411
/// <exception cref="ArgumentNullException">
11412
/// <paramref name="bitmap"/> is a null reference.
11414
public void CloneMetadataFrom(FreeImageBitmap bitmap)
11416
if (bitmap == null)
11418
throw new ArgumentNullException("bitmap");
11420
EnsureNotDisposed();
11421
bitmap.EnsureNotDisposed();
11422
FreeImage.CloneMetadata(dib, bitmap.dib);
11426
/// Copies the metadata from another <see cref="FreeImageBitmap"/> using
11427
/// the provided options.
11429
/// <param name="bitmap">The bitmap to read the metadata from.</param>
11430
/// <param name="flags">Specifies the way the metadata is copied.</param>
11431
/// <exception cref="ArgumentNullException">
11432
/// <paramref name="bitmap"/> is a null reference.
11434
public void CloneMetadataFrom(FreeImageBitmap bitmap, FREE_IMAGE_METADATA_COPY flags)
11436
if (bitmap == null)
11438
throw new ArgumentNullException("bitmap");
11440
EnsureNotDisposed();
11441
bitmap.EnsureNotDisposed();
11442
FreeImage.CloneMetadataEx(bitmap.dib, dib, flags);
11446
/// Saves this <see cref="FreeImageBitmap"/> to the specified file.
11448
/// <param name="filename">A string that contains the name of the file to which
11449
/// to save this <see cref="FreeImageBitmap"/>.</param>
11450
/// <exception cref="ArgumentException"><paramref name="filename"/> is null or empty.</exception>
11451
/// <exception cref="Exception">Saving the image failed.</exception>
11452
public void Save(string filename)
11454
Save(filename, FREE_IMAGE_FORMAT.FIF_UNKNOWN, FREE_IMAGE_SAVE_FLAGS.DEFAULT);
11458
/// Saves this <see cref="FreeImageBitmap"/> to the specified file in the specified format.
11460
/// <param name="filename">A string that contains the name of the file to which
11461
/// to save this <see cref="FreeImageBitmap"/>.</param>
11462
/// <param name="format">An <see cref="FREE_IMAGE_FORMAT"/> that specifies the format of the saved image.</param>
11463
/// <exception cref="ArgumentException"><paramref name="filename"/> is null or empty.</exception>
11464
/// <exception cref="Exception">Saving the image failed.</exception>
11465
public void Save(string filename, FREE_IMAGE_FORMAT format)
11467
Save(filename, format, FREE_IMAGE_SAVE_FLAGS.DEFAULT);
11471
/// Saves this <see cref="FreeImageBitmap"/> to the specified file in the specified format
11472
/// using the specified saving flags.
11474
/// <param name="filename">A string that contains the name of the file to which
11475
/// to save this <see cref="FreeImageBitmap"/>.</param>
11476
/// <param name="format">An <see cref="FREE_IMAGE_FORMAT"/> that specifies the format of the saved image.</param>
11477
/// <param name="flags">Flags to enable or disable plugin-features.</param>
11478
/// <exception cref="ArgumentException"><paramref name="filename"/> is null or empty.</exception>
11479
/// <exception cref="Exception">Saving the image failed.</exception>
11480
public void Save(string filename, FREE_IMAGE_FORMAT format, FREE_IMAGE_SAVE_FLAGS flags)
11482
EnsureNotDisposed();
11483
if (string.IsNullOrEmpty(filename))
11485
throw new ArgumentException("filename");
11487
if (!FreeImage.SaveEx(dib, filename, format, flags))
11489
throw new Exception("Unable to save bitmap");
11492
saveInformation.filename = filename;
11493
saveInformation.format = format;
11494
saveInformation.saveFlags = flags;
11498
/// Saves this <see cref="FreeImageBitmap"/> to the specified stream in the specified format.
11500
/// <param name="stream">The stream where this <see cref="FreeImageBitmap"/> will be saved.</param>
11501
/// <param name="format">An <see cref="FREE_IMAGE_FORMAT"/> that specifies the format of the saved image.</param>
11502
/// <exception cref="ArgumentNullException"><paramref name="stream"/> is a null reference.</exception>
11503
/// <exception cref="Exception">Saving the image failed.</exception>
11504
public void Save(Stream stream, FREE_IMAGE_FORMAT format)
11506
Save(stream, format, FREE_IMAGE_SAVE_FLAGS.DEFAULT);
11510
/// Saves this <see cref="FreeImageBitmap"/> to the specified stream in the specified format
11511
/// using the specified saving flags.
11513
/// <param name="stream">The stream where this <see cref="FreeImageBitmap"/> will be saved.</param>
11514
/// <param name="format">An <see cref="FREE_IMAGE_FORMAT"/> that specifies the format of the saved image.</param>
11515
/// <param name="flags">Flags to enable or disable plugin-features.</param>
11516
/// <exception cref="ArgumentNullException"><paramref name="stream"/> is a null reference.</exception>
11517
/// <exception cref="Exception">Saving the image failed.</exception>
11518
public void Save(Stream stream, FREE_IMAGE_FORMAT format, FREE_IMAGE_SAVE_FLAGS flags)
11520
EnsureNotDisposed();
11521
if (stream == null)
11523
throw new ArgumentNullException("stream");
11525
if (!FreeImage.SaveToStream(dib, stream, format, flags))
11527
throw new Exception("Unable to save bitmap");
11530
saveInformation.filename = null;
11534
/// Adds a frame to the file specified in a previous call to the <see cref="Save(String)"/>
11537
/// <exception cref="InvalidOperationException">
11538
/// This instance has not been saved to a file using Save(...) before.</exception>
11539
public void SaveAdd()
11545
/// Adds a frame to the file specified in a previous call to the <see cref="Save(String)"/> method.
11547
/// <param name="insertPosition">The position at which the frame should be inserted.</param>
11548
/// <exception cref="InvalidOperationException">
11549
/// This instance has not yet been saved to a file using the Save(...) method.</exception>
11550
/// <exception cref="ArgumentOutOfRangeException"><paramref name="insertPosition"/> is out of range.</exception>
11551
public void SaveAdd(int insertPosition)
11553
SaveAdd(this, insertPosition);
11557
/// Adds a frame to the file specified in a previous call to the <see cref="Save(String)"/> method.
11559
/// <param name="bitmap">A <see cref="FreeImageBitmap"/> that contains the frame to add.</param>
11560
/// <exception cref="InvalidOperationException">
11561
/// This instance has not yet been saved to a file using the Save(...) method.</exception>
11562
public void SaveAdd(FreeImageBitmap bitmap)
11564
if (saveInformation.filename == null)
11566
throw new InvalidOperationException("This operation requires a previous call of Save().");
11570
saveInformation.filename,
11572
saveInformation.format,
11573
saveInformation.loadFlags,
11574
saveInformation.saveFlags);
11578
/// Adds a frame to the file specified in a previous call to the <see cref="Save(String)"/> method.
11580
/// <param name="bitmap">A <see cref="FreeImageBitmap"/> that contains the frame to add.</param>
11581
/// <param name="insertPosition">The position at which the frame should be inserted.</param>
11582
/// <exception cref="InvalidOperationException">
11583
/// This instance has not yet been saved to a file using the Save(...) method.</exception>
11584
/// <exception cref="ArgumentOutOfRangeException"><paramref name="insertPosition"/> is out of range.</exception>
11585
public void SaveAdd(FreeImageBitmap bitmap, int insertPosition)
11587
if (saveInformation.filename == null)
11589
throw new InvalidOperationException("This operation requires a previous call of Save().");
11593
saveInformation.filename,
11596
saveInformation.format,
11597
saveInformation.loadFlags,
11598
saveInformation.saveFlags);
11602
/// Adds a frame to the file specified.
11604
/// <param name="filename">File to add this frame to.</param>
11605
/// <exception cref="ArgumentNullException"><paramref name="filename"/> is a null reference.</exception>
11606
/// <exception cref="FileNotFoundException"><paramref name="filename"/> does not exist.</exception>
11607
/// <exception cref="Exception">Saving the image has failed.</exception>
11608
public void SaveAdd(string filename)
11613
FREE_IMAGE_FORMAT.FIF_UNKNOWN,
11614
FREE_IMAGE_LOAD_FLAGS.DEFAULT,
11615
FREE_IMAGE_SAVE_FLAGS.DEFAULT);
11619
/// Adds a frame to the file specified.
11621
/// <param name="filename">File to add this frame to.</param>
11622
/// <param name="insertPosition">The position at which the frame should be inserted.</param>
11623
/// <exception cref="ArgumentNullException"><paramref name="filename"/> is a null reference.</exception>
11624
/// <exception cref="FileNotFoundException"><paramref name="filename"/> does not exist.</exception>
11625
/// <exception cref="Exception">Saving the image has failed.</exception>
11626
/// <exception cref="ArgumentOutOfRangeException"><paramref name="insertPosition"/> is out of range.</exception>
11627
public void SaveAdd(string filename, int insertPosition)
11633
FREE_IMAGE_FORMAT.FIF_UNKNOWN,
11634
FREE_IMAGE_LOAD_FLAGS.DEFAULT,
11635
FREE_IMAGE_SAVE_FLAGS.DEFAULT);
11639
/// Adds a frame to the file specified using the specified parameters.
11641
/// <param name="filename">File to add this frame to.</param>
11642
/// <param name="format">Format of the image.</param>
11643
/// <param name="loadFlags">Flags to enable or disable plugin-features.</param>
11644
/// <param name="saveFlags">Flags to enable or disable plugin-features.</param>
11645
/// <exception cref="ArgumentNullException"><paramref name="filename"/> is a null reference.</exception>
11646
/// <exception cref="FileNotFoundException"><paramref name="filename"/> does not exist.</exception>
11647
/// <exception cref="Exception">Saving the image has failed.</exception>
11648
public void SaveAdd(
11650
FREE_IMAGE_FORMAT format,
11651
FREE_IMAGE_LOAD_FLAGS loadFlags,
11652
FREE_IMAGE_SAVE_FLAGS saveFlags)
11663
/// Adds a frame to the file specified using the specified parameters.
11665
/// <param name="filename">File to add this frame to.</param>
11666
/// <param name="insertPosition">The position at which the frame should be inserted.</param>
11667
/// <param name="format">Format of the image.</param>
11668
/// <param name="loadFlags">Flags to enable or disable plugin-features.</param>
11669
/// <param name="saveFlags">Flags to enable or disable plugin-features.</param>
11670
/// <exception cref="ArgumentNullException"><paramref name="filename"/> is a null reference.</exception>
11671
/// <exception cref="FileNotFoundException"><paramref name="filename"/> does not exist.</exception>
11672
/// <exception cref="Exception">Saving the image has failed.</exception>
11673
/// <exception cref="ArgumentOutOfRangeException"><paramref name="insertPosition"/> is out of range.</exception>
11674
public void SaveAdd(
11676
int insertPosition,
11677
FREE_IMAGE_FORMAT format,
11678
FREE_IMAGE_LOAD_FLAGS loadFlags,
11679
FREE_IMAGE_SAVE_FLAGS saveFlags)
11691
/// Selects the frame specified by the index.
11693
/// <param name="frameIndex">The index of the active frame.</param>
11694
/// <exception cref="ArgumentOutOfRangeException">
11695
/// <paramref name="frameIndex"/> is out of range.</exception>
11696
/// <exception cref="Exception">The operation failed.</exception>
11697
/// <exception cref="InvalidOperationException">The source of the bitmap is not available.
11699
public void SelectActiveFrame(int frameIndex)
11701
EnsureNotDisposed();
11702
if ((frameIndex < 0) || (frameIndex >= frameCount))
11704
throw new ArgumentOutOfRangeException("frameIndex");
11707
if (frameIndex != this.frameIndex)
11709
if (stream == null)
11711
throw new InvalidOperationException("No source available.");
11714
FREE_IMAGE_FORMAT format = originalFormat;
11715
FIMULTIBITMAP mdib = FreeImage.OpenMultiBitmapFromStream(stream, ref format, saveInformation.loadFlags);
11717
throw new Exception(ErrorLoadingBitmap);
11721
if (frameIndex >= FreeImage.GetPageCount(mdib))
11723
throw new ArgumentOutOfRangeException("frameIndex");
11726
FIBITMAP newDib = FreeImage.LockPage(mdib, frameIndex);
11729
throw new Exception(ErrorLoadingFrame);
11734
FIBITMAP clone = FreeImage.Clone(newDib);
11737
throw new Exception(ErrorCreatingBitmap);
11743
if (!newDib.IsNull)
11745
FreeImage.UnlockPage(mdib, newDib, false);
11751
if (!FreeImage.CloseMultiBitmapEx(ref mdib))
11753
throw new Exception(ErrorUnloadBitmap);
11757
this.frameIndex = frameIndex;
11762
/// Creates a GDI bitmap object from this <see cref="FreeImageBitmap"/>.
11764
/// <returns>A handle to the GDI bitmap object that this method creates.</returns>
11765
public IntPtr GetHbitmap()
11767
EnsureNotDisposed();
11768
return FreeImage.GetHbitmap(dib, IntPtr.Zero, false);
11772
/// Creates a GDI bitmap object from this <see cref="FreeImageBitmap"/>.
11774
/// <param name="background">A <see cref="System.Drawing.Color"/> structure that specifies the background color.
11775
/// This parameter is ignored if the bitmap is totally opaque.</param>
11776
/// <returns>A handle to the GDI bitmap object that this method creates.</returns>
11777
public IntPtr GetHbitmap(Color background)
11779
EnsureNotDisposed();
11780
using (FreeImageBitmap temp = new FreeImageBitmap(this))
11782
temp.BackgroundColor = background;
11783
return temp.GetHbitmap();
11788
/// Returns the handle to an icon.
11790
/// <returns>A Windows handle to an icon with the same image as this <see cref="FreeImageBitmap"/>.</returns>
11791
public IntPtr GetHicon()
11793
EnsureNotDisposed();
11794
using (Bitmap bitmap = FreeImage.GetBitmap(dib, true))
11796
return bitmap.GetHicon();
11801
/// Creates a GDI bitmap object from this <see cref="FreeImageBitmap"/> with the same
11802
/// color depth as the primary device.
11804
/// <returns>A handle to the GDI bitmap object that this method creates.</returns>
11805
public IntPtr GetHbitmapForDevice()
11807
EnsureNotDisposed();
11808
return FreeImage.GetBitmapForDevice(dib, IntPtr.Zero, false);
11812
/// Gets the <see cref="Color"/> of the specified pixel in this <see cref="FreeImageBitmap"/>.
11814
/// <param name="x">The x-coordinate of the pixel to retrieve.</param>
11815
/// <param name="y">The y-coordinate of the pixel to retrieve.</param>
11816
/// <returns>A <see cref="System.Drawing.Color"/> structure that represents the color of the specified pixel.</returns>
11817
/// <exception cref="Exception">The operation failed.</exception>
11818
/// <exception cref="NotSupportedException">The type of this bitmap is not supported.</exception>
11819
public unsafe Color GetPixel(int x, int y)
11821
EnsureNotDisposed();
11822
if (FreeImage.GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP)
11824
if (ColorDepth == 16 || ColorDepth == 24 || ColorDepth == 32)
11827
if (!FreeImage.GetPixelColor(dib, (uint)x, (uint)y, out rgbq))
11829
throw new Exception("FreeImage.GetPixelColor() failed");
11833
else if (ColorDepth == 1 || ColorDepth == 4 || ColorDepth == 8)
11836
if (!FreeImage.GetPixelIndex(dib, (uint)x, (uint)y, out index))
11838
throw new Exception("FreeImage.GetPixelIndex() failed");
11840
RGBQUAD* palette = (RGBQUAD*)FreeImage.GetPalette(dib);
11841
return palette[index].Color;
11844
throw new NotSupportedException("The type of the image is not supported");
11848
/// Makes the default transparent color transparent for this <see cref="FreeImageBitmap"/>.
11850
public void MakeTransparent()
11852
EnsureNotDisposed();
11853
MakeTransparent(Color.Transparent);
11857
/// Makes the specified color transparent for this <see cref="FreeImageBitmap"/>.
11859
/// <param name="transparentColor">The <see cref="System.Drawing.Color"/> structure that represents
11860
/// the color to make transparent.</param>
11861
/// <exception cref="NotImplementedException">
11862
/// This method is not implemented.</exception>
11863
public void MakeTransparent(Color transparentColor)
11865
EnsureNotDisposed();
11866
throw new System.NotImplementedException();
11870
/// Sets the <see cref="System.Drawing.Color"/> of the specified pixel in this <see cref="FreeImageBitmap"/>.
11872
/// <param name="x">The x-coordinate of the pixel to set.</param>
11873
/// <param name="y">The y-coordinate of the pixel to set.</param>
11874
/// <param name="color">A <see cref="System.Drawing.Color"/> structure that represents the color
11875
/// to assign to the specified pixel.</param>
11876
/// <exception cref="Exception">The operation failed.</exception>
11877
/// <exception cref="NotSupportedException">The type of this bitmap is not supported.</exception>
11878
public unsafe void SetPixel(int x, int y, Color color)
11880
EnsureNotDisposed();
11881
if (FreeImage.GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP)
11883
if (ColorDepth == 16 || ColorDepth == 24 || ColorDepth == 32)
11885
RGBQUAD rgbq = color;
11886
if (!FreeImage.SetPixelColor(dib, (uint)x, (uint)y, ref rgbq))
11888
throw new Exception("FreeImage.SetPixelColor() failed");
11892
else if (ColorDepth == 1 || ColorDepth == 4 || ColorDepth == 8)
11894
uint colorsUsed = FreeImage.GetColorsUsed(dib);
11895
RGBQUAD* palette = (RGBQUAD*)FreeImage.GetPalette(dib);
11896
for (int i = 0; i < colorsUsed; i++)
11898
if (palette[i].Color == color)
11900
byte index = (byte)i;
11901
if (!FreeImage.SetPixelIndex(dib, (uint)x, (uint)y, ref index))
11903
throw new Exception("FreeImage.SetPixelIndex() failed");
11908
throw new ArgumentOutOfRangeException("color");
11911
throw new NotSupportedException("The type of the image is not supported");
11915
/// Sets the resolution for this <see cref="FreeImageBitmap"/>.
11917
/// <param name="xDpi">The horizontal resolution, in dots per inch, of this <see cref="FreeImageBitmap"/>.</param>
11918
/// <param name="yDpi">The vertical resolution, in dots per inch, of this <see cref="FreeImageBitmap"/>.</param>
11919
public void SetResolution(float xDpi, float yDpi)
11921
EnsureNotDisposed();
11922
FreeImage.SetResolutionX(dib, (uint)xDpi);
11923
FreeImage.SetResolutionY(dib, (uint)yDpi);
11927
/// This function is not yet implemented.
11929
/// <exception cref="NotImplementedException">
11930
/// This method is not implemented.</exception>
11931
public BitmapData LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format)
11933
throw new NotImplementedException();
11937
/// This function is not yet implemented.
11939
/// <exception cref="NotImplementedException">
11940
/// This method is not implemented.</exception>
11941
public BitmapData LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format, BitmapData bitmapData)
11943
throw new NotImplementedException();
11947
/// This function is not yet implemented.
11949
/// <exception cref="NotImplementedException">
11950
/// This method is not implemented.</exception>
11951
public void UnlockBits(BitmapData bitmapdata)
11953
throw new NotImplementedException();
11957
/// Converts this <see cref="FreeImageBitmap"/> into a different color depth.
11958
/// The parameter <paramref name="bpp"/> specifies color depth, greyscale conversion
11959
/// and palette reorder.
11960
/// <para>Adding the <see cref="FREE_IMAGE_COLOR_DEPTH.FICD_FORCE_GREYSCALE"/> flag
11961
/// will first perform a convesion to greyscale. This can be done with any target
11962
/// color depth.</para>
11963
/// <para>Adding the <see cref="FREE_IMAGE_COLOR_DEPTH.FICD_REORDER_PALETTE"/> flag
11964
/// will allow the algorithm to reorder the palette. This operation will not be performed to
11965
/// non-greyscale images to prevent data loss by mistake.</para>
11967
/// <param name="bpp">A bitfield containing information about the conversion
11968
/// to perform.</param>
11969
/// <returns>Returns true on success, false on failure.</returns>
11970
public bool ConvertColorDepth(FREE_IMAGE_COLOR_DEPTH bpp)
11972
EnsureNotDisposed();
11973
return ReplaceDib(FreeImage.ConvertColorDepth(dib, bpp, false));
11977
/// Converts this <see cref="FreeImageBitmap"/> <see cref="FREE_IMAGE_TYPE"/> to
11978
/// <paramref name="type"/> initializing a new instance.
11979
/// In case source and destination type are the same, the operation fails.
11980
/// An error message can be catched using the 'Message' event.
11982
/// <param name="type">Destination type.</param>
11983
/// <param name="scaleLinear">True to scale linear, else false.</param>
11984
/// <returns>Returns true on success, false on failure.</returns>
11985
public bool ConvertType(FREE_IMAGE_TYPE type, bool scaleLinear)
11987
EnsureNotDisposed();
11988
return (ImageType == type) ? false : ReplaceDib(FreeImage.ConvertToType(dib, type, scaleLinear));
11992
/// Converts this <see cref="FreeImageBitmap"/> <see cref="FreeImageBitmap"/> to <paramref name="type"/>.
11993
/// In case source and destination type are the same, the operation fails.
11994
/// An error message can be catched using the 'Message' event.
11996
/// <param name="type">Destination type.</param>
11997
/// <param name="scaleLinear">True to scale linear, else false.</param>
11998
/// <returns>The converted instance.</returns>
11999
public FreeImageBitmap GetTypeConvertedInstance(FREE_IMAGE_TYPE type, bool scaleLinear)
12001
EnsureNotDisposed();
12002
FreeImageBitmap result = null;
12003
if (ImageType != type)
12005
FIBITMAP newDib = FreeImage.ConvertToType(dib, type, scaleLinear);
12006
if (!newDib.IsNull)
12008
result = new FreeImageBitmap(newDib);
12015
/// Converts this <see cref="FreeImageBitmap"/> into a different color depth initializing
12016
/// a new instance.
12017
/// The parameter <paramref name="bpp"/> specifies color depth, greyscale conversion
12018
/// and palette reorder.
12019
/// <para>Adding the <see cref="FREE_IMAGE_COLOR_DEPTH.FICD_FORCE_GREYSCALE"/> flag will
12020
/// first perform a convesion to greyscale. This can be done with any target color depth.</para>
12021
/// <para>Adding the <see cref="FREE_IMAGE_COLOR_DEPTH.FICD_REORDER_PALETTE"/> flag will
12022
/// allow the algorithm to reorder the palette. This operation will not be performed to
12023
/// non-greyscale images to prevent data loss by mistake.</para>
12025
/// <param name="bpp">A bitfield containing information about the conversion
12026
/// to perform.</param>
12027
/// <returns>The converted instance.</returns>
12028
public FreeImageBitmap GetColorConvertedInstance(FREE_IMAGE_COLOR_DEPTH bpp)
12030
EnsureNotDisposed();
12031
FreeImageBitmap result = null;
12032
FIBITMAP newDib = FreeImage.ConvertColorDepth(dib, bpp, false);
12035
newDib = FreeImage.Clone(dib);
12037
if (!newDib.IsNull)
12039
result = new FreeImageBitmap(newDib);
12045
/// Rescales this <see cref="FreeImageBitmap"/> to the specified size using the
12046
/// specified filter.
12048
/// <param name="newSize">The Size structure that represent the
12049
/// size of the new <see cref="FreeImageBitmap"/>.</param>
12050
/// <param name="filter">Filter to use for resizing.</param>
12051
/// <returns>Returns true on success, false on failure.</returns>
12052
public bool Rescale(Size newSize, FREE_IMAGE_FILTER filter)
12054
return Rescale(newSize.Width, newSize.Height, filter);
12058
/// Rescales this <see cref="FreeImageBitmap"/> to the specified size using the
12059
/// specified filter.
12061
/// <param name="width">Width of the new <see cref="FreeImageBitmap"/>.</param>
12062
/// <param name="height">Height of the new <see cref="FreeImageBitmap"/>.</param>
12063
/// <param name="filter">Filter to use for resizing.</param>
12064
/// <returns>Returns true on success, false on failure.</returns>
12065
public bool Rescale(int width, int height, FREE_IMAGE_FILTER filter)
12067
EnsureNotDisposed();
12068
return ReplaceDib(FreeImage.Rescale(dib, width, height, filter));
12072
/// Rescales this <see cref="FreeImageBitmap"/> to the specified size using the
12073
/// specified filter initializing a new instance.
12075
/// <param name="newSize">The Size structure that represent the
12076
/// size of the new <see cref="FreeImageBitmap"/>.</param>
12077
/// <param name="filter">Filter to use for resizing.</param>
12078
/// <returns>The rescaled instance.</returns>
12079
public FreeImageBitmap GetScaledInstance(Size newSize, FREE_IMAGE_FILTER filter)
12081
return GetScaledInstance(newSize.Width, newSize.Height, filter);
12085
/// Rescales this <see cref="FreeImageBitmap"/> to the specified size using the
12086
/// specified filter initializing a new instance.
12088
/// <param name="width">Width of the new <see cref="FreeImageBitmap"/>.</param>
12089
/// <param name="height">Height of the new <see cref="FreeImageBitmap"/>.</param>
12090
/// <param name="filter">Filter to use for resizing.</param>
12091
/// <returns>The rescaled instance.</returns>
12092
public FreeImageBitmap GetScaledInstance(int width, int height, FREE_IMAGE_FILTER filter)
12094
EnsureNotDisposed();
12095
FreeImageBitmap result = null;
12096
FIBITMAP newDib = FreeImage.Rescale(dib, width, height, filter);
12097
if (!newDib.IsNull)
12099
result = new FreeImageBitmap(newDib);
12105
/// Enlarges or shrinks this <see cref="FreeImageBitmap"/> selectively per side and fills
12106
/// newly added areas with the specified background color.
12107
/// See <see cref="FreeImage.EnlargeCanvas<T>"/> for further details.
12109
/// <typeparam name="T">The type of the specified color.</typeparam>
12110
/// <param name="left">The number of pixels, the image should be enlarged on its left side.
12111
/// Negative values shrink the image on its left side.</param>
12112
/// <param name="top">The number of pixels, the image should be enlarged on its top side.
12113
/// Negative values shrink the image on its top side.</param>
12114
/// <param name="right">The number of pixels, the image should be enlarged on its right side.
12115
/// Negative values shrink the image on its right side.</param>
12116
/// <param name="bottom">The number of pixels, the image should be enlarged on its bottom side.
12117
/// Negative values shrink the image on its bottom side.</param>
12118
/// <param name="color">The color, the enlarged sides of the image should be filled with.</param>
12119
/// <returns><c>true</c> on success, <c>false</c> on failure.</returns>
12120
public bool EnlargeCanvas<T>(int left, int top, int right, int bottom, T? color) where T : struct
12122
return EnlargeCanvas(left, top, right, bottom, color, FREE_IMAGE_COLOR_OPTIONS.FICO_DEFAULT);
12126
/// Enlarges or shrinks this <see cref="FreeImageBitmap"/> selectively per side and fills
12127
/// newly added areas with the specified background color.
12128
/// See <see cref="FreeImage.EnlargeCanvas<T>"/> for further details.
12130
/// <typeparam name="T">The type of the specified color.</typeparam>
12131
/// <param name="left">The number of pixels, the image should be enlarged on its left side.
12132
/// Negative values shrink the image on its left side.</param>
12133
/// <param name="top">The number of pixels, the image should be enlarged on its top side.
12134
/// Negative values shrink the image on its top side.</param>
12135
/// <param name="right">The number of pixels, the image should be enlarged on its right side.
12136
/// Negative values shrink the image on its right side.</param>
12137
/// <param name="bottom">The number of pixels, the image should be enlarged on its bottom side.
12138
/// Negative values shrink the image on its bottom side.</param>
12139
/// <param name="color">The color, the enlarged sides of the image should be filled with.</param>
12140
/// <param name="options">Options that affect the color search process for palletized images.</param>
12141
/// <returns><c>true</c> on success, <c>false</c> on failure.</returns>
12142
public bool EnlargeCanvas<T>(int left, int top, int right, int bottom,
12143
T? color, FREE_IMAGE_COLOR_OPTIONS options) where T : struct
12145
EnsureNotDisposed();
12146
return ReplaceDib(FreeImage.EnlargeCanvas(dib, left, top, right, bottom, color, options));
12150
/// Enlarges or shrinks this <see cref="FreeImageBitmap"/> selectively per side and fills
12151
/// newly added areas with the specified background color returning a new instance.
12152
/// See <see cref="FreeImage.EnlargeCanvas<T>"/> for further details.
12154
/// <typeparam name="T">The type of the specified color.</typeparam>
12155
/// <param name="left">The number of pixels, the image should be enlarged on its left side.
12156
/// Negative values shrink the image on its left side.</param>
12157
/// <param name="top">The number of pixels, the image should be enlarged on its top side.
12158
/// Negative values shrink the image on its top side.</param>
12159
/// <param name="right">The number of pixels, the image should be enlarged on its right side.
12160
/// Negative values shrink the image on its right side.</param>
12161
/// <param name="bottom">The number of pixels, the image should be enlarged on its bottom side.
12162
/// Negative values shrink the image on its bottom side.</param>
12163
/// <param name="color">The color, the enlarged sides of the image should be filled with.</param>
12164
/// <returns>The enlarged instance.</returns>
12165
public FreeImageBitmap GetEnlargedInstance<T>(int left, int top, int right, int bottom,
12166
T? color) where T : struct
12168
return GetEnlargedInstance(left, top, right, bottom, color, FREE_IMAGE_COLOR_OPTIONS.FICO_DEFAULT);
12172
/// Enlarges or shrinks this <see cref="FreeImageBitmap"/> selectively per side and fills
12173
/// newly added areas with the specified background color returning a new instance.
12174
/// See <see cref="FreeImage.EnlargeCanvas<T>"/> for further details.
12176
/// <typeparam name="T">The type of the specified color.</typeparam>
12177
/// <param name="left">The number of pixels, the image should be enlarged on its left side.
12178
/// Negative values shrink the image on its left side.</param>
12179
/// <param name="top">The number of pixels, the image should be enlarged on its top side.
12180
/// Negative values shrink the image on its top side.</param>
12181
/// <param name="right">The number of pixels, the image should be enlarged on its right side.
12182
/// Negative values shrink the image on its right side.</param>
12183
/// <param name="bottom">The number of pixels, the image should be enlarged on its bottom side.
12184
/// Negative values shrink the image on its bottom side.</param>
12185
/// <param name="color">The color, the enlarged sides of the image should be filled with.</param>
12186
/// <param name="options">Options that affect the color search process for palletized images.</param>
12187
/// <returns>The enlarged instance.</returns>
12188
public FreeImageBitmap GetEnlargedInstance<T>(int left, int top, int right, int bottom,
12189
T? color, FREE_IMAGE_COLOR_OPTIONS options) where T : struct
12191
EnsureNotDisposed();
12192
FreeImageBitmap result = null;
12193
FIBITMAP newDib = FreeImage.EnlargeCanvas(dib, left, top, right, bottom, color, options);
12194
if (!newDib.IsNull)
12196
result = new FreeImageBitmap(newDib);
12202
/// Quantizes this <see cref="FreeImageBitmap"/> from 24 bit to 8bit creating a new
12203
/// palette with the specified <paramref name="paletteSize"/> using the specified
12204
/// <paramref name="algorithm"/>.
12206
/// <param name="algorithm">The color reduction algorithm to be used.</param>
12207
/// <param name="paletteSize">Size of the desired output palette.</param>
12208
/// <returns>Returns true on success, false on failure.</returns>
12209
public bool Quantize(FREE_IMAGE_QUANTIZE algorithm, int paletteSize)
12211
return Quantize(algorithm, paletteSize, 0, (RGBQUAD[])null);
12215
/// Quantizes this <see cref="FreeImageBitmap"/> from 24 bit to 8bit creating a new
12216
/// palette with the specified <paramref name="paletteSize"/> using the specified
12217
/// <paramref name="algorithm"/> and the specified
12218
/// <paramref name="reservePalette">palette</paramref> up to the
12219
/// specified <paramref name="paletteSize">length</paramref>.
12221
/// <param name="algorithm">The color reduction algorithm to be used.</param>
12222
/// <param name="paletteSize">Size of the desired output palette.</param>
12223
/// <param name="reservePalette">The provided palette.</param>
12224
/// <returns>Returns true on success, false on failure.</returns>
12225
public bool Quantize(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, Palette reservePalette)
12227
return Quantize(algorithm, paletteSize, reservePalette.Length, reservePalette.Data);
12231
/// Quantizes this <see cref="FreeImageBitmap"/> from 24 bit to 8bit creating a new
12232
/// palette with the specified <paramref name="paletteSize"/> using the specified
12233
/// <paramref name="algorithm"/> and the specified
12234
/// <paramref name="reservePalette">palette</paramref> up to the
12235
/// specified <paramref name="paletteSize">length</paramref>.
12237
/// <param name="algorithm">The color reduction algorithm to be used.</param>
12238
/// <param name="paletteSize">Size of the desired output palette.</param>
12239
/// <param name="reserveSize">Size of the provided palette of ReservePalette.</param>
12240
/// <param name="reservePalette">The provided palette.</param>
12241
/// <returns>Returns true on success, false on failure.</returns>
12242
public bool Quantize(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, int reserveSize, Palette reservePalette)
12244
return Quantize(algorithm, paletteSize, reserveSize, reservePalette.Data);
12248
/// Quantizes this <see cref="FreeImageBitmap"/> from 24 bit to 8bit creating a new
12249
/// palette with the specified <paramref name="paletteSize"/> using the specified
12250
/// <paramref name="algorithm"/> and the specified
12251
/// <paramref name="reservePalette">palette</paramref> up to the
12252
/// specified <paramref name="paletteSize">length</paramref>.
12254
/// <param name="algorithm">The color reduction algorithm to be used.</param>
12255
/// <param name="paletteSize">Size of the desired output palette.</param>
12256
/// <param name="reserveSize">Size of the provided palette of ReservePalette.</param>
12257
/// <param name="reservePalette">The provided palette.</param>
12258
/// <returns>Returns true on success, false on failure.</returns>
12259
public bool Quantize(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, int reserveSize, RGBQUAD[] reservePalette)
12261
EnsureNotDisposed();
12262
return ReplaceDib(FreeImage.ColorQuantizeEx(dib, algorithm, paletteSize, reserveSize, reservePalette));
12266
/// Quantizes this <see cref="FreeImageBitmap"/> from 24 bit, using the specified
12267
/// <paramref name="algorithm"/> initializing a new 8 bit instance with the
12268
/// specified <paramref name="paletteSize"/>.
12270
/// <param name="algorithm">The color reduction algorithm to be used.</param>
12271
/// <param name="paletteSize">Size of the desired output palette.</param>
12272
/// <returns>The quantized instance.</returns>
12273
public FreeImageBitmap GetQuantizedInstance(FREE_IMAGE_QUANTIZE algorithm, int paletteSize)
12275
return GetQuantizedInstance(algorithm, paletteSize, 0, (RGBQUAD[])null);
12279
/// Quantizes this <see cref="FreeImageBitmap"/> from 24 bit, using the specified
12280
/// <paramref name="algorithm"/> and <paramref name="reservePalette">palette</paramref>
12281
/// initializing a new 8 bit instance with the specified <paramref name="paletteSize"/>.
12283
/// <param name="algorithm">The color reduction algorithm to be used.</param>
12284
/// <param name="paletteSize">Size of the desired output palette.</param>
12285
/// <param name="reservePalette">The provided palette.</param>
12286
/// <returns>The quantized instance.</returns>
12287
public FreeImageBitmap GetQuantizedInstance(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, Palette reservePalette)
12289
return GetQuantizedInstance(algorithm, paletteSize, reservePalette.Length, reservePalette);
12293
/// Quantizes this <see cref="FreeImageBitmap"/> from 24 bit, using the specified
12294
/// <paramref name="algorithm"/> and up to <paramref name="reserveSize"/>
12295
/// entries from <paramref name="reservePalette">palette</paramref> initializing
12296
/// a new 8 bit instance with the specified <paramref name="paletteSize"/>.
12298
/// <param name="algorithm">The color reduction algorithm to be used.</param>
12299
/// <param name="paletteSize">Size of the desired output palette.</param>
12300
/// <param name="reserveSize">Size of the provided palette.</param>
12301
/// <param name="reservePalette">The provided palette.</param>
12302
/// <returns>The quantized instance.</returns>
12303
public FreeImageBitmap GetQuantizedInstance(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, int reserveSize, Palette reservePalette)
12305
return GetQuantizedInstance(algorithm, paletteSize, reserveSize, reservePalette.Data);
12309
/// Quantizes this <see cref="FreeImageBitmap"/> from 24 bit, using the specified
12310
/// <paramref name="algorithm"/> and up to <paramref name="reserveSize"/>
12311
/// entries from <paramref name="reservePalette">palette</paramref> initializing
12312
/// a new 8 bit instance with the specified <paramref name="paletteSize"/>.
12314
/// <param name="algorithm">The color reduction algorithm to be used.</param>
12315
/// <param name="paletteSize">Size of the desired output palette.</param>
12316
/// <param name="reserveSize">Size of the provided palette.</param>
12317
/// <param name="reservePalette">The provided palette.</param>
12318
/// <returns>The quantized instance.</returns>
12319
public FreeImageBitmap GetQuantizedInstance(FREE_IMAGE_QUANTIZE algorithm, int paletteSize, int reserveSize, RGBQUAD[] reservePalette)
12321
EnsureNotDisposed();
12322
FreeImageBitmap result = null;
12323
FIBITMAP newDib = FreeImage.ColorQuantizeEx(dib, algorithm, paletteSize, reserveSize, reservePalette);
12324
if (!newDib.IsNull)
12326
result = new FreeImageBitmap(newDib);
12332
/// Converts a High Dynamic Range image to a 24-bit RGB image using a global
12333
/// operator based on logarithmic compression of luminance values, imitating
12334
/// the human response to light.
12336
/// <param name="gamma">A gamma correction that is applied after the tone mapping.
12337
/// A value of 1 means no correction.</param>
12338
/// <param name="exposure">Scale factor allowing to adjust the brightness of the output image.</param>
12339
/// <returns>Returns true on success, false on failure.</returns>
12340
public bool TmoDrago03(double gamma, double exposure)
12342
EnsureNotDisposed();
12343
return ReplaceDib(FreeImage.TmoDrago03(dib, gamma, exposure));
12347
/// Converts a High Dynamic Range image to a 24-bit RGB image using a global operator inspired
12348
/// by photoreceptor physiology of the human visual system.
12350
/// <param name="intensity">Controls the overall image intensity in the range [-8, 8].</param>
12351
/// <param name="contrast">Controls the overall image contrast in the range [0.3, 1.0[.</param>
12352
/// <returns>Returns true on success, false on failure.</returns>
12353
public bool TmoReinhard05(double intensity, double contrast)
12355
EnsureNotDisposed();
12356
return ReplaceDib(FreeImage.TmoReinhard05(dib, intensity, contrast));
12360
/// Apply the Gradient Domain High Dynamic Range Compression to a RGBF image and convert to 24-bit RGB.
12362
/// <param name="color_saturation">Color saturation (s parameter in the paper) in [0.4..0.6]</param>
12363
/// <param name="attenuation">Atenuation factor (beta parameter in the paper) in [0.8..0.9]</param>
12364
/// <returns>Returns true on success, false on failure.</returns>
12365
public bool TmoFattal02(double color_saturation, double attenuation)
12367
EnsureNotDisposed();
12368
return ReplaceDib(FreeImage.TmoFattal02(dib, color_saturation, attenuation));
12372
/// This method rotates a 1-, 4-, 8-bit greyscale or a 24-, 32-bit color image by means of 3 shears.
12373
/// For 1- and 4-bit images, rotation is limited to angles whose value is an integer
12374
/// multiple of 90.
12376
/// <param name="angle">The angle of rotation.</param>
12377
/// <returns>Returns true on success, false on failure.</returns>
12378
public bool Rotate(double angle)
12380
EnsureNotDisposed();
12381
bool result = false;
12382
if (ColorDepth == 4)
12384
result = ReplaceDib(FreeImage.Rotate4bit(dib, angle));
12388
result = ReplaceDib(FreeImage.Rotate(dib, angle));
12394
/// This method rotates a 1-, 4-, 8-bit greyscale or a 24-, 32-bit color image by means of 3 shears.
12395
/// For 1- and 4-bit images, rotation is limited to angles whose value is an integer
12396
/// multiple of 90.
12398
/// <typeparam name="T">The type of the color to use as background.</typeparam>
12399
/// <param name="angle">The angle of rotation.</param>
12400
/// <param name="backgroundColor">The color used used to fill the bitmap's background.</param>
12401
/// <returns>Returns true on success, false on failure.</returns>
12402
public bool Rotate<T>(double angle, T? backgroundColor) where T : struct
12404
EnsureNotDisposed();
12405
bool result = false;
12406
if (ColorDepth == 4)
12408
result = ReplaceDib(FreeImage.Rotate4bit(dib, angle));
12412
result = ReplaceDib(FreeImage.Rotate(dib, angle, backgroundColor));
12418
/// Rotates this <see cref="FreeImageBitmap"/> by the specified angle initializing a new instance.
12419
/// For 1- and 4-bit images, rotation is limited to angles whose value is an integer
12420
/// multiple of 90.
12422
/// <typeparam name="T">The type of the color to use as background.</typeparam>
12423
/// <param name="angle">The angle of rotation.</param>
12424
/// <param name="backgroundColor">The color used used to fill the bitmap's background.</param>
12425
/// <returns>The rotated instance.</returns>
12426
public FreeImageBitmap GetRotatedInstance<T>(double angle, T? backgroundColor) where T : struct
12428
EnsureNotDisposed();
12429
FreeImageBitmap result = null;
12431
if (ColorDepth == 4)
12433
newDib = FreeImage.Rotate4bit(dib, angle);
12437
newDib = FreeImage.Rotate(dib, angle, backgroundColor);
12439
if (!newDib.IsNull)
12441
result = new FreeImageBitmap(newDib);
12447
/// Rotates this <see cref="FreeImageBitmap"/> by the specified angle initializing a new instance.
12448
/// For 1- and 4-bit images, rotation is limited to angles whose value is an integer
12449
/// multiple of 90.
12451
/// <param name="angle">The angle of rotation.</param>
12452
/// <returns>The rotated instance.</returns>
12453
public FreeImageBitmap GetRotatedInstance(double angle)
12455
EnsureNotDisposed();
12456
FreeImageBitmap result = null;
12458
if (ColorDepth == 4)
12460
newDib = FreeImage.Rotate4bit(dib, angle);
12464
newDib = FreeImage.Rotate(dib, angle);
12466
if (!newDib.IsNull)
12468
result = new FreeImageBitmap(newDib);
12474
/// This method performs a rotation and / or translation of an 8-bit greyscale,
12475
/// 24- or 32-bit image, using a 3rd order (cubic) B-Spline.
12477
/// <param name="angle">The angle of rotation.</param>
12478
/// <param name="xShift">Horizontal image translation.</param>
12479
/// <param name="yShift">Vertical image translation.</param>
12480
/// <param name="xOrigin">Rotation center x-coordinate.</param>
12481
/// <param name="yOrigin">Rotation center y-coordinate.</param>
12482
/// <param name="useMask">When true the irrelevant part of the image is set to a black color,
12483
/// otherwise, a mirroring technique is used to fill irrelevant pixels.</param>
12484
/// <returns>Returns true on success, false on failure.</returns>
12485
public bool Rotate(double angle, double xShift, double yShift,
12486
double xOrigin, double yOrigin, bool useMask)
12488
EnsureNotDisposed();
12489
return ReplaceDib(FreeImage.RotateEx(dib, angle, xShift, yShift, xOrigin, yOrigin, useMask));
12493
/// This method performs a rotation and / or translation of an 8-bit greyscale,
12494
/// 24- or 32-bit image, using a 3rd order (cubic) B-Spline initializing a new instance.
12496
/// <param name="angle">The angle of rotation.</param>
12497
/// <param name="xShift">Horizontal image translation.</param>
12498
/// <param name="yShift">Vertical image translation.</param>
12499
/// <param name="xOrigin">Rotation center x-coordinate.</param>
12500
/// <param name="yOrigin">Rotation center y-coordinate.</param>
12501
/// <param name="useMask">When true the irrelevant part of the image is set to a black color,
12502
/// otherwise, a mirroring technique is used to fill irrelevant pixels.</param>
12503
/// <returns>The rotated instance.</returns>
12504
public FreeImageBitmap GetRotatedInstance(double angle, double xShift, double yShift,
12505
double xOrigin, double yOrigin, bool useMask)
12507
EnsureNotDisposed();
12508
FreeImageBitmap result = null;
12509
FIBITMAP newDib = FreeImage.RotateEx(
12510
dib, angle, xShift, yShift, xOrigin, yOrigin, useMask);
12511
if (!newDib.IsNull)
12513
result = new FreeImageBitmap(newDib);
12519
/// Perfoms an histogram transformation on a 8-, 24- or 32-bit image.
12521
/// <param name="lookUpTable">The lookup table (LUT).
12522
/// It's size is assumed to be 256 in length.</param>
12523
/// <param name="channel">The color channel to be transformed.</param>
12524
/// <returns>Returns true on success, false on failure.</returns>
12525
public bool AdjustCurve(byte[] lookUpTable, FREE_IMAGE_COLOR_CHANNEL channel)
12527
EnsureNotDisposed();
12528
return FreeImage.AdjustCurve(dib, lookUpTable, channel);
12532
/// Performs gamma correction on a 8-, 24- or 32-bit image.
12534
/// <param name="gamma">The parameter represents the gamma value to use (gamma > 0).
12535
/// A value of 1.0 leaves the image alone, less than one darkens it, and greater than one lightens it.</param>
12536
/// <returns>Returns true on success, false on failure.</returns>
12537
public bool AdjustGamma(double gamma)
12539
EnsureNotDisposed();
12540
return FreeImage.AdjustGamma(dib, gamma);
12544
/// Adjusts the brightness of a 8-, 24- or 32-bit image by a certain amount.
12546
/// <param name="percentage">A value 0 means no change,
12547
/// less than 0 will make the image darker and greater than 0 will make the image brighter.</param>
12548
/// <returns>Returns true on success, false on failure.</returns>
12549
public bool AdjustBrightness(double percentage)
12551
EnsureNotDisposed();
12552
return FreeImage.AdjustBrightness(dib, percentage);
12556
/// Adjusts the contrast of a 8-, 24- or 32-bit image by a certain amount.
12558
/// <param name="percentage">A value 0 means no change,
12559
/// less than 0 will decrease the contrast and greater than 0 will increase the contrast of the image.</param>
12560
/// <returns>Returns true on success, false on failure.</returns>
12561
public bool AdjustContrast(double percentage)
12563
EnsureNotDisposed();
12564
return FreeImage.AdjustContrast(dib, percentage);
12568
/// Inverts each pixel data.
12570
/// <returns>Returns true on success, false on failure.</returns>
12571
public bool Invert()
12573
EnsureNotDisposed();
12574
return FreeImage.Invert(dib);
12578
/// Computes the image histogram.
12580
/// <param name="channel">Channel to compute from.</param>
12581
/// <param name="histogram">Array of integers containing the histogram.</param>
12582
/// <returns>Returns true on success, false on failure.</returns>
12583
public bool GetHistogram(FREE_IMAGE_COLOR_CHANNEL channel, out int[] histogram)
12585
EnsureNotDisposed();
12586
histogram = new int[256];
12587
return FreeImage.GetHistogram(dib, histogram, channel);
12591
/// Retrieves the red, green, blue or alpha channel of a 24- or 32-bit image.
12593
/// <param name="channel">The color channel to extract.</param>
12594
/// <returns>The color channel in a new instance.</returns>
12595
public FreeImageBitmap GetChannel(FREE_IMAGE_COLOR_CHANNEL channel)
12597
EnsureNotDisposed();
12598
FreeImageBitmap result = null;
12599
FIBITMAP newDib = FreeImage.GetChannel(dib, channel);
12600
if (!newDib.IsNull)
12602
result = new FreeImageBitmap(newDib);
12608
/// Insert a 8-bit dib into a 24- or 32-bit image.
12609
/// Both images must have to same width and height.
12611
/// <param name="bitmap">The <see cref="FreeImageBitmap"/> to insert.</param>
12612
/// <param name="channel">The color channel to replace.</param>
12613
/// <returns>Returns true on success, false on failure.</returns>
12614
public bool SetChannel(FreeImageBitmap bitmap, FREE_IMAGE_COLOR_CHANNEL channel)
12616
EnsureNotDisposed();
12617
bitmap.EnsureNotDisposed();
12618
return FreeImage.SetChannel(dib, bitmap.dib, channel);
12622
/// Retrieves the real part, imaginary part, magnitude or phase of a complex image.
12624
/// <param name="channel">The color channel to extract.</param>
12625
/// <returns>The color channel in a new instance.</returns>
12626
public FreeImageBitmap GetComplexChannel(FREE_IMAGE_COLOR_CHANNEL channel)
12628
EnsureNotDisposed();
12629
FreeImageBitmap result = null;
12630
FIBITMAP newDib = FreeImage.GetComplexChannel(dib, channel);
12631
if (!newDib.IsNull)
12633
result = new FreeImageBitmap(newDib);
12639
/// Set the real or imaginary part of a complex image.
12640
/// Both images must have to same width and height.
12642
/// <param name="bitmap">The <see cref="FreeImageBitmap"/> to insert.</param>
12643
/// <param name="channel">The color channel to replace.</param>
12644
/// <returns>Returns true on success, false on failure.</returns>
12645
public bool SetComplexChannel(FreeImageBitmap bitmap, FREE_IMAGE_COLOR_CHANNEL channel)
12647
EnsureNotDisposed();
12648
bitmap.EnsureNotDisposed();
12649
return FreeImage.SetComplexChannel(dib, bitmap.dib, channel);
12653
/// Copy a sub part of this <see cref="FreeImageBitmap"/>.
12655
/// <param name="rect">The subpart to copy.</param>
12656
/// <returns>The sub part in a new instance.</returns>
12657
public FreeImageBitmap Copy(Rectangle rect)
12659
EnsureNotDisposed();
12660
return Copy(rect.Left, rect.Top, rect.Right, rect.Bottom);
12664
/// Copy a sub part of this <see cref="FreeImageBitmap"/>.
12666
/// <param name="left">Specifies the left position of the cropped rectangle.</param>
12667
/// <param name="top">Specifies the top position of the cropped rectangle.</param>
12668
/// <param name="right">Specifies the right position of the cropped rectangle.</param>
12669
/// <param name="bottom">Specifies the bottom position of the cropped rectangle.</param>
12670
/// <returns>The sub part in a new instance.</returns>
12671
public FreeImageBitmap Copy(int left, int top, int right, int bottom)
12673
EnsureNotDisposed();
12674
FreeImageBitmap result = null;
12675
FIBITMAP newDib = FreeImage.Copy(dib, left, top, right, bottom);
12676
if (!newDib.IsNull)
12678
result = new FreeImageBitmap(newDib);
12684
/// Alpha blend or combine a sub part image with this <see cref="FreeImageBitmap"/>.
12685
/// The bit depth of <paramref name="bitmap"/> must be greater than or equal to the bit depth this instance.
12687
/// <param name="bitmap">The <see cref="FreeImageBitmap"/> to paste into this instance.</param>
12688
/// <param name="left">Specifies the left position of the sub image.</param>
12689
/// <param name="top">Specifies the top position of the sub image.</param>
12690
/// <param name="alpha">alpha blend factor.
12691
/// The source and destination images are alpha blended if alpha=0..255.
12692
/// If alpha > 255, then the source image is combined to the destination image.</param>
12693
/// <returns>Returns true on success, false on failure.</returns>
12694
public bool Paste(FreeImageBitmap bitmap, int left, int top, int alpha)
12696
EnsureNotDisposed();
12697
bitmap.EnsureNotDisposed();
12698
return FreeImage.Paste(dib, bitmap.dib, left, top, alpha);
12702
/// Alpha blend or combine a sub part image with tthis <see cref="FreeImageBitmap"/>.
12703
/// The bit depth of <paramref name="bitmap"/> must be greater than or equal to the bit depth this instance.
12705
/// <param name="bitmap">The <see cref="FreeImageBitmap"/> to paste into this instance.</param>
12706
/// <param name="point">Specifies the position of the sub image.</param>
12707
/// <param name="alpha">alpha blend factor.
12708
/// The source and destination images are alpha blended if alpha=0..255.
12709
/// If alpha > 255, then the source image is combined to the destination image.</param>
12710
/// <returns>Returns true on success, false on failure.</returns>
12711
public bool Paste(FreeImageBitmap bitmap, Point point, int alpha)
12713
EnsureNotDisposed();
12714
return Paste(bitmap, point.X, point.Y, alpha);
12718
/// This method composite a transparent foreground image against a single background color or
12719
/// against a background image.
12720
/// In case <paramref name="useBitmapBackground"/> is false and <paramref name="applicationBackground"/>
12721
/// and <paramref name="bitmapBackGround"/>
12722
/// are null, a checkerboard will be used as background.
12724
/// <param name="useBitmapBackground">When true the background of this instance is used
12725
/// if it contains one.</param>
12726
/// <param name="applicationBackground">Backgroundcolor used in case <paramref name="useBitmapBackground"/> is false
12727
/// and <paramref name="applicationBackground"/> is not null.</param>
12728
/// <param name="bitmapBackGround">Background used in case <paramref name="useBitmapBackground"/>
12729
/// is false and <paramref name="applicationBackground"/> is a null reference.</param>
12730
/// <returns>Returns true on success, false on failure.</returns>
12731
public bool Composite(bool useBitmapBackground, Color? applicationBackground, FreeImageBitmap bitmapBackGround)
12733
EnsureNotDisposed();
12734
bitmapBackGround.EnsureNotDisposed();
12735
RGBQUAD? rgb = applicationBackground;
12737
FreeImage.Composite(
12739
useBitmapBackground,
12740
rgb.HasValue ? new RGBQUAD[] { rgb.Value } : null,
12741
bitmapBackGround.dib));
12745
/// Applies the alpha value of each pixel to its color components.
12746
/// The aplha value stays unchanged.
12747
/// Only works with 32-bits color depth.
12749
/// <returns>Returns true on success, false on failure.</returns>
12750
public bool PreMultiplyWithAlpha()
12752
EnsureNotDisposed();
12753
return FreeImage.PreMultiplyWithAlpha(dib);
12757
/// Solves a Poisson equation, remap result pixels to [0..1] and returns the solution.
12759
/// <param name="ncycle">Number of cycles in the multigrid algorithm (usually 2 or 3)</param>
12760
/// <returns>Returns true on success, false on failure.</returns>
12761
public bool MultigridPoissonSolver(int ncycle)
12763
EnsureNotDisposed();
12764
return ReplaceDib(FreeImage.MultigridPoissonSolver(dib, ncycle));
12768
/// Adjusts an image's brightness, contrast and gamma as well as it may
12769
/// optionally invert the image within a single operation.
12771
/// <param name="brightness">Percentage brightness value where -100 <= brightness <= 100.
12772
/// <para>A value of 0 means no change, less than 0 will make the image darker and greater
12773
/// than 0 will make the image brighter.</para></param>
12774
/// <param name="contrast">Percentage contrast value where -100 <= contrast <= 100.
12775
/// <para>A value of 0 means no change, less than 0 will decrease the contrast
12776
/// and greater than 0 will increase the contrast of the image.</para></param>
12777
/// <param name="gamma">Gamma value to be used for gamma correction.
12778
/// <para>A value of 1.0 leaves the image alone, less than one darkens it,
12779
/// and greater than one lightens it.</para>
12780
/// This parameter must not be zero or smaller than zero.
12781
/// If so, it will be ignored and no gamma correction will be performed on the image.</param>
12782
/// <param name="invert">If set to true, the image will be inverted.</param>
12783
/// <returns>Returns true on success, false on failure.</returns>
12784
public bool AdjustColors(double brightness, double contrast, double gamma, bool invert)
12786
EnsureNotDisposed();
12787
return FreeImage.AdjustColors(dib, brightness, contrast, gamma, invert);
12791
/// Applies color mapping for one or several colors on a 1-, 4- or 8-bit
12792
/// palletized or a 16-, 24- or 32-bit high color image.
12794
/// <param name="srccolors">Array of colors to be used as the mapping source.</param>
12795
/// <param name="dstcolors">Array of colors to be used as the mapping destination.</param>
12796
/// <param name="ignore_alpha">If true, 32-bit images and colors are treated as 24-bit.</param>
12797
/// <param name="swap">If true, source and destination colors are swapped, that is,
12798
/// each destination color is also mapped to the corresponding source color.</param>
12799
/// <returns>The total number of pixels changed.</returns>
12800
/// <exception cref="ArgumentNullException">
12801
/// <paramref name="srccolors"/> or <paramref name="dstcolors"/> is a null reference.
12803
/// <exception cref="ArgumentException">
12804
/// <paramref name="srccolors"/> has a different length than <paramref name="dstcolors"/>.
12806
public uint ApplyColorMapping(RGBQUAD[] srccolors, RGBQUAD[] dstcolors, bool ignore_alpha, bool swap)
12808
EnsureNotDisposed();
12809
if (srccolors == null)
12811
throw new ArgumentNullException("srccolors");
12813
if (dstcolors == null)
12815
throw new ArgumentNullException("dstcolors");
12817
if (srccolors.Length != dstcolors.Length)
12819
throw new ArgumentException("srccolors and dstcolors must have the same length.");
12821
return FreeImage.ApplyColorMapping(dib, srccolors, dstcolors, (uint)srccolors.Length, ignore_alpha, swap);
12825
/// Swaps two specified colors on a 1-, 4- or 8-bit palletized
12826
/// or a 16-, 24- or 32-bit high color image.
12828
/// <param name="color_a">One of the two colors to be swapped.</param>
12829
/// <param name="color_b">The other of the two colors to be swapped.</param>
12830
/// <param name="ignore_alpha">If true, 32-bit images and colors are treated as 24-bit.</param>
12831
/// <returns>The total number of pixels changed.</returns>
12832
public uint SwapColors(RGBQUAD color_a, RGBQUAD color_b, bool ignore_alpha)
12834
EnsureNotDisposed();
12835
return FreeImage.SwapColors(dib, ref color_a, ref color_b, ignore_alpha);
12839
/// Applies palette index mapping for one or several indices
12840
/// on a 1-, 4- or 8-bit palletized image.
12842
/// <param name="srcindices">Array of palette indices to be used as the mapping source.</param>
12843
/// <param name="dstindices">Array of palette indices to be used as the mapping destination.</param>
12844
/// <param name="count">The number of palette indices to be mapped. This is the size of both
12845
/// srcindices and dstindices</param>
12846
/// <param name="swap">If true, source and destination palette indices are swapped, that is,
12847
/// each destination index is also mapped to the corresponding source index.</param>
12848
/// <returns>The total number of pixels changed.</returns>
12849
/// <exception cref="ArgumentNullException">
12850
/// <paramref name="srccolors"/> or <paramref name="dstcolors"/> is a null reference.
12852
/// <exception cref="ArgumentException">
12853
/// <paramref name="srccolors"/> has a different length than <paramref name="dstcolors"/>.
12855
public uint ApplyPaletteIndexMapping(byte[] srcindices, byte[] dstindices, uint count, bool swap)
12857
EnsureNotDisposed();
12858
if (srcindices == null)
12860
throw new ArgumentNullException("srcindices");
12862
if (dstindices == null)
12864
throw new ArgumentNullException("dstindices");
12866
if (srcindices.Length != dstindices.Length)
12868
throw new ArgumentException("srcindices and dstindices must have the same length.");
12870
return FreeImage.ApplyPaletteIndexMapping(dib, srcindices, dstindices, (uint)srcindices.Length, swap);
12874
/// Swaps two specified palette indices on a 1-, 4- or 8-bit palletized image.
12876
/// <param name="index_a">One of the two palette indices to be swapped.</param>
12877
/// <param name="index_b">The other of the two palette indices to be swapped.</param>
12878
/// <returns>The total number of pixels changed.</returns>
12879
public uint SwapPaletteIndices(byte index_a, byte index_b)
12881
EnsureNotDisposed();
12882
return FreeImage.SwapPaletteIndices(dib, ref index_a, ref index_b);
12886
/// Sets all pixels of this <see cref="FreeImageBitmap"/> to the specified color.
12887
/// See <see cref="FreeImage.FillBackground<T>"/> for further details.
12889
/// <typeparam name="T">The type of the specified color.</typeparam>
12890
/// <param name="color">The color to fill this <see cref="FreeImageBitmap"/> with.</param>
12891
/// <returns><c>true</c> on success, <c>false</c> on failure.</returns>
12892
public bool FillBackground<T>(T color) where T : struct
12894
return FillBackground(color, FREE_IMAGE_COLOR_OPTIONS.FICO_DEFAULT);
12898
/// Sets all pixels of this <see cref="FreeImageBitmap"/> to the specified color.
12899
/// See <see cref="FreeImage.FillBackground<T>"/> for further details.
12901
/// <typeparam name="T">The type of the specified color.</typeparam>
12902
/// <param name="color">The color to fill this <see cref="FreeImageBitmap"/> with.</param>
12903
/// <param name="options">Options that affect the color search process for palletized images.</param>
12904
/// <returns><c>true</c> on success, <c>false</c> on failure.</returns>
12905
public bool FillBackground<T>(T color, FREE_IMAGE_COLOR_OPTIONS options) where T : struct
12907
EnsureNotDisposed();
12908
return FreeImage.FillBackground(dib, color, options);
12912
/// Creates a new ICC-Profile.
12914
/// <param name="data">The data of the new ICC-Profile.</param>
12915
/// <returns>The new ICC-Profile of the bitmap.</returns>
12916
/// <exception cref="ArgumentNullException"><paramref name="data"/> is a null reference.</exception>
12917
public FIICCPROFILE CreateICCProfile(byte[] data)
12921
throw new ArgumentNullException("data");
12923
return CreateICCProfile(data, data.Length);
12927
/// Creates a new ICC-Profile.
12929
/// <param name="data">The data of the new ICC-Profile.</param>
12930
/// <param name="size">The number of bytes of <paramref name="data"/> to use.</param>
12931
/// <returns>The new ICC-Profile of the bitmap.</returns>
12932
/// <exception cref="ArgumentNullException"><paramref name="data"/> is null.</exception>
12933
public FIICCPROFILE CreateICCProfile(byte[] data, int size)
12935
EnsureNotDisposed();
12938
throw new ArgumentNullException("data");
12940
return FreeImage.CreateICCProfileEx(dib, data, size);
12944
/// Determines whether this and the specified instances are the same.
12946
/// <param name="obj">The object to test.</param>
12947
/// <returns><b>true</b> if this instance is the same <paramref name="obj"/>
12948
/// or if both are null references; otherwise, false.</returns>
12949
public override bool Equals(object obj)
12951
return ReferenceEquals(this, obj);
12955
/// Returns a hash code for this <see cref="FreeImageBitmap"/> structure.
12957
/// <returns>An integer value that specifies the hash code for this <see cref="FreeImageBitmap"/>.</returns>
12958
public override int GetHashCode()
12960
return dib.GetHashCode();
12965
#region Static functions
12968
/// Returns a value that indicates whether the pixel format for this <see cref="FreeImageBitmap"/> contains alpha information.
12970
/// <param name="pixfmt">The <see cref="System.Drawing.Imaging.PixelFormat"/> to test.</param>
12971
/// <returns><b>true</b> if pixfmt contains alpha information; otherwise, <b>false</b>.</returns>
12972
public static bool IsAlphaPixelFormat(PixelFormat pixfmt)
12974
return Bitmap.IsAlphaPixelFormat(pixfmt);
12978
/// Returns a value that indicates whether the pixel format is 32 bits per pixel.
12980
/// <param name="pixfmt">The <see cref="System.Drawing.Imaging.PixelFormat"/> to test.</param>
12981
/// <returns>true if pixfmt is canonical; otherwise, false.</returns>
12982
public static bool IsCanonicalPixelFormat(PixelFormat pixfmt)
12984
return Bitmap.IsCanonicalPixelFormat(pixfmt);
12988
/// Returns a value that indicates whether the pixel format is 64 bits per pixel.
12990
/// <param name="pixfmt">The <see cref="System.Drawing.Imaging.PixelFormat"/> enumeration to test.</param>
12991
/// <returns>true if pixfmt is extended; otherwise, false.</returns>
12992
public static bool IsExtendedPixelFormat(PixelFormat pixfmt)
12994
return Bitmap.IsExtendedPixelFormat(pixfmt);
12998
/// Creates a <see cref="FreeImageBitmap"/> from a Windows handle to an icon.
13000
/// <param name="hicon">A handle to an icon.</param>
13001
/// <returns>The <see cref="FreeImageBitmap"/> that this method creates.</returns>
13002
public static FreeImageBitmap FromHicon(IntPtr hicon)
13004
using (Bitmap bitmap = Bitmap.FromHicon(hicon))
13006
return new FreeImageBitmap(bitmap);
13011
/// Creates a <see cref="FreeImageBitmap"/> from the specified Windows resource.
13013
/// <param name="hinstance">A handle to an instance of the executable
13014
/// file that contains the resource.</param>
13015
/// <param name="bitmapName">A string containing the name of the resource bitmap.</param>
13016
/// <returns>The <see cref="FreeImageBitmap"/> that this method creates.</returns>
13017
public static FreeImageBitmap FromResource(IntPtr hinstance, string bitmapName)
13019
using (Bitmap bitmap = Bitmap.FromResource(hinstance, bitmapName))
13021
return new FreeImageBitmap(bitmap);
13026
/// Creates a <see cref="FreeImageBitmap"/> from the specified file.
13028
/// <param name="filename">A string that contains the name of the file
13029
/// from which to create the <see cref="FreeImageBitmap"/>.</param>
13030
/// <returns>The <see cref="FreeImageBitmap"/> this method creates.</returns>
13031
public static FreeImageBitmap FromFile(string filename)
13033
return new FreeImageBitmap(filename);
13037
/// Creates a <see cref="FreeImageBitmap"/> from the specified file
13038
/// using embedded color management information in that file.
13040
/// <param name="filename">A string that contains the
13041
/// name of the file from which to create the <see cref="FreeImageBitmap"/>.</param>
13042
/// <param name="useEmbeddedColorManagement">Ignored.</param>
13043
/// <returns>The <see cref="FreeImageBitmap"/> this method creates.</returns>
13044
public static FreeImageBitmap FromFile(string filename, bool useEmbeddedColorManagement)
13046
return new FreeImageBitmap(filename);
13050
/// Creates a <see cref="FreeImageBitmap"/> from a handle to a GDI bitmap.
13052
/// <param name="hbitmap">The GDI bitmap handle from which to create the <see cref="FreeImageBitmap"/>.</param>
13053
/// <returns>The <see cref="FreeImageBitmap"/> this method creates.</returns>
13054
public static FreeImageBitmap FromHbitmap(IntPtr hbitmap)
13056
FreeImageBitmap result = null;
13057
FIBITMAP newDib = FreeImage.CreateFromHbitmap(hbitmap, IntPtr.Zero);
13058
if (!newDib.IsNull)
13060
result = new FreeImageBitmap(newDib);
13066
/// Creates a <see cref="FreeImageBitmap"/> from a handle to a GDI bitmap and a handle to a GDI palette.
13068
/// <param name="hbitmap">The GDI bitmap handle from which to create the <see cref="FreeImageBitmap"/>.</param>
13069
/// <param name="hpalette">Ignored.</param>
13070
/// <returns>The <see cref="FreeImageBitmap"/> this method creates.</returns>
13071
public static FreeImageBitmap FromHbitmap(IntPtr hbitmap, IntPtr hpalette)
13073
return FromHbitmap(hbitmap);
13077
/// Frees a bitmap handle.
13079
/// <param name="hbitmap">Handle to a bitmap.</param>
13080
/// <returns><b>true</b> on success, <b>false</b> on failure.</returns>
13081
public static bool FreeHbitmap(IntPtr hbitmap)
13083
return FreeImage.FreeHbitmap(hbitmap);
13087
/// Creates a <see cref="FreeImageBitmap"/> from the specified data stream.
13089
/// <param name="stream">A <see cref="Stream"/> that contains the data for this <see cref="FreeImageBitmap"/>.</param>
13090
/// <returns>The <see cref="FreeImageBitmap"/> this method creates.</returns>
13091
public static FreeImageBitmap FromStream(Stream stream)
13093
return new FreeImageBitmap(stream);
13097
/// Creates a <see cref="FreeImageBitmap"/> from the specified data stream.
13099
/// <param name="stream">A <see cref="Stream"/> that contains the data for this <see cref="FreeImageBitmap"/>.</param>
13100
/// <param name="useEmbeddedColorManagement">Ignored.</param>
13101
/// <returns>The <see cref="FreeImageBitmap"/> this method creates.</returns>
13102
public static FreeImageBitmap FromStream(Stream stream, bool useEmbeddedColorManagement)
13104
return new FreeImageBitmap(stream);
13108
/// Creates a <see cref="FreeImageBitmap"/> from the specified data stream.
13110
/// <param name="stream">A <see cref="Stream"/> that contains the data for this <see cref="FreeImageBitmap"/>.</param>
13111
/// <param name="useEmbeddedColorManagement">Ignored.</param>
13112
/// <param name="validateImageData">Ignored.</param>
13113
/// <returns>The <see cref="FreeImageBitmap"/> this method creates.</returns>
13114
public static FreeImageBitmap FromStream(Stream stream, bool useEmbeddedColorManagement, bool validateImageData)
13116
return new FreeImageBitmap(stream);
13120
/// Returns the color depth, in number of bits per pixel,
13121
/// of the specified pixel format.
13123
/// <param name="pixfmt">The <see cref="System.Drawing.Imaging.PixelFormat"/> member that specifies
13124
/// the format for which to find the size.</param>
13125
/// <returns>The color depth of the specified pixel format.</returns>
13126
public static int GetPixelFormatSize(PixelFormat pixfmt)
13128
return Bitmap.GetPixelFormatSize(pixfmt);
13132
/// Performs a lossless rotation or flipping on a JPEG file.
13134
/// <param name="source">Source file.</param>
13135
/// <param name="destination">Destination file; can be the source file; will be overwritten.</param>
13136
/// <param name="operation">The operation to apply.</param>
13137
/// <param name="perfect">To avoid lossy transformation, you can set the perfect parameter to true.</param>
13138
/// <returns>Returns true on success, false on failure.</returns>
13139
public static bool JPEGTransform(string source, string destination, FREE_IMAGE_JPEG_OPERATION operation, bool perfect)
13141
return FreeImage.JPEGTransform(source, destination, operation, perfect);
13145
/// Performs a lossless crop on a JPEG file.
13147
/// <param name="source">Source filename.</param>
13148
/// <param name="destination">Destination filename.</param>
13149
/// <param name="rect">Specifies the cropped rectangle.</param>
13150
/// <returns>Returns true on success, false on failure.</returns>
13151
/// <exception cref="ArgumentNullException">
13152
/// <paramref name="source"/> or <paramref name="destination"/> is null.
13154
/// <exception cref="FileNotFoundException">
13155
/// <paramref name="source"/> does not exist.
13157
public static bool JPEGCrop(string source, string destination, Rectangle rect)
13159
if (source == null)
13161
throw new ArgumentNullException("source");
13163
if (!File.Exists(source))
13165
throw new FileNotFoundException("source");
13167
if (destination == null)
13169
throw new ArgumentNullException("destination");
13171
return JPEGCrop(source, destination, rect.Left, rect.Top, rect.Right, rect.Bottom);
13175
/// Performs a lossless crop on a JPEG file.
13177
/// <param name="source">Source filename.</param>
13178
/// <param name="destination">Destination filename.</param>
13179
/// <param name="left">Specifies the left position of the cropped rectangle.</param>
13180
/// <param name="top">Specifies the top position of the cropped rectangle.</param>
13181
/// <param name="right">Specifies the right position of the cropped rectangle.</param>
13182
/// <param name="bottom">Specifies the bottom position of the cropped rectangle.</param>
13183
/// <returns>Returns true on success, false on failure.</returns>
13184
/// <exception cref="ArgumentNullException">
13185
/// <paramref name="source"/> or <paramref name="destination"/> is null.
13187
/// <exception cref="FileNotFoundException">
13188
/// <paramref name="source"/> does not exist.
13190
public static bool JPEGCrop(string source, string destination, int left, int top, int right, int bottom)
13192
if (source == null)
13194
throw new ArgumentNullException("source");
13196
if (!File.Exists(source))
13198
throw new FileNotFoundException("source");
13200
if (destination == null)
13202
throw new ArgumentNullException("destination");
13204
return FreeImage.JPEGCrop(source, destination, left, top, right, bottom);
13208
/// Converts a X11 color name into a corresponding RGB value.
13210
/// <param name="color">Name of the color to convert.</param>
13211
/// <param name="red">Red component.</param>
13212
/// <param name="green">Green component.</param>
13213
/// <param name="blue">Blue component.</param>
13214
/// <returns>Returns true on success, false on failure.</returns>
13215
/// <exception cref="ArgumentNullException"><paramref name="color"/> is null.</exception>
13216
public static bool LookupX11Color(string color, out byte red, out byte green, out byte blue)
13220
throw new ArgumentNullException("color");
13222
return FreeImage.LookupX11Color(color, out red, out green, out blue);
13226
/// Converts a SVG color name into a corresponding RGB value.
13228
/// <param name="color">Name of the color to convert.</param>
13229
/// <param name="red">Red component.</param>
13230
/// <param name="green">Green component.</param>
13231
/// <param name="blue">Blue component.</param>
13232
/// <returns>Returns true on success, false on failure.</returns>
13233
/// <exception cref="ArgumentNullException"><paramref name="color"/> is null.</exception>
13234
public static bool LookupSVGColor(string color, out byte red, out byte green, out byte blue)
13238
throw new ArgumentNullException("color");
13240
return FreeImage.LookupSVGColor(color, out red, out green, out blue);
13244
/// Creates a lookup table to be used with AdjustCurve() which
13245
/// may adjusts brightness and contrast, correct gamma and invert the image with a
13246
/// single call to AdjustCurve().
13248
/// <param name="lookUpTable">Output lookup table to be used with AdjustCurve().
13249
/// The size of <paramref name="lookUpTable"/> is assumed to be 256.</param>
13250
/// <param name="brightness">Percentage brightness value where -100 <= brightness <= 100.
13251
/// <para>A value of 0 means no change, less than 0 will make the image darker and greater
13252
/// than 0 will make the image brighter.</para></param>
13253
/// <param name="contrast">Percentage contrast value where -100 <= contrast <= 100.
13254
/// <para>A value of 0 means no change, less than 0 will decrease the contrast
13255
/// and greater than 0 will increase the contrast of the image.</para></param>
13256
/// <param name="gamma">Gamma value to be used for gamma correction.
13257
/// <para>A value of 1.0 leaves the image alone, less than one darkens it,
13258
/// and greater than one lightens it.</para></param>
13259
/// <param name="invert">If set to true, the image will be inverted.</param>
13260
/// <returns>The number of adjustments applied to the resulting lookup table
13261
/// compared to a blind lookup table.</returns>
13262
/// <exception cref="ArgumentNullException"><paramref name="lookUpTable"/> is null.</exception>
13263
/// <exception cref="ArgumentException"><paramref name="lookUpTable.Length"/> is not 256.</exception>
13264
public static int GetAdjustColorsLookupTable(byte[] lookUpTable, double brightness, double contrast, double gamma, bool invert)
13266
if (lookUpTable == null)
13268
throw new ArgumentNullException("lookUpTable");
13270
if (lookUpTable.Length != 256)
13272
throw new ArgumentException("lookUpTable");
13274
return FreeImage.GetAdjustColorsLookupTable(lookUpTable, brightness, contrast, gamma, invert);
13278
/// Adds a specified frame to the file specified using the specified parameters.
13279
/// Use this method to save selected frames from an to a multiple-frame image.
13281
/// <param name="filename">File to add this frame to.</param>
13282
/// <param name="bitmap">A <see cref="FreeImageBitmap"/> that contains the frame to add.</param>
13283
/// <param name="format">Format of the image.</param>
13284
/// <param name="loadFlags">Flags to enable or disable plugin-features.</param>
13285
/// <param name="saveFlags">Flags to enable or disable plugin-features.</param>
13286
/// <exception cref="ArgumentNullException">
13287
/// <paramref name="filename"/> or <paramref name="bitmap"/> is null.
13289
/// <exception cref="FileNotFoundException"><paramref name="filename"/> does not exist.</exception>
13290
/// <exception cref="Exception">Saving the image failed.</exception>
13291
public static void SaveAdd(
13293
FreeImageBitmap bitmap,
13294
FREE_IMAGE_FORMAT format,
13295
FREE_IMAGE_LOAD_FLAGS loadFlags,
13296
FREE_IMAGE_SAVE_FLAGS saveFlags)
13298
if (filename == null)
13300
throw new ArgumentNullException("filename");
13302
if (!File.Exists(filename))
13304
throw new FileNotFoundException("filename");
13306
if (bitmap == null)
13308
throw new ArgumentNullException("bitmap");
13310
bitmap.EnsureNotDisposed();
13312
FIBITMAP dib = bitmap.dib;
13314
throw new ArgumentNullException("bitmap");
13316
FIMULTIBITMAP mpBitmap =
13317
FreeImage.OpenMultiBitmapEx(filename, ref format, loadFlags, false, false, true);
13319
if (mpBitmap.IsNull)
13320
throw new Exception(ErrorLoadingBitmap);
13322
FreeImage.AppendPage(mpBitmap, bitmap.dib);
13324
if (!FreeImage.CloseMultiBitmap(mpBitmap, saveFlags))
13325
throw new Exception(ErrorUnloadBitmap);
13329
/// Adds a specified frame to the file specified using the specified parameters.
13330
/// Use this method to save selected frames from an image to a multiple-frame image.
13332
/// <param name="filename">File to add this frame to.</param>
13333
/// <param name="bitmap">A <see cref="FreeImageBitmap"/> that contains the frame to add.</param>
13334
/// <param name="insertPosition">The position of the inserted frame.</param>
13335
/// <param name="format">Format of the image.</param>
13336
/// <param name="loadFlags">Flags to enable or disable plugin-features.</param>
13337
/// <param name="saveFlags">Flags to enable or disable plugin-features.</param>
13338
/// <exception cref="ArgumentNullException">
13339
/// <paramref name="filename"/> or <paramref name="bitmap"/> is null.
13341
/// <exception cref="FileNotFoundException"><paramref name="filename"/> does not exist.</exception>
13342
/// <exception cref="Exception">Saving the image failed.</exception>
13343
/// <exception cref="ArgumentOutOfRangeException"><paramref name="insertPosition"/> is out of range.</exception>
13344
public static void SaveAdd(
13346
FreeImageBitmap bitmap,
13347
int insertPosition,
13348
FREE_IMAGE_FORMAT format,
13349
FREE_IMAGE_LOAD_FLAGS loadFlags,
13350
FREE_IMAGE_SAVE_FLAGS saveFlags)
13352
if (filename == null)
13354
throw new ArgumentNullException("filename");
13356
if (!File.Exists(filename))
13358
throw new FileNotFoundException("filename");
13360
if (bitmap == null)
13362
throw new ArgumentNullException("bitmap");
13364
if (insertPosition < 0)
13366
throw new ArgumentOutOfRangeException("insertPosition");
13368
bitmap.EnsureNotDisposed();
13370
FIBITMAP dib = bitmap.dib;
13372
throw new ArgumentNullException("bitmap");
13374
FIMULTIBITMAP mpBitmap =
13375
FreeImage.OpenMultiBitmapEx(filename, ref format, loadFlags, false, false, true);
13377
if (mpBitmap.IsNull)
13378
throw new Exception(ErrorLoadingBitmap);
13380
int pageCount = FreeImage.GetPageCount(mpBitmap);
13382
if (insertPosition > pageCount)
13383
throw new ArgumentOutOfRangeException("insertPosition");
13385
if (insertPosition == pageCount)
13386
FreeImage.AppendPage(mpBitmap, bitmap.dib);
13388
FreeImage.InsertPage(mpBitmap, insertPosition, bitmap.dib);
13390
if (!FreeImage.CloseMultiBitmap(mpBitmap, saveFlags))
13391
throw new Exception(ErrorUnloadBitmap);
13395
/// Returns a new instance of the <see cref="PropertyItem"/> class which
13396
/// has no public accessible constructor.
13398
/// <returns>A new instace of <see cref="PropertyItem"/>.</returns>
13399
public static PropertyItem CreateNewPropertyItem()
13401
return FreeImage.CreatePropertyItem();
13406
#region Helper functions
13409
/// Throws an exception in case the instance has already been disposed.
13411
private void EnsureNotDisposed()
13415
if (!this.disposed)
13420
throw new ObjectDisposedException(ToString());
13424
/// Tries to replace the wrapped <see cref="FIBITMAP"/> with a new one.
13425
/// In case the new dib is null or the same as the already
13426
/// wrapped one, nothing will be changed and the result will
13428
/// Otherwise the wrapped <see cref="FIBITMAP"/> will be unloaded and replaced.
13430
/// <param name="newDib">The new dib.</param>
13431
/// <returns>Returns true on success, false on failure.</returns>
13432
private bool ReplaceDib(FIBITMAP newDib)
13434
bool result = false;
13435
if ((dib != newDib) && (!newDib.IsNull))
13439
AddMemoryPressure();
13446
/// Unloads currently wrapped <see cref="FIBITMAP"/> or unlocks the locked page
13447
/// in case it came from a multipaged bitmap.
13449
private void UnloadDib()
13453
long size = FreeImage.GetDIBSize(dib);
13454
FreeImage.UnloadEx(ref dib);
13456
GC.RemoveMemoryPressure(size);
13461
/// Informs the runtime about unmanaged allocoted memory.
13463
private void AddMemoryPressure()
13466
if ((dataSize = DataSize) > 0L)
13467
GC.AddMemoryPressure(dataSize);
13471
/// Opens the stream and reads the number of available pages.
13472
/// Then loads the first page to this instance.
13474
private void LoadFromStream(Stream stream, FREE_IMAGE_FORMAT format, FREE_IMAGE_LOAD_FLAGS flags)
13476
FIMULTIBITMAP mdib = FreeImage.OpenMultiBitmapFromStream(stream, ref format, flags);
13479
throw new Exception(ErrorLoadingBitmap);
13483
frameCount = FreeImage.GetPageCount(mdib);
13487
if (!FreeImage.CloseMultiBitmapEx(ref mdib))
13489
throw new Exception(ErrorUnloadBitmap);
13493
dib = FreeImage.LoadFromStream(stream, flags, ref format);
13496
throw new Exception(ErrorLoadingBitmap);
13499
saveInformation.loadFlags = flags;
13500
originalFormat = format;
13501
AddMemoryPressure();
13509
/// Helper class to store informations for <see cref="FreeImageBitmap.SaveAdd()"/>.
13511
private sealed class SaveInformation : ICloneable
13513
public string filename;
13514
public FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN;
13515
public FREE_IMAGE_LOAD_FLAGS loadFlags = FREE_IMAGE_LOAD_FLAGS.DEFAULT;
13516
public FREE_IMAGE_SAVE_FLAGS saveFlags = FREE_IMAGE_SAVE_FLAGS.DEFAULT;
13518
public object Clone()
13520
return base.MemberwiseClone();
13525
/// Creates a deep copy of this <see cref="FreeImageBitmap"/>.
13527
/// <returns>A deep copy of this <see cref="FreeImageBitmap"/>.</returns>
13528
public object Clone()
13530
EnsureNotDisposed();
13531
FreeImageBitmap result = null;
13532
FIBITMAP newDib = FreeImage.Clone(dib);
13535
result = new FreeImageBitmap(newDib);
13536
result.saveInformation = (SaveInformation)saveInformation.Clone();
13538
result.originalFormat = originalFormat;
13544
/// Performs application-defined tasks associated with freeing,
13545
/// releasing, or resetting unmanaged resources.
13547
public void Dispose()
13550
GC.SuppressFinalize(this);
13554
/// Performs application-defined tasks associated with freeing,
13555
/// releasing, or resetting unmanaged resources.
13557
/// <param name="disposing">If true managed ressources are released.</param>
13558
protected virtual void Dispose(bool disposing)
13560
// Only clean up once
13570
// Clean up managed resources
13573
if (stream != null)
13584
saveInformation = null;
13586
// Clean up unmanaged resources
13591
/// Retrieves an object that can iterate through the individual scanlines in this <see cref="FreeImageBitmap"/>.
13593
/// <returns>An <see cref="IEnumerator"/> for the <see cref="FreeImageBitmap"/>.</returns>
13594
/// <exception cref="ArgumentException">The bitmaps's type is not supported.</exception>
13595
IEnumerator IEnumerable.GetEnumerator()
13597
return GetScanlines().GetEnumerator();
13600
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
13602
EnsureNotDisposed();
13603
using (MemoryStream memory = new MemoryStream(DataSize))
13605
if (!FreeImage.SaveToStream(dib, memory, FREE_IMAGE_FORMAT.FIF_TIFF, FREE_IMAGE_SAVE_FLAGS.TIFF_LZW))
13607
throw new SerializationException();
13609
memory.Capacity = (int)memory.Length;
13610
info.AddValue("Bitmap Data", memory.GetBuffer());
13618
namespace FreeImageAPI
13621
/// Class handling non-bitmap related functions.
13623
public static class FreeImageEngine
13627
// Callback delegate
13628
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
13629
private static readonly OutputMessageFunction outputMessageFunction;
13631
static FreeImageEngine()
13633
// Check if FreeImage.dll is present and cancel setting the callbackfuntion if not
13638
// Create a delegate (function pointer) to 'OnMessage'
13639
outputMessageFunction = new OutputMessageFunction(OnMessage);
13640
// Set the callback
13641
FreeImage.SetOutputMessage(outputMessageFunction);
13645
/// Internal callback
13647
private static void OnMessage(FREE_IMAGE_FORMAT fif, string message)
13649
// Get a local copy of the multicast-delegate
13650
OutputMessageFunction m = Message;
13652
// Check the local copy instead of the static instance
13653
// to prevent a second thread from setting the delegate
13654
// to null, which would cause a nullreference exception
13657
// Invoke the multicast-delegate
13658
m.Invoke(fif, message);
13663
/// Gets a value indicating if the FreeImage DLL is available or not.
13665
public static bool IsAvailable
13669
return FreeImage.IsAvailable();
13674
/// Internal errors in FreeImage generate a logstring that can be
13675
/// captured by this event.
13677
public static event OutputMessageFunction Message;
13682
/// Gets a string containing the current version of the library.
13684
public static string Version
13688
return FreeImage.GetVersion();
13693
/// Gets a string containing a standard copyright message.
13695
public static string CopyrightMessage
13699
return FreeImage.GetCopyrightMessage();
13704
/// Gets whether the platform is using Little Endian.
13706
public static bool IsLittleEndian
13710
return FreeImage.IsLittleEndian();
13716
namespace FreeImageAPI.Plugins
13719
/// Class representing a FreeImage format.
13721
public sealed class FreeImagePlugin
13723
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
13724
private readonly FREE_IMAGE_FORMAT fif;
13727
/// Initializes a new instance of this class.
13729
/// <param name="fif">The FreeImage format to wrap.</param>
13730
internal FreeImagePlugin(FREE_IMAGE_FORMAT fif)
13736
/// Gets the format of this instance.
13738
public FREE_IMAGE_FORMAT FIFormat
13747
/// Gets or sets whether this plugin is enabled.
13749
public bool Enabled
13753
return (FreeImage.IsPluginEnabled(fif) == 1);
13757
FreeImage.SetPluginEnabled(fif, value);
13762
/// Gets a string describing the format.
13764
public string Format
13768
return FreeImage.GetFormatFromFIF(fif);
13773
/// Gets a comma-delimited file extension list describing the bitmap formats
13774
/// this plugin can read and/or write.
13776
public string ExtentsionList
13780
return FreeImage.GetFIFExtensionList(fif);
13785
/// Gets a descriptive string that describes the bitmap formats
13786
/// this plugin can read and/or write.
13788
public string Description
13792
return FreeImage.GetFIFDescription(fif);
13797
/// Returns a regular expression string that can be used by
13798
/// a regular expression engine to identify the bitmap.
13799
/// FreeImageQt makes use of this function.
13801
public string RegExpr
13805
return FreeImage.GetFIFRegExpr(fif);
13810
/// Gets whether this plugin can load bitmaps.
13812
public bool SupportsReading
13816
return FreeImage.FIFSupportsReading(fif);
13821
/// Gets whether this plugin can save bitmaps.
13823
public bool SupportsWriting
13827
return FreeImage.FIFSupportsWriting(fif);
13832
/// Checks whether this plugin can save a bitmap in the desired data type.
13834
/// <param name="type">The desired image type.</param>
13835
/// <returns>True if this plugin can save bitmaps as the desired type, else false.</returns>
13836
public bool SupportsExportType(FREE_IMAGE_TYPE type)
13838
return FreeImage.FIFSupportsExportType(fif, type);
13842
/// Checks whether this plugin can save bitmaps in the desired bit depth.
13844
/// <param name="bpp">The desired bit depth.</param>
13845
/// <returns>True if this plugin can save bitmaps in the desired bit depth, else false.</returns>
13846
public bool SupportsExportBPP(int bpp)
13848
return FreeImage.FIFSupportsExportBPP(fif, bpp);
13852
/// Gets whether this plugin can load or save an ICC profile.
13854
public bool SupportsICCProfiles
13858
return FreeImage.FIFSupportsICCProfiles(fif);
13863
/// Checks whether an extension is valid for this format.
13865
/// <param name="extension">The desired extension.</param>
13866
/// <returns>True if the extension is valid for this format, false otherwise.</returns>
13867
public bool ValidExtension(string extension)
13869
return FreeImage.IsExtensionValidForFIF(fif, extension);
13873
/// Checks whether an extension is valid for this format.
13875
/// <param name="extension">The desired extension.</param>
13876
/// <param name="comparisonType">The string comparison type.</param>
13877
/// <returns>True if the extension is valid for this format, false otherwise.</returns>
13878
public bool ValidExtension(string extension, StringComparison comparisonType)
13880
return FreeImage.IsExtensionValidForFIF(fif, extension, comparisonType);
13884
/// Checks whether a filename is valid for this format.
13886
/// <param name="filename">The desired filename.</param>
13887
/// <returns>True if the filename is valid for this format, false otherwise.</returns>
13888
public bool ValidFilename(string filename)
13890
return FreeImage.IsFilenameValidForFIF(fif, filename);
13894
/// Checks whether a filename is valid for this format.
13896
/// <param name="filename">The desired filename.</param>
13897
/// <param name="comparisonType">The string comparison type.</param>
13898
/// <returns>True if the filename is valid for this format, false otherwise.</returns>
13899
public bool ValidFilename(string filename, StringComparison comparisonType)
13901
return FreeImage.IsFilenameValidForFIF(fif, filename, comparisonType);
13905
/// Gets a descriptive string that describes the bitmap formats
13906
/// this plugin can read and/or write.
13908
/// <returns>A descriptive string that describes the bitmap formats.</returns>
13909
public override string ToString()
13911
return Description;
13916
namespace FreeImageAPI.IO
13919
/// Internal class wrapping stream io functions.
13922
/// FreeImage can read files from a disk or a network drive but also allows the user to
13923
/// implement their own loading or saving functions to load them directly from an ftp or web
13924
/// server for example.
13926
/// In .NET streams are a common way to handle data. The <b>FreeImageStreamIO</b> class handles
13927
/// the loading and saving from and to streams. It implements the funtions FreeImage needs
13928
/// to load data from an an arbitrary source.
13930
/// The class is for internal use only.
13932
internal static class FreeImageStreamIO
13935
/// <see cref="FreeImageAPI.IO.FreeImageIO"/> structure that can be used to read from streams via
13936
/// <see cref="FreeImageAPI.FreeImage.LoadFromHandle(FREE_IMAGE_FORMAT, ref FreeImageIO, fi_handle, FREE_IMAGE_LOAD_FLAGS)"/>.
13938
public static readonly FreeImageIO io;
13941
/// Initializes a new instances which can be used to
13942
/// create a FreeImage compatible <see cref="FreeImageAPI.IO.FreeImageIO"/> structure.
13944
static FreeImageStreamIO()
13946
io.readProc = new ReadProc(streamRead);
13947
io.writeProc = new WriteProc(streamWrite);
13948
io.seekProc = new SeekProc(streamSeek);
13949
io.tellProc = new TellProc(streamTell);
13953
/// Reads the requested data from the stream and writes it to the given address.
13955
static unsafe uint streamRead(IntPtr buffer, uint size, uint count, fi_handle handle)
13957
Stream stream = handle.GetObject() as Stream;
13958
if ((stream == null) || (!stream.CanRead))
13962
uint readCount = 0;
13963
byte* ptr = (byte*)buffer;
13964
byte[] bufferTemp = new byte[size];
13966
while (readCount < count)
13968
read = stream.Read(bufferTemp, 0, (int)size);
13969
if (read != (int)size)
13971
stream.Seek(-read, SeekOrigin.Current);
13974
for (int i = 0; i < read; i++, ptr++)
13976
*ptr = bufferTemp[i];
13980
return (uint)readCount;
13984
/// Reads the given data and writes it into the stream.
13986
static unsafe uint streamWrite(IntPtr buffer, uint size, uint count, fi_handle handle)
13988
Stream stream = handle.GetObject() as Stream;
13989
if ((stream == null) || (!stream.CanWrite))
13993
uint writeCount = 0;
13994
byte[] bufferTemp = new byte[size];
13995
byte* ptr = (byte*)buffer;
13996
while (writeCount < count)
13998
for (int i = 0; i < size; i++, ptr++)
14000
bufferTemp[i] = *ptr;
14004
stream.Write(bufferTemp, 0, bufferTemp.Length);
14016
/// Moves the streams position.
14018
static int streamSeek(fi_handle handle, int offset, SeekOrigin origin)
14020
Stream stream = handle.GetObject() as Stream;
14021
if (stream == null)
14025
stream.Seek((long)offset, origin);
14030
/// Returns the streams current position
14032
static int streamTell(fi_handle handle)
14034
Stream stream = handle.GetObject() as Stream;
14035
if (stream == null)
14039
return (int)stream.Position;
14044
namespace FreeImageAPI.Metadata
14047
/// Provides additional information specific for GIF files. This class cannot be inherited.
14049
public class GifInformation : MDM_ANIMATION
14052
/// Initializes a new instance of the <see cref="GifInformation"/> class
14053
/// with the specified <see cref="FreeImageBitmap"/>.
14055
/// <param name="bitmap">A reference to a <see cref="FreeImageBitmap"/> instance.</param>
14056
public GifInformation(FreeImageBitmap bitmap)
14062
/// Gets or sets a value indicating whether this frame uses the
14063
/// GIF image's global palette. If set to <b>false</b>, this
14064
/// frame uses its local palette.
14067
/// <b>Handling of null values</b><para/>
14068
/// A null value indicates, that the corresponding metadata tag is not
14069
/// present in the metadata model.
14070
/// Setting this property's value to a non-null reference creates the
14071
/// metadata tag if necessary.
14072
/// Setting this property's value to a null reference deletes the
14073
/// metadata tag from the metadata model.
14075
public bool? UseGlobalPalette
14079
byte? useGlobalPalette = GetTagValue<byte>("NoLocalPalette");
14080
return useGlobalPalette.HasValue ? (useGlobalPalette.Value != 0) : default(bool?);
14085
if (value.HasValue)
14087
val = (byte)(value.Value ? 1 : 0);
14089
SetTagValue("NoLocalPalette", val);
14094
/// Creates a global palette for the GIF image, intialized with all entries of the
14095
/// current local palette.
14096
/// The property <see cref="UseGlobalPalette"/> will be set to <b>true</b> when
14097
/// invoking this method. This effectively enables the newly created global palette.
14099
/// <exception cref="InvalidOperationException">
14100
/// The image does not have a palette.
14102
public void CreateGlobalPalette()
14104
CreateGlobalPalette(new Palette(dib));
14108
/// Creates a global palette for the GIF image with the specified size, intialized
14109
/// with the first <paramref name="size"/> entries of the current local palette.
14110
/// The property <see cref="UseGlobalPalette"/> will be set to <b>true</b> when
14111
/// invoking this method. This effectively enables the newly created global palette.
14113
/// <param name="size">The size of the newly created global palette.</param>
14114
/// <exception cref="ArgumentNullException">
14115
/// <paramref name="palette"/> is a null reference.</exception>
14116
public void CreateGlobalPalette(int size)
14118
CreateGlobalPalette(new Palette(dib), size);
14122
/// Creates a global palette for the GIF image, intialized with the entries
14123
/// of the specified palette.
14124
/// The property <see cref="UseGlobalPalette"/> will be set to <b>true</b> when
14125
/// invoking this method. This effectively enables the newly created global palette.
14127
/// <param name="palette">The palette that contains the initial values for
14128
/// the newly created global palette.</param>
14129
/// <exception cref="ArgumentNullException">
14130
/// <paramref name="palette"/> is a null reference.</exception>
14131
public void CreateGlobalPalette(Palette palette)
14133
if (palette == null)
14135
throw new ArgumentNullException("palette");
14138
GlobalPalette = palette;
14139
UseGlobalPalette = true;
14143
/// Creates a global palette for the GIF image with the specified size, intialized
14144
/// with the first <paramref name="size"/> entries of the specified palette.
14145
/// The property <see cref="UseGlobalPalette"/> will be set to <b>true</b> when
14146
/// invoking this method. This effectively enables the newly created global palette.
14148
/// <param name="palette">The palette that contains the initial values for
14149
/// the newly created global palette.</param>
14150
/// <param name="size">The size of the newly created global palette.</param>
14151
/// <exception cref="ArgumentNullException">
14152
/// <paramref name="palette"/> is a null reference.</exception>
14153
public void CreateGlobalPalette(Palette palette, int size)
14155
if (palette == null)
14157
throw new ArgumentNullException("palette");
14161
throw new ArgumentOutOfRangeException("size");
14164
Palette pal = new Palette(size);
14165
pal.CopyFrom(palette);
14166
GlobalPalette = palette;
14167
UseGlobalPalette = true;
14172
namespace FreeImageAPI.Metadata
14175
/// Class handling metadata of a FreeImage bitmap.
14177
public class ImageMetadata : IEnumerable, IComparable, IComparable<ImageMetadata>
14179
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
14180
private readonly List<MetadataModel> data;
14181
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
14182
private readonly FIBITMAP dib;
14183
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
14184
private bool hideEmptyModels;
14187
/// Initializes a new instance based on the specified <see cref="FIBITMAP"/>,
14188
/// showing all known models.
14190
/// <param name="dib">Handle to a FreeImage bitmap.</param>
14191
public ImageMetadata(FIBITMAP dib) : this(dib, false) { }
14194
/// Initializes a new instance based on the specified <see cref="FIBITMAP"/>,
14195
/// showing or hiding empry models.
14197
/// <param name="dib">Handle to a FreeImage bitmap.</param>
14198
/// <param name="hideEmptyModels">When <b>true</b>, empty metadata models
14199
/// will be hidden until a tag to this model is added.</param>
14200
public ImageMetadata(FIBITMAP dib, bool hideEmptyModels)
14202
if (dib.IsNull) throw new ArgumentNullException("dib");
14203
data = new List<MetadataModel>(FreeImage.FREE_IMAGE_MDMODELS.Length);
14205
this.hideEmptyModels = hideEmptyModels;
14207
data.Add(new MDM_ANIMATION(dib));
14208
data.Add(new MDM_COMMENTS(dib));
14209
data.Add(new MDM_CUSTOM(dib));
14210
data.Add(new MDM_EXIF_EXIF(dib));
14211
data.Add(new MDM_EXIF_GPS(dib));
14212
data.Add(new MDM_INTEROP(dib));
14213
data.Add(new MDM_EXIF_MAIN(dib));
14214
data.Add(new MDM_MAKERNOTE(dib));
14215
data.Add(new MDM_GEOTIFF(dib));
14216
data.Add(new MDM_IPTC(dib));
14217
data.Add(new MDM_NODATA(dib));
14218
data.Add(new MDM_XMP(dib));
14222
/// Gets or sets the <see cref="MetadataModel"/> of the specified type.
14223
/// <para>In case the getter returns <c>null</c> the model is not contained
14224
/// by the list.</para>
14225
/// <para><c>null</c> can be used calling the setter to destroy the model.</para>
14227
/// <param name="model">Type of the model.</param>
14228
/// <returns>The <see cref="FreeImageAPI.Metadata.MetadataModel"/> object of the specified type.</returns>
14229
public MetadataModel this[FREE_IMAGE_MDMODEL model]
14233
for (int i = 0; i < data.Count; i++)
14235
if (data[i].Model == model)
14237
if (!data[i].Exists && hideEmptyModels)
14249
/// Gets or sets the <see cref="FreeImageAPI.Metadata.MetadataModel"/> at the specified index.
14250
/// <para>In case the getter returns <c>null</c> the model is not contained
14251
/// by the list.</para>
14252
/// <para><c>null</c> can be used calling the setter to destroy the model.</para>
14254
/// <param name="index">Index of the <see cref="FreeImageAPI.Metadata.MetadataModel"/> within
14255
/// this instance.</param>
14256
/// <returns>The <see cref="FreeImageAPI.Metadata.MetadataModel"/>
14257
/// object at the specified index.</returns>
14258
public MetadataModel this[int index]
14262
if (index < 0 || index >= data.Count)
14264
throw new ArgumentOutOfRangeException("index");
14266
return (hideEmptyModels && !data[index].Exists) ? null : data[index];
14271
/// Returns a list of all visible
14272
/// <see cref="FreeImageAPI.Metadata.MetadataModel">MetadataModels</see>.
14274
public List<MetadataModel> List
14278
if (hideEmptyModels)
14280
List<MetadataModel> result = new List<MetadataModel>();
14281
for (int i = 0; i < data.Count; i++)
14283
if (data[i].Exists)
14285
result.Add(data[i]);
14298
/// Adds new tag to the bitmap or updates its value in case it already exists.
14299
/// <see cref="FreeImageAPI.Metadata.MetadataTag.Key"/> will be used as key.
14301
/// <param name="tag">The tag to add or update.</param>
14302
/// <returns>Returns true on success, false on failure.</returns>
14303
/// <exception cref="ArgumentNullException">
14304
/// <paramref name="tag"/> is null.</exception>
14305
public bool AddTag(MetadataTag tag)
14307
for (int i = 0; i < data.Count; i++)
14309
if (tag.Model == data[i].Model)
14311
return data[i].AddTag(tag);
14318
/// Returns the number of visible
14319
/// <see cref="FreeImageAPI.Metadata.MetadataModel">MetadataModels</see>.
14325
if (hideEmptyModels)
14328
for (int i = 0; i < data.Count; i++)
14330
if (data[i].Exists)
14345
/// Gets or sets whether empty
14346
/// <see cref="FreeImageAPI.Metadata.MetadataModel">MetadataModels</see> are hidden.
14348
public bool HideEmptyModels
14352
return hideEmptyModels;
14356
hideEmptyModels = value;
14361
/// Retrieves an object that can iterate through the individual
14362
/// <see cref="FreeImageAPI.Metadata.MetadataModel">MetadataModels</see>
14363
/// in this <see cref="ImageMetadata"/>.
14365
/// <returns>An <see cref="IEnumerator"/> for this <see cref="ImageMetadata"/>.</returns>
14366
public IEnumerator GetEnumerator()
14368
if (hideEmptyModels)
14370
List<MetadataModel> tempList = new List<MetadataModel>(data.Count);
14371
for (int i = 0; i < data.Count; i++)
14373
if (data[i].Exists)
14375
tempList.Add(data[i]);
14378
return tempList.GetEnumerator();
14382
return data.GetEnumerator();
14387
/// Compares this instance with a specified <see cref="Object"/>.
14389
/// <param name="obj">An object to compare with this instance.</param>
14390
/// <returns>A 32-bit signed integer indicating the lexical relationship between the two comparands.</returns>
14391
/// <exception cref="ArgumentException"><paramref name="obj"/> is not a <see cref="ImageMetadata"/>.</exception>
14392
public int CompareTo(object obj)
14398
if (!(obj is ImageMetadata))
14400
throw new ArgumentException("obj");
14402
return CompareTo((ImageMetadata)obj);
14406
/// Compares this instance with a specified <see cref="ImageMetadata"/> object.
14408
/// <param name="other">A <see cref="ImageMetadata"/> to compare.</param>
14409
/// <returns>A signed number indicating the relative values of this instance
14410
/// and <paramref name="other"/>.</returns>
14411
public int CompareTo(ImageMetadata other)
14413
return this.dib.CompareTo(other.dib);
14418
namespace FreeImageAPI.Plugins
14421
/// Class representing own FreeImage-Plugins.
14424
/// FreeImages itself is plugin based. Each supported format is integrated by a seperat plugin,
14425
/// that handles loading, saving, descriptions, identifing ect.
14426
/// And of course the user can create own plugins and use them in FreeImage.
14427
/// To do that the above mentioned predefined methodes need to be implemented.
14429
/// The class below handles the creation of such a plugin. The class itself is abstract
14430
/// as well as some core functions that need to be implemented.
14431
/// The class can be used to enable or disable the plugin in FreeImage after regististration or
14432
/// retrieve the formatid, assigned by FreeImage.
14433
/// The class handles the callback functions, garbage collector and pointer operation to make
14434
/// the implementation as user friendly as possible.
14437
/// There are two functions that need to be implemented:
14438
/// <see cref="FreeImageAPI.Plugins.LocalPlugin.GetImplementedMethods"/> and
14439
/// <see cref="FreeImageAPI.Plugins.LocalPlugin.FormatProc"/>.
14440
/// <see cref="FreeImageAPI.Plugins.LocalPlugin.GetImplementedMethods"/> is used by the constructor
14441
/// of the abstract class. FreeImage wants a list of the implemented functions. Each function is
14442
/// represented by a function pointer (a .NET <see cref="System.Delegate"/>). In case a function
14443
/// is not implemented FreeImage receives an empty <b>delegate</b>). To tell the constructor
14444
/// which functions have been implemented the information is represented by a disjunction of
14445
/// <see cref="FreeImageAPI.Plugins.LocalPlugin.MethodFlags"/>.
14448
/// return MethodFlags.LoadProc | MethodFlags.SaveProc;
14450
/// The above statement means that LoadProc and SaveProc have been implemented by the user.
14451
/// Keep in mind, that each function has a standard implementation that has static return
14452
/// values that may cause errors if listed in
14453
/// <see cref="FreeImageAPI.Plugins.LocalPlugin.GetImplementedMethods"/> without a real implementation.
14455
/// <see cref="FreeImageAPI.Plugins.LocalPlugin.FormatProc"/> is used by some checks of FreeImage and
14456
/// must be implemented. <see cref="FreeImageAPI.Plugins.LocalPlugin.LoadProc"/> for example can be
14457
/// implemented if the plugin supports reading, but it doesn't have to, the plugin could only
14458
/// be used to save an already loaded bitmap in a special format.
14460
public abstract class LocalPlugin
14463
/// Struct containing function pointers.
14465
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
14466
private Plugin plugin;
14469
/// Delegate for register callback by FreeImage.
14471
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
14472
private InitProc initProc;
14475
/// The format id assiged to the plugin.
14477
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
14478
protected FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN;
14481
/// When true the plugin was registered successfully else false.
14483
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
14484
protected readonly bool registered = false;
14487
/// A copy of the functions used to register.
14489
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
14490
protected readonly MethodFlags implementedMethods;
14493
/// MethodFlags defines values to fill a bitfield telling which
14494
/// functions have been implemented by a plugin.
14497
protected enum MethodFlags
14500
/// No mothods implemented.
14505
/// DescriptionProc has been implemented.
14507
DescriptionProc = 0x1,
14510
/// ExtensionListProc has been implemented.
14512
ExtensionListProc = 0x2,
14515
/// RegExprProc has been implemented.
14520
/// OpenProc has been implemented.
14525
/// CloseProc has been implemented.
14530
/// PageCountProc has been implemented.
14532
PageCountProc = 0x20,
14535
/// PageCapabilityProc has been implemented.
14537
PageCapabilityProc = 0x40,
14540
/// LoadProc has been implemented.
14545
/// SaveProc has been implemented.
14550
/// ValidateProc has been implemented.
14552
ValidateProc = 0x200,
14555
/// MimeProc has been implemented.
14560
/// SupportsExportBPPProc has been implemented.
14562
SupportsExportBPPProc = 0x800,
14565
/// SupportsExportTypeProc has been implemented.
14567
SupportsExportTypeProc = 0x1000,
14570
/// SupportsICCProfilesProc has been implemented.
14572
SupportsICCProfilesProc = 0x2000
14575
// Functions that must be implemented.
14578
/// Function that returns a bitfield containing the
14579
/// implemented methods.
14581
/// <returns>Bitfield of the implemented methods.</returns>
14582
protected abstract MethodFlags GetImplementedMethods();
14585
/// Implementation of <b>FormatProc</b>
14587
/// <returns>A string containing the plugins format.</returns>
14588
protected abstract string FormatProc();
14590
// Functions that can be implemented.
14593
/// Function that can be implemented.
14595
protected virtual string DescriptionProc() { return ""; }
14597
/// Function that can be implemented.
14599
protected virtual string ExtensionListProc() { return ""; }
14601
/// Function that can be implemented.
14603
protected virtual string RegExprProc() { return ""; }
14605
/// Function that can be implemented.
14607
protected virtual IntPtr OpenProc(ref FreeImageIO io, fi_handle handle, bool read) { return IntPtr.Zero; }
14609
/// Function that can be implemented.
14611
protected virtual void CloseProc(ref FreeImageIO io, fi_handle handle, IntPtr data) { }
14613
/// Function that can be implemented.
14615
protected virtual int PageCountProc(ref FreeImageIO io, fi_handle handle, IntPtr data) { return 0; }
14617
/// Function that can be implemented.
14619
protected virtual int PageCapabilityProc(ref FreeImageIO io, fi_handle handle, IntPtr data) { return 0; }
14621
/// Function that can be implemented.
14623
protected virtual FIBITMAP LoadProc(ref FreeImageIO io, fi_handle handle, int page, int flags, IntPtr data) { return FIBITMAP.Zero; }
14625
/// Function that can be implemented.
14627
protected virtual bool SaveProc(ref FreeImageIO io, FIBITMAP dib, fi_handle handle, int page, int flags, IntPtr data) { return false; }
14629
/// Function that can be implemented.
14631
protected virtual bool ValidateProc(ref FreeImageIO io, fi_handle handle) { return false; }
14633
/// Function that can be implemented.
14635
protected virtual string MimeProc() { return ""; }
14637
/// Function that can be implemented.
14639
protected virtual bool SupportsExportBPPProc(int bpp) { return false; }
14641
/// Function that can be implemented.
14643
protected virtual bool SupportsExportTypeProc(FREE_IMAGE_TYPE type) { return false; }
14645
/// Function that can be implemented.
14647
protected virtual bool SupportsICCProfilesProc() { return false; }
14650
/// The constructor automatically registeres the plugin in FreeImage.
14651
/// To do this it prepares a FreeImage defined structure with function pointers
14652
/// to the implemented functions or null if not implemented.
14653
/// Before registing the functions they are pinned in memory so the garbage collector
14654
/// can't move them around in memory after we passed there addresses to FreeImage.
14656
public LocalPlugin()
14658
implementedMethods = GetImplementedMethods();
14660
if ((implementedMethods & MethodFlags.DescriptionProc) != 0)
14662
plugin.descriptionProc = new DescriptionProc(DescriptionProc);
14664
if ((implementedMethods & MethodFlags.ExtensionListProc) != 0)
14666
plugin.extensionListProc = new ExtensionListProc(ExtensionListProc);
14668
if ((implementedMethods & MethodFlags.RegExprProc) != 0)
14670
plugin.regExprProc = new RegExprProc(RegExprProc);
14672
if ((implementedMethods & MethodFlags.OpenProc) != 0)
14674
plugin.openProc = new OpenProc(OpenProc);
14676
if ((implementedMethods & MethodFlags.CloseProc) != 0)
14678
plugin.closeProc = new CloseProc(CloseProc);
14680
if ((implementedMethods & MethodFlags.PageCountProc) != 0)
14682
plugin.pageCountProc = new PageCountProc(PageCountProc);
14684
if ((implementedMethods & MethodFlags.PageCapabilityProc) != 0)
14686
plugin.pageCapabilityProc = new PageCapabilityProc(PageCapabilityProc);
14688
if ((implementedMethods & MethodFlags.LoadProc) != 0)
14690
plugin.loadProc = new LoadProc(LoadProc);
14692
if ((implementedMethods & MethodFlags.SaveProc) != 0)
14694
plugin.saveProc = new SaveProc(SaveProc);
14696
if ((implementedMethods & MethodFlags.ValidateProc) != 0)
14698
plugin.validateProc = new ValidateProc(ValidateProc);
14700
if ((implementedMethods & MethodFlags.MimeProc) != 0)
14702
plugin.mimeProc = new MimeProc(MimeProc);
14704
if ((implementedMethods & MethodFlags.SupportsExportBPPProc) != 0)
14706
plugin.supportsExportBPPProc = new SupportsExportBPPProc(SupportsExportBPPProc);
14708
if ((implementedMethods & MethodFlags.SupportsExportTypeProc) != 0)
14710
plugin.supportsExportTypeProc = new SupportsExportTypeProc(SupportsExportTypeProc);
14712
if ((implementedMethods & MethodFlags.SupportsICCProfilesProc) != 0)
14714
plugin.supportsICCProfilesProc = new SupportsICCProfilesProc(SupportsICCProfilesProc);
14717
// FormatProc is always implemented
14718
plugin.formatProc = new FormatProc(FormatProc);
14720
// InitProc is the register call back.
14721
initProc = new InitProc(RegisterProc);
14723
// Register the plugin. The result will be saved and can be accessed later.
14724
registered = FreeImage.RegisterLocalPlugin(initProc, null, null, null, null) != FREE_IMAGE_FORMAT.FIF_UNKNOWN;
14727
PluginRepository.RegisterLocalPlugin(this);
14731
private void RegisterProc(ref Plugin plugin, int format_id)
14733
// Copy the function pointers
14734
plugin = this.plugin;
14735
// Retrieve the format if assigned to this plugin by FreeImage.
14736
format = (FREE_IMAGE_FORMAT)format_id;
14740
/// Gets or sets if the plugin is enabled.
14742
public bool Enabled
14748
return (FreeImage.IsPluginEnabled(format) > 0);
14752
throw new ObjectDisposedException("plugin not registered");
14759
FreeImage.SetPluginEnabled(format, value);
14763
throw new ObjectDisposedException("plugin not registered");
14769
/// Gets if the plugin was registered successfully.
14771
public bool Registered
14773
get { return registered; }
14777
/// Gets the <see cref="FREE_IMAGE_FORMAT"/> FreeImage assigned to this plugin.
14779
public FREE_IMAGE_FORMAT Format
14788
/// Reads from an unmanaged stream.
14790
protected unsafe int Read(FreeImageIO io, fi_handle handle, uint size, uint count, ref byte[] buffer)
14792
fixed (byte* ptr = buffer)
14794
return (int)io.readProc(new IntPtr(ptr), size, count, handle);
14799
/// Reads a single byte from an unmanaged stream.
14801
protected unsafe int ReadByte(FreeImageIO io, fi_handle handle)
14804
return (int)io.readProc(new IntPtr(&buffer), 1, 1, handle) > 0 ? buffer : -1;
14808
/// Writes to an unmanaged stream.
14810
protected unsafe int Write(FreeImageIO io, fi_handle handle, uint size, uint count, ref byte[] buffer)
14812
fixed (byte* ptr = buffer)
14814
return (int)io.writeProc(new IntPtr(ptr), size, count, handle);
14819
/// Writes a single byte to an unmanaged stream.
14821
protected unsafe int WriteByte(FreeImageIO io, fi_handle handle, byte value)
14823
return (int)io.writeProc(new IntPtr(&value), 1, 1, handle);
14827
/// Seeks in an unmanaged stream.
14829
protected int Seek(FreeImageIO io, fi_handle handle, int offset, SeekOrigin origin)
14831
return io.seekProc(handle, offset, origin);
14835
/// Retrieves the position of an unmanaged stream.
14837
protected int Tell(FreeImageIO io, fi_handle handle)
14839
return io.tellProc(handle);
14844
namespace FreeImageAPI
14847
/// Represents unmanaged memory, containing an array of a given structure.
14849
/// <typeparam name="T">Structuretype represented by the instance.</typeparam>
14851
/// <see cref="System.Boolean"/> and <see cref="System.Char"/> can not be marshalled.
14853
/// Use <see cref="System.Int32"/> instead of <see cref="System.Boolean"/> and
14854
/// <see cref="System.Byte"/> instead of <see cref="System.Char"/>.
14856
public unsafe class MemoryArray<T> : IDisposable, ICloneable, ICollection, IEnumerable<T>, IEquatable<MemoryArray<T>> where T : struct
14859
/// Baseaddress of the wrapped memory.
14861
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
14862
protected byte* baseAddress;
14865
/// Number of elements being wrapped.
14867
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
14868
protected int length;
14871
/// Size, in bytes, of each element.
14873
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
14874
private static readonly int size;
14877
/// Array of <b>T</b> containing a single element.
14878
/// The array is used as a workaround, because there are no pointer for generic types.
14880
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
14881
protected T[] buffer;
14884
/// Pointer to the element of <b>buffer</b>.
14886
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
14887
protected byte* ptr;
14890
/// Handle for pinning <b>buffer</b>.
14892
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
14893
protected GCHandle handle;
14896
/// Indicates whether the wrapped memory is handled like a bitfield.
14898
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
14899
protected readonly bool isOneBit;
14902
/// Indicates whther the wrapped memory is handles like 4-bit blocks.
14904
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
14905
protected readonly bool isFourBit;
14908
/// An object that can be used to synchronize access to the <see cref="MemoryArray<T>"/>.
14910
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
14911
protected object syncRoot = null;
14913
static MemoryArray()
14915
T[] dummy = new T[2];
14916
long marshalledSize = Marshal.SizeOf(typeof(T));
14917
long structureSize =
14918
Marshal.UnsafeAddrOfPinnedArrayElement(dummy, 1).ToInt64() -
14919
Marshal.UnsafeAddrOfPinnedArrayElement(dummy, 0).ToInt64();
14920
if (marshalledSize != structureSize)
14922
throw new NotSupportedException(
14923
"The desired type can not be handled, " +
14924
"because its managed and unmanaged size in bytes are different.");
14927
size = (int)marshalledSize;
14931
/// Initializes a new instance.
14933
protected MemoryArray()
14938
/// Initializes a new instance of the <see cref="MemoryArray<T>"/> class.
14940
/// <param name="baseAddress">Address of the memory block.</param>
14941
/// <param name="length">Length of the array.</param>
14942
/// <exception cref="ArgumentNullException">
14943
/// <paramref name="baseAddress"/> is null.</exception>
14944
/// <exception cref="ArgumentOutOfRangeException">
14945
/// <paramref name="length"/> is less or equal zero.</exception>
14946
/// <exception cref="NotSupportedException">
14947
/// The type is not supported.</exception>
14948
public MemoryArray(IntPtr baseAddress, int length)
14949
: this(baseAddress.ToPointer(), length)
14954
/// Initializes a new instance of the <see cref="MemoryArray<T>"/> class.
14956
/// <param name="baseAddress">Address of the memory block.</param>
14957
/// <param name="length">Length of the array.</param>
14958
/// <exception cref="ArgumentNullException">
14959
/// <paramref name="baseAddress"/> is null.</exception>
14960
/// <exception cref="ArgumentOutOfRangeException">
14961
/// <paramref name="length"/> is less or equal zero.</exception>
14962
/// <exception cref="NotSupportedException">
14963
/// The type is not supported.</exception>
14964
public MemoryArray(void* baseAddress, int length)
14966
if (typeof(T) == typeof(FI1BIT))
14970
else if (typeof(T) == typeof(FI4BIT))
14975
if (baseAddress == null)
14977
throw new ArgumentNullException("baseAddress");
14981
throw new ArgumentOutOfRangeException("length");
14984
this.baseAddress = (byte*)baseAddress;
14985
this.length = (int)length;
14987
if (!isOneBit && !isFourBit)
14989
// Create an array containing a single element.
14990
// Due to the fact, that it's not possible to create pointers
14991
// of generic types, an array is used to obtain the memory
14992
// address of an element of T.
14993
this.buffer = new T[1];
14994
// The array is pinned immediately to prevent the GC from
14995
// moving it to a different position in memory.
14996
this.handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
14997
// The array and its content have beed pinned, so that its address
14998
// can be safely requested and stored for the whole lifetime
15000
this.ptr = (byte*)handle.AddrOfPinnedObject();
15005
/// Frees the allocated <see cref="System.Runtime.InteropServices.GCHandle"/>.
15013
/// Tests whether two specified <see cref="MemoryArray<T>"/> structures are equivalent.
15015
/// <param name="left">The <see cref="MemoryArray<T>"/> that is to the left of the equality operator.</param>
15016
/// <param name="right">The <see cref="MemoryArray<T>"/> that is to the right of the equality operator.</param>
15018
/// <b>true</b> if the two <see cref="MemoryArray<T>"/> structures are equal; otherwise, <b>false</b>.
15020
public static bool operator ==(MemoryArray<T> left, MemoryArray<T> right)
15022
if (object.ReferenceEquals(left, right))
15026
if (object.ReferenceEquals(right, null) ||
15027
object.ReferenceEquals(left, null) ||
15028
(left.length != right.length))
15032
if (left.baseAddress == right.baseAddress)
15036
return FreeImage.CompareMemory(left.baseAddress, right.baseAddress, (uint)left.length);
15040
/// Tests whether two specified <see cref="MemoryArray<T>"/> structures are different.
15042
/// <param name="left">The <see cref="MemoryArray<T>"/> that is to the left of the inequality operator.</param>
15043
/// <param name="right">The <see cref="MemoryArray<T>"/> that is to the right of the inequality operator.</param>
15045
/// <b>true</b> if the two <see cref="MemoryArray<T>"/> structures are different; otherwise, <b>false</b>.
15047
public static bool operator !=(MemoryArray<T> left, MemoryArray<T> right)
15049
return (!(left == right));
15053
/// Gets the value at the specified position.
15055
/// <param name="index">A 32-bit integer that represents the position
15056
/// of the array element to get.</param>
15057
/// <returns>The value at the specified position.</returns>
15058
/// <exception cref="ArgumentOutOfRangeException">
15059
/// <paramref name="index"/> is outside the range of valid indexes
15060
/// for the unmanaged array.</exception>
15061
public T GetValue(int index)
15063
if ((index >= this.length) || (index < 0))
15065
throw new ArgumentOutOfRangeException("index");
15068
return GetValueInternal(index);
15071
private T GetValueInternal(int index)
15073
EnsureNotDisposed();
15076
return (T)(object)(FI1BIT)(((baseAddress[index / 8] & ((1 << (7 - (index % 8))))) == 0) ? 0 : 1);
15078
else if (isFourBit)
15080
return (T)(object)(FI4BIT)(((index % 2) == 0) ? (baseAddress[index / 2] >> 4) : (baseAddress[index / 2] & 0x0F));
15084
CopyMemory(ptr, baseAddress + (index * size), size);
15090
/// Sets a value to the element at the specified position.
15092
/// <param name="value">The new value for the specified element.</param>
15093
/// <param name="index">A 32-bit integer that represents the
15094
/// position of the array element to set.</param>
15095
/// <exception cref="ArgumentOutOfRangeException">
15096
/// <paramref name="index"/> is outside the range of valid indexes
15097
/// for the unmanaged array.</exception>
15098
public void SetValue(T value, int index)
15100
if ((index >= this.length) || (index < 0))
15102
throw new ArgumentOutOfRangeException("index");
15104
SetValueInternal(value, index);
15107
private void SetValueInternal(T value, int index)
15109
EnsureNotDisposed();
15112
if ((FI1BIT)(object)value != 0)
15114
baseAddress[index / 8] |= (byte)(1 << (7 - (index % 8)));
15118
baseAddress[index / 8] &= (byte)(~(1 << (7 - (index % 8))));
15121
else if (isFourBit)
15123
if ((index % 2) == 0)
15125
baseAddress[index / 2] = (byte)((baseAddress[index / 2] & 0x0F) | ((FI4BIT)(object)value << 4));
15129
baseAddress[index / 2] = (byte)((baseAddress[index / 2] & 0xF0) | ((FI4BIT)(object)value & 0x0F));
15135
CopyMemory(baseAddress + (index * size), ptr, size);
15140
/// Gets the values at the specified position and length.
15142
/// <param name="index">A 32-bit integer that represents the position
15143
/// of the array elements to get.</param>
15144
/// <param name="length"> A 32-bit integer that represents the length
15145
/// of the array elements to get.</param>
15146
/// <returns>The values at the specified position and length.</returns>
15147
/// <exception cref="ArgumentOutOfRangeException">
15148
/// <paramref name="index"/> is outside the range of valid indexes
15149
/// for the unmanaged array or <paramref name="length"/> is greater than the number of elements
15150
/// from <paramref name="index"/> to the end of the unmanaged array.</exception>
15151
public T[] GetValues(int index, int length)
15153
EnsureNotDisposed();
15154
if ((index >= this.length) || (index < 0))
15156
throw new ArgumentOutOfRangeException("index");
15158
if (((index + length) > this.length) || (length < 1))
15160
throw new ArgumentOutOfRangeException("length");
15163
T[] data = new T[length];
15164
if (isOneBit || isFourBit)
15166
for (int i = 0; i < length; i++)
15168
data[i] = GetValueInternal(i);
15173
GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
15174
byte* dst = (byte*)Marshal.UnsafeAddrOfPinnedArrayElement(data, 0);
15175
CopyMemory(dst, baseAddress + (size * index), size * length);
15182
/// Sets the values at the specified position.
15184
/// <param name="values">An array containing the new values for the specified elements.</param>
15185
/// <param name="index">A 32-bit integer that represents the position
15186
/// of the array elements to set.</param>
15187
/// <exception cref="ArgumentNullException">
15188
/// <paramref name="values"/> is a null reference (Nothing in Visual Basic).</exception>
15189
/// <exception cref="ArgumentOutOfRangeException">
15190
/// <paramref name="index"/> is outside the range of valid indexes
15191
/// for the unmanaged array or <paramref name="values.Length"/> is greater than the number of elements
15192
/// from <paramref name="index"/> to the end of the array.</exception>
15193
public void SetValues(T[] values, int index)
15195
EnsureNotDisposed();
15196
if (values == null)
15198
throw new ArgumentNullException("values");
15200
if ((index >= this.length) || (index < 0))
15202
throw new ArgumentOutOfRangeException("index");
15204
if ((index + values.Length) > this.length)
15206
throw new ArgumentOutOfRangeException("values.Length");
15209
if (isOneBit || isFourBit)
15211
for (int i = 0; i != values.Length; )
15213
SetValueInternal(values[i++], index++);
15218
GCHandle handle = GCHandle.Alloc(values, GCHandleType.Pinned);
15219
byte* src = (byte*)Marshal.UnsafeAddrOfPinnedArrayElement(values, 0);
15220
CopyMemory(baseAddress + (index * size), src, size * length);
15226
/// Copies the entire array to a compatible one-dimensional <see cref="System.Array"/>,
15227
/// starting at the specified index of the target array.
15229
/// <param name="array">The one-dimensional <see cref="System.Array"/> that is the destination
15230
/// of the elements copied from <see cref="MemoryArray<T>"/>.
15231
/// The <see cref="System.Array"/> must have zero-based indexing.</param>
15232
/// <param name="index">The zero-based index in <paramref name="array"/>
15233
/// at which copying begins.</param>
15234
public void CopyTo(Array array, int index)
15236
EnsureNotDisposed();
15237
if (!(array is T[]))
15239
throw new InvalidCastException("array");
15243
CopyTo((T[])array, 0, index, length);
15245
catch (ArgumentOutOfRangeException ex)
15247
throw new ArgumentException(ex.Message, ex);
15252
/// Copies a range of elements from the unmanaged array starting at the specified
15253
/// <typeparamref name="sourceIndex"/> and pastes them to <paramref name="array"/>
15254
/// starting at the specified <paramref name="destinationIndex"/>.
15255
/// The length and the indexes are specified as 32-bit integers.
15257
/// <param name="array">The array that receives the data.</param>
15258
/// <param name="sourceIndex">A 32-bit integer that represents the index
15259
/// in the unmanaged array at which copying begins.</param>
15260
/// <param name="destinationIndex">A 32-bit integer that represents the index in
15261
/// the destination array at which storing begins.</param>
15262
/// <param name="length">A 32-bit integer that represents the number of elements to copy.</param>
15263
/// <exception cref="ArgumentNullException">
15264
/// <paramref name="array"/> is a null reference (Nothing in Visual Basic).</exception>
15265
/// <exception cref="ArgumentOutOfRangeException">
15266
/// <paramref name="sourceIndex"/> is outside the range of valid indexes
15267
/// for the unmanaged array or <paramref name="length"/> is greater than the number of elements
15268
/// from <paramref name="index"/> to the end of the unmanaged array
15269
/// <para>-or-</para>
15270
/// <paramref name="destinationIndex"/> is outside the range of valid indexes
15271
/// for the array or <paramref name="length"/> is greater than the number of elements
15272
/// from <paramref name="index"/> to the end of the array.
15274
public void CopyTo(T[] array, int sourceIndex, int destinationIndex, int length)
15276
EnsureNotDisposed();
15279
throw new ArgumentNullException("array");
15281
if ((sourceIndex >= this.length) || (sourceIndex < 0))
15283
throw new ArgumentOutOfRangeException("sourceIndex");
15285
if ((destinationIndex >= array.Length) || (destinationIndex < 0))
15287
throw new ArgumentOutOfRangeException("destinationIndex");
15289
if ((sourceIndex + length > this.length) ||
15290
(destinationIndex + length > array.Length) ||
15293
throw new ArgumentOutOfRangeException("length");
15296
if (isOneBit || isFourBit)
15298
for (int i = 0; i != length; i++)
15300
array[destinationIndex++] = GetValueInternal(sourceIndex++);
15305
GCHandle handle = GCHandle.Alloc(array, GCHandleType.Pinned);
15306
byte* dst = (byte*)Marshal.UnsafeAddrOfPinnedArrayElement(array, destinationIndex);
15307
CopyMemory(dst, baseAddress + (size * sourceIndex), size * length);
15313
/// Copies a range of elements from the array starting at the specified
15314
/// <typeparamref name="sourceIndex"/> and pastes them to the unmanaged array
15315
/// starting at the specified <paramref name="destinationIndex"/>.
15316
/// The length and the indexes are specified as 32-bit integers.
15318
/// <param name="array">The array that holds the data.</param>
15319
/// <param name="sourceIndex">A 32-bit integer that represents the index
15320
/// in the array at which copying begins.</param>
15321
/// <param name="destinationIndex">A 32-bit integer that represents the index in
15322
/// the unmanaged array at which storing begins.</param>
15323
/// <param name="length">A 32-bit integer that represents the number of elements to copy.</param>
15324
/// <exception cref="ArgumentNullException">
15325
/// <paramref name="array"/> is a null reference (Nothing in Visual Basic).</exception>
15326
/// <exception cref="ArgumentOutOfRangeException">
15327
/// <paramref name="sourceIndex"/> is outside the range of valid indexes
15328
/// for the array or <paramref name="length"/> is greater than the number of elements
15329
/// from <paramref name="index"/> to the end of the array
15330
/// <para>-or-</para>
15331
/// <paramref name="destinationIndex"/> is outside the range of valid indexes
15332
/// for the unmanaged array or <paramref name="length"/> is greater than the number of elements
15333
/// from <paramref name="index"/> to the end of the unmanaged array.
15335
public void CopyFrom(T[] array, int sourceIndex, int destinationIndex, int length)
15337
EnsureNotDisposed();
15340
throw new ArgumentNullException("array");
15342
if ((destinationIndex >= this.length) || (destinationIndex < 0))
15344
throw new ArgumentOutOfRangeException("destinationIndex");
15346
if ((sourceIndex >= array.Length) || (sourceIndex < 0))
15348
throw new ArgumentOutOfRangeException("sourceIndex");
15350
if ((destinationIndex + length > this.length) ||
15351
(sourceIndex + length > array.Length) ||
15354
throw new ArgumentOutOfRangeException("length");
15357
if (isOneBit || isFourBit)
15359
for (int i = 0; i != length; i++)
15361
SetValueInternal(array[sourceIndex++], destinationIndex++);
15366
GCHandle handle = GCHandle.Alloc(array, GCHandleType.Pinned);
15367
byte* src = (byte*)Marshal.UnsafeAddrOfPinnedArrayElement(array, sourceIndex);
15368
CopyMemory(baseAddress + (size * destinationIndex), src, size * length);
15374
/// Returns the represented block of memory as an array of <see cref="Byte"/>.
15376
/// <returns>The represented block of memory.</returns>
15377
public byte[] ToByteArray()
15379
EnsureNotDisposed();
15383
result = new byte[(length + 7) / 8];
15385
else if (isFourBit)
15387
result = new byte[(length + 3) / 4];
15391
result = new byte[size * length];
15393
fixed (byte* dst = result)
15395
CopyMemory(dst, baseAddress, result.Length);
15401
/// Gets or sets the value at the specified position in the array.
15403
/// <param name="index">A 32-bit integer that represents the position
15404
/// of the array element to get.</param>
15405
/// <returns>The value at the specified position in the array.</returns>
15406
/// <exception cref="ArgumentOutOfRangeException">
15407
/// <paramref name="index"/> is outside the range of valid indexes
15408
/// for the unmanaged array.</exception>
15409
public T this[int index]
15413
return GetValue(index);
15417
SetValue(value, index);
15422
/// Gets or sets the values of the unmanaged array.
15428
return GetValues(0, length);
15434
throw new ArgumentNullException("value");
15436
if (value.Length != length)
15438
throw new ArgumentOutOfRangeException("value.Lengt");
15440
SetValues(value, 0);
15445
/// Gets the length of the unmanaged array.
15451
EnsureNotDisposed();
15457
/// Gets the base address of the represented memory block.
15459
public IntPtr BaseAddress
15463
EnsureNotDisposed();
15464
return new IntPtr(baseAddress);
15469
/// Creates a shallow copy of the <see cref="MemoryArray<T>"/>.
15471
/// <returns>A shallow copy of the <see cref="MemoryArray<T>"/>.</returns>
15472
public object Clone()
15474
EnsureNotDisposed();
15475
return new MemoryArray<T>(baseAddress, length);
15479
/// Gets a 32-bit integer that represents the total number of elements
15480
/// in the <see cref="MemoryArray<T>"/>.
15484
get { EnsureNotDisposed(); return length; }
15488
/// Gets a value indicating whether access to the <see cref="MemoryArray<T>"/>
15489
/// is synchronized (thread safe).
15491
public bool IsSynchronized
15493
get { EnsureNotDisposed(); return false; }
15497
/// Gets an object that can be used to synchronize access to the <see cref="MemoryArray<T>"/>.
15499
public object SyncRoot
15503
EnsureNotDisposed();
15504
if (syncRoot == null)
15506
System.Threading.Interlocked.CompareExchange(ref syncRoot, new object(), null);
15513
/// Retrieves an object that can iterate through the individual
15514
/// elements in this <see cref="MemoryArray<T>"/>.
15516
/// <returns>An <see cref="IEnumerator"/> for the <see cref="MemoryArray<T>"/>.</returns>
15517
public IEnumerator GetEnumerator()
15519
EnsureNotDisposed();
15520
T[] values = GetValues(0, length);
15521
for (int i = 0; i != values.Length; i++)
15523
yield return values[i];
15528
/// Retrieves an object that can iterate through the individual
15529
/// elements in this <see cref="MemoryArray<T>"/>.
15531
/// <returns>An <see cref="IEnumerator<T>"/> for the <see cref="MemoryArray<T>"/>.</returns>
15532
IEnumerator<T> IEnumerable<T>.GetEnumerator()
15534
EnsureNotDisposed();
15535
T[] values = GetValues(0, length);
15536
for (int i = 0; i != values.Length; i++)
15538
yield return values[i];
15543
/// Releases all ressources.
15545
public void Dispose()
15548
GC.SuppressFinalize(this);
15552
/// Releases allocated handles associated with this instance.
15554
/// <param name="disposing"><b>true</b> to release managed resources.</param>
15555
protected virtual void Dispose(bool disposing)
15557
if (baseAddress != null)
15559
if (handle.IsAllocated)
15561
baseAddress = null;
15569
/// Throws an <see cref="ObjectDisposedException"/> if
15570
/// this instance is disposed.
15572
protected virtual void EnsureNotDisposed()
15574
if (baseAddress == null)
15575
throw new ObjectDisposedException("This instance is disposed.");
15579
/// Tests whether the specified <see cref="MemoryArray<T>"/> structure is equivalent to this
15580
/// <see cref="MemoryArray<T>"/> structure.
15582
/// <param name="obj">The structure to test.</param>
15583
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="MemoryArray<T>"/>
15584
/// instance equivalent to this <see cref="MemoryArray<T>"/> structure; otherwise,
15585
/// <b>false</b>.</returns>
15586
public override bool Equals(object obj)
15588
EnsureNotDisposed();
15589
return ((obj is MemoryArray<T>) && Equals((MemoryArray<T>)obj));
15593
/// Tests whether the specified <see cref="MemoryArray<T>"/> structure is equivalent to this
15594
/// <see cref="MemoryArray<T>"/> structure.
15596
/// <param name="other">The structure to test.</param>
15597
/// <returns><b>true</b> if <paramref name="other"/> is equivalent to this
15598
/// <see cref="MemoryArray<T>"/> structure; otherwise,
15599
/// <b>false</b>.</returns>
15600
public bool Equals(MemoryArray<T> other)
15602
EnsureNotDisposed();
15603
return ((this.baseAddress == other.baseAddress) && (this.length == other.length));
15607
/// Serves as a hash function for a particular type.
15609
/// <returns>A hash code for the current <see cref="MemoryArray<T>"/>.</returns>
15610
public override int GetHashCode()
15612
EnsureNotDisposed();
15613
return (int)baseAddress ^ length;
15617
/// Copies a block of memory from one location to another.
15619
/// <param name="dest">Pointer to the starting address of the copy destination.</param>
15620
/// <param name="src">Pointer to the starting address of the block of memory to be copied.</param>
15621
/// <param name="len">Size of the block of memory to copy, in bytes.</param>
15622
protected static unsafe void CopyMemory(byte* dest, byte* src, int len)
15628
*((int*)dest) = *((int*)src);
15629
*((int*)(dest + 4)) = *((int*)(src + 4));
15630
*((int*)(dest + 8)) = *((int*)(src + 8));
15631
*((int*)(dest + 12)) = *((int*)(src + 12));
15635
while ((len -= 0x10) >= 0x10);
15639
if ((len & 8) != 0)
15641
*((int*)dest) = *((int*)src);
15642
*((int*)(dest + 4)) = *((int*)(src + 4));
15646
if ((len & 4) != 0)
15648
*((int*)dest) = *((int*)src);
15652
if ((len & 2) != 0)
15654
*((short*)dest) = *((short*)src);
15658
if ((len & 1) != 0)
15667
namespace FreeImageAPI.Metadata
15670
/// Base class that represents a collection of all tags contained in a metadata model.
15673
/// The <b>MetedataModel</b> class is an abstract base class, which is inherited by
15674
/// several derived classes, one for each existing metadata model.
15676
public abstract class MetadataModel : IEnumerable
15679
/// Handle to the encapsulated FreeImage-bitmap.
15681
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
15682
protected readonly FIBITMAP dib;
15685
/// Initializes a new instance of this class.
15687
/// <param name="dib">Handle to a FreeImage bitmap.</param>
15688
/// <exception cref="ArgumentNullException">
15689
/// <paramref name="dib"/> is null.</exception>
15690
protected MetadataModel(FIBITMAP dib)
15694
throw new ArgumentNullException("dib");
15700
/// Retrieves the datamodel that this instance represents.
15702
public abstract FREE_IMAGE_MDMODEL Model
15708
/// Adds new tag to the bitmap or updates its value in case it already exists.
15709
/// <see cref="FreeImageAPI.Metadata.MetadataTag.Key"/> will be used as key.
15711
/// <param name="tag">The tag to add or update.</param>
15712
/// <returns>Returns true on success, false on failure.</returns>
15713
/// <exception cref="ArgumentNullException">
15714
/// <paramref name="tag"/> is null.</exception>
15715
/// <exception cref="ArgumentException">
15716
/// The tags model differs from this instances model.</exception>
15717
public bool AddTag(MetadataTag tag)
15721
throw new ArgumentNullException("tag");
15723
if (tag.Model != Model)
15725
throw new ArgumentException("tag.Model");
15727
return tag.AddToImage(dib);
15731
/// Adds a list of tags to the bitmap or updates their values in case they already exist.
15732
/// <see cref="FreeImageAPI.Metadata.MetadataTag.Key"/> will be used as key.
15734
/// <param name="list">A list of tags to add or update.</param>
15735
/// <returns>Returns the number of successfully added tags.</returns>
15736
/// <exception cref="ArgumentNullException">
15737
/// <paramref name="list"/> is null.</exception>
15738
public int AddTag(IEnumerable<MetadataTag> list)
15742
throw new ArgumentNullException("list");
15745
foreach (MetadataTag tag in list)
15747
if (tag.Model == Model && tag.AddToImage(dib))
15756
/// Removes the specified tag from the bitmap.
15758
/// <param name="key">The key of the tag.</param>
15759
/// <returns>Returns true on success, false on failure.</returns>
15760
/// <exception cref="ArgumentNullException">
15761
/// <paramref name="key"/> is null.</exception>
15762
public bool RemoveTag(string key)
15766
throw new ArgumentNullException("key");
15768
return FreeImage.SetMetadata(Model, dib, key, FITAG.Zero);
15772
/// Destroys the metadata model
15773
/// which will remove all tags of this model from the bitmap.
15775
/// <returns>Returns true on success, false on failure.</returns>
15776
public bool DestoryModel()
15778
return FreeImage.SetMetadata(Model, dib, null, FITAG.Zero);
15782
/// Returns the specified metadata tag.
15784
/// <param name="key">The key of the tag.</param>
15785
/// <returns>The metadata tag.</returns>
15786
/// <exception cref="ArgumentNullException">
15787
/// <paramref name="key"/> is null.</exception>
15788
public MetadataTag GetTag(string key)
15792
throw new ArgumentNullException("key");
15795
return FreeImage.GetMetadata(Model, dib, key, out tag) ? tag : null;
15799
/// Returns whether the specified tag exists.
15801
/// <param name="key">The key of the tag.</param>
15802
/// <returns>True in case the tag exists, else false.</returns>
15803
/// <exception cref="ArgumentNullException">
15804
/// <paramref name="key"/> is null.</exception>
15805
public bool TagExists(string key)
15809
throw new ArgumentNullException("key");
15812
return FreeImage.GetMetadata(Model, dib, key, out tag);
15816
/// Returns a list of all metadata tags this instance represents.
15818
public List<MetadataTag> List
15822
List<MetadataTag> list = new List<MetadataTag>((int)FreeImage.GetMetadataCount(Model, dib));
15824
FIMETADATA mdHandle = FreeImage.FindFirstMetadata(Model, dib, out tag);
15825
if (!mdHandle.IsNull)
15831
while (FreeImage.FindNextMetadata(mdHandle, out tag));
15832
FreeImage.FindCloseMetadata(mdHandle);
15839
/// Returns the tag at the given index.
15841
/// <param name="index">Index of the tag to return.</param>
15842
/// <returns>The tag at the given index.</returns>
15843
protected MetadataTag GetTagFromIndex(int index)
15845
if (index >= Count || index < 0)
15847
throw new ArgumentOutOfRangeException("index");
15851
FIMETADATA mdHandle = FreeImage.FindFirstMetadata(Model, dib, out tag);
15852
if (!mdHandle.IsNull)
15858
if (count++ == index)
15863
while (FreeImage.FindNextMetadata(mdHandle, out tag));
15867
FreeImage.FindCloseMetadata(mdHandle);
15874
/// Returns the metadata tag at the given index. This operation is slow when accessing all tags.
15876
/// <param name="index">Index of the tag.</param>
15877
/// <returns>The metadata tag.</returns>
15878
/// <exception cref="ArgumentOutOfRangeException">
15879
/// <paramref name="index"/> is greater or equal <b>Count</b>
15880
/// or index is less than zero.</exception>
15881
public MetadataTag this[int index]
15885
return GetTagFromIndex(index);
15890
/// Retrieves an object that can iterate through the individual MetadataTags in this MetadataModel.
15892
/// <returns>An <see cref="IEnumerator"/> for the
15893
/// <see cref="FreeImageAPI.Metadata.MetadataModel"/>.</returns>
15894
public IEnumerator GetEnumerator()
15896
return List.GetEnumerator();
15900
/// Returns the number of metadata tags this instance represents.
15904
get { return (int)FreeImage.GetMetadataCount(Model, dib); }
15908
/// Returns whether this model exists in the bitmaps metadata structure.
15919
/// Searches for a pattern in each metadata tag and returns the result as a list.
15921
/// <param name="searchPattern">The regular expression to use for the search.</param>
15922
/// <param name="flags">A bitfield that controls which fields should be searched in.</param>
15923
/// <returns>A list containing all found metadata tags.</returns>
15924
/// <exception cref="ArgumentNullException">
15925
/// <typeparamref name="searchPattern"/> is null.</exception>
15926
/// <exception cref="ArgumentException">
15927
/// <typeparamref name="searchPattern"/> is empty.</exception>
15928
public List<MetadataTag> RegexSearch(string searchPattern, MD_SEARCH_FLAGS flags)
15930
if (searchPattern == null)
15932
throw new ArgumentNullException("searchString");
15934
if (searchPattern.Length == 0)
15936
throw new ArgumentException("searchString is empty");
15938
List<MetadataTag> result = new List<MetadataTag>(Count);
15939
Regex regex = new Regex(searchPattern);
15940
List<MetadataTag> list = List;
15941
foreach (MetadataTag tag in list)
15943
if (((flags & MD_SEARCH_FLAGS.KEY) > 0) && regex.Match(tag.Key).Success)
15948
if (((flags & MD_SEARCH_FLAGS.DESCRIPTION) > 0) && regex.Match(tag.Description).Success)
15953
if (((flags & MD_SEARCH_FLAGS.TOSTRING) > 0) && regex.Match(tag.ToString()).Success)
15959
result.Capacity = result.Count;
15964
/// Returns the value of the specified tag.
15966
/// <typeparam name="T">Type of the tag's data.</typeparam>
15967
/// <param name="key">The key of the tag.</param>
15968
/// <returns>The value of the specified tag.</returns>
15969
protected T? GetTagValue<T>(string key) where T : struct
15971
if (string.IsNullOrEmpty(key))
15973
throw new ArgumentNullException("key");
15975
MetadataTag tag = GetTag(key);
15978
T[] value = tag.Value as T[];
15979
if ((value != null) && (value.Length != 0))
15988
/// Returns an array containing the data of the specified tag.
15990
/// <typeparam name="T">The type of the tag's data.</typeparam>
15991
/// <param name="key">The key of the tag.</param>
15992
/// <returns>An array containing the data of the specified tag.</returns>
15993
protected T[] GetTagArray<T>(string key) where T : struct
15995
if (string.IsNullOrEmpty(key))
15997
throw new ArgumentNullException("key");
15999
MetadataTag tag = GetTag(key);
16000
return (tag == null) ? null : tag.Value as T[];
16004
/// Returns the string contained by the specified tag.
16006
/// <param name="key">The key of the tag.</param>
16007
/// <returns>The string contained by the specified tag.</returns>
16008
protected string GetTagText(string key)
16010
if (string.IsNullOrEmpty(key))
16012
throw new ArgumentNullException("key");
16014
MetadataTag tag = GetTag(key);
16015
return (tag == null) ? null : tag.Value as string;
16019
/// Returns an array containg the data of the specified tag
16020
/// as unsigned 32bit integer.
16022
/// <param name="key">The key of the tag.</param>
16023
/// <returns>An array containg the data of the specified tag
16024
/// as unsigned 32bit integer.</returns>
16025
protected uint[] GetUInt32Array(string key)
16027
if (string.IsNullOrEmpty(key))
16029
throw new ArgumentNullException("key");
16031
uint[] result = null;
16032
MetadataTag tag = GetTag(key);
16035
object value = tag.Value;
16038
if (value is ushort[])
16040
ushort[] array = (ushort[])value;
16041
result = new uint[array.Length];
16042
for (int i = 0, j = array.Length; i < j; i++)
16044
result[i] = (uint)array[i];
16047
else if (value is uint[])
16049
result = (uint[])value;
16057
/// Returns the value of the tag as unsigned 32bit integer.
16059
/// <param name="key">The key of the tag.</param>
16060
/// <returns>The value of the tag as unsigned 32bit integer.</returns>
16061
protected uint? GetUInt32Value(string key)
16063
uint[] value = GetUInt32Array(key);
16064
return value == null ? default(uint?) : value[0];
16068
/// Sets the value of the specified tag.
16070
/// <typeparam name="T">The type of the tag's data.</typeparam>
16071
/// <param name="key">The key of the tag.</param>
16072
/// <param name="value">The new value of the specified tag or null.</param>
16073
protected void SetTagValue<T>(string key, T? value) where T : struct
16075
SetTagValue(key, value.HasValue ? new T[] { value.Value } : null);
16079
/// Sets the value of the specified tag.
16081
/// <param name="key">The key of the tag.</param>
16082
/// <param name="value">The new value of the specified tag or null.</param>
16083
protected void SetTagValue(string key, object value)
16085
if (string.IsNullOrEmpty(key))
16087
throw new ArgumentNullException("key");
16095
MetadataTag tag = GetTag(key);
16098
tag = new MetadataTag(Model);
16111
/// Sets the value of the specified tag as undefined.
16113
/// <param name="key">The key of the tag.</param>
16114
/// <param name="value">The new value of the specified tag or null.</param>
16115
protected void SetTagValueUndefined(string key, byte[] value)
16117
if (string.IsNullOrEmpty(key))
16119
throw new ArgumentNullException("key");
16127
MetadataTag tag = GetTag(key);
16130
tag = new MetadataTag(Model);
16132
tag.SetValue(value, FREE_IMAGE_MDTYPE.FIDT_UNDEFINED);
16143
/// Returns the equivalent <see cref="DirectionReference"/> for the
16144
/// specified <see cref="String"/>.
16146
/// <param name="s">The string containing the <see cref="DirectionReference"/>.</param>
16147
/// <returns>The equivalent <see cref="DirectionReference"/> for the
16148
/// specified <see cref="String"/>.</returns>
16149
protected static DirectionReference? ToDirectionType(string s)
16151
if (string.IsNullOrEmpty(s))
16156
return DirectionReference.TrueDirection;
16158
return DirectionReference.MagneticDirection;
16160
return DirectionReference.Undefined;
16165
/// Returns the equivalent <see cref="String"/> for the
16166
/// specified <see cref="DirectionReference"/>.
16168
/// <param name="type">The <see cref="DirectionReference"/> to convert.</param>
16169
/// <returns>The equivalent <see cref="String"/> for the
16170
/// specified <see cref="DirectionReference"/>.</returns>
16171
protected static string ToString(DirectionReference? type)
16175
switch (type.Value)
16177
case DirectionReference.TrueDirection:
16179
case DirectionReference.MagneticDirection:
16189
/// Returns the equivalent <see cref="VelocityUnit"/> for the
16190
/// specified <see cref="String"/>.
16192
/// <param name="s">The string containing the <see cref="VelocityUnit"/>.</param>
16193
/// <returns>The equivalent <see cref="VelocityUnit"/> for the
16194
/// specified <see cref="String"/>.</returns>
16195
protected static VelocityUnit? ToUnitType(string s)
16197
if (string.IsNullOrEmpty(s))
16202
return VelocityUnit.Kilometers;
16204
return VelocityUnit.Miles;
16206
return VelocityUnit.Knots;
16208
return VelocityUnit.Undefinied;
16213
/// Returns the equivalent <see cref="String"/> for the
16214
/// specified <see cref="VelocityUnit"/>.
16216
/// <param name="type">The <see cref="VelocityUnit"/> to convert.</param>
16217
/// <returns>The equivalent <see cref="String"/> for the
16218
/// specified <see cref="VelocityUnit"/>.</returns>
16219
protected static string ToString(VelocityUnit? type)
16223
switch (type.Value)
16225
case VelocityUnit.Kilometers:
16227
case VelocityUnit.Miles:
16229
case VelocityUnit.Knots:
16239
/// Returns the equivalent <see cref="LongitudeType"/> for the
16240
/// specified <see cref="String"/>.
16242
/// <param name="s">The string containing the <see cref="LongitudeType"/>.</param>
16243
/// <returns>The equivalent <see cref="LongitudeType"/> for the
16244
/// specified <see cref="String"/>.</returns>
16245
protected static LongitudeType? ToLongitudeType(string s)
16247
if (string.IsNullOrEmpty(s))
16252
return LongitudeType.East;
16254
return LongitudeType.West;
16256
return LongitudeType.Undefined;
16261
/// Returns the equivalent <see cref="String"/> for the
16262
/// specified <see cref="LongitudeType"/>.
16264
/// <param name="type">The <see cref="LongitudeType"/> to convert.</param>
16265
/// <returns>The equivalent <see cref="String"/> for the
16266
/// specified <see cref="LongitudeType"/>.</returns>
16267
protected static string ToString(LongitudeType? type)
16271
switch (type.Value)
16273
case LongitudeType.East:
16275
case LongitudeType.West:
16285
/// Returns the equivalent <see cref="LatitudeType"/> for the
16286
/// specified <see cref="String"/>.
16288
/// <param name="s">The string containing the <see cref="LatitudeType"/>.</param>
16289
/// <returns>The equivalent <see cref="LatitudeType"/> for the
16290
/// specified <see cref="String"/>.</returns>
16291
protected static LatitudeType? ToLatitudeType(string s)
16293
if (string.IsNullOrEmpty(s))
16298
return LatitudeType.North;
16300
return LatitudeType.South;
16302
return LatitudeType.Undefined;
16307
/// Returns the equivalent <see cref="String"/> for the
16308
/// specified <see cref="LatitudeType"/>.
16310
/// <param name="type">The <see cref="LatitudeType"/> to convert.</param>
16311
/// <returns>The equivalent <see cref="String"/> for the
16312
/// specified <see cref="LatitudeType"/>.</returns>
16313
protected static string ToString(LatitudeType? type)
16317
switch (type.Value)
16319
case LatitudeType.North:
16321
case LatitudeType.South:
16331
/// Returns the equivalent <see cref="InteroperabilityMode"/> for the
16332
/// specified <see cref="String"/>.
16334
/// <param name="s">The string containing the <see cref="InteroperabilityMode"/>.</param>
16335
/// <returns>The equivalent <see cref="InteroperabilityMode"/> for the
16336
/// specified <see cref="String"/>.</returns>
16337
protected static InteroperabilityMode? ToInteroperabilityType(string s)
16339
if (string.IsNullOrEmpty(s))
16341
if (s.StartsWith("R98"))
16342
return InteroperabilityMode.R98;
16343
if (s.StartsWith("THM"))
16344
return InteroperabilityMode.THM;
16345
return InteroperabilityMode.Undefined;
16349
/// Returns the equivalent <see cref="String"/> for the
16350
/// specified <see cref="InteroperabilityMode"/>.
16352
/// <param name="type">The <see cref="InteroperabilityMode"/> to convert.</param>
16353
/// <returns>The equivalent <see cref="String"/> for the
16354
/// specified <see cref="InteroperabilityMode"/>.</returns>
16355
protected static string ToString(InteroperabilityMode? type)
16359
switch (type.Value)
16361
case InteroperabilityMode.R98:
16363
case InteroperabilityMode.THM:
16373
/// Specified different unit types.
16375
public enum VelocityUnit
16378
/// No or unknown type.
16383
/// Kilometers per hour.
16388
/// Miles per hour.
16399
/// Specifies different direction types.
16401
public enum DirectionReference
16404
/// No or unknown direction type.
16409
/// True direction.
16414
/// Magnatic direction.
16420
/// Specifies the type of a latitude value.
16422
public enum LatitudeType
16425
/// No or unknown type.
16441
/// Specifies the type of a longitude value.
16443
public enum LongitudeType
16446
/// No or unknown type.
16462
/// Specifies different altitude types.
16464
public enum AltitudeType
16467
/// No or unknown type.
16483
/// Specifies interoperability types.
16485
public enum InteroperabilityMode
16488
/// No or unknown type.
16493
/// Indicates a file conforming to R98 file specification of Recommended
16494
/// Exif Interoperability Rules (ExifR98) or to DCF basic file stipulated
16495
/// by Design Rule for Camera File System.
16500
/// Indicates a file conforming to DCF thumbnail file stipulated by Design
16501
/// rule for Camera File System.
16507
/// Specifies orientation of images.
16509
public enum ExifImageOrientation : ushort
16512
/// Undefinied orientation.
16558
/// Converts the model of the MetadataModel object to its equivalent string representation.
16560
/// <returns>The string representation of the value of this instance.</returns>
16561
public override string ToString()
16563
return Model.ToString();
16568
#region Metadata Models
16570
namespace FreeImageAPI.Metadata
16573
/// Represents a collection of all tags contained in the metadata model
16574
/// <see cref="FREE_IMAGE_MDMODEL.FIMD_ANIMATION"/>.
16576
public class MDM_ANIMATION : MetadataModel
16579
/// Initializes a new instance of this class.
16581
/// <param name="dib">Handle to a FreeImage bitmap.</param>
16582
public MDM_ANIMATION(FIBITMAP dib) : base(dib) { }
16585
/// Retrieves the datamodel that this instance represents.
16587
public override FREE_IMAGE_MDMODEL Model
16589
get { return FREE_IMAGE_MDMODEL.FIMD_ANIMATION; }
16593
/// Gets or sets the width of the entire canvas area, that each page is displayed in.
16596
/// <b>Handling of null values</b><para/>
16597
/// A null value indicates, that the corresponding metadata tag is not
16598
/// present in the metadata model.
16599
/// Setting this property's value to a non-null reference creates the
16600
/// metadata tag if necessary.
16601
/// Setting this property's value to a null reference deletes the
16602
/// metadata tag from the metadata model.
16604
public ushort? LogicalWidth
16608
return GetTagValue<ushort>("LogicalWidth");
16612
SetTagValue("LogicalWidth", value);
16617
/// Gets or sets the height of the entire canvas area, that each page is displayed in.
16620
/// <b>Handling of null values</b><para/>
16621
/// A null value indicates, that the corresponding metadata tag is not
16622
/// present in the metadata model.
16623
/// Setting this property's value to a non-null reference creates the
16624
/// metadata tag if necessary.
16625
/// Setting this property's value to a null reference deletes the
16626
/// metadata tag from the metadata model.
16628
public ushort? LogicalHeight
16632
return GetTagValue<ushort>("LogicalHeight");
16636
SetTagValue("LogicalHeight", value);
16641
/// Gets or sets the global palette of the GIF image.
16644
/// <b>Handling of null values</b><para/>
16645
/// A null value indicates, that the corresponding metadata tag is not
16646
/// present in the metadata model.
16647
/// Setting this property's value to a non-null reference creates the
16648
/// metadata tag if necessary.
16649
/// Setting this property's value to a null reference deletes the
16650
/// metadata tag from the metadata model.
16652
public Palette GlobalPalette
16656
MetadataTag mdtag = GetTag("GlobalPalette");
16657
return (mdtag == null) ? null : new Palette(mdtag);
16661
SetTagValue("GlobalPalette", (value != null) ? null : value.Data);
16666
/// Gets or sets the number of replays for the animation.
16667
/// Use 0 (zero) to specify an infinte number of replays.
16670
/// <b>Handling of null values</b><para/>
16671
/// A null value indicates, that the corresponding metadata tag is not
16672
/// present in the metadata model.
16673
/// Setting this property's value to a non-null reference creates the
16674
/// metadata tag if necessary.
16675
/// Setting this property's value to a null reference deletes the
16676
/// metadata tag from the metadata model.
16678
public uint? LoopCount
16682
return GetTagValue<uint>("Loop");
16686
SetTagValue("Loop", value);
16691
/// Gets or sets the horizontal offset within the logical canvas area, this frame is to be displayed at.
16694
/// <b>Handling of null values</b><para/>
16695
/// A null value indicates, that the corresponding metadata tag is not
16696
/// present in the metadata model.
16697
/// Setting this property's value to a non-null reference creates the
16698
/// metadata tag if necessary.
16699
/// Setting this property's value to a null reference deletes the
16700
/// metadata tag from the metadata model.
16702
public ushort? FrameLeft
16706
return GetTagValue<ushort>("FrameLeft");
16710
SetTagValue("FrameLeft", value);
16715
/// Gets or sets the vertical offset within the logical canvas area, this frame is to be displayed at.
16718
/// <b>Handling of null values</b><para/>
16719
/// A null value indicates, that the corresponding metadata tag is not
16720
/// present in the metadata model.
16721
/// Setting this property's value to a non-null reference creates the
16722
/// metadata tag if necessary.
16723
/// Setting this property's value to a null reference deletes the
16724
/// metadata tag from the metadata model.
16726
public ushort? FrameTop
16730
return GetTagValue<ushort>("FrameTop");
16734
SetTagValue("FrameTop", value);
16739
/// Gets or sets a flag to supress saving the dib's attached palette
16740
/// (making it use the global palette). The local palette is the palette used by a page.
16743
/// <b>Handling of null values</b><para/>
16744
/// A null value indicates, that the corresponding metadata tag is not
16745
/// present in the metadata model.
16746
/// Setting this property's value to a non-null reference creates the
16747
/// metadata tag if necessary.
16748
/// Setting this property's value to a null reference deletes the
16749
/// metadata tag from the metadata model.
16751
public bool? NoLocalPalette
16755
byte? useGlobalPalette = GetTagValue<byte>("NoLocalPalette");
16756
return useGlobalPalette.HasValue ? (useGlobalPalette.Value != 0) : default(bool?);
16761
if (value.HasValue)
16763
val = (byte)(value.Value ? 1 : 0);
16765
SetTagValue("NoLocalPalette", val);
16770
/// Gets or sets a value indicating whether the image is interlaced.
16773
/// <b>Handling of null values</b><para/>
16774
/// A null value indicates, that the corresponding metadata tag is not
16775
/// present in the metadata model.
16776
/// Setting this property's value to a non-null reference creates the
16777
/// metadata tag if necessary.
16778
/// Setting this property's value to a null reference deletes the
16779
/// metadata tag from the metadata model.
16781
public bool? Interlaced
16785
byte? useGlobalPalette = GetTagValue<byte>("Interlaced");
16786
return useGlobalPalette.HasValue ? (useGlobalPalette.Value != 0) : default(bool?);
16791
if (value.HasValue)
16793
val = (byte)(value.Value ? 1 : 0);
16795
SetTagValue("Interlaced", val);
16800
/// Gets or sets the amout of time in milliseconds this frame is to be displayed.
16803
/// <b>Handling of null values</b><para/>
16804
/// A null value indicates, that the corresponding metadata tag is not
16805
/// present in the metadata model.
16806
/// Setting this property's value to a non-null reference creates the
16807
/// metadata tag if necessary.
16808
/// Setting this property's value to a null reference deletes the
16809
/// metadata tag from the metadata model.
16811
public uint? FrameTime
16815
return GetTagValue<uint>("FrameTime");
16819
SetTagValue("FrameTime", value);
16824
/// Gets or sets this frame's disposal method. Generally, this method defines, how to
16825
/// remove or replace a frame when the next frame has to be drawn.<para/>
16828
/// <b>Handling of null values</b><para/>
16829
/// A null value indicates, that the corresponding metadata tag is not
16830
/// present in the metadata model.
16831
/// Setting this property's value to a non-null reference creates the
16832
/// metadata tag if necessary.
16833
/// Setting this property's value to a null reference deletes the
16834
/// metadata tag from the metadata model.
16836
public DisposalMethodType? DisposalMethod
16840
return GetTagValue<DisposalMethodType>("DisposalMethod");
16844
SetTagValue("DisposalMethod", value);
16850
/// Represents a collection of all tags contained in the metadata model
16851
/// <see cref="FREE_IMAGE_MDMODEL.FIMD_COMMENTS"/>.
16853
public class MDM_COMMENTS : MetadataModel
16856
/// Initializes a new instance of this class.
16858
/// <param name="dib">Handle to a FreeImage bitmap.</param>
16859
public MDM_COMMENTS(FIBITMAP dib) : base(dib) { }
16862
/// Retrieves the datamodel that this instance represents.
16864
public override FREE_IMAGE_MDMODEL Model
16866
get { return FREE_IMAGE_MDMODEL.FIMD_COMMENTS; }
16870
/// Gets or sets the comment of the image.
16871
/// Supported formats are JPEG, PNG and GIF.
16874
/// <b>Handling of null values</b><para/>
16875
/// A null value indicates, that the corresponding metadata tag is not
16876
/// present in the metadata model.
16877
/// Setting this property's value to a non-null reference creates the
16878
/// metadata tag if necessary.
16879
/// Setting this property's value to a null reference deletes the
16880
/// metadata tag from the metadata model.
16882
public string Comment
16886
return GetTagText("Comment");
16890
SetTagValue("Comment", value);
16896
/// Represents a collection of all tags contained in the metadata model
16897
/// <see cref="FREE_IMAGE_MDMODEL.FIMD_CUSTOM"/>.
16899
public class MDM_CUSTOM : MetadataModel
16902
/// Initializes a new instance of this class.
16904
/// <param name="dib">Handle to a FreeImage bitmap.</param>
16905
public MDM_CUSTOM(FIBITMAP dib) : base(dib) { }
16908
/// Retrieves the datamodel that this instance represents.
16910
public override FREE_IMAGE_MDMODEL Model
16912
get { return FREE_IMAGE_MDMODEL.FIMD_CUSTOM; }
16917
/// Represents a collection of all tags contained in the metadata model
16918
/// <see cref="FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF"/>.
16920
public class MDM_EXIF_EXIF : MetadataModel
16923
/// Initializes a new instance of this class.
16925
/// <param name="dib">Handle to a FreeImage bitmap.</param>
16926
public MDM_EXIF_EXIF(FIBITMAP dib) : base(dib) { }
16929
/// Retrieves the datamodel that this instance represents.
16931
public override FREE_IMAGE_MDMODEL Model
16933
get { return FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF; }
16937
/// Gets or sets the version of this standard supported.
16938
/// Constant length or 4.
16941
/// <b>Handling of null values</b><para/>
16942
/// A null value indicates, that the corresponding metadata tag is not
16943
/// present in the metadata model.
16944
/// Setting this property's value to a non-null reference creates the
16945
/// metadata tag if necessary.
16946
/// Setting this property's value to a null reference deletes the
16947
/// metadata tag from the metadata model.
16949
public byte[] ExifVersion
16953
return GetTagArray<byte>("ExifVersion");
16957
FreeImage.Resize(ref value, 4);
16958
SetTagValueUndefined("ExifVersion", value);
16963
/// Gets or sets the Flashpix format version supported by a FPXR file.
16964
/// Constant length or 4.
16967
/// <b>Handling of null values</b><para/>
16968
/// A null value indicates, that the corresponding metadata tag is not
16969
/// present in the metadata model.
16970
/// Setting this property's value to a non-null reference creates the
16971
/// metadata tag if necessary.
16972
/// Setting this property's value to a null reference deletes the
16973
/// metadata tag from the metadata model.
16975
public byte[] FlashpixVersion
16979
return GetTagArray<byte>("FlashpixVersion");
16983
FreeImage.Resize(ref value, 4);
16984
SetTagValueUndefined("FlashpixVersion", value);
16989
/// Gets or sets the color space information tag.
16990
/// See remarks for further information.
16993
/// The following values are defined:<para/>
16994
/// <list type="table">
16996
/// <term>ID</term>
16997
/// <description>Description</description>
17001
/// <description>sRGB (default)</description>
17004
/// <term>0xFFFF</term>
17005
/// <description>uncalibrated</description>
17008
/// <term>other</term>
17009
/// <description>reserved</description>
17013
/// <br/><b>Handling of null values</b><para/>
17014
/// A null value indicates, that the corresponding metadata tag is not
17015
/// present in the metadata model.
17016
/// Setting this property's value to a non-null reference creates the
17017
/// metadata tag if necessary.
17018
/// Setting this property's value to a null reference deletes the
17019
/// metadata tag from the metadata model.
17021
public ushort? ColorSpace
17025
return GetTagValue<ushort>("ColorSpace");
17029
SetTagValue("ColorSpace", value);
17034
/// Gets or sets the valid width of a compressed image.
17037
/// <b>Handling of null values</b><para/>
17038
/// A null value indicates, that the corresponding metadata tag is not
17039
/// present in the metadata model.
17040
/// Setting this property's value to a non-null reference creates the
17041
/// metadata tag if necessary.
17042
/// Setting this property's value to a null reference deletes the
17043
/// metadata tag from the metadata model.
17045
public uint? PixelXDimension
17049
return GetUInt32Value("PixelXDimension");
17053
RemoveTag("PixelXDimension");
17054
if (value.HasValue)
17056
SetTagValue("PixelXDimension", value.Value);
17062
/// Gets or sets the valid height of a compressed image.
17065
/// <b>Handling of null values</b><para/>
17066
/// A null value indicates, that the corresponding metadata tag is not
17067
/// present in the metadata model.
17068
/// Setting this property's value to a non-null reference creates the
17069
/// metadata tag if necessary.
17070
/// Setting this property's value to a null reference deletes the
17071
/// metadata tag from the metadata model.
17073
public uint? PixelYDimension
17077
return GetUInt32Value("PixelYDimension");
17081
RemoveTag("PixelYDimension");
17082
if (value.HasValue)
17084
SetTagValue("PixelYDimension", value.Value);
17090
/// Gets or sets components configuration. See remarks for further information.
17091
/// Constant length of 4.
17094
/// The channels of each component are arranged in order from the 1st component to the 4th.
17095
/// For uncompressed data the data arrangement is given in the PhotometricInterpretation tag.
17096
/// However, since PhotometricInterpretation can only express the order of Y,Cb and Cr,
17097
/// this tag is provided for cases when compressed data uses components other than Y, Cb,
17098
/// and Cr and to enable support of other sequences.<para/>
17099
/// Default = 4 5 6 0 (if RGB uncompressed)<para/>
17100
/// The following values are defined:<para/>
17101
/// <list type="table">
17103
/// <term>ID</term>
17104
/// <description>Description</description>
17108
/// <description>does not exist</description>
17112
/// <description>Y</description>
17116
/// <description>Cb</description>
17120
/// <description>Cr</description>
17124
/// <description>R</description>
17128
/// <description>R</description>
17132
/// <description>R</description>
17135
/// <term>other</term>
17136
/// <description>reserved</description>
17140
/// <br/><b>Handling of null values</b><para/>
17141
/// A null value indicates, that the corresponding metadata tag is not
17142
/// present in the metadata model.
17143
/// Setting this property's value to a non-null reference creates the
17144
/// metadata tag if necessary.
17145
/// Setting this property's value to a null reference deletes the
17146
/// metadata tag from the metadata model.
17148
public byte[] ComponentsConfiguration
17152
return GetTagArray<byte>("ComponentsConfiguration");
17156
FreeImage.Resize(ref value, 4);
17157
SetTagValueUndefined("ComponentsConfiguration", value);
17162
/// Gets or sets compression mode used for a compressed image is indicated
17163
/// in unit bits per pixel.
17166
/// <b>Handling of null values</b><para/>
17167
/// A null value indicates, that the corresponding metadata tag is not
17168
/// present in the metadata model.
17169
/// Setting this property's value to a non-null reference creates the
17170
/// metadata tag if necessary.
17171
/// Setting this property's value to a null reference deletes the
17172
/// metadata tag from the metadata model.
17174
public FIURational? CompressedBitsPerPixel
17178
return GetTagValue<FIURational>("CompressedBitsPerPixel");
17182
SetTagValue("CompressedBitsPerPixel", value);
17187
/// Gets or sets a tag for manufacturers of Exif writers to record any desired information.
17188
/// The contents are up to the manufacturer, but this tag should not be used for any other
17189
/// than its intended purpose.
17192
/// <b>Handling of null values</b><para/>
17193
/// A null value indicates, that the corresponding metadata tag is not
17194
/// present in the metadata model.
17195
/// Setting this property's value to a non-null reference creates the
17196
/// metadata tag if necessary.
17197
/// Setting this property's value to a null reference deletes the
17198
/// metadata tag from the metadata model.
17200
public byte[] MakerNote
17204
return GetTagArray<byte>("FlashpixVersion");
17208
SetTagValueUndefined("FlashpixVersion", value);
17213
/// Gets or sets a tag for Exif users to write keywords or comments on the image besides
17214
/// those in ImageDescription, and without the character code limitations of the ImageDescription tag.
17215
/// Minimum length of 8. See remarks for further information.
17218
/// The character code used in the UserComment tag is identified based on an ID code in a fixed 8-byte
17219
/// area at the start of the tag data area. The unused portion of the area is padded with NULL.
17220
/// The ID code for the UserComment area may be a Defined code such as JIS or ASCII, or may be Undefined.
17222
/// <br/><b>Handling of null values</b><para/>
17223
/// A null value indicates, that the corresponding metadata tag is not
17224
/// present in the metadata model.
17225
/// Setting this property's value to a non-null reference creates the
17226
/// metadata tag if necessary.
17227
/// Setting this property's value to a null reference deletes the
17228
/// metadata tag from the metadata model.
17230
public byte[] UserComment
17234
return GetTagArray<byte>("UserComment");
17238
FreeImage.Resize(ref value, 8, int.MaxValue);
17239
SetTagValueUndefined("UserComment", value);
17244
/// Gets or sets the name of an audio file related to the image data.
17245
/// The format is 8.3.
17246
/// Constant length of 12
17249
/// <b>Handling of null values</b><para/>
17250
/// A null value indicates, that the corresponding metadata tag is not
17251
/// present in the metadata model.
17252
/// Setting this property's value to a non-null reference creates the
17253
/// metadata tag if necessary.
17254
/// Setting this property's value to a null reference deletes the
17255
/// metadata tag from the metadata model.
17257
public string RelatedSoundFile
17261
string text = GetTagText("RelatedSoundFile");
17262
if (!string.IsNullOrEmpty(text))
17264
text = text.Substring(0, text.Length - 1);
17272
FreeImage.Resize(ref value, 12);
17275
SetTagValue("RelatedSoundFile", value);
17280
/// Gets or sets the date and time when the original image data was generated.
17283
/// <b>Handling of null values</b><para/>
17284
/// A null value indicates, that the corresponding metadata tag is not
17285
/// present in the metadata model.
17286
/// Setting this property's value to a non-null reference creates the
17287
/// metadata tag if necessary.
17288
/// Setting this property's value to a null reference deletes the
17289
/// metadata tag from the metadata model.
17291
public DateTime? DateTimeOriginal
17295
DateTime? result = null;
17296
string text = GetTagText("DateTimeOriginal");
17301
result = System.DateTime.ParseExact(text, "yyyy:MM:dd HH:mm:ss\0", null);
17312
if (value.HasValue)
17316
val = value.Value.ToString("yyyy:MM:dd HH:mm:ss\0");
17322
SetTagValue("DateTimeOriginal", val);
17327
/// Gets or sets the date and time when the image was stored as digital data.
17330
/// <b>Handling of null values</b><para/>
17331
/// A null value indicates, that the corresponding metadata tag is not
17332
/// present in the metadata model.
17333
/// Setting this property's value to a non-null reference creates the
17334
/// metadata tag if necessary.
17335
/// Setting this property's value to a null reference deletes the
17336
/// metadata tag from the metadata model.
17338
public DateTime? DateTimeDigitized
17342
DateTime? result = null;
17343
string text = GetTagText("DateTimeDigitized");
17348
result = System.DateTime.ParseExact(text, "yyyy:MM:dd HH:mm:ss\0", null);
17359
if (value.HasValue)
17363
val = value.Value.ToString("yyyy:MM:dd HH:mm:ss\0");
17369
SetTagValue("DateTimeDigitized", val);
17374
/// Gets or sets a tag used to record fractions of seconds for the DateTime tag.
17377
/// <b>Handling of null values</b><para/>
17378
/// A null value indicates, that the corresponding metadata tag is not
17379
/// present in the metadata model.
17380
/// Setting this property's value to a non-null reference creates the
17381
/// metadata tag if necessary.
17382
/// Setting this property's value to a null reference deletes the
17383
/// metadata tag from the metadata model.
17385
public string SubsecTime
17389
string text = GetTagText("SubsecTime");
17390
if (!string.IsNullOrEmpty(text))
17392
text = text.Substring(0, text.Length - 1);
17402
SetTagValue("SubsecTime", value);
17407
/// Gets or sets a tag used to record fractions of seconds for the DateTimeOriginal tag.
17410
/// <b>Handling of null values</b><para/>
17411
/// A null value indicates, that the corresponding metadata tag is not
17412
/// present in the metadata model.
17413
/// Setting this property's value to a non-null reference creates the
17414
/// metadata tag if necessary.
17415
/// Setting this property's value to a null reference deletes the
17416
/// metadata tag from the metadata model.
17418
public string SubsecTimeOriginal
17422
string text = GetTagText("SubsecTimeOriginal");
17423
if (!string.IsNullOrEmpty(text))
17425
text = text.Substring(0, text.Length - 1);
17435
SetTagValue("SubsecTimeOriginal", value);
17440
/// Gets or sets a tag used to record fractions of seconds for the DateTimeDigitized tag.
17443
/// <b>Handling of null values</b><para/>
17444
/// A null value indicates, that the corresponding metadata tag is not
17445
/// present in the metadata model.
17446
/// Setting this property's value to a non-null reference creates the
17447
/// metadata tag if necessary.
17448
/// Setting this property's value to a null reference deletes the
17449
/// metadata tag from the metadata model.
17451
public string SubsecTimeDigitized
17455
string text = GetTagText("SubsecTimeDigitized");
17456
if (!string.IsNullOrEmpty(text))
17458
text = text.Substring(0, text.Length - 1);
17468
SetTagValue("SubsecTimeDigitized", value);
17473
/// Gets or the exposure time, given in seconds (sec).
17476
/// <b>Handling of null values</b><para/>
17477
/// A null value indicates, that the corresponding metadata tag is not
17478
/// present in the metadata model.
17479
/// Setting this property's value to a non-null reference creates the
17480
/// metadata tag if necessary.
17481
/// Setting this property's value to a null reference deletes the
17482
/// metadata tag from the metadata model.
17484
public FIURational? ExposureTime
17488
return GetTagValue<FIURational>("ExposureTime");
17492
SetTagValue("ExposureTime", value);
17497
/// Gets or the F number.
17500
/// <b>Handling of null values</b><para/>
17501
/// A null value indicates, that the corresponding metadata tag is not
17502
/// present in the metadata model.
17503
/// Setting this property's value to a non-null reference creates the
17504
/// metadata tag if necessary.
17505
/// Setting this property's value to a null reference deletes the
17506
/// metadata tag from the metadata model.
17508
public FIURational? FNumber
17512
return GetTagValue<FIURational>("FNumber");
17516
SetTagValue("FNumber", value);
17521
/// Gets or sets the class of the program used by the camera to set exposure when the
17522
/// picture is taken.
17523
/// See remarks for further information.
17526
/// The following values are defined:<para/>
17527
/// <list type="table">
17529
/// <term>ID</term>
17530
/// <description>Description</description>
17534
/// <description>not defined</description>
17538
/// <description>manual</description>
17542
/// <description>normal program</description>
17546
/// <description>aperture priority</description>
17550
/// <description>shutter priority</description>
17554
/// <description>create program</description>
17558
/// <description>action program</description>
17562
/// <description>portrait mode</description>
17566
/// <description>landscape mode</description>
17569
/// <term>others</term>
17570
/// <description>reserved</description>
17574
/// <br/><b>Handling of null values</b><para/>
17575
/// A null value indicates, that the corresponding metadata tag is not
17576
/// present in the metadata model.
17577
/// Setting this property's value to a non-null reference creates the
17578
/// metadata tag if necessary.
17579
/// Setting this property's value to a null reference deletes the
17580
/// metadata tag from the metadata model.
17582
public ushort? ExposureProgram
17586
return GetTagValue<ushort>("ExposureProgram");
17590
SetTagValue("ExposureProgram", value);
17595
/// Gets or sets the spectral sensitivity of each channel of the camera used.
17598
/// <b>Handling of null values</b><para/>
17599
/// A null value indicates, that the corresponding metadata tag is not
17600
/// present in the metadata model.
17601
/// Setting this property's value to a non-null reference creates the
17602
/// metadata tag if necessary.
17603
/// Setting this property's value to a null reference deletes the
17604
/// metadata tag from the metadata model.
17606
public string SpectralSensitivity
17610
string text = GetTagText("SpectralSensitivity");
17611
if (!string.IsNullOrEmpty(text))
17613
text = text.Substring(0, text.Length - 1);
17623
SetTagValue("SpectralSensitivity", value);
17628
/// Gets or sets the the ISO Speed and ISO Latitude of the camera or input device as
17629
/// specified in ISO 12232.
17632
/// <b>Handling of null values</b><para/>
17633
/// A null value indicates, that the corresponding metadata tag is not
17634
/// present in the metadata model.
17635
/// Setting this property's value to a non-null reference creates the
17636
/// metadata tag if necessary.
17637
/// Setting this property's value to a null reference deletes the
17638
/// metadata tag from the metadata model.
17640
public ushort[] ISOSpeedRatings
17644
return GetTagArray<ushort>("ISOSpeedRatings");
17648
SetTagValue("ISOSpeedRatings", value);
17653
/// Gets or sets the Opto-Electric Conversion Function (OECF) specified in ISO 14524.
17654
/// OECF is the relationship between the camera optical input and the image values.
17657
/// <b>Handling of null values</b><para/>
17658
/// A null value indicates, that the corresponding metadata tag is not
17659
/// present in the metadata model.
17660
/// Setting this property's value to a non-null reference creates the
17661
/// metadata tag if necessary.
17662
/// Setting this property's value to a null reference deletes the
17663
/// metadata tag from the metadata model.
17669
return GetTagArray<byte>("OECF");
17673
SetTagValueUndefined("OECF", value);
17678
/// Gets or sets the shutter speed. The unit is the APEX (Additive System of Photographic Exposure).
17681
/// <b>Handling of null values</b><para/>
17682
/// A null value indicates, that the corresponding metadata tag is not
17683
/// present in the metadata model.
17684
/// Setting this property's value to a non-null reference creates the
17685
/// metadata tag if necessary.
17686
/// Setting this property's value to a null reference deletes the
17687
/// metadata tag from the metadata model.
17689
public FIRational? ShutterSpeedValue
17693
return GetTagValue<FIRational>("ShutterSpeedValue");
17697
SetTagValue("ShutterSpeedValue", value);
17702
/// Gets or sets the lens aperture. The unit is the APEX value.
17705
/// <b>Handling of null values</b><para/>
17706
/// A null value indicates, that the corresponding metadata tag is not
17707
/// present in the metadata model.
17708
/// Setting this property's value to a non-null reference creates the
17709
/// metadata tag if necessary.
17710
/// Setting this property's value to a null reference deletes the
17711
/// metadata tag from the metadata model.
17713
public FIURational? ApertureValue
17717
return GetTagValue<FIURational>("ApertureValue");
17721
SetTagValue("ApertureValue", value);
17726
/// Gets or sets the value of brightness. The unit is the APEX value.
17727
/// Ordinarily it is given in the range of -99.99 to 99.99.
17730
/// <b>Handling of null values</b><para/>
17731
/// A null value indicates, that the corresponding metadata tag is not
17732
/// present in the metadata model.
17733
/// Setting this property's value to a non-null reference creates the
17734
/// metadata tag if necessary.
17735
/// Setting this property's value to a null reference deletes the
17736
/// metadata tag from the metadata model.
17738
public FIRational? BrightnessValue
17742
return GetTagValue<FIRational>("BrightnessValue");
17746
SetTagValue("BrightnessValue", value);
17751
/// Gets or sets the exposure bias. The unit is the APEX value.
17752
/// Ordinarily it is given in the range of �99.99 to 99.99.
17755
/// <b>Handling of null values</b><para/>
17756
/// A null value indicates, that the corresponding metadata tag is not
17757
/// present in the metadata model.
17758
/// Setting this property's value to a non-null reference creates the
17759
/// metadata tag if necessary.
17760
/// Setting this property's value to a null reference deletes the
17761
/// metadata tag from the metadata model.
17763
public FIRational? ExposureBiasValue
17767
return GetTagValue<FIRational>("ExposureBiasValue");
17771
SetTagValue("ExposureBiasValue", value);
17776
/// Gets or sets the smallest F number of the lens. The unit is the APEX value.
17777
/// Ordinarily it is given in the range of 00.00 to 99.99,
17778
/// but it is not limited to this range.
17781
/// <b>Handling of null values</b><para/>
17782
/// A null value indicates, that the corresponding metadata tag is not
17783
/// present in the metadata model.
17784
/// Setting this property's value to a non-null reference creates the
17785
/// metadata tag if necessary.
17786
/// Setting this property's value to a null reference deletes the
17787
/// metadata tag from the metadata model.
17789
public FIURational? MaxApertureValue
17793
return GetTagValue<FIURational>("MaxApertureValue");
17797
SetTagValue("MaxApertureValue", value);
17802
/// Gets or sets distance to the subject, given in meters.
17803
/// Note that if the numerator of the recorded value is FFFFFFFF, infinity shall be indicated;
17804
/// and if the numerator is 0, distance unknown shall be indicated.
17807
/// <b>Handling of null values</b><para/>
17808
/// A null value indicates, that the corresponding metadata tag is not
17809
/// present in the metadata model.
17810
/// Setting this property's value to a non-null reference creates the
17811
/// metadata tag if necessary.
17812
/// Setting this property's value to a null reference deletes the
17813
/// metadata tag from the metadata model.
17815
public FIURational? SubjectDistance
17819
return GetTagValue<FIURational>("SubjectDistance");
17823
SetTagValue("SubjectDistance", value);
17828
/// Gets or sets the metering mode. See remarks for further information.
17831
/// The following values are defined:<para/>
17832
/// <list type="table">
17834
/// <term>ID</term>
17835
/// <description>Description</description>
17839
/// <description>unknown</description>
17843
/// <description>average</description>
17847
/// <description>center-weighted-average</description>
17851
/// <description>spot</description>
17855
/// <description>multi-spot</description>
17859
/// <description>pattern</description>
17863
/// <description>partial</description>
17866
/// <term>other</term>
17867
/// <description>reserved</description>
17870
/// <term>255</term>
17871
/// <description>other</description>
17875
/// <br/><b>Handling of null values</b><para/>
17876
/// A null value indicates, that the corresponding metadata tag is not
17877
/// present in the metadata model.
17878
/// Setting this property's value to a non-null reference creates the
17879
/// metadata tag if necessary.
17880
/// Setting this property's value to a null reference deletes the
17881
/// metadata tag from the metadata model.
17883
public ushort? MeteringMode
17887
return GetTagValue<ushort>("MeteringMode");
17891
SetTagValue("MeteringMode", value);
17896
/// Gets or sets the kind of light source.
17897
/// See remarks for further information.
17900
/// The following values are defined:<para/>
17901
/// <list type="table">
17903
/// <term>ID</term>
17904
/// <description>Description</description>
17908
/// <description>unknown</description>
17912
/// <description>daylight</description>
17916
/// <description>fluorescent</description>
17920
/// <description>tungsten</description>
17924
/// <description>flash</description>
17928
/// <description>fine weather</description>
17931
/// <term>10</term>
17932
/// <description>cloudy weather</description>
17935
/// <term>11</term>
17936
/// <description>shade</description>
17939
/// <term>12</term>
17940
/// <description>daylight fluorecent (D 5700 - 7100K)</description>
17943
/// <term>13</term>
17944
/// <description>day white fluorescent (N 4600 - 5400K)</description>
17947
/// <term>14</term>
17948
/// <description>cool white fluorescent (W 3900 - 4500K)</description>
17951
/// <term>15</term>
17952
/// <description>white fluorescent (WW 3200 - 3700K)</description>
17955
/// <term>17</term>
17956
/// <description>standard light A</description>
17959
/// <term>18</term>
17960
/// <description>standard light B</description>
17963
/// <term>19</term>
17964
/// <description>standard light C</description>
17967
/// <term>20</term>
17968
/// <description>D55</description>
17971
/// <term>21</term>
17972
/// <description>D65</description>
17975
/// <term>22</term>
17976
/// <description>D75</description>
17979
/// <term>23</term>
17980
/// <description>D50</description>
17983
/// <term>24</term>
17984
/// <description>ISO studio tungsten</description>
17987
/// <term>255</term>
17988
/// <description>other light source</description>
17991
/// <term>other</term>
17992
/// <description>reserved</description>
17996
/// <br/><b>Handling of null values</b><para/>
17997
/// A null value indicates, that the corresponding metadata tag is not
17998
/// present in the metadata model.
17999
/// Setting this property's value to a non-null reference creates the
18000
/// metadata tag if necessary.
18001
/// Setting this property's value to a null reference deletes the
18002
/// metadata tag from the metadata model.
18004
public ushort? LightSource
18008
return GetTagValue<ushort>("LightSource");
18012
SetTagValue("LightSource", value);
18017
/// Gets or sets a value indicating the status of flash when the image was shot.
18018
/// Bit 0 indicates the flash firing status, bits 1 and 2 indicate the flash return
18019
/// status, bits 3 and 4 indicate the flash mode, bit 5 indicates whether the flash
18020
/// function is present, and bit 6 indicates "red eye" mode.
18023
/// <b>Handling of null values</b><para/>
18024
/// A null value indicates, that the corresponding metadata tag is not
18025
/// present in the metadata model.
18026
/// Setting this property's value to a non-null reference creates the
18027
/// metadata tag if necessary.
18028
/// Setting this property's value to a null reference deletes the
18029
/// metadata tag from the metadata model.
18031
public ushort? Flash
18035
return GetTagValue<ushort>("Flash");
18039
SetTagValue("Flash", value);
18044
/// Gets or sets a value indicating the location and area of the main subject in
18045
/// the overall scene. Variable length between 2 and 4.
18048
/// <b>Handling of null values</b><para/>
18049
/// A null value indicates, that the corresponding metadata tag is not
18050
/// present in the metadata model.
18051
/// Setting this property's value to a non-null reference creates the
18052
/// metadata tag if necessary.
18053
/// Setting this property's value to a null reference deletes the
18054
/// metadata tag from the metadata model.
18056
public ushort[] SubjectArea
18060
return GetTagArray<ushort>("SubjectArea");
18064
FreeImage.Resize(ref value, 2, 4);
18065
SetTagValue("SubjectArea", value);
18070
/// Gets or sets the actual focal length of the lens, in mm.
18071
/// Conversion is not made to the focal length of a 35 mm film camera.
18074
/// <b>Handling of null values</b><para/>
18075
/// A null value indicates, that the corresponding metadata tag is not
18076
/// present in the metadata model.
18077
/// Setting this property's value to a non-null reference creates the
18078
/// metadata tag if necessary.
18079
/// Setting this property's value to a null reference deletes the
18080
/// metadata tag from the metadata model.
18082
public FIURational? FocalLength
18086
return GetTagValue<FIURational>("FocalLength");
18090
SetTagValue("FocalLength", value);
18095
/// Gets or sets the strobe energy at the time the image is captured,
18096
/// as measured in Beam Candle Power Seconds (BCPS).
18099
/// <b>Handling of null values</b><para/>
18100
/// A null value indicates, that the corresponding metadata tag is not
18101
/// present in the metadata model.
18102
/// Setting this property's value to a non-null reference creates the
18103
/// metadata tag if necessary.
18104
/// Setting this property's value to a null reference deletes the
18105
/// metadata tag from the metadata model.
18107
public FIURational? FlashEnergy
18111
return GetTagValue<FIURational>("FlashEnergy");
18115
SetTagValue("FlashEnergy", value);
18120
/// Gets or sets the camera or input device spatial frequency table and SFR values
18121
/// in the direction of image width, image height, and diagonal direction,
18122
/// as specified in ISO 12233.
18125
/// <b>Handling of null values</b><para/>
18126
/// A null value indicates, that the corresponding metadata tag is not
18127
/// present in the metadata model.
18128
/// Setting this property's value to a non-null reference creates the
18129
/// metadata tag if necessary.
18130
/// Setting this property's value to a null reference deletes the
18131
/// metadata tag from the metadata model.
18133
public byte[] SpatialFrequencyResponse
18137
return GetTagArray<byte>("SpatialFrequencyResponse");
18141
SetTagValueUndefined("SpatialFrequencyResponse", value);
18146
/// Gets or sets the number of pixels in the image width (X) direction per
18147
/// FocalPlaneResolutionUnit on the camera focal plane.
18150
/// <b>Handling of null values</b><para/>
18151
/// A null value indicates, that the corresponding metadata tag is not
18152
/// present in the metadata model.
18153
/// Setting this property's value to a non-null reference creates the
18154
/// metadata tag if necessary.
18155
/// Setting this property's value to a null reference deletes the
18156
/// metadata tag from the metadata model.
18158
public FIURational? FocalPlaneXResolution
18162
return GetTagValue<FIURational>("FocalPlaneXResolution");
18166
SetTagValue("FocalPlaneXResolution", value);
18171
/// Gets or sets the number of pixels in the image height (Y) direction per
18172
/// FocalPlaneResolutionUnit on the camera focal plane.
18175
/// <b>Handling of null values</b><para/>
18176
/// A null value indicates, that the corresponding metadata tag is not
18177
/// present in the metadata model.
18178
/// Setting this property's value to a non-null reference creates the
18179
/// metadata tag if necessary.
18180
/// Setting this property's value to a null reference deletes the
18181
/// metadata tag from the metadata model.
18183
public FIURational? FocalPlaneYResolution
18187
return GetTagValue<FIURational>("FocalPlaneYResolution");
18191
SetTagValue("FocalPlaneYResolution", value);
18196
/// Gets or sets the unit for measuring FocalPlaneXResolution and FocalPlaneYResolution.
18197
/// This value is the same as the ResolutionUnit.
18200
/// <b>Handling of null values</b><para/>
18201
/// A null value indicates, that the corresponding metadata tag is not
18202
/// present in the metadata model.
18203
/// Setting this property's value to a non-null reference creates the
18204
/// metadata tag if necessary.
18205
/// Setting this property's value to a null reference deletes the
18206
/// metadata tag from the metadata model.
18208
public ushort? FocalPlaneResolutionUnit
18212
return GetTagValue<ushort>("FocalPlaneResolutionUnit");
18216
SetTagValue("FocalPlaneResolutionUnit", value);
18221
/// Gets or sets the location of the main subject in the scene.
18222
/// The value of this tag represents the pixel at the center of the main subject
18223
/// relative to the left edge, prior to rotation processing as per the Rotation tag.
18224
/// The first value indicates the X column number and second indicates the Y row number.
18227
/// <b>Handling of null values</b><para/>
18228
/// A null value indicates, that the corresponding metadata tag is not
18229
/// present in the metadata model.
18230
/// Setting this property's value to a non-null reference creates the
18231
/// metadata tag if necessary.
18232
/// Setting this property's value to a null reference deletes the
18233
/// metadata tag from the metadata model.
18235
public ushort? SubjectLocation
18239
return GetTagValue<ushort>("SubjectLocation");
18243
SetTagValue("SubjectLocation", value);
18248
/// Gets or sets the exposure index selected on the camera or input device at the
18249
/// time the image was captured.
18252
/// <b>Handling of null values</b><para/>
18253
/// A null value indicates, that the corresponding metadata tag is not
18254
/// present in the metadata model.
18255
/// Setting this property's value to a non-null reference creates the
18256
/// metadata tag if necessary.
18257
/// Setting this property's value to a null reference deletes the
18258
/// metadata tag from the metadata model.
18260
public FIURational? ExposureIndex
18264
return GetTagValue<FIURational>("ExposureIndex");
18268
SetTagValue("ExposureIndex", value);
18273
/// Gets or sets the image sensor type on the camera or input device.
18274
/// See remarks for further information.
18277
/// The following values are defined:<para/>
18278
/// <list type="table">
18280
/// <term>ID</term>
18281
/// <description>Description</description>
18285
/// <description>not defined</description>
18289
/// <description>one-chip color area sensor</description>
18293
/// <description>two-chip color area sensor</description>
18297
/// <description>three-chip color area sensor</description>
18301
/// <description>color sequential area sensor</description>
18305
/// <description>trilinear sensor</description>
18309
/// <description>color sequential linear sensor</description>
18312
/// <term>other</term>
18313
/// <description>reserved</description>
18317
/// <br/><b>Handling of null values</b><para/>
18318
/// A null value indicates, that the corresponding metadata tag is not
18319
/// present in the metadata model.
18320
/// Setting this property's value to a non-null reference creates the
18321
/// metadata tag if necessary.
18322
/// Setting this property's value to a null reference deletes the
18323
/// metadata tag from the metadata model.
18325
public ushort? SensingMethod
18329
return GetTagValue<ushort>("SensingMethod");
18333
SetTagValue("SensingMethod", value);
18338
/// Gets or sets the image source. If a DSC recorded the image, this tag value of this
18339
/// tag always be set to 3, indicating that the image was recorded on a DSC.
18342
/// <b>Handling of null values</b><para/>
18343
/// A null value indicates, that the corresponding metadata tag is not
18344
/// present in the metadata model.
18345
/// Setting this property's value to a non-null reference creates the
18346
/// metadata tag if necessary.
18347
/// Setting this property's value to a null reference deletes the
18348
/// metadata tag from the metadata model.
18350
public byte? FileSource
18354
return GetTagValue<byte>("FileSource");
18358
SetTagValueUndefined("FileSource", value.HasValue ? new byte[] { value.Value } : null);
18363
/// Gets or sets the type of scene. If a DSC recorded the image, this tag value shall
18364
/// always be set to 1, indicating that the image was directly photographed.
18367
/// <b>Handling of null values</b><para/>
18368
/// A null value indicates, that the corresponding metadata tag is not
18369
/// present in the metadata model.
18370
/// Setting this property's value to a non-null reference creates the
18371
/// metadata tag if necessary.
18372
/// Setting this property's value to a null reference deletes the
18373
/// metadata tag from the metadata model.
18375
public byte? SceneType
18379
return GetTagValue<byte>("SceneType");
18383
SetTagValueUndefined("SceneType", value.HasValue ? new byte[] { value.Value } : null);
18388
/// Gets or sets the color filter array (CFA) geometric pattern of the image sensor
18389
/// when a one-chip color area sensor is used. It does not apply to all sensing methods.
18392
/// <b>Handling of null values</b><para/>
18393
/// A null value indicates, that the corresponding metadata tag is not
18394
/// present in the metadata model.
18395
/// Setting this property's value to a non-null reference creates the
18396
/// metadata tag if necessary.
18397
/// Setting this property's value to a null reference deletes the
18398
/// metadata tag from the metadata model.
18400
public byte[] CFAPattern
18404
return GetTagArray<byte>("CFAPattern");
18408
SetTagValueUndefined("CFAPattern", value);
18413
/// Gets or sets the use of special processing on image data, such as rendering geared to output.
18414
/// When special processing is performed, the reader is expected to disable or minimize any
18415
/// further processing. See remarks for further information.
18418
/// The following values are definied:<para/>
18419
/// <list type="table">
18421
/// <term>ID</term>
18422
/// <description>Description</description>
18426
/// <description>normal process</description>
18430
/// <description>custom process</description>
18433
/// <term>other</term>
18434
/// <description>reserved</description>
18438
/// <br/><b>Handling of null values</b><para/>
18439
/// A null value indicates, that the corresponding metadata tag is not
18440
/// present in the metadata model.
18441
/// Setting this property's value to a non-null reference creates the
18442
/// metadata tag if necessary.
18443
/// Setting this property's value to a null reference deletes the
18444
/// metadata tag from the metadata model.
18446
public ushort? CustomRendered
18450
return GetTagValue<ushort>("CustomRendered");
18454
SetTagValue("CustomRendered", value);
18459
/// Gets or sets the exposure mode set when the image was shot.
18460
/// In auto-bracketing mode, the camera shoots a series of frames of the same scene
18461
/// at different exposure settings. See remarks for further information.
18464
/// The following values are definied:<para/>
18465
/// <list type="table">
18467
/// <term>ID</term>
18468
/// <description>Description</description>
18472
/// <description>auto exposure</description>
18476
/// <description>manual exposure</description>
18480
/// <description>auto bracket</description>
18483
/// <term>other</term>
18484
/// <description>reserved</description>
18488
/// <br/><b>Handling of null values</b><para/>
18489
/// A null value indicates, that the corresponding metadata tag is not
18490
/// present in the metadata model.
18491
/// Setting this property's value to a non-null reference creates the
18492
/// metadata tag if necessary.
18493
/// Setting this property's value to a null reference deletes the
18494
/// metadata tag from the metadata model.
18496
public ushort? ExposureMode
18500
return GetTagValue<ushort>("ExposureMode");
18504
SetTagValue("ExposureMode", value);
18509
/// Gets or sets the white balance mode set when the image was shot.
18510
/// See remarks for further information.
18513
/// The following values are definied:<para/>
18514
/// <list type="table">
18516
/// <term>ID</term>
18517
/// <description>Description</description>
18521
/// <description>auto white balance</description>
18525
/// <description>manual white balance</description>
18528
/// <term>other</term>
18529
/// <description>reserved</description>
18533
/// <br/><b>Handling of null values</b><para/>
18534
/// A null value indicates, that the corresponding metadata tag is not
18535
/// present in the metadata model.
18536
/// Setting this property's value to a non-null reference creates the
18537
/// metadata tag if necessary.
18538
/// Setting this property's value to a null reference deletes the
18539
/// metadata tag from the metadata model.
18541
public ushort? WhiteBalance
18545
return GetTagValue<ushort>("WhiteBalance");
18549
SetTagValue("WhiteBalance", value);
18554
/// Gets or sets the digital zoom ratio when the image was shot.
18555
/// If the numerator of the recorded value is 0, this indicates that digital zoom was not used.
18558
/// <b>Handling of null values</b><para/>
18559
/// A null value indicates, that the corresponding metadata tag is not
18560
/// present in the metadata model.
18561
/// Setting this property's value to a non-null reference creates the
18562
/// metadata tag if necessary.
18563
/// Setting this property's value to a null reference deletes the
18564
/// metadata tag from the metadata model.
18566
public FIURational? DigitalZoomRatio
18570
return GetTagValue<FIURational>("DigitalZoomRatio");
18574
SetTagValue("DigitalZoomRatio", value);
18579
/// Gets or sets the equivalent focal length assuming a 35mm film camera, in mm.
18580
/// A value of 0 means the focal length is unknown. Note that this tag differs
18581
/// from the FocalLength tag.
18584
/// <b>Handling of null values</b><para/>
18585
/// A null value indicates, that the corresponding metadata tag is not
18586
/// present in the metadata model.
18587
/// Setting this property's value to a non-null reference creates the
18588
/// metadata tag if necessary.
18589
/// Setting this property's value to a null reference deletes the
18590
/// metadata tag from the metadata model.
18592
public ushort? FocalLengthIn35mmFilm
18596
return GetTagValue<ushort>("DigitalZoomRatio");
18600
SetTagValue("DigitalZoomRatio", value);
18605
/// Gets or sets the type of scene that was shot.
18606
/// It can also be used to record the mode in which the image was shot.
18607
/// See remarks for further information.
18610
/// The following values are definied:<para/>
18611
/// <list type="table">
18613
/// <term>ID</term>
18614
/// <description>Description</description>
18618
/// <description>standard</description>
18622
/// <description>landscape</description>
18626
/// <description>portrait</description>
18630
/// <description>night scene</description>
18633
/// <term>other</term>
18634
/// <description>reserved</description>
18638
/// <br/><b>Handling of null values</b><para/>
18639
/// A null value indicates, that the corresponding metadata tag is not
18640
/// present in the metadata model.
18641
/// Setting this property's value to a non-null reference creates the
18642
/// metadata tag if necessary.
18643
/// Setting this property's value to a null reference deletes the
18644
/// metadata tag from the metadata model.
18646
public ushort? SceneCaptureType
18650
return GetTagValue<ushort>("SceneCaptureType");
18654
SetTagValue("SceneCaptureType", value);
18659
/// Gets or sets the degree of overall image gain adjustment.
18660
/// See remarks for further information.
18663
/// The following values are definied:<para/>
18664
/// <list type="table">
18666
/// <term>ID</term>
18667
/// <description>Description</description>
18671
/// <description>none</description>
18675
/// <description>low gain up</description>
18679
/// <description>high gain up</description>
18683
/// <description>low gain down</description>
18687
/// <description>high gain down</description>
18690
/// <term>other</term>
18691
/// <description>reserved</description>
18695
/// <br/><b>Handling of null values</b><para/>
18696
/// A null value indicates, that the corresponding metadata tag is not
18697
/// present in the metadata model.
18698
/// Setting this property's value to a non-null reference creates the
18699
/// metadata tag if necessary.
18700
/// Setting this property's value to a null reference deletes the
18701
/// metadata tag from the metadata model.
18703
public ushort? GainControl
18707
return GetTagValue<ushort>("GainControl");
18711
SetTagValue("GainControl", value);
18716
/// Gets or sets the direction of contrast processing applied by the camera
18717
/// when the image was shot.
18718
/// See remarks for further information.
18721
/// The following values are definied:<para/>
18722
/// <list type="table">
18724
/// <term>ID</term>
18725
/// <description>Description</description>
18729
/// <description>normal</description>
18733
/// <description>soft</description>
18737
/// <description>hard</description>
18740
/// <term>other</term>
18741
/// <description>reserved</description>
18745
/// <br/><b>Handling of null values</b><para/>
18746
/// A null value indicates, that the corresponding metadata tag is not
18747
/// present in the metadata model.
18748
/// Setting this property's value to a non-null reference creates the
18749
/// metadata tag if necessary.
18750
/// Setting this property's value to a null reference deletes the
18751
/// metadata tag from the metadata model.
18753
public ushort? Contrast
18757
return GetTagValue<ushort>("Contrast");
18761
SetTagValue("Contrast", value);
18766
/// Gets or sets the direction of saturation processing applied by the camera
18767
/// when the image was shot.
18768
/// See remarks for further information.
18771
/// The following values are definied:<para/>
18772
/// <list type="table">
18774
/// <term>ID</term>
18775
/// <description>Description</description>
18779
/// <description>normal</description>
18783
/// <description>low saturation</description>
18787
/// <description>high saturation</description>
18790
/// <term>other</term>
18791
/// <description>reserved</description>
18795
/// <br/><b>Handling of null values</b><para/>
18796
/// A null value indicates, that the corresponding metadata tag is not
18797
/// present in the metadata model.
18798
/// Setting this property's value to a non-null reference creates the
18799
/// metadata tag if necessary.
18800
/// Setting this property's value to a null reference deletes the
18801
/// metadata tag from the metadata model.
18803
public ushort? Saturation
18807
return GetTagValue<ushort>("Saturation");
18811
SetTagValue("Saturation", value);
18816
/// Gets or sets the direction of sharpness processing applied by the camera
18817
/// when the image was shot.
18818
/// See remarks for further information.
18821
/// The following values are definied:<para/>
18822
/// <list type="table">
18824
/// <term>ID</term>
18825
/// <description>Description</description>
18829
/// <description>normal</description>
18833
/// <description>soft</description>
18837
/// <description>hard</description>
18840
/// <term>other</term>
18841
/// <description>reserved</description>
18845
/// <br/><b>Handling of null values</b><para/>
18846
/// A null value indicates, that the corresponding metadata tag is not
18847
/// present in the metadata model.
18848
/// Setting this property's value to a non-null reference creates the
18849
/// metadata tag if necessary.
18850
/// Setting this property's value to a null reference deletes the
18851
/// metadata tag from the metadata model.
18853
public ushort? Sharpness
18857
return GetTagValue<ushort>("Sharpness");
18861
SetTagValue("Sharpness", value);
18866
/// Gets or sets information on the picture-taking conditions of a particular camera model.
18867
/// The tag is used only to indicate the picture-taking conditions in the reader.
18870
/// <b>Handling of null values</b><para/>
18871
/// A null value indicates, that the corresponding metadata tag is not
18872
/// present in the metadata model.
18873
/// Setting this property's value to a non-null reference creates the
18874
/// metadata tag if necessary.
18875
/// Setting this property's value to a null reference deletes the
18876
/// metadata tag from the metadata model.
18878
public byte[] DeviceSettingDescription
18882
return GetTagArray<byte>("DeviceSettingDescription");
18886
SetTagValueUndefined("DeviceSettingDescription", value);
18891
/// Gets or sets the distance to the subject.
18892
/// See remarks for further information.
18895
/// The following values are definied:<para/>
18896
/// <list type="table">
18898
/// <term>ID</term>
18899
/// <description>Description</description>
18903
/// <description>unknown</description>
18907
/// <description>macro</description>
18911
/// <description>close view</description>
18915
/// <description>distant view</description>
18918
/// <term>other</term>
18919
/// <description>reserved</description>
18923
/// <br/><b>Handling of null values</b><para/>
18924
/// A null value indicates, that the corresponding metadata tag is not
18925
/// present in the metadata model.
18926
/// Setting this property's value to a non-null reference creates the
18927
/// metadata tag if necessary.
18928
/// Setting this property's value to a null reference deletes the
18929
/// metadata tag from the metadata model.
18931
public ushort? SubjectDistanceRange
18935
return GetTagValue<ushort>("SubjectDistanceRange");
18939
SetTagValue("SubjectDistanceRange", value);
18944
/// Gets or sets an identifier assigned uniquely to each image.
18945
/// It is recorded as an ASCII string equivalent to hexadecimal notation and 128-bit fixed length.
18946
/// Constant length of 32.
18949
/// <b>Handling of null values</b><para/>
18950
/// A null value indicates, that the corresponding metadata tag is not
18951
/// present in the metadata model.
18952
/// Setting this property's value to a non-null reference creates the
18953
/// metadata tag if necessary.
18954
/// Setting this property's value to a null reference deletes the
18955
/// metadata tag from the metadata model.
18957
public string ImageUniqueID
18961
string text = GetTagText("ImageUniqueID");
18962
if (!string.IsNullOrEmpty(text))
18964
text = text.Substring(0, text.Length - 1);
18972
FreeImage.Resize(ref value, 32);
18975
SetTagValue("ImageUniqueID", value);
18981
/// Represents a collection of all tags contained in the metadata model
18982
/// <see cref="FREE_IMAGE_MDMODEL.FIMD_EXIF_GPS"/>.
18984
public class MDM_EXIF_GPS : MetadataModel
18987
/// Initializes a new instance of this class.
18989
/// <param name="dib">Handle to a FreeImage bitmap.</param>
18990
public MDM_EXIF_GPS(FIBITMAP dib) : base(dib) { }
18993
/// Retrieves the datamodel that this instance represents.
18995
public override FREE_IMAGE_MDMODEL Model
18997
get { return FREE_IMAGE_MDMODEL.FIMD_EXIF_GPS; }
19001
/// Gets or sets the GPS version ID. Constant length of 4.
19004
/// <b>Handling of null values</b><para/>
19005
/// A null value indicates, that the corresponding metadata tag is not
19006
/// present in the metadata model.
19007
/// Setting this property's value to a non-null reference creates the
19008
/// metadata tag if necessary.
19009
/// Setting this property's value to a null reference deletes the
19010
/// metadata tag from the metadata model.
19012
public byte[] VersionID
19016
return GetTagArray<byte>("GPSVersionID");
19020
FreeImage.Resize(ref value, 4);
19021
SetTagValue("GPSVersionID", value);
19026
/// Gets or sets a value indicating whether the <see cref="Latitude"/>
19027
/// is north or south latitude.
19030
/// <b>Handling of null values</b><para/>
19031
/// A null value indicates, that the corresponding metadata tag is not
19032
/// present in the metadata model.
19033
/// Setting this property's value to a non-null reference creates the
19034
/// metadata tag if necessary.
19035
/// Setting this property's value to a null reference deletes the
19036
/// metadata tag from the metadata model.
19038
public LatitudeType? LatitudeDirection
19042
return ToLatitudeType(GetTagText("GPSLatitudeRef"));
19046
SetTagValue("GPSLatitudeRef", ToString(value) + '\0');
19051
/// Gets or sets the latitude of the image. The latitude is expressed as three rational
19052
/// values giving the degrees, minutes, and seconds, respectively. Constant length of 3.
19055
/// <b>Handling of null values</b><para/>
19056
/// A null value indicates, that the corresponding metadata tag is not
19057
/// present in the metadata model.
19058
/// Setting this property's value to a non-null reference creates the
19059
/// metadata tag if necessary.
19060
/// Setting this property's value to a null reference deletes the
19061
/// metadata tag from the metadata model.
19063
/// <seealso cref="LatitudeDirection"/>
19064
public FIURational[] Latitude
19068
return GetTagArray<FIURational>("GPSLatitude");
19072
FreeImage.Resize(ref value, 3);
19073
SetTagValue("GPSLatitude", value);
19078
/// Gets or sets a value indicating whether <see cref="Longitude"/>
19079
/// is east or west longitude.
19082
/// <b>Handling of null values</b><para/>
19083
/// A null value indicates, that the corresponding metadata tag is not
19084
/// present in the metadata model.
19085
/// Setting this property's value to a non-null reference creates the
19086
/// metadata tag if necessary.
19087
/// Setting this property's value to a null reference deletes the
19088
/// metadata tag from the metadata model.
19090
public LongitudeType? LongitudeDirection
19094
return ToLongitudeType(GetTagText("GPSLongitudeRef"));
19098
SetTagValue("GPSLongitudeRef", ToString(value) + '\0');
19103
/// Gets or sets the longitude of the image. The longitude is expressed as three rational
19104
/// values giving the degrees, minutes, and seconds, respectively. Constant length of 3.
19107
/// <b>Handling of null values</b><para/>
19108
/// A null value indicates, that the corresponding metadata tag is not
19109
/// present in the metadata model.
19110
/// Setting this property's value to a non-null reference creates the
19111
/// metadata tag if necessary.
19112
/// Setting this property's value to a null reference deletes the
19113
/// metadata tag from the metadata model.
19115
/// <seealso cref="LongitudeDirection"/>
19116
public FIURational[] Longitude
19120
return GetTagArray<FIURational>("GPSLongitude");
19124
FreeImage.Resize(ref value, 3);
19125
SetTagValue("GPSLongitude", value);
19130
/// Gets a value indicating whether <see cref="Altitude"/> is sea level and the altitude
19131
/// is above sea level. If the altitude is below sea level <see cref="Altitude"/> is
19132
/// indicated as an absolute value.
19135
/// <b>Handling of null values</b><para/>
19136
/// A null value indicates, that the corresponding metadata tag is not
19137
/// present in the metadata model.
19138
/// Setting this property's value to a non-null reference creates the
19139
/// metadata tag if necessary.
19140
/// Setting this property's value to a null reference deletes the
19141
/// metadata tag from the metadata model.
19143
public AltitudeType? AltitudeDirection
19147
byte? flag = GetTagValue<byte>("GPSAltitudeRef");
19150
switch (flag.Value)
19153
return AltitudeType.AboveSeaLevel;
19155
return AltitudeType.BelowSeaLevel;
19157
return AltitudeType.Undefined;
19165
if (value.HasValue)
19167
switch (value.Value)
19169
case AltitudeType.AboveSeaLevel:
19173
case AltitudeType.BelowSeaLevel:
19182
SetTagValue("GPSAltitudeRef", val);
19187
/// Gets or sets the altitude based on the reference in <see cref="AltitudeDirection"/>.
19188
/// Altitude is expressed as one rational value. The reference unit is meters.
19191
/// <b>Handling of null values</b><para/>
19192
/// A null value indicates, that the corresponding metadata tag is not
19193
/// present in the metadata model.
19194
/// Setting this property's value to a non-null reference creates the
19195
/// metadata tag if necessary.
19196
/// Setting this property's value to a null reference deletes the
19197
/// metadata tag from the metadata model.
19199
public FIURational? Altitude
19203
return GetTagValue<FIURational>("GPSAltitude");
19207
SetTagValue("GPSAltitude", value);
19212
/// Gets or sets the sign of the <see cref="SignedAltitude"/>.
19215
/// This is a derived property. There is no metadata tag directly associated
19216
/// with this property value.
19218
/// <br/><b>Handling of null values</b><para/>
19219
/// A null value indicates, that the corresponding metadata tag is not
19220
/// present in the metadata model.
19221
/// Setting this property's value to a non-null reference creates the
19222
/// metadata tag if necessary.
19223
/// Setting this property's value to a null reference deletes the
19224
/// metadata tag from the metadata model.
19226
public int? AltitudeSign
19230
AltitudeType? seaLevel = AltitudeDirection;
19231
if (seaLevel.HasValue)
19233
return (seaLevel.Value == AltitudeType.BelowSeaLevel) ? -1 : 1;
19239
if (value.HasValue)
19241
AltitudeDirection = value.Value >= 0 ? AltitudeType.AboveSeaLevel : AltitudeType.BelowSeaLevel;
19245
AltitudeDirection = null;
19251
/// Gets or sets the signed altitude.
19252
/// Altitude is expressed as one rational value. The reference unit is meters.
19254
/// <exception cref="OverflowException">
19255
/// Altitude is too large to fit into a FIRational.
19258
/// This is a derived property. There is no metadata tag directly associated
19259
/// with this property value.
19261
/// <br/><b>Handling of null values</b><para/>
19262
/// A null value indicates, that the corresponding metadata tag is not
19263
/// present in the metadata model.
19264
/// Setting this property's value to a non-null reference creates the
19265
/// metadata tag if necessary.
19266
/// Setting this property's value to a null reference deletes the
19267
/// metadata tag from the metadata model.
19269
public FIRational? SignedAltitude
19273
FIRational? result = null;
19274
FIURational? altitude = Altitude;
19275
if (altitude.HasValue)
19277
int sign = AltitudeSign ?? 1;
19278
if (((int)altitude.Value.Numerator < 0) || ((int)altitude.Value.Denominator < 0))
19279
throw new OverflowException();
19280
result = new FIRational((int)altitude.Value.Numerator * sign, (int)altitude.Value.Denominator);
19286
FIURational? val = null;
19287
if (value.HasValue)
19289
if (value.Value < 0)
19292
value = -value.Value;
19298
val = new FIURational((uint)value.Value.Numerator, (uint)value.Value.Denominator);
19306
/// Gets or sets the time as UTC (Coordinated Universal Time). Constant length of 3.
19309
/// <b>Handling of null values</b><para/>
19310
/// A null value indicates, that the corresponding metadata tag is not
19311
/// present in the metadata model.
19312
/// Setting this property's value to a non-null reference creates the
19313
/// metadata tag if necessary.
19314
/// Setting this property's value to a null reference deletes the
19315
/// metadata tag from the metadata model.
19317
public TimeSpan? TimeStamp
19321
FIURational[] stamp = GetTagArray<FIURational>("GPSTimeStamp");
19322
if ((stamp == null) || stamp.Length != 3)
19328
return new TimeSpan((int)stamp[0], (int)stamp[1], (int)stamp[2]);
19333
FIURational[] stamp = null;
19334
if (value.HasValue)
19336
TimeSpan span = value.Value;
19337
stamp = new FIURational[3];
19338
stamp[0] = span.Hours;
19339
stamp[1] = span.Minutes;
19340
stamp[2] = span.Seconds;
19342
SetTagValue("GPSTimeStamp", stamp);
19347
/// Gets or sets the GPS satellites used for measurements. This tag can be used to describe
19348
/// the number of satellites, their ID number, angle of elevation, azimuth, SNR and other
19349
/// information in ASCII notation. The format is not specified.
19352
/// <b>Handling of null values</b><para/>
19353
/// A null value indicates, that the corresponding metadata tag is not
19354
/// present in the metadata model.
19355
/// Setting this property's value to a non-null reference creates the
19356
/// metadata tag if necessary.
19357
/// Setting this property's value to a null reference deletes the
19358
/// metadata tag from the metadata model.
19360
public string Satellites
19364
string result = GetTagText("GPSSatellites");
19365
if (!string.IsNullOrEmpty(result))
19367
result = result.Substring(0, result.Length - 1);
19377
SetTagValue("GPSTimeStamp", value);
19382
/// Gets or sets a value indicating the status of the GPS receiver when the image was recorded.
19383
/// <b>true</b> indicates measurement was in progress;
19384
/// <b>false</b> indicates measurement was Interoperability.
19387
/// <b>Handling of null values</b><para/>
19388
/// A null value indicates, that the corresponding metadata tag is not
19389
/// present in the metadata model.
19390
/// Setting this property's value to a non-null reference creates the
19391
/// metadata tag if necessary.
19392
/// Setting this property's value to a null reference deletes the
19393
/// metadata tag from the metadata model.
19395
public bool? Status
19399
string text = GetTagText("GPSStatus");
19400
return string.IsNullOrEmpty(text) ? default(bool?) : text[0] == 'A';
19404
SetTagValue("GPSStatus", value.HasValue ? (value.Value ? "A\0" : "V\0") : null);
19409
/// Gets or sets a value indicating the GPS measurement mode.
19410
/// <b>true</b> indicates three-dimensional measurement;
19411
/// <b>false</b> indicated two-dimensional measurement was in progress.
19414
/// <b>Handling of null values</b><para/>
19415
/// A null value indicates, that the corresponding metadata tag is not
19416
/// present in the metadata model.
19417
/// Setting this property's value to a non-null reference creates the
19418
/// metadata tag if necessary.
19419
/// Setting this property's value to a null reference deletes the
19420
/// metadata tag from the metadata model.
19422
public bool? MeasureMode3D
19426
string text = GetTagText("GPSMeasureMode");
19427
return string.IsNullOrEmpty(text) ? default(bool?) : text[0] == '3';
19431
SetTagValue("GPSMeasureMode", value.HasValue ? (value.Value ? "3\0" : "2\0") : null);
19436
/// Gets or sets the GPS DOP (data degree of precision). An HDOP value is written during
19437
/// two-dimensional measurement, and PDOP during three-dimensional measurement.
19440
/// <b>Handling of null values</b><para/>
19441
/// A null value indicates, that the corresponding metadata tag is not
19442
/// present in the metadata model.
19443
/// Setting this property's value to a non-null reference creates the
19444
/// metadata tag if necessary.
19445
/// Setting this property's value to a null reference deletes the
19446
/// metadata tag from the metadata model.
19448
public FIURational? DOP
19452
return GetTagValue<FIURational>("GPSDOP");
19456
SetTagValue("GPSDOP", value);
19461
/// Gets or sets the unit used to express the GPS receiver <see cref="Speed"/> of movement.
19464
/// <b>Handling of null values</b><para/>
19465
/// A null value indicates, that the corresponding metadata tag is not
19466
/// present in the metadata model.
19467
/// Setting this property's value to a non-null reference creates the
19468
/// metadata tag if necessary.
19469
/// Setting this property's value to a null reference deletes the
19470
/// metadata tag from the metadata model.
19472
/// <seealso cref="Speed"/>
19473
public VelocityUnit? SpeedUnit
19477
return ToUnitType(GetTagText("GPSSpeedRef"));
19481
SetTagValue("GPSSpeedRef", ToString(value) + '\0');
19486
/// Gets or sets the speed of GPS receiver movement.
19489
/// <b>Handling of null values</b><para/>
19490
/// A null value indicates, that the corresponding metadata tag is not
19491
/// present in the metadata model.
19492
/// Setting this property's value to a non-null reference creates the
19493
/// metadata tag if necessary.
19494
/// Setting this property's value to a null reference deletes the
19495
/// metadata tag from the metadata model.
19497
/// <seealso cref="SpeedUnit"/>
19498
public FIURational? Speed
19502
return GetTagValue<FIURational>("GPSSpeed");
19506
SetTagValue("GPSSpeed", value);
19511
/// Gets or sets the reference for giving the direction of GPS receiver movement.
19514
/// <b>Handling of null values</b><para/>
19515
/// A null value indicates, that the corresponding metadata tag is not
19516
/// present in the metadata model.
19517
/// Setting this property's value to a non-null reference creates the
19518
/// metadata tag if necessary.
19519
/// Setting this property's value to a null reference deletes the
19520
/// metadata tag from the metadata model.
19522
/// <seealso cref="Track"/>
19523
public DirectionReference? TrackDirectionReference
19527
return ToDirectionType(GetTagText("GPSTrackRef"));
19531
SetTagValue("GPSTrackRef", ToString(value) + '\0');
19536
/// Gets or sets the direction of GPS receiver movement.
19537
/// The range of values is from 0.00 to 359.99.
19540
/// <b>Handling of null values</b><para/>
19541
/// A null value indicates, that the corresponding metadata tag is not
19542
/// present in the metadata model.
19543
/// Setting this property's value to a non-null reference creates the
19544
/// metadata tag if necessary.
19545
/// Setting this property's value to a null reference deletes the
19546
/// metadata tag from the metadata model.
19548
/// <seealso cref="TrackDirectionReference"/>
19549
public FIURational? Track
19553
return GetTagValue<FIURational>("GPSTrack");
19557
SetTagValue("GPSTrack", value);
19562
/// Gets or sets the reference for giving the direction of GPS receiver movement.
19565
/// <b>Handling of null values</b><para/>
19566
/// A null value indicates, that the corresponding metadata tag is not
19567
/// present in the metadata model.
19568
/// Setting this property's value to a non-null reference creates the
19569
/// metadata tag if necessary.
19570
/// Setting this property's value to a null reference deletes the
19571
/// metadata tag from the metadata model.
19573
/// <seealso cref="ImageDirection"/>
19574
public DirectionReference? ImageDirectionReference
19578
return ToDirectionType(GetTagText("GPSImgDirectionRef"));
19582
SetTagValue("GPSImgDirectionRef", ToString(value) + '\0');
19587
/// Gets or sets the direction of the image when it was captured.
19588
/// The range of values is from 0.00 to 359.99.
19591
/// <b>Handling of null values</b><para/>
19592
/// A null value indicates, that the corresponding metadata tag is not
19593
/// present in the metadata model.
19594
/// Setting this property's value to a non-null reference creates the
19595
/// metadata tag if necessary.
19596
/// Setting this property's value to a null reference deletes the
19597
/// metadata tag from the metadata model.
19599
/// <seealso cref="ImageDirectionReference"/>
19600
public FIURational? ImageDirection
19604
return GetTagValue<FIURational>("GPSImgDirection");
19608
SetTagValue("GPSImgDirection", value);
19613
/// Gets or sets the geodetic survey data used by the GPS receiver. If the survey data
19614
/// is restricted to Japan, the value of this tag is 'TOKYO' or 'WGS-84'.
19617
/// <b>Handling of null values</b><para/>
19618
/// A null value indicates, that the corresponding metadata tag is not
19619
/// present in the metadata model.
19620
/// Setting this property's value to a non-null reference creates the
19621
/// metadata tag if necessary.
19622
/// Setting this property's value to a null reference deletes the
19623
/// metadata tag from the metadata model.
19625
public string MapDatum
19629
string result = GetTagText("GPSMapDatum");
19630
if (!string.IsNullOrEmpty(result))
19632
result = result.Substring(0, result.Length - 1);
19638
SetTagValue("GPSMapDatum", value + '\0');
19643
/// Gets or sets a value indicating whether the destination point
19644
/// is north or south latitude.
19647
/// <b>Handling of null values</b><para/>
19648
/// A null value indicates, that the corresponding metadata tag is not
19649
/// present in the metadata model.
19650
/// Setting this property's value to a non-null reference creates the
19651
/// metadata tag if necessary.
19652
/// Setting this property's value to a null reference deletes the
19653
/// metadata tag from the metadata model.
19655
/// <seealso cref="Latitude"/>
19656
public LatitudeType? DestinationLatitudeDirection
19660
return ToLatitudeType(GetTagText("GPSDestLatitudeRef"));
19664
SetTagValue("GPSDestLatitudeRef", ToString(value) + '\0');
19669
/// Gets or sets the latitude of the destination point. The latitude is expressed as three rational
19670
/// values giving the degrees, minutes, and seconds, respectively. Constant length of 3.
19673
/// <b>Handling of null values</b><para/>
19674
/// A null value indicates, that the corresponding metadata tag is not
19675
/// present in the metadata model.
19676
/// Setting this property's value to a non-null reference creates the
19677
/// metadata tag if necessary.
19678
/// Setting this property's value to a null reference deletes the
19679
/// metadata tag from the metadata model.
19681
/// <seealso cref="DestinationLatitudeDirection"/>
19682
public FIURational[] DestinationLatitude
19686
return GetTagArray<FIURational>("GPSDestLatitude");
19690
FreeImage.Resize(ref value, 3);
19691
SetTagValue("GPSDestLatitude", value);
19696
/// Gets or sets a value indicating whether the destination point
19697
/// is east or west longitude.
19700
/// <b>Handling of null values</b><para/>
19701
/// A null value indicates, that the corresponding metadata tag is not
19702
/// present in the metadata model.
19703
/// Setting this property's value to a non-null reference creates the
19704
/// metadata tag if necessary.
19705
/// Setting this property's value to a null reference deletes the
19706
/// metadata tag from the metadata model.
19708
/// <seealso cref="Latitude"/>
19709
public LongitudeType? DestinationLongitudeDirection
19713
return ToLongitudeType(GetTagText("GPSDestLongitudeRef"));
19717
SetTagValue("GPSDestLongitudeRef", ToString(value) + '\0');
19722
/// Gets or sets the longitude of the destination point. The longitude is expressed as three rational
19723
/// values giving the degrees, minutes, and seconds, respectively. Constant length of 3.
19726
/// <b>Handling of null values</b><para/>
19727
/// A null value indicates, that the corresponding metadata tag is not
19728
/// present in the metadata model.
19729
/// Setting this property's value to a non-null reference creates the
19730
/// metadata tag if necessary.
19731
/// Setting this property's value to a null reference deletes the
19732
/// metadata tag from the metadata model.
19734
public FIURational[] DestinationLongitude
19738
return GetTagArray<FIURational>("GPSDestLongitude");
19742
FreeImage.Resize(ref value, 3);
19743
SetTagValue("GPSDestLongitude", value);
19748
/// Gets or sets the reference used for giving the bearing to the destination point.
19751
/// <b>Handling of null values</b><para/>
19752
/// A null value indicates, that the corresponding metadata tag is not
19753
/// present in the metadata model.
19754
/// Setting this property's value to a non-null reference creates the
19755
/// metadata tag if necessary.
19756
/// Setting this property's value to a null reference deletes the
19757
/// metadata tag from the metadata model.
19759
/// <seealso cref="DestinationBearing"/>
19760
public DirectionReference? DestinationDirectionReference
19764
return ToDirectionType(GetTagText("GPSDestBearingRef"));
19768
SetTagValue("GPSDestBearingRef", ToString(value) + '\0');
19773
/// Gets or sets the bearing to the destination point.
19774
/// The range of values is from 0.00 to 359.99.
19777
/// <b>Handling of null values</b><para/>
19778
/// A null value indicates, that the corresponding metadata tag is not
19779
/// present in the metadata model.
19780
/// Setting this property's value to a non-null reference creates the
19781
/// metadata tag if necessary.
19782
/// Setting this property's value to a null reference deletes the
19783
/// metadata tag from the metadata model.
19785
/// <seealso cref="DestinationDirectionReference"/>
19786
public FIURational? DestinationBearing
19790
return GetTagValue<FIURational>("GPSDestBearing");
19794
SetTagValue("GPSDestBearing", value);
19799
/// Gets or sets the unit used to express the distance to the destination point.
19802
/// <b>Handling of null values</b><para/>
19803
/// A null value indicates, that the corresponding metadata tag is not
19804
/// present in the metadata model.
19805
/// Setting this property's value to a non-null reference creates the
19806
/// metadata tag if necessary.
19807
/// Setting this property's value to a null reference deletes the
19808
/// metadata tag from the metadata model.
19810
/// <seealso cref="DestinationBearing"/>
19811
public VelocityUnit? DestinationUnit
19815
return ToUnitType(GetTagText("GPSDestDistanceRef"));
19819
SetTagValue("GPSDestDistanceRef", ToString(value) + '\0');
19824
/// Gets or sets a character string recording the name of the method used
19825
/// for location finding. The first byte indicates the character code used,
19826
/// and this is followed by the name of the method. Since the Type is not ASCII,
19827
/// NULL termination is not necessary.
19830
/// <b>Handling of null values</b><para/>
19831
/// A null value indicates, that the corresponding metadata tag is not
19832
/// present in the metadata model.
19833
/// Setting this property's value to a non-null reference creates the
19834
/// metadata tag if necessary.
19835
/// Setting this property's value to a null reference deletes the
19836
/// metadata tag from the metadata model.
19838
public byte[] ProcessingMethod
19842
return GetTagArray<byte>("GPSProcessingMethod");
19846
SetTagValue("GPSProcessingMethod", value);
19851
/// Gets or sets a character string recording the name of the GPS area.
19852
/// The first byte indicates the character code used, and this is followed by
19853
/// the name of the GPS area. Since the Type is not ASCII, NULL termination is
19857
/// <b>Handling of null values</b><para/>
19858
/// A null value indicates, that the corresponding metadata tag is not
19859
/// present in the metadata model.
19860
/// Setting this property's value to a non-null reference creates the
19861
/// metadata tag if necessary.
19862
/// Setting this property's value to a null reference deletes the
19863
/// metadata tag from the metadata model.
19865
public byte[] AreaInformation
19869
return GetTagArray<byte>("GPSAreaInformation");
19873
SetTagValue("GPSAreaInformation", value);
19878
/// Gets or sets date and time information relative to UTC (Coordinated Universal Time).
19881
/// This is a derived property. There is no metadata tag directly associated
19882
/// with this property value.
19884
/// <br/><b>Handling of null values</b><para/>
19885
/// A null value indicates, that the corresponding metadata tag is not
19886
/// present in the metadata model.
19887
/// Setting this property's value to a non-null reference creates the
19888
/// metadata tag if necessary.
19889
/// Setting this property's value to a null reference deletes the
19890
/// metadata tag from the metadata model.
19892
public DateTime? DateTimeStamp
19896
DateTime? date = DateStamp;
19897
TimeSpan? time = TimeStamp;
19898
if ((date == null) && (time == null))
19906
date = DateTime.MinValue;
19910
time = TimeSpan.MinValue;
19912
return date.Value.Add(time.Value);
19917
if (value.HasValue)
19919
DateStamp = value.Value.Date;
19920
TimeStamp = value.Value.TimeOfDay;
19931
/// Gets or sets date information relative to UTC (Coordinated Universal Time).
19934
/// <b>Handling of null values</b><para/>
19935
/// A null value indicates, that the corresponding metadata tag is not
19936
/// present in the metadata model.
19937
/// Setting this property's value to a non-null reference creates the
19938
/// metadata tag if necessary.
19939
/// Setting this property's value to a null reference deletes the
19940
/// metadata tag from the metadata model.
19942
public DateTime? DateStamp
19946
string stamp = GetTagText("GPSDateStamp");
19951
return DateTime.ParseExact(stamp, "yyyy:MM:dd\0", null);
19962
if (value.HasValue)
19966
val = value.Value.ToString("yyyy:MM:dd\0");
19972
SetTagValue("GPSDateStamp", val);
19977
/// Gets or sets a value indicating whether differential correction was applied to
19978
/// the GPS receiver.
19981
/// <b>Handling of null values</b><para/>
19982
/// A null value indicates, that the corresponding metadata tag is not
19983
/// present in the metadata model.
19984
/// Setting this property's value to a non-null reference creates the
19985
/// metadata tag if necessary.
19986
/// Setting this property's value to a null reference deletes the
19987
/// metadata tag from the metadata model.
19989
public bool? IsDifferential
19993
ushort? value = GetTagValue<ushort>("GPSDifferential");
19994
return value.HasValue ? (value != 0) : (default(bool?));
19998
SetTagValue("GPSDifferential", value.HasValue ? (object)(value.Value ? (ushort)1 : (ushort)0) : (null));
20004
/// Represents a collection of all tags contained in the metadata model
20005
/// <see cref="FREE_IMAGE_MDMODEL.FIMD_EXIF_INTEROP"/>.
20007
public class MDM_INTEROP : MetadataModel
20010
/// Initializes a new instance of this class.
20012
/// <param name="dib">Handle to a FreeImage bitmap.</param>
20013
public MDM_INTEROP(FIBITMAP dib) : base(dib) { }
20016
/// Retrieves the datamodel that this instance represents.
20018
public override FREE_IMAGE_MDMODEL Model
20020
get { return FREE_IMAGE_MDMODEL.FIMD_EXIF_INTEROP; }
20024
/// Gets or sets the identification of the Interoperability rule.
20027
/// <b>Handling of null values</b><para/>
20028
/// A null value indicates, that the corresponding metadata tag is not
20029
/// present in the metadata model.
20030
/// Setting this property's value to a non-null reference creates the
20031
/// metadata tag if necessary.
20032
/// Setting this property's value to a null reference deletes the
20033
/// metadata tag from the metadata model.
20035
public InteroperabilityMode? Identification
20039
return ToInteroperabilityType(GetTagText("InteroperabilityIndex"));
20043
SetTagValue("InteroperabilityIndex", ToString(value) + '\0');
20049
/// Represents a collection of all tags contained in the metadata model
20050
/// <see cref="FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN"/>.
20052
/// <b>This class is obsolete. Use class <see cref="MDM_EXIF_MAIN"/> instead.</b>
20054
[Obsolete("To be removed in future releases. Use MDM_EXIF_MAIN instead.")]
20055
public class MDM_MAIN : MDM_EXIF_MAIN
20058
/// Initializes a new instance of this class.
20060
/// <param name="dib">Handle to a FreeImage bitmap.</param>
20061
public MDM_MAIN(FIBITMAP dib) : base(dib) { }
20065
/// Represents a collection of all tags contained in the metadata model
20066
/// <see cref="FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN"/>.
20068
public class MDM_EXIF_MAIN : MetadataModel
20071
/// Initializes a new instance of this class.
20073
/// <param name="dib">Handle to a FreeImage bitmap.</param>
20074
public MDM_EXIF_MAIN(FIBITMAP dib) : base(dib) { }
20077
/// Retrieves the datamodel that this instance represents.
20079
public override FREE_IMAGE_MDMODEL Model
20081
get { return FREE_IMAGE_MDMODEL.FIMD_EXIF_MAIN; }
20085
/// Gets or sets the number of columns of image data, equal to the number
20086
/// of pixels per row. In JPEG compressed data a JPEG marker is used
20087
/// instead of this tag.
20090
/// <b>Handling of null values</b><para/>
20091
/// A null value indicates, that the corresponding metadata tag is not
20092
/// present in the metadata model.
20093
/// Setting this property's value to a non-null reference creates the
20094
/// metadata tag if necessary.
20095
/// Setting this property's value to a null reference deletes the
20096
/// metadata tag from the metadata model.
20098
public uint? ImageWidth
20102
return GetUInt32Value("ImageWidth");
20106
RemoveTag("ImageWidth");
20107
if (value.HasValue)
20109
SetTagValue("ImageWidth", value);
20115
/// Gets or sets number of rows of image data. In JPEG compressed data a JPEG marker
20116
/// is used instead of this tag.
20119
/// <b>Handling of null values</b><para/>
20120
/// A null value indicates, that the corresponding metadata tag is not
20121
/// present in the metadata model.
20122
/// Setting this property's value to a non-null reference creates the
20123
/// metadata tag if necessary.
20124
/// Setting this property's value to a null reference deletes the
20125
/// metadata tag from the metadata model.
20127
public uint? ImageHeight
20131
return GetUInt32Value("ImageLength");
20135
RemoveTag("ImageLength");
20136
if (value.HasValue)
20138
SetTagValue("ImageLength", value);
20144
/// Gets or sets number of bits per image component. In this standard
20145
/// each component of the image is 8 bits, so the value for this tag is 8.
20146
/// Constant length of 3.
20149
/// <b>Handling of null values</b><para/>
20150
/// A null value indicates, that the corresponding metadata tag is not
20151
/// present in the metadata model.
20152
/// Setting this property's value to a non-null reference creates the
20153
/// metadata tag if necessary.
20154
/// Setting this property's value to a null reference deletes the
20155
/// metadata tag from the metadata model.
20157
public ushort[] BitsPerSample
20161
return GetTagArray<ushort>("BitsPerSample");
20165
FreeImage.Resize(ref value, 3);
20166
SetTagValue("BitsPerSample", value);
20171
/// Gets or sets compression scheme used for the image data. When a primary image
20172
/// is JPEG compressed, this designation is not necessary and is omitted.
20173
/// When thumbnails use JPEG compression, this tag value is set to 6.
20176
/// <b>Handling of null values</b><para/>
20177
/// A null value indicates, that the corresponding metadata tag is not
20178
/// present in the metadata model.
20179
/// Setting this property's value to a non-null reference creates the
20180
/// metadata tag if necessary.
20181
/// Setting this property's value to a null reference deletes the
20182
/// metadata tag from the metadata model.
20184
public ushort? Compression
20188
return GetTagValue<ushort>("Compression");
20192
SetTagValue("Compression", value);
20197
/// Gets or sets pixel composition. In JPEG compressed data a JPEG marker is
20198
/// used instead of this tag. See remarks for further information.
20201
/// The following values are definied:<para/>
20202
/// <list type="table">
20204
/// <term>ID</term>
20205
/// <description>Description</description>
20209
/// <description>RGB</description>
20213
/// <description>YCbCr</description>
20216
/// <term>other</term>
20217
/// <description>reserved</description>
20221
/// <br/><b>Handling of null values</b><para/>
20222
/// A null value indicates, that the corresponding metadata tag is not
20223
/// present in the metadata model.
20224
/// Setting this property's value to a non-null reference creates the
20225
/// metadata tag if necessary.
20226
/// Setting this property's value to a null reference deletes the
20227
/// metadata tag from the metadata model.
20229
public ushort? PhotometricInterpretation
20233
return GetTagValue<ushort>("PhotometricInterpretation");
20237
SetTagValue("PhotometricInterpretation", value);
20242
/// Gets or sets the image orientation viewed in terms of rows and columns.
20245
/// <b>Handling of null values</b><para/>
20246
/// A null value indicates, that the corresponding metadata tag is not
20247
/// present in the metadata model.
20248
/// Setting this property's value to a non-null reference creates the
20249
/// metadata tag if necessary.
20250
/// Setting this property's value to a null reference deletes the
20251
/// metadata tag from the metadata model.
20253
public ExifImageOrientation? Orientation
20257
return (ExifImageOrientation?)GetTagValue<ushort>("Orientation");
20261
SetTagValue("Orientation", (ushort?)value);
20266
/// Gets or sets the number of components per pixel. Since this standard applies
20267
/// to RGB and YCbCr images, the value set for this tag is 3. In JPEG compressed
20268
/// data a JPEG marker is used instead of this tag.
20271
/// <b>Handling of null values</b><para/>
20272
/// A null value indicates, that the corresponding metadata tag is not
20273
/// present in the metadata model.
20274
/// Setting this property's value to a non-null reference creates the
20275
/// metadata tag if necessary.
20276
/// Setting this property's value to a null reference deletes the
20277
/// metadata tag from the metadata model.
20279
public ushort? SamplesPerPixel
20283
return GetTagValue<ushort>("SamplesPerPixel");
20287
SetTagValue("SamplesPerPixel", value);
20292
/// Gets or sets a value that indicates whether pixel components are recorded in
20293
/// chunky or planar format. In JPEG compressed files a JPEG marker is used instead
20294
/// of this tag. If this field does not exist, the TIFF default of 1 (chunky) is assumed.
20295
/// See remarks for further information.
20298
/// The following values are definied:<para/>
20299
/// <list type="table">
20301
/// <term>ID</term>
20302
/// <description>Description</description>
20306
/// <description>chunky format</description>
20310
/// <description>planar format</description>
20313
/// <term>other</term>
20314
/// <description>reserved</description>
20318
/// <br/><b>Handling of null values</b><para/>
20319
/// A null value indicates, that the corresponding metadata tag is not
20320
/// present in the metadata model.
20321
/// Setting this property's value to a non-null reference creates the
20322
/// metadata tag if necessary.
20323
/// Setting this property's value to a null reference deletes the
20324
/// metadata tag from the metadata model.
20326
public ushort? PlanarConfiguration
20330
return GetTagValue<ushort>("PlanarConfiguration");
20334
SetTagValue("PlanarConfiguration", value);
20339
/// Gets or sets the sampling ratio of chrominance components in relation to
20340
/// the luminance component. In JPEG compressed dat a JPEG marker is used
20341
/// instead of this tag.
20342
/// See remarks for further information.
20345
/// The following values are definied:<para/>
20346
/// <list type="table">
20348
/// <term>ID</term>
20349
/// <description>Description</description>
20352
/// <term>[2,1]</term>
20353
/// <description>YCbCr4:2:2</description>
20356
/// <term>[2,2]</term>
20357
/// <description>YCbCr4:2:0</description>
20360
/// <term>other</term>
20361
/// <description>reserved</description>
20365
/// <br/><b>Handling of null values</b><para/>
20366
/// A null value indicates, that the corresponding metadata tag is not
20367
/// present in the metadata model.
20368
/// Setting this property's value to a non-null reference creates the
20369
/// metadata tag if necessary.
20370
/// Setting this property's value to a null reference deletes the
20371
/// metadata tag from the metadata model.
20373
public ushort[] YCbCrSubSampling
20377
return GetTagArray<ushort>("YCbCrSubSampling");
20381
FreeImage.Resize(ref value, 2);
20382
SetTagValue("YCbCrSubSampling", value);
20387
/// Gets or sets position of chrominance components in relation to the luminance component.
20388
/// See remarks for further information.
20391
/// This field is designated only for JPEG compressed data or uncompressed YCbCr data.
20392
/// The TIFF default is 1 (centered); but when Y:Cb:Cr = 4:2:2 it is recommended in
20393
/// this standard that 2 (co-sited) be used to record data, in order to improve the
20394
/// image quality when viewed on TV systems.
20396
/// When this field does not exist, the reader shall assume the TIFF default.
20397
/// In the case of Y:Cb:Cr = 4:2:0, the TIFF default (centered) is recommended.
20398
/// If the reader does not have the capability of supporting both kinds of YCbCrPositioning,
20399
/// it shall follow the TIFF default regardless of the value in this field.
20400
/// It is preferable that readers be able to support both centered and co-sited positioning.
20402
/// The following values are definied:<para/>
20403
/// <list type="table">
20405
/// <term>ID</term>
20406
/// <description>Description</description>
20410
/// <description>centered</description>
20414
/// <description>co-sited</description>
20417
/// <term>other</term>
20418
/// <description>reserved</description>
20422
/// <br/><b>Handling of null values</b><para/>
20423
/// A null value indicates, that the corresponding metadata tag is not
20424
/// present in the metadata model.
20425
/// Setting this property's value to a non-null reference creates the
20426
/// metadata tag if necessary.
20427
/// Setting this property's value to a null reference deletes the
20428
/// metadata tag from the metadata model.
20430
public ushort? YCbCrPositioning
20434
return GetTagValue<ushort>("YCbCrPositioning");
20438
SetTagValue("YCbCrPositioning", value);
20443
/// Gets or sets the number of pixels per <see cref="ResolutionUnit"/>
20444
/// in the <see cref="ImageWidth"/> direction. When the image resolution is unknown,
20445
/// 72 [dpi] is designated.
20448
/// <b>Handling of null values</b><para/>
20449
/// A null value indicates, that the corresponding metadata tag is not
20450
/// present in the metadata model.
20451
/// Setting this property's value to a non-null reference creates the
20452
/// metadata tag if necessary.
20453
/// Setting this property's value to a null reference deletes the
20454
/// metadata tag from the metadata model.
20456
public FIURational? XResolution
20460
return GetTagValue<FIURational>("XResolution");
20464
SetTagValue("XResolution", value);
20469
/// Gets or sets the number of pixels per <see cref="ResolutionUnit"/>
20470
/// in the <see cref="ImageHeight"/> direction. When the image resolution is unknown,
20471
/// 72 [dpi] is designated.
20474
/// <b>Handling of null values</b><para/>
20475
/// A null value indicates, that the corresponding metadata tag is not
20476
/// present in the metadata model.
20477
/// Setting this property's value to a non-null reference creates the
20478
/// metadata tag if necessary.
20479
/// Setting this property's value to a null reference deletes the
20480
/// metadata tag from the metadata model.
20482
public FIURational? YResolution
20486
return GetTagValue<FIURational>("YResolution");
20490
SetTagValue("YResolution", value);
20495
/// Gets or sets the unit for measuring <see cref="XResolution"/> and <see cref="YResolution"/>.
20496
/// The same unit is used for both <see cref="XResolution"/> and <see cref="YResolution"/>.
20497
/// If the image resolution in unknown, 2 (inches) is designated.
20498
/// See remarks for further information.
20501
/// The following values are definied:<para/>
20502
/// <list type="table">
20504
/// <term>ID</term>
20505
/// <description>Description</description>
20509
/// <description>inches</description>
20513
/// <description>YCbCr4:2:0</description>
20516
/// <term>other</term>
20517
/// <description>centimeters</description>
20521
/// <br/><b>Handling of null values</b><para/>
20522
/// A null value indicates, that the corresponding metadata tag is not
20523
/// present in the metadata model.
20524
/// Setting this property's value to a non-null reference creates the
20525
/// metadata tag if necessary.
20526
/// Setting this property's value to a null reference deletes the
20527
/// metadata tag from the metadata model.
20529
public ushort? ResolutionUnit
20533
return GetTagValue<ushort>("ResolutionUnit");
20537
SetTagValue("ResolutionUnit", value);
20542
/// Gets or sets the byte offset of that strip.
20543
/// It is recommended that this be selected so the number of strip bytes
20544
/// does not exceed 64 Kbytes.
20545
/// With JPEG compressed data this designation is not needed and is omitted.
20546
/// Constant length of <see cref="SamplesPerPixel"/> * StripsPerImage.
20549
/// <b>Handling of null values</b><para/>
20550
/// A null value indicates, that the corresponding metadata tag is not
20551
/// present in the metadata model.
20552
/// Setting this property's value to a non-null reference creates the
20553
/// metadata tag if necessary.
20554
/// Setting this property's value to a null reference deletes the
20555
/// metadata tag from the metadata model.
20557
/// <seealso cref="RowsPerStrip"/>
20558
/// <see cref="StripByteCounts"/>
20559
public uint[] StripOffsets
20563
return GetUInt32Array("StripOffsets");
20567
RemoveTag("StripOffsets");
20570
SetTagValue("StripOffsets", value);
20576
/// Gets or sets number of rows per strip. This is the number of rows in the image of
20577
/// one strip when an image is divided into strips. With JPEG compressed data this
20578
/// designation is not needed and is omitted.
20581
/// <b>Handling of null values</b><para/>
20582
/// A null value indicates, that the corresponding metadata tag is not
20583
/// present in the metadata model.
20584
/// Setting this property's value to a non-null reference creates the
20585
/// metadata tag if necessary.
20586
/// Setting this property's value to a null reference deletes the
20587
/// metadata tag from the metadata model.
20589
/// <seealso cref="StripByteCounts"/>
20590
public uint? RowsPerStrip
20594
return GetUInt32Value("RowsPerStrip");
20598
RemoveTag("RowsPerStrip");
20599
if (value.HasValue)
20601
SetTagValue("RowsPerStrip", value);
20607
/// Gets or sets the total number of bytes in each strip.
20608
/// With JPEG compressed data this designation is not needed and is omitted.
20609
/// Constant length of <see cref="SamplesPerPixel"/> * StripsPerImage.
20612
/// <b>Handling of null values</b><para/>
20613
/// A null value indicates, that the corresponding metadata tag is not
20614
/// present in the metadata model.
20615
/// Setting this property's value to a non-null reference creates the
20616
/// metadata tag if necessary.
20617
/// Setting this property's value to a null reference deletes the
20618
/// metadata tag from the metadata model.
20620
public uint[] StripByteCounts
20624
return GetUInt32Array("StripByteCounts");
20628
RemoveTag("StripByteCounts");
20631
SetTagValue("StripByteCounts", value);
20637
/// Gets or sets the offset to the start byte (SOI) of JPEG compressed thumbnail data.
20638
/// This is not used for primary image JPEG data.
20641
/// <b>Handling of null values</b><para/>
20642
/// A null value indicates, that the corresponding metadata tag is not
20643
/// present in the metadata model.
20644
/// Setting this property's value to a non-null reference creates the
20645
/// metadata tag if necessary.
20646
/// Setting this property's value to a null reference deletes the
20647
/// metadata tag from the metadata model.
20649
public uint? JPEGInterchangeFormat
20653
return GetTagValue<uint>("JPEGInterchangeFormat");
20657
SetTagValue("JPEGInterchangeFormat", value);
20662
/// Gets or sets the number of bytes of JPEG compressed thumbnail data.
20665
/// This is not used for primary image JPEG data.
20666
/// JPEG thumbnails are not divided but are recorded as a continuous
20667
/// JPEG bitstream from SOI to EOI. APPn and COM markers should not be recorded.
20668
/// Compressed thumbnails shall be recorded in no more than 64 Kbytes,
20669
/// including all other data to be recorded in APP1.
20671
/// <br/><b>Handling of null values</b><para/>
20672
/// A null value indicates, that the corresponding metadata tag is not
20673
/// present in the metadata model.
20674
/// Setting this property's value to a non-null reference creates the
20675
/// metadata tag if necessary.
20676
/// Setting this property's value to a null reference deletes the
20677
/// metadata tag from the metadata model.
20679
public uint? JPEGInterchangeFormatLength
20683
return GetTagValue<uint>("JPEGInterchangeFormatLength");
20687
SetTagValue("JPEGInterchangeFormatLength", value);
20692
/// Gets or sets a transfer function for the image, described in tabular style.
20693
/// Constant length of 3 * 256.
20696
/// <b>Handling of null values</b><para/>
20697
/// A null value indicates, that the corresponding metadata tag is not
20698
/// present in the metadata model.
20699
/// Setting this property's value to a non-null reference creates the
20700
/// metadata tag if necessary.
20701
/// Setting this property's value to a null reference deletes the
20702
/// metadata tag from the metadata model.
20704
public ushort[] TransferFunction
20708
return GetTagArray<ushort>("TransferFunction");
20712
FreeImage.Resize(ref value, 3 * 256);
20713
SetTagValue("TransferFunction", value);
20718
/// Gets or sets the chromaticity of the white point of the image.
20719
/// Constant length of 2.
20722
/// <b>Handling of null values</b><para/>
20723
/// A null value indicates, that the corresponding metadata tag is not
20724
/// present in the metadata model.
20725
/// Setting this property's value to a non-null reference creates the
20726
/// metadata tag if necessary.
20727
/// Setting this property's value to a null reference deletes the
20728
/// metadata tag from the metadata model.
20730
public FIURational[] WhitePoint
20734
return GetTagArray<FIURational>("WhitePoint");
20738
FreeImage.Resize(ref value, 2);
20739
SetTagValue("WhitePoint", value);
20744
/// Gets or sets the chromaticity of the three primary colors of the image.
20745
/// Constant length of 6.
20748
/// <b>Handling of null values</b><para/>
20749
/// A null value indicates, that the corresponding metadata tag is not
20750
/// present in the metadata model.
20751
/// Setting this property's value to a non-null reference creates the
20752
/// metadata tag if necessary.
20753
/// Setting this property's value to a null reference deletes the
20754
/// metadata tag from the metadata model.
20756
public FIURational[] PrimaryChromaticities
20760
return GetTagArray<FIURational>("PrimaryChromaticities");
20764
FreeImage.Resize(ref value, 6);
20765
SetTagValue("PrimaryChromaticities", value);
20770
/// Gets or sets the matrix coefficients for transformation from RGB to YCbCr image data.
20771
/// Constant length of 3.
20774
/// <b>Handling of null values</b><para/>
20775
/// A null value indicates, that the corresponding metadata tag is not
20776
/// present in the metadata model.
20777
/// Setting this property's value to a non-null reference creates the
20778
/// metadata tag if necessary.
20779
/// Setting this property's value to a null reference deletes the
20780
/// metadata tag from the metadata model.
20782
public FIURational[] YCbCrCoefficients
20786
return GetTagArray<FIURational>("YCbCrCoefficients");
20790
FreeImage.Resize(ref value, 3);
20791
SetTagValue("PrimaryChromaticities", value);
20796
/// Gets or sets the reference black point value and reference white point value.
20797
/// Constant length of 6.
20800
/// <b>Handling of null values</b><para/>
20801
/// A null value indicates, that the corresponding metadata tag is not
20802
/// present in the metadata model.
20803
/// Setting this property's value to a non-null reference creates the
20804
/// metadata tag if necessary.
20805
/// Setting this property's value to a null reference deletes the
20806
/// metadata tag from the metadata model.
20808
public FIURational[] ReferenceBlackWhite
20812
return GetTagArray<FIURational>("ReferenceBlackWhite");
20816
FreeImage.Resize(ref value, 6);
20817
SetTagValue("ReferenceBlackWhite", value);
20822
/// Gets or sets the date and time of image creation.
20825
/// <b>Handling of null values</b><para/>
20826
/// A null value indicates, that the corresponding metadata tag is not
20827
/// present in the metadata model.
20828
/// Setting this property's value to a non-null reference creates the
20829
/// metadata tag if necessary.
20830
/// Setting this property's value to a null reference deletes the
20831
/// metadata tag from the metadata model.
20833
public DateTime? DateTime
20837
DateTime? result = null;
20838
string text = GetTagText("DateTime");
20843
result = System.DateTime.ParseExact(text, "yyyy:MM:dd HH:mm:ss\0", null);
20854
if (value.HasValue)
20858
val = value.Value.ToString("yyyy:MM:dd HH:mm:ss\0");
20864
SetTagValue("DateTime", val);
20869
/// Gets or sets a string giving the title of the image.
20872
/// <b>Handling of null values</b><para/>
20873
/// A null value indicates, that the corresponding metadata tag is not
20874
/// present in the metadata model.
20875
/// Setting this property's value to a non-null reference creates the
20876
/// metadata tag if necessary.
20877
/// Setting this property's value to a null reference deletes the
20878
/// metadata tag from the metadata model.
20880
public string ImageDescription
20884
string result = GetTagText("ImageDescription");
20885
if (!string.IsNullOrEmpty(result))
20887
result = result.Substring(0, result.Length - 1);
20897
SetTagValue("ImageDescription", value);
20902
/// Gets or sets the manufacturer of the recording equipment.
20905
/// <b>Handling of null values</b><para/>
20906
/// A null value indicates, that the corresponding metadata tag is not
20907
/// present in the metadata model.
20908
/// Setting this property's value to a non-null reference creates the
20909
/// metadata tag if necessary.
20910
/// Setting this property's value to a null reference deletes the
20911
/// metadata tag from the metadata model.
20917
string result = GetTagText("Make");
20918
if (!string.IsNullOrEmpty(result))
20920
result = result.Substring(0, result.Length - 1);
20930
SetTagValue("Make", value);
20935
/// Gets or sets the model name or model number of the equipment.
20938
/// <b>Handling of null values</b><para/>
20939
/// A null value indicates, that the corresponding metadata tag is not
20940
/// present in the metadata model.
20941
/// Setting this property's value to a non-null reference creates the
20942
/// metadata tag if necessary.
20943
/// Setting this property's value to a null reference deletes the
20944
/// metadata tag from the metadata model.
20946
public string EquipmentModel
20950
string result = GetTagText("Model");
20951
if (!string.IsNullOrEmpty(result))
20953
result = result.Substring(0, result.Length - 1);
20963
SetTagValue("Model", value);
20968
/// Gets or sets the name and version of the software or firmware of the camera
20969
/// or image input device used to generate the image.
20972
/// <b>Handling of null values</b><para/>
20973
/// A null value indicates, that the corresponding metadata tag is not
20974
/// present in the metadata model.
20975
/// Setting this property's value to a non-null reference creates the
20976
/// metadata tag if necessary.
20977
/// Setting this property's value to a null reference deletes the
20978
/// metadata tag from the metadata model.
20980
public string Software
20984
string result = GetTagText("Software");
20985
if (!string.IsNullOrEmpty(result))
20987
result = result.Substring(0, result.Length - 1);
20997
SetTagValue("Software", value);
21002
/// Gets or sets the name of the camera owner, photographer or image creator.
21005
/// <b>Handling of null values</b><para/>
21006
/// A null value indicates, that the corresponding metadata tag is not
21007
/// present in the metadata model.
21008
/// Setting this property's value to a non-null reference creates the
21009
/// metadata tag if necessary.
21010
/// Setting this property's value to a null reference deletes the
21011
/// metadata tag from the metadata model.
21013
public string Artist
21017
string result = GetTagText("Artist");
21018
if (!string.IsNullOrEmpty(result))
21020
result = result.Substring(0, result.Length - 1);
21030
SetTagValue("Artist", value);
21035
/// Gets or sets the photographer and editor copyrights.
21036
/// Constant length of 1-2.
21039
/// <b>Handling of null values</b><para/>
21040
/// A null value indicates, that the corresponding metadata tag is not
21041
/// present in the metadata model.
21042
/// Setting this property's value to a non-null reference creates the
21043
/// metadata tag if necessary.
21044
/// Setting this property's value to a null reference deletes the
21045
/// metadata tag from the metadata model.
21047
public string[] Copyright
21051
string[] result = null;
21052
string text = GetTagText("Copyright");
21053
if (!string.IsNullOrEmpty(text))
21055
result = text.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);
21064
if (value.Length == 1)
21066
if (value[0] != null)
21068
val = value[0] + '\0';
21071
else if (value.Length == 2)
21073
if ((value[0] != null) && (value[1] != null))
21075
val = value[0] + '\0' + value[1] + '\0';
21079
SetTagValue("Copyright", val);
21085
/// Represents a collection of all tags contained in the metadata model
21086
/// <see cref="FREE_IMAGE_MDMODEL.FIMD_EXIF_MAKERNOTE"/>.
21088
public class MDM_MAKERNOTE : MetadataModel
21091
/// Initializes a new instance of this class.
21093
/// <param name="dib">Handle to a FreeImage bitmap.</param>
21094
public MDM_MAKERNOTE(FIBITMAP dib) : base(dib) { }
21097
/// Retrieves the datamodel that this instance represents.
21099
public override FREE_IMAGE_MDMODEL Model
21101
get { return FREE_IMAGE_MDMODEL.FIMD_EXIF_MAKERNOTE; }
21106
/// Represents a collection of all tags contained in the metadata model
21107
/// <see cref="FREE_IMAGE_MDMODEL.FIMD_GEOTIFF"/>.
21109
public class MDM_GEOTIFF : MetadataModel
21112
/// Initializes a new instance of this class.
21114
/// <param name="dib">Handle to a FreeImage bitmap.</param>
21115
public MDM_GEOTIFF(FIBITMAP dib) : base(dib) { }
21118
/// Retrieves the datamodel that this instance represents.
21120
public override FREE_IMAGE_MDMODEL Model
21122
get { return FREE_IMAGE_MDMODEL.FIMD_GEOTIFF; }
21126
/// Gets or sets the value of the GeoTIFF GeoASCIIParamsTag.
21129
/// The GeoASCIIParamsTag is used to store all of the <see cref="String"/> valued
21130
/// GeoKeys, referenced by the <see cref="GeoKeyDirectory"/> property. Since keys
21131
/// defined in the GeoKeyDirectoryTag use offsets into this tag, any special
21132
/// comments may be placed at the beginning of this tag.
21133
/// For the most part, the only keys that are <see cref="String"/> valued are
21134
/// <i>Citation</i> keys, giving documentation and references for obscure
21135
/// projections, datums, etc.
21137
/// Special handling is required for <see cref="String"/>-valued keys. While it
21138
/// is true that TIFF 6.0 permits multiple NULL-delimited strings within a single
21139
/// ASCII tag, the secondary strings might not appear in the output of naive
21140
/// <i>tiffdump</i> programs. For this reason, the NULL delimiter of each ASCII key
21141
/// value shall be converted to a "|" (pipe) character before being installed
21142
/// back into the <see cref="String"/> holding tag, so that a dump of the tag
21143
/// will look like this.
21145
/// AsciiTag="first_value|second_value|etc...last_value|"
21147
/// A baseline GeoTIFF-reader must check for and convert the final "|" pipe
21148
/// character of a key back into a NULL before returning it to the client
21151
/// <br/><b>Handling of null values</b><para/>
21152
/// A null value indicates, that the corresponding metadata tag is not
21153
/// present in the metadata model.
21154
/// Setting this property's value to a non-null reference creates the
21155
/// metadata tag if necessary.
21156
/// Setting this property's value to a null reference deletes the
21157
/// metadata tag from the metadata model.
21159
public string GeoASCIIParams
21163
string text = GetTagText("GeoASCIIParams");
21164
if (!string.IsNullOrEmpty(text))
21166
text = text.Substring(0, text.Length - 1);
21176
SetTagValue("GeoASCIIParams", value);
21181
/// Gets or sets the value of the GeoTIFF GeoDoubleParamsTag.
21184
/// The GeoDoubleParamsTag is used to store all of the <see cref="Double"/> valued
21185
/// GeoKeys, referenced by the <see cref="GeoKeyDirectory"/> property. The meaning of
21186
/// any value of this double array is determined from the GeoKeyDirectoryTag reference
21187
/// pointing to it. <see cref="Single"/> values should first be converted to
21188
/// <see cref="Double"/> and stored here.
21190
/// <br/><b>Handling of null values</b><para/>
21191
/// A null value indicates, that the corresponding metadata tag is not
21192
/// present in the metadata model.
21193
/// Setting this property's value to a non-null reference creates the
21194
/// metadata tag if necessary.
21195
/// Setting this property's value to a null reference deletes the
21196
/// metadata tag from the metadata model.
21198
public double[] GeoDoubleParams
21202
return GetTagArray<double>("GeoDoubleParams");
21206
SetTagValue("GeoDoubleParams", value);
21211
/// Gets or sets the value of the GeoTIFF GeoKeyDirectoryTag.
21214
/// The GeoKeyDirectoryTag may be used to store the GeoKey Directory, which defines and
21215
/// references the <i>GeoKeys</i>.
21217
/// The tag is an array of unsigned <see cref="UInt16"/> values, which are primarily
21218
/// grouped into blocks of 4. The first 4 values are special, and contain GeoKey directory
21219
/// header information. The header values consist of the following information, in order:
21221
/// Header={KeyDirectoryVersion, KeyRevision, MinorRevision, NumberOfKeys}
21225
/// <i>KeyDirectoryVersion</i> indicates the current version of Key implementation, and will
21226
/// only change if this Tag's Key structure is changed. (Similar to the TIFFVersion (42)).
21227
/// The current DirectoryVersion number is 1. This value will most likely never change,
21228
/// and may be used to ensure that this is a valid Key-implementation.
21230
/// <i>KeyRevision</i> indicates what revision of Key-Sets are used.
21232
/// <i>MinorRevision</i> indicates what set of Key-Codes are used. The complete revision number
21233
/// is denoted <KeyRevision>.<MinorRevision>.
21235
/// <i>NumberOfKeys</i> indicates how many Keys are defined by the rest of this Tag.
21237
/// This header is immediately followed by a collection of <NumberOfKeys> KeyEntry
21238
/// sets, each of which is also 4-<see cref="UInt16"/> long. Each KeyEntry is modeled on the
21239
/// <i>TIFFEntry</i> format of the TIFF directory header, and is of the form:
21241
/// KeyEntry = { KeyID, TIFFTagLocation, Count, Value_Offset }
21245
/// <i>KeyID</i> gives the Key-ID value of the Key (identical in function to TIFF tag ID,
21246
/// but completely independent of TIFF tag-space),
21248
/// <i>TIFFTagLocation</i> indicates which TIFF tag contains the value(s) of the Key: if
21249
/// TIFFTagLocation is 0, then the value is <see cref="UInt16"/>, and is contained in the
21250
/// <i>Value_Offset</i> entry. Otherwise, the type (format) of the value is implied by the
21251
/// TIFF-Type of the tag containing the value.
21253
/// <i>Count</i> indicates the number of values in this key.
21255
/// <i>Value_Offset</i> Value_Offset indicates the index-offset into the TagArray indicated
21256
/// by TIFFTagLocation, if it is nonzero. If TIFFTagLocation is 0 (zero) , then Value_Offset
21257
/// contains the actual (<see cref="UInt16"/>) value of the Key, and Count=1 is implied.
21258
/// Note that the offset is not a byte-offset, but rather an index based on the natural data
21259
/// type of the specified tag array.
21261
/// Following the KeyEntry definitions, the KeyDirectory tag may also contain additional
21262
/// values. For example, if a key requires multiple <see cref="UInt16"/> values, they shall
21263
/// be placed at the end of this tag, and the KeyEntry will set
21264
/// TIFFTagLocation=GeoKeyDirectoryTag, with the Value_Offset pointing to the location of the
21267
/// <br/><b>Handling of null values</b><para/>
21268
/// A null value indicates, that the corresponding metadata tag is not
21269
/// present in the metadata model.
21270
/// Setting this property's value to a non-null reference creates the
21271
/// metadata tag if necessary.
21272
/// Setting this property's value to a null reference deletes the
21273
/// metadata tag from the metadata model.
21275
public ushort[] GeoKeyDirectory
21279
return GetTagArray<ushort>("GeoKeyDirectory");
21283
SetTagValue("GeoKeyDirectory", value);
21288
/// Gets or sets the value of the GeoTIFF ModelPixelScaleTag.
21291
/// The ModelPixelScaleTag tag may be used to specify the size of raster pixel spacing
21292
/// in the model space units, when the raster space can be embedded in the model space
21293
/// coordinate system without rotation, and consists of the following 3 values:
21295
/// ModelPixelScaleTag = (ScaleX, ScaleY, ScaleZ)
21297
/// where <i>ScaleX</i> and <i>ScaleY</i> give the horizontal and vertical spacing of
21298
/// raster pixels. The <i>ScaleZ</i> is primarily used to map the pixel value of a
21299
/// digital elevation model into the correct Z-scale, and so for most other purposes
21300
/// this value should be zero (since most model spaces are 2-D, with Z=0).
21302
/// A single tiepoint in the <see cref="ModelTiePoints"/> tag, together with this tag,
21303
/// completely determine the relationship between raster and model space; thus they
21304
/// comprise the two tags which Baseline GeoTIFF files most often will use to place a
21305
/// raster image into a "standard position" in model space.
21307
/// Like the <see cref="ModelTiePoints"/> tag, this tag information is independent of the
21308
/// XPosition, YPosition, Resolution and Orientation tags of the standard TIFF 6.0 spec.
21309
/// However, simple reversals of orientation between raster and model space
21310
/// (e.g. horizontal or vertical flips) may be indicated by reversal of sign in the
21311
/// corresponding component of the ModelPixelScaleTag. GeoTIFF compliant readers must
21312
/// honor this signreversal convention.
21314
/// This tag must not be used if the raster image requires rotation or shearing to place
21315
/// it into the standard model space. In such cases the transformation shall be defined
21316
/// with the more general <see cref="ModelTransformationMatrix"/>.
21318
/// <br/><b>Naming differences</b><para/>
21319
/// In the native FreeImage library and thus, in the FreeImage API documentation, this
21320
/// property's key is named <i>GeoPixelScale</i>. Since the GeoTIFF specification
21321
/// as well as Java's <c>EXIFTIFFTagSet</c> class call this tag
21322
/// <see cref="ModelPixelScale"/>, this property was renamed accordingly.
21323
/// However, when accessing this property's tag by its <see cref="MetadataTag"/> object,
21324
/// the native FreeImage tag key <i>GeoPixelScale</i> must be used.
21326
/// <br/><b>Handling of null values</b><para/>
21327
/// A null value indicates, that the corresponding metadata tag is not
21328
/// present in the metadata model.
21329
/// Setting this property's value to a non-null reference creates the
21330
/// metadata tag if necessary.
21331
/// Setting this property's value to a null reference deletes the
21332
/// metadata tag from the metadata model.
21334
public double[] ModelPixelScale
21338
return GetTagArray<double>("GeoPixelScale");
21342
SetTagValue("GeoPixelScale", value);
21347
/// Gets or sets the value of the GeoTIFF GeoTiePointsTag.
21350
/// The GeoTiePointsTag stores raster -> model tiepoint pairs in the order
21352
/// ModelTiePoints = (...,I,J,K, X,Y,Z...),
21354
/// where <i>(I,J,K)</i> is the point at location <i>(I,J)</i> in raster space with
21355
/// pixel-value <i>K</i>, and <i>(X,Y,Z)</i> is a vector in model space. In most cases
21356
/// the model space is only two-dimensional, in which case both K and Z should be set
21357
/// to zero; this third dimension is provided in anticipation of future support for 3D
21358
/// digital elevation models and vertical coordinate systems.
21360
/// A raster image may be georeferenced simply by specifying its location, size and
21361
/// orientation in the model coordinate space M. This may be done by specifying the
21362
/// location of three of the four bounding corner points. However, tiepoints are only
21363
/// to be considered exact at the points specified; thus defining such a set of
21364
/// bounding tiepoints does not imply that the model space locations of the interior
21365
/// of the image may be exactly computed by a linear interpolation of these tiepoints.
21367
/// However, since the relationship between the Raster space and the model space will
21368
/// often be an exact, affine transformation, this relationship can be defined using
21369
/// one set of tiepoints and the <see cref="ModelPixelScale"/>, described below, which
21370
/// gives the vertical and horizontal raster grid cell size, specified in model units.
21372
/// If possible, the first tiepoint placed in this tag shall be the one establishing
21373
/// the location of the point (0,0) in raster space. However, if this is not possible
21374
/// (for example, if (0,0) is goes to a part of model space in which the projection is
21375
/// ill-defined), then there is no particular order in which the tiepoints need be
21378
/// For orthorectification or mosaicking applications a large number of tiepoints may
21379
/// be specified on a mesh over the raster image. However, the definition of associated
21380
/// grid interpolation methods is not in the scope of the current GeoTIFF spec.
21382
/// <br/><b>Naming differences</b><para/>
21383
/// In the native FreeImage library and thus, in the FreeImage API documentation, this
21384
/// property's key is named <i>GeoTiePoints</i>. Since the GeoTIFF specification
21385
/// as well as Java's <c>EXIFTIFFTagSet</c> class call this tag
21386
/// <see cref="ModelTiePoints"/>, this property was renamed accordingly.
21387
/// However, when accessing this property's tag by its <see cref="MetadataTag"/> object,
21388
/// the native FreeImage tag key <i>GeoTiePoints</i> must be used.
21390
/// <br/><b>Handling of null values</b><para/>
21391
/// A null value indicates, that the corresponding metadata tag is not
21392
/// present in the metadata model.
21393
/// Setting this property's value to a non-null reference creates the
21394
/// metadata tag if necessary.
21395
/// Setting this property's value to a null reference deletes the
21396
/// metadata tag from the metadata model.
21398
public double[] ModelTiePoints
21402
return GetTagArray<double>("GeoTiePoints");
21406
SetTagValue("GeoTiePoints", value);
21411
/// Gets or sets the value of the GeoTIFF ModelTransformationMatrixTag.
21414
/// This tag may be used to specify the transformation matrix between the raster space
21415
/// (and its dependent pixel-value space) and the (possibly 3D) model space.
21417
/// <br/><b>Naming differences</b><para/>
21418
/// In the native FreeImage library and thus, in the FreeImage API documentation, this
21419
/// property's key is named <i>GeoTransformationMatrix</i>. Since the GeoTIFF specification
21420
/// as well as Java's <c>EXIFTIFFTagSet</c> class call this tag
21421
/// <see cref="ModelTransformationMatrix"/>, this property was renamed accordingly.
21422
/// However, when accessing this property's tag by its <see cref="MetadataTag"/> object,
21423
/// the native FreeImage tag key <i>GeoTransformationMatrix</i> must be used.
21425
/// <br/><b>Handling of null values</b><para/>
21426
/// A null value indicates, that the corresponding metadata tag is not
21427
/// present in the metadata model.
21428
/// Setting this property's value to a non-null reference creates the
21429
/// metadata tag if necessary.
21430
/// Setting this property's value to a null reference deletes the
21431
/// metadata tag from the metadata model.
21433
public double[] ModelTransformationMatrix
21437
return GetTagArray<double>("GeoTransformationMatrix");
21441
SetTagValue("GeoTransformationMatrix", value);
21446
/// Gets or sets the value of the GeoTIFF IntergraphTransformationMatrixTag.
21449
/// The IntergraphTransformationMatrixTag conflicts with an internal software implementation
21450
/// at Intergraph, and so its use is no longer encouraged. A GeoTIFF reader should look first
21451
/// for the new tag, and only if it is not found should it check for this older tag. If found,
21452
/// it should only consider it to be contain valid GeoTIFF matrix information if the tag-count
21453
/// is 16; the Intergraph version uses 17 values.
21455
/// <br/><b>Handling of null values</b><para/>
21456
/// A null value indicates, that the corresponding metadata tag is not
21457
/// present in the metadata model.
21458
/// Setting this property's value to a non-null reference creates the
21459
/// metadata tag if necessary.
21460
/// Setting this property's value to a null reference deletes the
21461
/// metadata tag from the metadata model.
21463
public double[] IntergraphTransformationMatrix
21467
return GetTagArray<double>("Intergraph TransformationMatrix");
21471
SetTagValue("Intergraph TransformationMatrix", value);
21476
/// Gets or sets the value of the GeoTIFF JPLCartoIFDOffsetTag.
21479
/// <b>Handling of null values</b><para/>
21480
/// A null value indicates, that the corresponding metadata tag is not
21481
/// present in the metadata model.
21482
/// Setting this property's value to a non-null reference creates the
21483
/// metadata tag if necessary.
21484
/// Setting this property's value to a null reference deletes the
21485
/// metadata tag from the metadata model.
21487
public uint? JPLCartoIFDOffset
21491
return GetTagValue<uint>("JPL Carto IFD offset");
21495
SetTagValue("JPL Carto IFD offset", value);
21501
/// Represents a collection of all tags contained in the metadata model
21502
/// <see cref="FREE_IMAGE_MDMODEL.FIMD_IPTC"/>.
21504
public class MDM_IPTC : MetadataModel
21507
/// Initializes a new instance of this class.
21509
/// <param name="dib">Handle to a FreeImage bitmap.</param>
21510
public MDM_IPTC(FIBITMAP dib) : base(dib) { }
21513
/// Retrieves the datamodel that this instance represents.
21516
/// <b>Handling of null values</b><para/>
21517
/// A null value indicates, that the corresponding metadata tag is not
21518
/// present in the metadata model.
21519
/// Setting this property's value to a non-null reference creates the
21520
/// metadata tag if necessary.
21521
/// Setting this property's value to a null reference deletes the
21522
/// metadata tag from the metadata model.
21524
public override FREE_IMAGE_MDMODEL Model
21526
get { return FREE_IMAGE_MDMODEL.FIMD_IPTC; }
21530
/// Gets the Application Record Version.
21533
/// <b>Handling of null values</b><para/>
21534
/// A null value indicates, that the corresponding metadata tag is not
21535
/// present in the metadata model.
21536
/// Setting this property's value to a non-null reference creates the
21537
/// metadata tag if necessary.
21538
/// Setting this property's value to a null reference deletes the
21539
/// metadata tag from the metadata model.
21541
public short? ApplicationRecordVersion
21545
return GetTagValue<short>("ApplicationRecordVersion");
21550
/// Gets or sets the value of the IPTC/NAA tag Object Type Reference.
21553
/// <b>Handling of null values</b><para/>
21554
/// A null value indicates, that the corresponding metadata tag is not
21555
/// present in the metadata model.
21556
/// Setting this property's value to a non-null reference creates the
21557
/// metadata tag if necessary.
21558
/// Setting this property's value to a null reference deletes the
21559
/// metadata tag from the metadata model.
21561
public string ObjectTypeReference
21565
return GetTagText("ObjectTypeReference");
21569
SetTagValue("ObjectTypeReference", value);
21574
/// Gets or sets the value of the IPTC/NAA tag Object Attribute Reference.
21577
/// <b>Handling of null values</b><para/>
21578
/// A null value indicates, that the corresponding metadata tag is not
21579
/// present in the metadata model.
21580
/// Setting this property's value to a non-null reference creates the
21581
/// metadata tag if necessary.
21582
/// Setting this property's value to a null reference deletes the
21583
/// metadata tag from the metadata model.
21585
public string ObjectAttributeReference
21589
return GetTagText("ObjectAttributeReference");
21593
SetTagValue("ObjectAttributeReference", value);
21598
/// Gets or sets the value of the IPTC/NAA tag Object Name.
21599
/// This is also referred to as Title.
21602
/// <b>Handling of null values</b><para/>
21603
/// A null value indicates, that the corresponding metadata tag is not
21604
/// present in the metadata model.
21605
/// Setting this property's value to a non-null reference creates the
21606
/// metadata tag if necessary.
21607
/// Setting this property's value to a null reference deletes the
21608
/// metadata tag from the metadata model.
21610
public string ObjectName
21614
return GetTagText("ObjectName");
21618
SetTagValue("ObjectName", value);
21623
/// Gets or sets the value of the IPTC/NAA tag Edit Status.
21626
/// <b>Handling of null values</b><para/>
21627
/// A null value indicates, that the corresponding metadata tag is not
21628
/// present in the metadata model.
21629
/// Setting this property's value to a non-null reference creates the
21630
/// metadata tag if necessary.
21631
/// Setting this property's value to a null reference deletes the
21632
/// metadata tag from the metadata model.
21634
public string EditStatus
21638
return GetTagText("EditStatus");
21642
SetTagValue("EditStatus", value);
21647
/// Gets or sets the value of the IPTC/NAA tag Editorial Update.
21650
/// <b>Handling of null values</b><para/>
21651
/// A null value indicates, that the corresponding metadata tag is not
21652
/// present in the metadata model.
21653
/// Setting this property's value to a non-null reference creates the
21654
/// metadata tag if necessary.
21655
/// Setting this property's value to a null reference deletes the
21656
/// metadata tag from the metadata model.
21658
public string EditorialUpdate
21662
return GetTagText("EditorialUpdate");
21666
SetTagValue("EditorialUpdate", value);
21671
/// Gets or sets the value of the IPTC/NAA tag Urgency.
21674
/// <b>Handling of null values</b><para/>
21675
/// A null value indicates, that the corresponding metadata tag is not
21676
/// present in the metadata model.
21677
/// Setting this property's value to a non-null reference creates the
21678
/// metadata tag if necessary.
21679
/// Setting this property's value to a null reference deletes the
21680
/// metadata tag from the metadata model.
21682
public string Urgency
21686
return GetTagText("Urgency");
21690
SetTagValue("Urgency", value);
21695
/// Gets or sets the value of the IPTC/NAA tag Subject Reference.
21698
/// <b>Handling of null values</b><para/>
21699
/// A null value indicates, that the corresponding metadata tag is not
21700
/// present in the metadata model.
21701
/// Setting this property's value to a non-null reference creates the
21702
/// metadata tag if necessary.
21703
/// Setting this property's value to a null reference deletes the
21704
/// metadata tag from the metadata model.
21706
public string SubjectReference
21710
return GetTagText("SubjectReference");
21714
SetTagValue("SubjectReference", value);
21719
/// Gets or sets the value of the IPTC/NAA tag Category.
21722
/// <b>Handling of null values</b><para/>
21723
/// A null value indicates, that the corresponding metadata tag is not
21724
/// present in the metadata model.
21725
/// Setting this property's value to a non-null reference creates the
21726
/// metadata tag if necessary.
21727
/// Setting this property's value to a null reference deletes the
21728
/// metadata tag from the metadata model.
21730
public string Category
21734
return GetTagText("Category");
21738
SetTagValue("Category", value);
21743
/// Gets or sets the value of the IPTC/NAA tag Supplemental Categories.
21746
/// <b>Handling of null values</b><para/>
21747
/// A null value indicates, that the corresponding metadata tag is not
21748
/// present in the metadata model.
21749
/// Setting this property's value to a non-null reference creates the
21750
/// metadata tag if necessary.
21751
/// Setting this property's value to a null reference deletes the
21752
/// metadata tag from the metadata model.
21754
public string SupplementalCategories
21758
return GetTagText("SupplementalCategories");
21762
SetTagValue("SupplementalCategories", value);
21767
/// Gets or sets the value of the IPTC/NAA tag Fixture Identifier.
21770
/// <b>Handling of null values</b><para/>
21771
/// A null value indicates, that the corresponding metadata tag is not
21772
/// present in the metadata model.
21773
/// Setting this property's value to a non-null reference creates the
21774
/// metadata tag if necessary.
21775
/// Setting this property's value to a null reference deletes the
21776
/// metadata tag from the metadata model.
21778
public string FixtureIdentifier
21782
return GetTagText("FixtureIdentifier");
21786
SetTagValue("FixtureIdentifier", value);
21791
/// Gets or sets the value of the IPTC/NAA tag Keywords.
21794
/// <b>Handling of null values</b><para/>
21795
/// A null value indicates, that the corresponding metadata tag is not
21796
/// present in the metadata model.
21797
/// Setting this property's value to a non-null reference creates the
21798
/// metadata tag if necessary.
21799
/// Setting this property's value to a null reference deletes the
21800
/// metadata tag from the metadata model.
21802
public string Keywords
21806
return GetTagText("Keywords");
21810
SetTagValue("Keywords", value);
21815
/// Gets or sets the value of the IPTC/NAA tag Content Location Code.
21818
/// <b>Handling of null values</b><para/>
21819
/// A null value indicates, that the corresponding metadata tag is not
21820
/// present in the metadata model.
21821
/// Setting this property's value to a non-null reference creates the
21822
/// metadata tag if necessary.
21823
/// Setting this property's value to a null reference deletes the
21824
/// metadata tag from the metadata model.
21826
public string ContentLocationCode
21830
return GetTagText("ContentLocationCode");
21834
SetTagValue("ContentLocationCode", value);
21839
/// Gets or sets the value of the IPTC/NAA tag Content Location Name.
21842
/// <b>Handling of null values</b><para/>
21843
/// A null value indicates, that the corresponding metadata tag is not
21844
/// present in the metadata model.
21845
/// Setting this property's value to a non-null reference creates the
21846
/// metadata tag if necessary.
21847
/// Setting this property's value to a null reference deletes the
21848
/// metadata tag from the metadata model.
21850
public string ContentLocationName
21854
return GetTagText("ContentLocationName");
21858
SetTagValue("ContentLocationName", value);
21863
/// Gets or sets the value of the IPTC/NAA tag Release Date.
21866
/// <b>Handling of null values</b><para/>
21867
/// A null value indicates, that the corresponding metadata tag is not
21868
/// present in the metadata model.
21869
/// Setting this property's value to a non-null reference creates the
21870
/// metadata tag if necessary.
21871
/// Setting this property's value to a null reference deletes the
21872
/// metadata tag from the metadata model.
21874
public string ReleaseDate
21878
return GetTagText("ReleaseDate");
21882
SetTagValue("ReleaseDate", value);
21887
/// Gets or sets the value of the IPTC/NAA tag Release Time.
21890
/// <b>Handling of null values</b><para/>
21891
/// A null value indicates, that the corresponding metadata tag is not
21892
/// present in the metadata model.
21893
/// Setting this property's value to a non-null reference creates the
21894
/// metadata tag if necessary.
21895
/// Setting this property's value to a null reference deletes the
21896
/// metadata tag from the metadata model.
21898
public string ReleaseTime
21902
return GetTagText("ReleaseTime");
21906
SetTagValue("ReleaseTime", value);
21911
/// Gets or sets the value of the IPTC/NAA tag Expiration Date.
21914
/// <b>Handling of null values</b><para/>
21915
/// A null value indicates, that the corresponding metadata tag is not
21916
/// present in the metadata model.
21917
/// Setting this property's value to a non-null reference creates the
21918
/// metadata tag if necessary.
21919
/// Setting this property's value to a null reference deletes the
21920
/// metadata tag from the metadata model.
21922
public string ExpirationDate
21926
return GetTagText("ExpirationDate");
21930
SetTagValue("ExpirationDate", value);
21935
/// Gets or sets the value of the IPTC/NAA tag Expiration Time.
21938
/// <b>Handling of null values</b><para/>
21939
/// A null value indicates, that the corresponding metadata tag is not
21940
/// present in the metadata model.
21941
/// Setting this property's value to a non-null reference creates the
21942
/// metadata tag if necessary.
21943
/// Setting this property's value to a null reference deletes the
21944
/// metadata tag from the metadata model.
21946
public string ExpirationTime
21950
return GetTagText("ExpirationTime");
21954
SetTagValue("ExpirationTime", value);
21959
/// Gets or sets the value of the IPTC/NAA tag Special Instructions.
21962
/// <b>Handling of null values</b><para/>
21963
/// A null value indicates, that the corresponding metadata tag is not
21964
/// present in the metadata model.
21965
/// Setting this property's value to a non-null reference creates the
21966
/// metadata tag if necessary.
21967
/// Setting this property's value to a null reference deletes the
21968
/// metadata tag from the metadata model.
21970
public string SpecialInstructions
21974
return GetTagText("SpecialInstructions");
21978
SetTagValue("SpecialInstructions", value);
21983
/// Gets or sets the value of the IPTC/NAA tag Action Advised.
21986
/// <b>Handling of null values</b><para/>
21987
/// A null value indicates, that the corresponding metadata tag is not
21988
/// present in the metadata model.
21989
/// Setting this property's value to a non-null reference creates the
21990
/// metadata tag if necessary.
21991
/// Setting this property's value to a null reference deletes the
21992
/// metadata tag from the metadata model.
21994
public string ActionAdvised
21998
return GetTagText("ActionAdvised");
22002
SetTagValue("ActionAdvised", value);
22007
/// Gets or sets the value of the IPTC/NAA tag Reference Service.
22010
/// <b>Handling of null values</b><para/>
22011
/// A null value indicates, that the corresponding metadata tag is not
22012
/// present in the metadata model.
22013
/// Setting this property's value to a non-null reference creates the
22014
/// metadata tag if necessary.
22015
/// Setting this property's value to a null reference deletes the
22016
/// metadata tag from the metadata model.
22018
public string ReferenceService
22022
return GetTagText("ReferenceService");
22026
SetTagValue("ReferenceService", value);
22031
/// Gets or sets the value of the IPTC/NAA tag Reference Date.
22034
/// <b>Handling of null values</b><para/>
22035
/// A null value indicates, that the corresponding metadata tag is not
22036
/// present in the metadata model.
22037
/// Setting this property's value to a non-null reference creates the
22038
/// metadata tag if necessary.
22039
/// Setting this property's value to a null reference deletes the
22040
/// metadata tag from the metadata model.
22042
public string ReferenceDate
22046
return GetTagText("ReferenceDate");
22050
SetTagValue("ReferenceDate", value);
22055
/// Gets or sets the value of the IPTC/NAA tag Reference Number.
22058
/// <b>Handling of null values</b><para/>
22059
/// A null value indicates, that the corresponding metadata tag is not
22060
/// present in the metadata model.
22061
/// Setting this property's value to a non-null reference creates the
22062
/// metadata tag if necessary.
22063
/// Setting this property's value to a null reference deletes the
22064
/// metadata tag from the metadata model.
22066
public string ReferenceNumber
22070
return GetTagText("ReferenceNumber");
22074
SetTagValue("ReferenceNumber", value);
22079
/// Gets or sets the value of the IPTC/NAA tag Date Created.
22082
/// <b>Handling of null values</b><para/>
22083
/// A null value indicates, that the corresponding metadata tag is not
22084
/// present in the metadata model.
22085
/// Setting this property's value to a non-null reference creates the
22086
/// metadata tag if necessary.
22087
/// Setting this property's value to a null reference deletes the
22088
/// metadata tag from the metadata model.
22090
public string DateCreated
22094
return GetTagText("DateCreated");
22098
SetTagValue("DateCreated", value);
22103
/// Gets or sets the value of the IPTC/NAA tag Time Created.
22106
/// <b>Handling of null values</b><para/>
22107
/// A null value indicates, that the corresponding metadata tag is not
22108
/// present in the metadata model.
22109
/// Setting this property's value to a non-null reference creates the
22110
/// metadata tag if necessary.
22111
/// Setting this property's value to a null reference deletes the
22112
/// metadata tag from the metadata model.
22114
public string TimeCreated
22118
return GetTagText("TimeCreated");
22122
SetTagValue("TimeCreated", value);
22127
/// Gets or sets the value of the IPTC/NAA tag Digital Creation Date.
22130
/// <b>Handling of null values</b><para/>
22131
/// A null value indicates, that the corresponding metadata tag is not
22132
/// present in the metadata model.
22133
/// Setting this property's value to a non-null reference creates the
22134
/// metadata tag if necessary.
22135
/// Setting this property's value to a null reference deletes the
22136
/// metadata tag from the metadata model.
22138
public string DigitalCreationDate
22142
return GetTagText("DigitalCreationDate");
22146
SetTagValue("DigitalCreationDate", value);
22151
/// Gets or sets the value of the IPTC/NAA tag Digital Creation Time.
22154
/// <b>Handling of null values</b><para/>
22155
/// A null value indicates, that the corresponding metadata tag is not
22156
/// present in the metadata model.
22157
/// Setting this property's value to a non-null reference creates the
22158
/// metadata tag if necessary.
22159
/// Setting this property's value to a null reference deletes the
22160
/// metadata tag from the metadata model.
22162
public string DigitalCreationTime
22166
return GetTagText("DigitalCreationTime");
22170
SetTagValue("DigitalCreationTime", value);
22175
/// Gets or sets the value of the IPTC/NAA tag Originating Program.
22178
/// <b>Handling of null values</b><para/>
22179
/// A null value indicates, that the corresponding metadata tag is not
22180
/// present in the metadata model.
22181
/// Setting this property's value to a non-null reference creates the
22182
/// metadata tag if necessary.
22183
/// Setting this property's value to a null reference deletes the
22184
/// metadata tag from the metadata model.
22186
public string OriginatingProgram
22190
return GetTagText("OriginatingProgram");
22194
SetTagValue("OriginatingProgram", value);
22199
/// Gets or sets the value of the IPTC/NAA tag Program Version.
22202
/// <b>Handling of null values</b><para/>
22203
/// A null value indicates, that the corresponding metadata tag is not
22204
/// present in the metadata model.
22205
/// Setting this property's value to a non-null reference creates the
22206
/// metadata tag if necessary.
22207
/// Setting this property's value to a null reference deletes the
22208
/// metadata tag from the metadata model.
22210
public string ProgramVersion
22214
return GetTagText("ProgramVersion");
22218
SetTagValue("ProgramVersion", value);
22223
/// Gets or sets the value of the IPTC/NAA tag Object Cycle.
22226
/// <b>Handling of null values</b><para/>
22227
/// A null value indicates, that the corresponding metadata tag is not
22228
/// present in the metadata model.
22229
/// Setting this property's value to a non-null reference creates the
22230
/// metadata tag if necessary.
22231
/// Setting this property's value to a null reference deletes the
22232
/// metadata tag from the metadata model.
22234
public string ObjectCycle
22238
return GetTagText("ObjectCycle");
22242
SetTagValue("ObjectCycle", value);
22247
/// Gets or sets the value of the IPTC/NAA tag By Line.
22248
/// This is the author's name.
22251
/// <b>Handling of null values</b><para/>
22252
/// A null value indicates, that the corresponding metadata tag is not
22253
/// present in the metadata model.
22254
/// Setting this property's value to a non-null reference creates the
22255
/// metadata tag if necessary.
22256
/// Setting this property's value to a null reference deletes the
22257
/// metadata tag from the metadata model.
22259
public string ByLine
22263
return GetTagText("By-line");
22267
SetTagValue("By-line", value);
22272
/// Gets or sets the value of the IPTC/NAA tag By Line Title.
22273
/// This is the author's position.
22276
/// <b>Handling of null values</b><para/>
22277
/// A null value indicates, that the corresponding metadata tag is not
22278
/// present in the metadata model.
22279
/// Setting this property's value to a non-null reference creates the
22280
/// metadata tag if necessary.
22281
/// Setting this property's value to a null reference deletes the
22282
/// metadata tag from the metadata model.
22284
public string ByLineTitle
22288
return GetTagText("By-lineTitle");
22292
SetTagValue("By-lineTitle", value);
22297
/// Gets or sets the value of the IPTC/NAA tag City.
22300
/// <b>Handling of null values</b><para/>
22301
/// A null value indicates, that the corresponding metadata tag is not
22302
/// present in the metadata model.
22303
/// Setting this property's value to a non-null reference creates the
22304
/// metadata tag if necessary.
22305
/// Setting this property's value to a null reference deletes the
22306
/// metadata tag from the metadata model.
22312
return GetTagText("City");
22316
SetTagValue("City", value);
22321
/// Gets or sets the value of the IPTC/NAA tag Sub Location.
22324
/// <b>Handling of null values</b><para/>
22325
/// A null value indicates, that the corresponding metadata tag is not
22326
/// present in the metadata model.
22327
/// Setting this property's value to a non-null reference creates the
22328
/// metadata tag if necessary.
22329
/// Setting this property's value to a null reference deletes the
22330
/// metadata tag from the metadata model.
22332
public string SubLocation
22336
return GetTagText("SubLocation");
22340
SetTagValue("SubLocation", value);
22345
/// Gets or sets the value of the IPTC/NAA tag Province State.
22348
/// <b>Handling of null values</b><para/>
22349
/// A null value indicates, that the corresponding metadata tag is not
22350
/// present in the metadata model.
22351
/// Setting this property's value to a non-null reference creates the
22352
/// metadata tag if necessary.
22353
/// Setting this property's value to a null reference deletes the
22354
/// metadata tag from the metadata model.
22356
public string ProvinceState
22360
return GetTagText("ProvinceState");
22364
SetTagValue("ProvinceState", value);
22369
/// Gets or sets the value of the IPTC/NAA tag Country Primary Location Code.
22372
/// <b>Handling of null values</b><para/>
22373
/// A null value indicates, that the corresponding metadata tag is not
22374
/// present in the metadata model.
22375
/// Setting this property's value to a non-null reference creates the
22376
/// metadata tag if necessary.
22377
/// Setting this property's value to a null reference deletes the
22378
/// metadata tag from the metadata model.
22380
public string CountryPrimaryLocationCode
22384
return GetTagText("Country-PrimaryLocationCode");
22388
SetTagValue("Country-PrimaryLocationCode", value);
22393
/// Gets or sets the value of the IPTC/NAA tag Country Primary Location Name.
22396
/// <b>Handling of null values</b><para/>
22397
/// A null value indicates, that the corresponding metadata tag is not
22398
/// present in the metadata model.
22399
/// Setting this property's value to a non-null reference creates the
22400
/// metadata tag if necessary.
22401
/// Setting this property's value to a null reference deletes the
22402
/// metadata tag from the metadata model.
22404
public string CountryPrimaryLocationName
22408
return GetTagText("Country-PrimaryLocationName");
22412
SetTagValue("Country-PrimaryLocationName", value);
22417
/// Gets or sets the value of the IPTC/NAA tag Original Transmission Reference.
22420
/// <b>Handling of null values</b><para/>
22421
/// A null value indicates, that the corresponding metadata tag is not
22422
/// present in the metadata model.
22423
/// Setting this property's value to a non-null reference creates the
22424
/// metadata tag if necessary.
22425
/// Setting this property's value to a null reference deletes the
22426
/// metadata tag from the metadata model.
22428
public string OriginalTransmissionReference
22432
return GetTagText("OriginalTransmissionReference");
22436
SetTagValue("OriginalTransmissionReference", value);
22441
/// Gets or sets the value of the IPTC/NAA tag Headline.
22444
/// <b>Handling of null values</b><para/>
22445
/// A null value indicates, that the corresponding metadata tag is not
22446
/// present in the metadata model.
22447
/// Setting this property's value to a non-null reference creates the
22448
/// metadata tag if necessary.
22449
/// Setting this property's value to a null reference deletes the
22450
/// metadata tag from the metadata model.
22452
public string Headline
22456
return GetTagText("Headline");
22460
SetTagValue("Headline", value);
22465
/// Gets or sets the value of the IPTC/NAA tag Credit.
22468
/// <b>Handling of null values</b><para/>
22469
/// A null value indicates, that the corresponding metadata tag is not
22470
/// present in the metadata model.
22471
/// Setting this property's value to a non-null reference creates the
22472
/// metadata tag if necessary.
22473
/// Setting this property's value to a null reference deletes the
22474
/// metadata tag from the metadata model.
22476
public string Credit
22480
return GetTagText("Credit");
22484
SetTagValue("Credit", value);
22489
/// Gets or sets the value of the IPTC/NAA tag Source.
22492
/// <b>Handling of null values</b><para/>
22493
/// A null value indicates, that the corresponding metadata tag is not
22494
/// present in the metadata model.
22495
/// Setting this property's value to a non-null reference creates the
22496
/// metadata tag if necessary.
22497
/// Setting this property's value to a null reference deletes the
22498
/// metadata tag from the metadata model.
22500
public string Source
22504
return GetTagText("Source");
22508
SetTagValue("Source", value);
22513
/// Gets or sets the value of the IPTC/NAA tag Copyright Notice.
22516
/// <b>Handling of null values</b><para/>
22517
/// A null value indicates, that the corresponding metadata tag is not
22518
/// present in the metadata model.
22519
/// Setting this property's value to a non-null reference creates the
22520
/// metadata tag if necessary.
22521
/// Setting this property's value to a null reference deletes the
22522
/// metadata tag from the metadata model.
22524
public string CopyrightNotice
22528
return GetTagText("CopyrightNotice");
22532
SetTagValue("CopyrightNotice", value);
22537
/// Gets or sets the value of the IPTC/NAA tag Contact.
22540
/// <b>Handling of null values</b><para/>
22541
/// A null value indicates, that the corresponding metadata tag is not
22542
/// present in the metadata model.
22543
/// Setting this property's value to a non-null reference creates the
22544
/// metadata tag if necessary.
22545
/// Setting this property's value to a null reference deletes the
22546
/// metadata tag from the metadata model.
22548
public string Contact
22552
return GetTagText("Contact");
22556
SetTagValue("Contact", value);
22561
/// Gets or sets the value of the IPTC/NAA tag Caption Abstract.
22564
/// <b>Handling of null values</b><para/>
22565
/// A null value indicates, that the corresponding metadata tag is not
22566
/// present in the metadata model.
22567
/// Setting this property's value to a non-null reference creates the
22568
/// metadata tag if necessary.
22569
/// Setting this property's value to a null reference deletes the
22570
/// metadata tag from the metadata model.
22572
public string CaptionAbstract
22576
return GetTagText("CaptionAbstract");
22580
SetTagValue("CaptionAbstract", value);
22585
/// Gets or sets the value of the IPTC/NAA tag Writer Editor.
22586
/// This is also referred to as Caption Writer.
22589
/// <b>Handling of null values</b><para/>
22590
/// A null value indicates, that the corresponding metadata tag is not
22591
/// present in the metadata model.
22592
/// Setting this property's value to a non-null reference creates the
22593
/// metadata tag if necessary.
22594
/// Setting this property's value to a null reference deletes the
22595
/// metadata tag from the metadata model.
22597
public string WriterEditor
22601
return GetTagText("WriterEditor");
22605
SetTagValue("WriterEditor", value);
22610
/// Gets or sets the value of the IPTC/NAA tag Rasterized Caption.
22613
/// <b>Handling of null values</b><para/>
22614
/// A null value indicates, that the corresponding metadata tag is not
22615
/// present in the metadata model.
22616
/// Setting this property's value to a non-null reference creates the
22617
/// metadata tag if necessary.
22618
/// Setting this property's value to a null reference deletes the
22619
/// metadata tag from the metadata model.
22621
public string RasterizedCaption
22625
return GetTagText("RasterizedCaption");
22629
SetTagValue("RasterizedCaption", value);
22634
/// Gets or sets the value of the IPTC/NAA tag Image Type.
22637
/// <b>Handling of null values</b><para/>
22638
/// A null value indicates, that the corresponding metadata tag is not
22639
/// present in the metadata model.
22640
/// Setting this property's value to a non-null reference creates the
22641
/// metadata tag if necessary.
22642
/// Setting this property's value to a null reference deletes the
22643
/// metadata tag from the metadata model.
22645
public string ImageType
22649
return GetTagText("ImageType");
22653
SetTagValue("ImageType", value);
22658
/// Gets or sets the value of the IPTC/NAA tag Image Orientation.
22661
/// <b>Handling of null values</b><para/>
22662
/// A null value indicates, that the corresponding metadata tag is not
22663
/// present in the metadata model.
22664
/// Setting this property's value to a non-null reference creates the
22665
/// metadata tag if necessary.
22666
/// Setting this property's value to a null reference deletes the
22667
/// metadata tag from the metadata model.
22669
public string ImageOrientation
22673
return GetTagText("ImageOrientation");
22677
SetTagValue("ImageOrientation", value);
22682
/// Gets or sets the value of the IPTC/NAA tag Language Identifier.
22685
/// <b>Handling of null values</b><para/>
22686
/// A null value indicates, that the corresponding metadata tag is not
22687
/// present in the metadata model.
22688
/// Setting this property's value to a non-null reference creates the
22689
/// metadata tag if necessary.
22690
/// Setting this property's value to a null reference deletes the
22691
/// metadata tag from the metadata model.
22693
public string LanguageIdentifier
22697
return GetTagText("LanguageIdentifier");
22701
SetTagValue("LanguageIdentifier", value);
22706
/// Gets or sets the value of the IPTC/NAA tag Audio Type.
22709
/// <b>Handling of null values</b><para/>
22710
/// A null value indicates, that the corresponding metadata tag is not
22711
/// present in the metadata model.
22712
/// Setting this property's value to a non-null reference creates the
22713
/// metadata tag if necessary.
22714
/// Setting this property's value to a null reference deletes the
22715
/// metadata tag from the metadata model.
22717
public string AudioType
22721
return GetTagText("AudioType");
22725
SetTagValue("AudioType", value);
22730
/// Gets or sets the value of the IPTC/NAA tag Audio Sampling Rate.
22733
/// <b>Handling of null values</b><para/>
22734
/// A null value indicates, that the corresponding metadata tag is not
22735
/// present in the metadata model.
22736
/// Setting this property's value to a non-null reference creates the
22737
/// metadata tag if necessary.
22738
/// Setting this property's value to a null reference deletes the
22739
/// metadata tag from the metadata model.
22741
public string AudioSamplingRate
22745
return GetTagText("AudioSamplingRate");
22749
SetTagValue("AudioSamplingRate", value);
22754
/// Gets or sets the value of the IPTC/NAA tag Audio Sampling Resolution.
22757
/// <b>Handling of null values</b><para/>
22758
/// A null value indicates, that the corresponding metadata tag is not
22759
/// present in the metadata model.
22760
/// Setting this property's value to a non-null reference creates the
22761
/// metadata tag if necessary.
22762
/// Setting this property's value to a null reference deletes the
22763
/// metadata tag from the metadata model.
22765
public string AudioSamplingResolution
22769
return GetTagText("AudioSamplingResolution");
22773
SetTagValue("AudioSamplingResolution", value);
22778
/// Gets or sets the value of the IPTC/NAA tag Audio Duration.
22781
/// <b>Handling of null values</b><para/>
22782
/// A null value indicates, that the corresponding metadata tag is not
22783
/// present in the metadata model.
22784
/// Setting this property's value to a non-null reference creates the
22785
/// metadata tag if necessary.
22786
/// Setting this property's value to a null reference deletes the
22787
/// metadata tag from the metadata model.
22789
public string AudioDuration
22793
return GetTagText("AudioDuration");
22797
SetTagValue("AudioDuration", value);
22802
/// Gets or sets the value of the IPTC/NAA tag Audio Outcue.
22805
/// <b>Handling of null values</b><para/>
22806
/// A null value indicates, that the corresponding metadata tag is not
22807
/// present in the metadata model.
22808
/// Setting this property's value to a non-null reference creates the
22809
/// metadata tag if necessary.
22810
/// Setting this property's value to a null reference deletes the
22811
/// metadata tag from the metadata model.
22813
public string AudioOutcue
22817
return GetTagText("AudioOutcue");
22821
SetTagValue("AudioOutcue", value);
22826
/// Gets or sets the value of the IPTC/NAA tag Job I D.
22829
/// <b>Handling of null values</b><para/>
22830
/// A null value indicates, that the corresponding metadata tag is not
22831
/// present in the metadata model.
22832
/// Setting this property's value to a non-null reference creates the
22833
/// metadata tag if necessary.
22834
/// Setting this property's value to a null reference deletes the
22835
/// metadata tag from the metadata model.
22837
public string JobID
22841
return GetTagText("JobID");
22845
SetTagValue("JobID", value);
22850
/// Gets or sets the value of the IPTC/NAA tag Master Document I D.
22853
/// <b>Handling of null values</b><para/>
22854
/// A null value indicates, that the corresponding metadata tag is not
22855
/// present in the metadata model.
22856
/// Setting this property's value to a non-null reference creates the
22857
/// metadata tag if necessary.
22858
/// Setting this property's value to a null reference deletes the
22859
/// metadata tag from the metadata model.
22861
public string MasterDocumentID
22865
return GetTagText("MasterDocumentID");
22869
SetTagValue("MasterDocumentID", value);
22874
/// Gets or sets the value of the IPTC/NAA tag Short Document I D.
22877
/// <b>Handling of null values</b><para/>
22878
/// A null value indicates, that the corresponding metadata tag is not
22879
/// present in the metadata model.
22880
/// Setting this property's value to a non-null reference creates the
22881
/// metadata tag if necessary.
22882
/// Setting this property's value to a null reference deletes the
22883
/// metadata tag from the metadata model.
22885
public string ShortDocumentID
22889
return GetTagText("ShortDocumentID");
22893
SetTagValue("ShortDocumentID", value);
22898
/// Gets or sets the value of the IPTC/NAA tag Unique Document I D.
22901
/// <b>Handling of null values</b><para/>
22902
/// A null value indicates, that the corresponding metadata tag is not
22903
/// present in the metadata model.
22904
/// Setting this property's value to a non-null reference creates the
22905
/// metadata tag if necessary.
22906
/// Setting this property's value to a null reference deletes the
22907
/// metadata tag from the metadata model.
22909
public string UniqueDocumentID
22913
return GetTagText("UniqueDocumentID");
22917
SetTagValue("UniqueDocumentID", value);
22922
/// Gets or sets the value of the IPTC/NAA tag Owner I D.
22925
/// <b>Handling of null values</b><para/>
22926
/// A null value indicates, that the corresponding metadata tag is not
22927
/// present in the metadata model.
22928
/// Setting this property's value to a non-null reference creates the
22929
/// metadata tag if necessary.
22930
/// Setting this property's value to a null reference deletes the
22931
/// metadata tag from the metadata model.
22933
public string OwnerID
22937
return GetTagText("OwnerID");
22941
SetTagValue("OwnerID", value);
22946
/// Gets or sets the value of the IPTC/NAA tag Object Preview File Format.
22949
/// <b>Handling of null values</b><para/>
22950
/// A null value indicates, that the corresponding metadata tag is not
22951
/// present in the metadata model.
22952
/// Setting this property's value to a non-null reference creates the
22953
/// metadata tag if necessary.
22954
/// Setting this property's value to a null reference deletes the
22955
/// metadata tag from the metadata model.
22957
public string ObjectPreviewFileFormat
22961
return GetTagText("ObjectPreviewFileFormat");
22965
SetTagValue("ObjectPreviewFileFormat", value);
22970
/// Gets or sets the value of the IPTC/NAA tag Object Preview File Version.
22973
/// <b>Handling of null values</b><para/>
22974
/// A null value indicates, that the corresponding metadata tag is not
22975
/// present in the metadata model.
22976
/// Setting this property's value to a non-null reference creates the
22977
/// metadata tag if necessary.
22978
/// Setting this property's value to a null reference deletes the
22979
/// metadata tag from the metadata model.
22981
public string ObjectPreviewFileVersion
22985
return GetTagText("ObjectPreviewFileVersion");
22989
SetTagValue("ObjectPreviewFileVersion", value);
22994
/// Gets or sets the value of the IPTC/NAA tag Object Preview Data.
22995
/// This is also referred to as Audio Outcue.
22998
/// <b>Handling of null values</b><para/>
22999
/// A null value indicates, that the corresponding metadata tag is not
23000
/// present in the metadata model.
23001
/// Setting this property's value to a non-null reference creates the
23002
/// metadata tag if necessary.
23003
/// Setting this property's value to a null reference deletes the
23004
/// metadata tag from the metadata model.
23006
public string ObjectPreviewData
23010
return GetTagText("ObjectPreviewData");
23014
SetTagValue("ObjectPreviewData", value);
23019
/// Gets or sets the value of the IPTC/NAA tag Prefs.
23020
/// This is also referred to as photo-mechanic preferences.
23023
/// <b>Handling of null values</b><para/>
23024
/// A null value indicates, that the corresponding metadata tag is not
23025
/// present in the metadata model.
23026
/// Setting this property's value to a non-null reference creates the
23027
/// metadata tag if necessary.
23028
/// Setting this property's value to a null reference deletes the
23029
/// metadata tag from the metadata model.
23031
public string Prefs
23035
return GetTagText("Prefs");
23039
SetTagValue("Prefs", value);
23044
/// Gets or sets the value of the IPTC/NAA tag Classify State.
23047
/// <b>Handling of null values</b><para/>
23048
/// A null value indicates, that the corresponding metadata tag is not
23049
/// present in the metadata model.
23050
/// Setting this property's value to a non-null reference creates the
23051
/// metadata tag if necessary.
23052
/// Setting this property's value to a null reference deletes the
23053
/// metadata tag from the metadata model.
23055
public string ClassifyState
23059
return GetTagText("ClassifyState");
23063
SetTagValue("ClassifyState", value);
23068
/// Gets or sets the value of the IPTC/NAA tag Similarity Index.
23071
/// <b>Handling of null values</b><para/>
23072
/// A null value indicates, that the corresponding metadata tag is not
23073
/// present in the metadata model.
23074
/// Setting this property's value to a non-null reference creates the
23075
/// metadata tag if necessary.
23076
/// Setting this property's value to a null reference deletes the
23077
/// metadata tag from the metadata model.
23079
public string SimilarityIndex
23083
return GetTagText("SimilarityIndex");
23087
SetTagValue("SimilarityIndex", value);
23092
/// Gets or sets the value of the IPTC/NAA tag Document Notes.
23095
/// <b>Handling of null values</b><para/>
23096
/// A null value indicates, that the corresponding metadata tag is not
23097
/// present in the metadata model.
23098
/// Setting this property's value to a non-null reference creates the
23099
/// metadata tag if necessary.
23100
/// Setting this property's value to a null reference deletes the
23101
/// metadata tag from the metadata model.
23103
public string DocumentNotes
23107
return GetTagText("DocumentNotes");
23111
SetTagValue("DocumentNotes", value);
23116
/// Gets or sets the value of the IPTC/NAA tag Document History.
23119
/// <b>Handling of null values</b><para/>
23120
/// A null value indicates, that the corresponding metadata tag is not
23121
/// present in the metadata model.
23122
/// Setting this property's value to a non-null reference creates the
23123
/// metadata tag if necessary.
23124
/// Setting this property's value to a null reference deletes the
23125
/// metadata tag from the metadata model.
23127
public string DocumentHistory
23131
return GetTagText("DocumentHistory");
23135
SetTagValue("DocumentHistory", value);
23140
/// Gets or sets the value of the IPTC/NAA tag Exif Camera Info.
23143
/// <b>Handling of null values</b><para/>
23144
/// A null value indicates, that the corresponding metadata tag is not
23145
/// present in the metadata model.
23146
/// Setting this property's value to a non-null reference creates the
23147
/// metadata tag if necessary.
23148
/// Setting this property's value to a null reference deletes the
23149
/// metadata tag from the metadata model.
23151
public string ExifCameraInfo
23155
return GetTagText("ExifCameraInfo");
23159
SetTagValue("ExifCameraInfo", value);
23165
/// Represents a collection of all tags contained in the metadata model
23166
/// <see cref="FREE_IMAGE_MDMODEL.FIMD_NODATA"/>.
23168
public class MDM_NODATA : MetadataModel
23171
/// Initializes a new instance of this class.
23173
/// <param name="dib">Handle to a FreeImage bitmap.</param>
23174
public MDM_NODATA(FIBITMAP dib) : base(dib) { }
23177
/// Retrieves the datamodel that this instance represents.
23179
public override FREE_IMAGE_MDMODEL Model
23181
get { return FREE_IMAGE_MDMODEL.FIMD_NODATA; }
23186
/// Represents a collection of all tags contained in the metadata model
23187
/// <see cref="FREE_IMAGE_MDMODEL.FIMD_XMP"/>.
23189
public class MDM_XMP : MetadataModel
23192
/// Initializes a new instance of this class.
23194
/// <param name="dib">Handle to a FreeImage bitmap.</param>
23195
public MDM_XMP(FIBITMAP dib) : base(dib) { }
23198
/// Retrieves the datamodel that this instance represents.
23200
public override FREE_IMAGE_MDMODEL Model
23202
get { return FREE_IMAGE_MDMODEL.FIMD_XMP; }
23206
/// Gets or sets the XMP XML content.
23209
/// <b>Handling of null values</b><para/>
23210
/// A null value indicates, that the corresponding metadata tag is not
23211
/// present in the metadata model.
23212
/// Setting this property's value to a non-null reference creates the
23213
/// metadata tag if necessary.
23214
/// Setting this property's value to a null reference deletes the
23215
/// metadata tag from the metadata model.
23221
return GetTagText("XMLPacket");
23225
SetTagValue("XMLPacket", value);
23230
/// Gets an <see cref="XmlReader"/> initialized to read the XMP XML content.
23231
/// Returns null, if the metadata tag <i>XMLPacket</i> is not present in
23234
public XmlReader XmlReader
23238
string xmlString = Xml;
23239
if (xmlString == null)
23245
MemoryStream stream = new MemoryStream();
23246
StreamWriter writer = new StreamWriter(stream);
23247
writer.Write(xmlString);
23248
return XmlReader.Create(stream);
23257
namespace FreeImageAPI.Metadata
23260
/// Manages metadata objects and operations.
23262
public sealed class MetadataTag : IComparable, IComparable<MetadataTag>, ICloneable, IEquatable<MetadataTag>, IDisposable
23265
/// The encapsulated FreeImage-tag.
23267
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
23268
internal FITAG tag;
23271
/// The metadata model of <see cref="tag"/>.
23273
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
23274
private FREE_IMAGE_MDMODEL model;
23277
/// Indicates whether this instance has already been disposed.
23279
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
23280
private bool disposed = false;
23283
/// Indicates whether this instance was created by FreeImage or
23286
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
23287
private bool selfCreated;
23290
/// List linking metadata-model and Type.
23292
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
23293
private static readonly Dictionary<FREE_IMAGE_MDTYPE, Type> idList;
23296
/// List linking Type and metadata-model.
23298
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
23299
private static readonly Dictionary<Type, FREE_IMAGE_MDTYPE> typeList;
23302
/// Initializes a new instance of this class.
23304
private MetadataTag()
23309
/// Initializes a new instance of this class.
23311
/// <param name="model">The new model the tag should be of.</param>
23312
public MetadataTag(FREE_IMAGE_MDMODEL model)
23314
this.model = model;
23315
tag = FreeImage.CreateTag();
23316
selfCreated = true;
23318
if (model == FREE_IMAGE_MDMODEL.FIMD_XMP)
23325
/// Initializes a new instance of this class.
23327
/// <param name="tag">The <see cref="FITAG"/> to represent.</param>
23328
/// <param name="dib">The bitmap <paramref name="tag"/> was extracted from.</param>
23329
public MetadataTag(FITAG tag, FIBITMAP dib)
23333
throw new ArgumentNullException("tag");
23337
throw new ArgumentNullException("dib");
23340
model = GetModel(dib, tag);
23341
selfCreated = false;
23343
if (model == FREE_IMAGE_MDMODEL.FIMD_XMP)
23350
/// Initializes a new instance of this class.
23352
/// <param name="tag">The <see cref="FITAG"/> to represent.</param>
23353
/// <param name="model">The model of <paramref name="tag"/>.</param>
23354
public MetadataTag(FITAG tag, FREE_IMAGE_MDMODEL model)
23358
throw new ArgumentNullException("tag");
23361
this.model = model;
23362
selfCreated = false;
23364
if (model == FREE_IMAGE_MDMODEL.FIMD_XMP)
23370
static MetadataTag()
23372
idList = new Dictionary<FREE_IMAGE_MDTYPE, Type>();
23373
idList.Add(FREE_IMAGE_MDTYPE.FIDT_BYTE, typeof(byte));
23374
idList.Add(FREE_IMAGE_MDTYPE.FIDT_SHORT, typeof(ushort));
23375
idList.Add(FREE_IMAGE_MDTYPE.FIDT_LONG, typeof(uint));
23376
idList.Add(FREE_IMAGE_MDTYPE.FIDT_RATIONAL, typeof(FIURational));
23377
idList.Add(FREE_IMAGE_MDTYPE.FIDT_SBYTE, typeof(sbyte));
23378
idList.Add(FREE_IMAGE_MDTYPE.FIDT_UNDEFINED, typeof(byte));
23379
idList.Add(FREE_IMAGE_MDTYPE.FIDT_SSHORT, typeof(short));
23380
idList.Add(FREE_IMAGE_MDTYPE.FIDT_SLONG, typeof(int));
23381
idList.Add(FREE_IMAGE_MDTYPE.FIDT_SRATIONAL, typeof(FIRational));
23382
idList.Add(FREE_IMAGE_MDTYPE.FIDT_FLOAT, typeof(float));
23383
idList.Add(FREE_IMAGE_MDTYPE.FIDT_DOUBLE, typeof(double));
23384
idList.Add(FREE_IMAGE_MDTYPE.FIDT_IFD, typeof(uint));
23385
idList.Add(FREE_IMAGE_MDTYPE.FIDT_PALETTE, typeof(RGBQUAD));
23387
typeList = new Dictionary<Type, FREE_IMAGE_MDTYPE>();
23388
typeList.Add(typeof(ushort), FREE_IMAGE_MDTYPE.FIDT_SHORT);
23389
typeList.Add(typeof(ushort[]), FREE_IMAGE_MDTYPE.FIDT_SHORT);
23390
typeList.Add(typeof(string), FREE_IMAGE_MDTYPE.FIDT_ASCII);
23391
typeList.Add(typeof(uint), FREE_IMAGE_MDTYPE.FIDT_LONG);
23392
typeList.Add(typeof(uint[]), FREE_IMAGE_MDTYPE.FIDT_LONG);
23393
typeList.Add(typeof(FIURational), FREE_IMAGE_MDTYPE.FIDT_RATIONAL);
23394
typeList.Add(typeof(FIURational[]), FREE_IMAGE_MDTYPE.FIDT_RATIONAL);
23395
typeList.Add(typeof(sbyte), FREE_IMAGE_MDTYPE.FIDT_SBYTE);
23396
typeList.Add(typeof(sbyte[]), FREE_IMAGE_MDTYPE.FIDT_SBYTE);
23397
typeList.Add(typeof(byte), FREE_IMAGE_MDTYPE.FIDT_BYTE);
23398
typeList.Add(typeof(byte[]), FREE_IMAGE_MDTYPE.FIDT_BYTE);
23399
typeList.Add(typeof(short), FREE_IMAGE_MDTYPE.FIDT_SSHORT);
23400
typeList.Add(typeof(short[]), FREE_IMAGE_MDTYPE.FIDT_SSHORT);
23401
typeList.Add(typeof(int), FREE_IMAGE_MDTYPE.FIDT_SLONG);
23402
typeList.Add(typeof(int[]), FREE_IMAGE_MDTYPE.FIDT_SLONG);
23403
typeList.Add(typeof(FIRational), FREE_IMAGE_MDTYPE.FIDT_SRATIONAL);
23404
typeList.Add(typeof(FIRational[]), FREE_IMAGE_MDTYPE.FIDT_SRATIONAL);
23405
typeList.Add(typeof(float), FREE_IMAGE_MDTYPE.FIDT_FLOAT);
23406
typeList.Add(typeof(float[]), FREE_IMAGE_MDTYPE.FIDT_FLOAT);
23407
typeList.Add(typeof(double), FREE_IMAGE_MDTYPE.FIDT_DOUBLE);
23408
typeList.Add(typeof(double[]), FREE_IMAGE_MDTYPE.FIDT_DOUBLE);
23409
typeList.Add(typeof(RGBQUAD), FREE_IMAGE_MDTYPE.FIDT_PALETTE);
23410
typeList.Add(typeof(RGBQUAD[]), FREE_IMAGE_MDTYPE.FIDT_PALETTE);
23414
/// Releases all resources used by the instance.
23422
/// Determines whether two specified <see cref="MetadataTag"/> objects have the same value.
23424
/// <param name="left">A <see cref="MetadataTag"/> or a null reference (<b>Nothing</b> in Visual Basic).</param>
23425
/// <param name="right">A <see cref="MetadataTag"/> or a null reference (<b>Nothing</b> in Visual Basic).</param>
23427
/// <b>true</b> if the value of left is the same as the value of right; otherwise, <b>false</b>.
23429
public static bool operator ==(MetadataTag left, MetadataTag right)
23431
// Check whether both are null
23432
if ((object)left == (object)right)
23436
else if ((object)left == null || (object)right == null)
23440
left.CheckDisposed();
23441
right.CheckDisposed();
23442
// Check all properties
23443
if ((left.Key != right.Key) ||
23444
(left.ID != right.ID) ||
23445
(left.Description != right.Description) ||
23446
(left.Count != right.Count) ||
23447
(left.Length != right.Length) ||
23448
(left.Model != right.Model) ||
23449
(left.Type != right.Type))
23453
if (left.Length == 0)
23457
IntPtr ptr1 = FreeImage.GetTagValue(left.tag);
23458
IntPtr ptr2 = FreeImage.GetTagValue(right.tag);
23459
return FreeImage.CompareMemory(ptr1, ptr2, left.Length);
23463
/// Determines whether two specified <see cref="MetadataTag"/> objects have different values.
23465
/// <param name="left">A <see cref="MetadataTag"/> or a null reference (<b>Nothing</b> in Visual Basic).</param>
23466
/// <param name="right">A <see cref="MetadataTag"/> or a null reference (<b>Nothing</b> in Visual Basic).</param>
23468
/// true if the value of left is different from the value of right; otherwise, <b>false</b>.
23470
public static bool operator !=(MetadataTag left, MetadataTag right)
23472
return !(left == right);
23476
/// Extracts the value of a <see cref="MetadataTag"/> instance to a <see cref="FITAG"/> handle.
23478
/// <param name="value">A <see cref="MetadataTag"/> instance.</param>
23479
/// <returns>A new instance of <see cref="FITAG"/> initialized to <paramref name="value"/>.</returns>
23480
public static implicit operator FITAG(MetadataTag value)
23485
private static FREE_IMAGE_MDMODEL GetModel(FIBITMAP dib, FITAG tag)
23488
foreach (FREE_IMAGE_MDMODEL model in FreeImage.FREE_IMAGE_MDMODELS)
23490
FIMETADATA mData = FreeImage.FindFirstMetadata(model, dib, out value);
23504
while (FreeImage.FindNextMetadata(mData, out value));
23510
FreeImage.FindCloseMetadata(mData);
23514
throw new ArgumentException("'tag' is no metadata object of 'dib'");
23518
/// Gets the model of the metadata.
23520
public FREE_IMAGE_MDMODEL Model
23522
get { CheckDisposed(); return model; }
23526
/// Gets or sets the key of the metadata.
23530
get { CheckDisposed(); return FreeImage.GetTagKey(tag); }
23534
if ((model != FREE_IMAGE_MDMODEL.FIMD_XMP) || (value == "XMLPacket"))
23536
FreeImage.SetTagKey(tag, value);
23542
/// Gets or sets the description of the metadata.
23544
public string Description
23546
get { CheckDisposed(); return FreeImage.GetTagDescription(tag); }
23547
set { CheckDisposed(); FreeImage.SetTagDescription(tag, value); }
23551
/// Gets or sets the ID of the metadata.
23555
get { CheckDisposed(); return FreeImage.GetTagID(tag); }
23556
set { CheckDisposed(); FreeImage.SetTagID(tag, value); }
23560
/// Gets the type of the metadata.
23562
public FREE_IMAGE_MDTYPE Type
23564
get { CheckDisposed(); return FreeImage.GetTagType(tag); }
23565
internal set { FreeImage.SetTagType(tag, value); }
23569
/// Gets the number of elements the metadata object contains.
23573
get { CheckDisposed(); return FreeImage.GetTagCount(tag); }
23574
private set { FreeImage.SetTagCount(tag, value); }
23578
/// Gets the length of the value in bytes.
23582
get { CheckDisposed(); return FreeImage.GetTagLength(tag); }
23583
private set { FreeImage.SetTagLength(tag, value); }
23586
private unsafe byte[] GetData()
23588
uint length = Length;
23589
byte[] value = new byte[length];
23590
byte* ptr = (byte*)FreeImage.GetTagValue(tag);
23591
for (int i = 0; i < length; i++)
23599
/// Gets or sets the value of the metadata.
23601
public object Value
23608
int cnt = (int)Count;
23610
if (Type == FREE_IMAGE_MDTYPE.FIDT_ASCII)
23612
byte* value = (byte*)FreeImage.GetTagValue(tag);
23613
StringBuilder sb = new StringBuilder();
23614
for (int i = 0; i < cnt; i++)
23616
sb.Append(Convert.ToChar(value[i]));
23618
return sb.ToString();
23620
else if (Type == FREE_IMAGE_MDTYPE.FIDT_NOTYPE)
23625
Array array = Array.CreateInstance(idList[Type], Count);
23626
void* src = (void*)FreeImage.GetTagValue(tag);
23627
FreeImage.CopyMemory(array, src, Length);
23638
/// Sets the value of the metadata.
23639
/// <para> In case value is of byte or byte[] <see cref="FREE_IMAGE_MDTYPE.FIDT_UNDEFINED"/> is assumed.</para>
23640
/// <para> In case value is of uint or uint[] <see cref="FREE_IMAGE_MDTYPE.FIDT_LONG"/> is assumed.</para>
23642
/// <param name="value">New data of the metadata.</param>
23643
/// <returns>True on success, false on failure.</returns>
23644
/// <exception cref="NotSupportedException">
23645
/// The data format is not supported.</exception>
23646
/// <exception cref="ArgumentNullException">
23647
/// <paramref name="value"/> is null.</exception>
23648
public bool SetValue(object value)
23650
Type type = value.GetType();
23651
if (!typeList.ContainsKey(type))
23653
throw new NotSupportedException("The type of value is not supported");
23655
return SetValue(value, typeList[type]);
23659
/// Sets the value of the metadata.
23661
/// <param name="value">New data of the metadata.</param>
23662
/// <param name="type">Type of the data.</param>
23663
/// <returns>True on success, false on failure.</returns>
23664
/// <exception cref="NotSupportedException">
23665
/// The data type is not supported.</exception>
23666
/// <exception cref="ArgumentNullException">
23667
/// <paramref name="value"/> is null.</exception>
23668
/// <exception cref="ArgumentException">
23669
/// <paramref name="value"/> and <paramref name="type"/> to not fit.</exception>
23670
public bool SetValue(object value, FREE_IMAGE_MDTYPE type)
23673
if ((!value.GetType().IsArray) && (!(value is string)))
23675
Array array = Array.CreateInstance(value.GetType(), 1);
23676
array.SetValue(value, 0);
23677
return SetArrayValue(array, type);
23679
return SetArrayValue(value, type);
23683
/// Sets the value of this tag to the value of <paramref name="value"/>
23684
/// using the given type.
23686
/// <param name="value">New value of the tag.</param>
23687
/// <param name="type">Data-type of the tag.</param>
23688
/// <returns></returns>
23689
/// <exception cref="ArgumentNullException">
23690
/// <paramref name="value"/> is a null reference.
23692
/// <exception cref="ArgumentException">
23693
/// <paramref name="type"/> is FIDT_ASCII and
23694
/// <paramref name="value"/> is not String.
23695
/// <paramref name="type"/> is not FIDT_ASCII and
23696
/// <paramref name="value"/> is not Array.</exception>
23697
/// <exception cref="NotSupportedException">
23698
/// <paramref name="type"/> is FIDT_NOTYPE.</exception>
23699
private unsafe bool SetArrayValue(object value, FREE_IMAGE_MDTYPE type)
23703
throw new ArgumentNullException("value");
23706
byte[] data = null;
23708
if (type == FREE_IMAGE_MDTYPE.FIDT_ASCII)
23710
string tempValue = value as string;
23711
if (tempValue == null)
23713
throw new ArgumentException("value");
23716
Length = Count = (uint)tempValue.Length;
23717
data = new byte[Length];
23719
for (int i = 0; i < tempValue.Length; i++)
23721
data[i] = (byte)tempValue[i];
23724
else if (type == FREE_IMAGE_MDTYPE.FIDT_NOTYPE)
23726
throw new NotSupportedException("type is not supported.");
23730
Array array = value as Array;
23733
throw new ArgumentException("value");
23736
if (array.Length != 0)
23737
if (!CheckType(array.GetValue(0).GetType(), type))
23738
throw new ArgumentException("The type of value is incorrect.");
23741
Count = (uint)array.Length;
23742
Length = (uint)(array.Length * Marshal.SizeOf(idList[type]));
23743
data = new byte[Length];
23744
FreeImage.CopyMemory(data, array, Length);
23747
return FreeImage.SetTagValue(tag, data);
23750
private static bool CheckType(Type dataType, FREE_IMAGE_MDTYPE type)
23752
if (dataType != null)
23755
case FREE_IMAGE_MDTYPE.FIDT_ASCII:
23756
return dataType == typeof(string);
23757
case FREE_IMAGE_MDTYPE.FIDT_BYTE:
23758
return dataType == typeof(byte);
23759
case FREE_IMAGE_MDTYPE.FIDT_DOUBLE:
23760
return dataType == typeof(double);
23761
case FREE_IMAGE_MDTYPE.FIDT_FLOAT:
23762
return dataType == typeof(float);
23763
case FREE_IMAGE_MDTYPE.FIDT_IFD:
23764
return dataType == typeof(uint);
23765
case FREE_IMAGE_MDTYPE.FIDT_LONG:
23766
return dataType == typeof(uint);
23767
case FREE_IMAGE_MDTYPE.FIDT_NOTYPE:
23769
case FREE_IMAGE_MDTYPE.FIDT_PALETTE:
23770
return dataType == typeof(RGBQUAD);
23771
case FREE_IMAGE_MDTYPE.FIDT_RATIONAL:
23772
return dataType == typeof(FIURational);
23773
case FREE_IMAGE_MDTYPE.FIDT_SBYTE:
23774
return dataType == typeof(sbyte);
23775
case FREE_IMAGE_MDTYPE.FIDT_SHORT:
23776
return dataType == typeof(ushort);
23777
case FREE_IMAGE_MDTYPE.FIDT_SLONG:
23778
return dataType == typeof(int);
23779
case FREE_IMAGE_MDTYPE.FIDT_SRATIONAL:
23780
return dataType == typeof(FIRational);
23781
case FREE_IMAGE_MDTYPE.FIDT_SSHORT:
23782
return dataType == typeof(short);
23783
case FREE_IMAGE_MDTYPE.FIDT_UNDEFINED:
23784
return dataType == typeof(byte);
23790
/// Add this metadata to an image.
23792
/// <param name="dib">Handle to a FreeImage bitmap.</param>
23793
/// <returns>True on success, false on failure.</returns>
23794
public bool AddToImage(FIBITMAP dib)
23799
throw new ArgumentNullException("dib");
23803
throw new ArgumentNullException("Key");
23807
tag = FreeImage.CloneTag(tag);
23810
throw new Exception("FreeImage.CloneTag() failed.");
23812
selfCreated = true;
23814
if (!FreeImage.SetMetadata(Model, dib, Key, tag))
23818
FREE_IMAGE_MDMODEL _model = Model;
23820
selfCreated = false;
23821
FreeImage.DeleteTag(tag);
23822
return FreeImage.GetMetadata(_model, dib, _key, out tag);
23826
/// Gets a .NET PropertyItem for this metadata tag.
23828
/// <returns>The .NET PropertyItem.</returns>
23829
public unsafe System.Drawing.Imaging.PropertyItem GetPropertyItem()
23831
System.Drawing.Imaging.PropertyItem item = FreeImage.CreatePropertyItem();
23833
item.Len = (int)Length;
23834
item.Type = (short)Type;
23835
FreeImage.CopyMemory(item.Value = new byte[item.Len], FreeImage.GetTagValue(tag), item.Len);
23840
/// Converts the value of the <see cref="MetadataTag"/> object
23841
/// to its equivalent string representation.
23843
/// <returns>The string representation of the value of this instance.</returns>
23844
public override string ToString()
23847
string fiString = FreeImage.TagToString(model, tag, 0);
23849
if (String.IsNullOrEmpty(fiString))
23851
return tag.ToString();
23860
/// Creates a deep copy of this <see cref="MetadataTag"/>.
23862
/// <returns>A deep copy of this <see cref="MetadataTag"/>.</returns>
23863
public object Clone()
23866
MetadataTag clone = new MetadataTag();
23867
clone.model = model;
23868
clone.tag = FreeImage.CloneTag(tag);
23869
clone.selfCreated = true;
23874
/// Tests whether the specified object is a <see cref="MetadataTag"/> instance
23875
/// and is equivalent to this <see cref="MetadataTag"/> instance.
23877
/// <param name="obj">The object to test.</param>
23878
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="MetadataTag"/> instance
23879
/// equivalent to this <see cref="MetadataTag"/> instance; otherwise, <b>false</b>.</returns>
23880
public override bool Equals(object obj)
23882
return ((obj is MetadataTag) && (Equals((MetadataTag)obj)));
23886
/// Tests whether the specified <see cref="MetadataTag"/> instance is equivalent to this <see cref="MetadataTag"/> instance.
23888
/// <param name="other">A <see cref="MetadataTag"/> instance to compare to this instance.</param>
23889
/// <returns><b>true</b> if <paramref name="obj"/> equivalent to this <see cref="MetadataTag"/> instance;
23890
/// otherwise, <b>false</b>.</returns>
23891
public bool Equals(MetadataTag other)
23893
return (this == other);
23897
/// Returns a hash code for this <see cref="MetadataTag"/> structure.
23899
/// <returns>An integer value that specifies the hash code for this <see cref="MetadataTag"/>.</returns>
23900
public override int GetHashCode()
23902
return tag.GetHashCode();
23906
/// Compares this instance with a specified <see cref="Object"/>.
23908
/// <param name="obj">An object to compare with this instance.</param>
23909
/// <returns>A 32-bit signed integer indicating the lexical relationship between the two comparands.</returns>
23910
/// <exception cref="ArgumentException"><paramref name="obj"/> is not a <see cref="MetadataTag"/>.</exception>
23911
public int CompareTo(object obj)
23917
if (!(obj is MetadataTag))
23919
throw new ArgumentException("obj");
23921
return CompareTo((MetadataTag)obj);
23925
/// Compares the current instance with another object of the same type.
23927
/// <param name="other">An object to compare with this instance.</param>
23928
/// <returns>A 32-bit signed integer that indicates the relative order of the objects being compared.</returns>
23929
public int CompareTo(MetadataTag other)
23932
other.CheckDisposed();
23933
return tag.CompareTo(other.tag);
23937
/// Releases all resources used by the instance.
23939
public void Dispose()
23946
FreeImage.DeleteTag(tag);
23953
/// Gets whether this instance has already been disposed.
23955
public bool Disposed
23957
get { return disposed; }
23961
/// Throwns an <see cref="ObjectDisposedException"/> in case
23962
/// this instance has already been disposed.
23964
private void CheckDisposed()
23968
throw new ObjectDisposedException("The object has already been disposed.");
23974
namespace FreeImageAPI
23977
/// Provides methods for working with the standard bitmap palette.
23979
public sealed class Palette : MemoryArray<RGBQUAD>
23981
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
23982
private GCHandle paletteHandle;
23984
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
23985
private RGBQUAD[] array;
23988
/// Initializes a new instance for the given FreeImage bitmap.
23990
/// <param name="dib">Handle to a FreeImage bitmap.</param>
23991
/// <exception cref="ArgumentNullException"><paramref name="dib"/> is null.</exception>
23992
/// <exception cref="ArgumentException"><paramref name="dib"/> is not
23993
/// <see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/><para/>-or-<para/>
23994
/// <paramref name="dib"/> has more than 8bpp.</exception>
23995
public Palette(FIBITMAP dib)
23996
: base(FreeImage.GetPalette(dib), (int)FreeImage.GetColorsUsed(dib))
24000
throw new ArgumentNullException("dib");
24002
if (FreeImage.GetImageType(dib) != FREE_IMAGE_TYPE.FIT_BITMAP)
24004
throw new ArgumentException("dib");
24006
if (FreeImage.GetBPP(dib) > 8u)
24008
throw new ArgumentException("dib");
24013
/// Initializes a new instance for the given FITAG that contains
24016
/// <param name="tag">The tag containing the palette.</param>
24017
/// <exception cref="ArgumentNullException"><paramref name="tag"/> is null.</exception>
24018
/// <exception cref="ArgumentException"><paramref name="tag"/> is not
24019
/// <see cref="FREE_IMAGE_MDTYPE.FIDT_PALETTE"/>.</exception>
24020
public Palette(FITAG tag)
24021
: base(FreeImage.GetTagValue(tag), (int)FreeImage.GetTagCount(tag))
24023
if (FreeImage.GetTagType(tag) != FREE_IMAGE_MDTYPE.FIDT_PALETTE)
24025
throw new ArgumentException("tag");
24030
/// Initializes a new instance for the given MetadataTag that contains
24033
/// <param name="tag">The tag containing the palette.</param>
24034
/// <exception cref="ArgumentNullException"><paramref name="dib"/> is null.</exception>
24035
/// <exception cref="ArgumentException"><paramref name="tag"/> is not
24036
/// <see cref="FREE_IMAGE_MDTYPE.FIDT_PALETTE"/>.</exception>
24037
public Palette(MetadataTag tag)
24038
: base(FreeImage.GetTagValue(tag.tag), (int)tag.Count)
24040
if (FreeImage.GetTagType(tag) != FREE_IMAGE_MDTYPE.FIDT_PALETTE)
24042
throw new ArgumentException("tag");
24047
/// Initializes a new instance for the given array of <see cref="RGBQUAD"/> that contains
24050
/// <param name="palette">A RGBQUAD array containing the palette data to initialize this instance.</param>
24051
public Palette(RGBQUAD[] palette)
24055
this.array = (RGBQUAD[])palette.Clone();
24056
this.paletteHandle = GCHandle.Alloc(array, GCHandleType.Pinned);
24058
base.baseAddress = (byte*)this.paletteHandle.AddrOfPinnedObject();
24059
base.length = (int)this.array.Length;
24061
// Create an array containing a single element.
24062
// Due to the fact, that it's not possible to create pointers
24063
// of generic types, an array is used to obtain the memory
24064
// address of an element of T.
24065
base.buffer = new RGBQUAD[1];
24066
// The array is pinned immediately to prevent the GC from
24067
// moving it to a different position in memory.
24068
base.handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
24069
// The array and its content have beed pinned, so that its address
24070
// can be safely requested and stored for the whole lifetime
24072
base.ptr = (byte*)base.handle.AddrOfPinnedObject();
24077
/// Initializes a new instance for the given array of <see cref="Color"/> that contains
24080
/// <param name="palette">A Color array containing the palette data to initialize this instance.</param>
24081
public Palette(Color[] palette)
24082
: this(RGBQUAD.ToRGBQUAD(palette))
24087
/// Initializes a new instance with the specified size.
24089
/// <param name="size">The size of the palette.</param>
24090
public Palette(int size)
24091
: this(new RGBQUAD[size])
24096
/// Gets or sets the palette through an array of <see cref="RGBQUAD"/>.
24098
public RGBQUAD[] AsArray
24111
/// Get an array of <see cref="System.Drawing.Color"/> that the block of memory represents.
24112
/// This property is used for internal palette operations.
24114
internal unsafe Color[] ColorData
24118
EnsureNotDisposed();
24119
Color[] data = new Color[length];
24120
for (int i = 0; i < length; i++)
24122
data[i] = Color.FromArgb((int)(((uint*)baseAddress)[i] | 0xFF000000));
24129
/// Returns the palette as an array of <see cref="RGBQUAD"/>.
24131
/// <returns>The palette as an array of <see cref="RGBQUAD"/>.</returns>
24132
public RGBQUAD[] ToArray()
24138
/// Creates a linear palette based on the provided <paramref name="color"/>.
24140
/// <param name="color">The <see cref="System.Drawing.Color"/> used to colorize the palette.</param>
24142
/// Only call this method on linear palettes.
24144
public void Colorize(Color color)
24146
Colorize(color, 0.5d);
24150
/// Creates a linear palette based on the provided <paramref name="color"/>.
24152
/// <param name="color">The <see cref="System.Drawing.Color"/> used to colorize the palette.</param>
24153
/// <param name="splitSize">The position of the color within the new palette.
24154
/// 0 < <paramref name="splitSize"/> < 1.</param>
24156
/// Only call this method on linear palettes.
24158
public void Colorize(Color color, double splitSize)
24160
Colorize(color, (int)(length * splitSize));
24164
/// Creates a linear palette based on the provided <paramref name="color"/>.
24166
/// <param name="color">The <see cref="System.Drawing.Color"/> used to colorize the palette.</param>
24167
/// <param name="splitSize">The position of the color within the new palette.
24168
/// 0 < <paramref name="splitSize"/> < <see cref="MemoryArray<T>.Length"/>.</param>
24170
/// Only call this method on linear palettes.
24172
public void Colorize(Color color, int splitSize)
24174
EnsureNotDisposed();
24175
if (splitSize < 1 || splitSize >= length)
24177
throw new ArgumentOutOfRangeException("splitSize");
24180
RGBQUAD[] pal = new RGBQUAD[length];
24182
double red = color.R;
24183
double green = color.G;
24184
double blue = color.B;
24189
r = red / splitSize;
24190
g = green / splitSize;
24191
b = blue / splitSize;
24193
for (; i <= splitSize; i++)
24195
pal[i].rgbRed = (byte)(i * r);
24196
pal[i].rgbGreen = (byte)(i * g);
24197
pal[i].rgbBlue = (byte)(i * b);
24200
r = (255 - red) / (length - splitSize);
24201
g = (255 - green) / (length - splitSize);
24202
b = (255 - blue) / (length - splitSize);
24204
for (; i < length; i++)
24206
pal[i].rgbRed = (byte)(red + ((i - splitSize) * r));
24207
pal[i].rgbGreen = (byte)(green + ((i - splitSize) * g));
24208
pal[i].rgbBlue = (byte)(blue + ((i - splitSize) * b));
24215
/// Creates a linear grayscale palette.
24217
public void CreateGrayscalePalette()
24219
Colorize(Color.White, length - 1);
24223
/// Creates a linear grayscale palette.
24225
/// <param name="inverse"><b>true</b> to create an inverse grayscale palette.</param>
24226
public void CreateGrayscalePalette(bool inverse)
24228
Colorize(Color.White, inverse ? 0 : length - 1);
24232
/// Creates a linear palette with the specified <see cref="Color"/>.
24235
/// A linear grayscale palette contains all shades of colors from
24236
/// black to white. This method creates a similar palette with the white
24237
/// color being replaced by the specified color.
24239
/// <param name="color">The <see cref="Color"/> used to create the palette.</param>
24240
/// <param name="inverse"><b>true</b> to create an inverse palette.</param>
24241
public void CreateGrayscalePalette(Color color, bool inverse)
24243
Colorize(color, inverse ? 0 : length - 1);
24247
/// Reverses the palette.
24249
public void Reverse()
24251
EnsureNotDisposed();
24254
Array.Reverse(array);
24258
RGBQUAD[] localArray = Data;
24259
Array.Reverse(localArray);
24265
/// Copies the values from the specified <see cref="Palette"/> to this instance.
24267
/// <param name="palette">The palette to copy from.</param>
24268
/// <exception cref="ArgumentNullException">
24269
/// <paramref name="palette"/> is a null reference.</exception>
24270
public void CopyFrom(Palette palette)
24272
EnsureNotDisposed();
24273
if (palette == null)
24275
throw new ArgumentNullException("palette");
24277
CopyFrom(palette.Data, 0, 0, Math.Min(palette.Length, this.Length));
24281
/// Copies the values from the specified <see cref="Palette"/> to this instance,
24282
/// starting at the specified <paramref name="offset"/>.
24284
/// <param name="palette">The palette to copy from.</param>
24285
/// <param name="offset">The position in this instance where the values
24286
/// will be copied to.</param>
24287
/// <exception cref="ArgumentNullException">
24288
/// <paramref name="palette"/> is a null reference.</exception>
24289
/// <exception cref="ArgumentOutOfRangeException">
24290
/// <paramref name="offset"/> is outside the range of valid indexes.</exception>
24291
public void CopyFrom(Palette palette, int offset)
24293
EnsureNotDisposed();
24294
CopyFrom(palette.Data, 0, offset, Math.Min(palette.Length, this.Length - offset));
24298
/// Saves this <see cref="Palette"/> to the specified file.
24300
/// <param name="filename">
24301
/// A string that contains the name of the file to which to save this <see cref="Palette"/>.
24303
public void Save(string filename)
24305
using (Stream stream = new FileStream(filename, FileMode.Create, FileAccess.Write))
24312
/// Saves this <see cref="Palette"/> to the specified stream.
24314
/// <param name="stream">
24315
/// The <see cref="Stream"/> where the image will be saved.
24317
public void Save(Stream stream)
24319
Save(new BinaryWriter(stream));
24323
/// Saves this <see cref="Palette"/> using the specified writer.
24325
/// <param name="writer">
24326
/// The <see cref="BinaryWriter"/> used to save the image.
24328
public void Save(BinaryWriter writer)
24330
EnsureNotDisposed();
24331
writer.Write(ToByteArray());
24335
/// Loads a palette from the specified file.
24337
/// <param name="filename">The name of the palette file.</param>
24338
public void Load(string filename)
24340
using (Stream stream = new FileStream(filename, FileMode.Open, FileAccess.Read))
24347
/// Loads a palette from the specified stream.
24349
/// <param name="stream">The stream to load the palette from.</param>
24350
public void Load(Stream stream)
24352
Load(new BinaryReader(stream));
24356
/// Loads a palette from the reader.
24358
/// <param name="reader">The reader to load the palette from.</param>
24359
public void Load(BinaryReader reader)
24361
EnsureNotDisposed();
24364
int size = length * sizeof(RGBQUAD);
24365
byte[] data = reader.ReadBytes(size);
24366
fixed (byte* src = data)
24368
CopyMemory(baseAddress, src, data.Length);
24374
/// Releases allocated handles associated with this instance.
24376
/// <param name="disposing"><b>true</b> to release managed resources.</param>
24377
protected override void Dispose(bool disposing)
24379
if (paletteHandle.IsAllocated)
24380
paletteHandle.Free();
24383
base.Dispose(disposing);
24388
namespace FreeImageAPI.Plugins
24391
/// Class representing all registered <see cref="FreeImageAPI.Plugins.FreeImagePlugin"/> in FreeImage.
24393
public static class PluginRepository
24395
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
24396
private static readonly List<FreeImagePlugin> plugins = null;
24398
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
24399
private static readonly List<FreeImagePlugin> localPlugins = null;
24401
static PluginRepository()
24403
plugins = new List<FreeImagePlugin>(FreeImage.GetFIFCount());
24404
localPlugins = new List<FreeImagePlugin>(0);
24405
for (int i = 0; i < plugins.Capacity; i++)
24407
plugins.Add(new FreeImagePlugin((FREE_IMAGE_FORMAT)i));
24412
/// Adds local plugin to this class.
24414
/// <param name="localPlugin">The registered plugin.</param>
24415
internal static void RegisterLocalPlugin(LocalPlugin localPlugin)
24417
FreeImagePlugin plugin = new FreeImagePlugin(localPlugin.Format);
24418
plugins.Add(plugin);
24419
localPlugins.Add(plugin);
24423
/// Returns an instance of <see cref="FreeImageAPI.Plugins.FreeImagePlugin"/>, representing the given format.
24425
/// <param name="fif">The representing format.</param>
24426
/// <returns>An instance of <see cref="FreeImageAPI.Plugins.FreeImagePlugin"/>.</returns>
24427
public static FreeImagePlugin Plugin(FREE_IMAGE_FORMAT fif)
24429
return Plugin((int)fif);
24433
/// Returns an instance of <see cref="FreeImageAPI.Plugins.FreeImagePlugin"/>,
24434
/// representing the format at the given index.
24436
/// <param name="index">The index of the representing format.</param>
24437
/// <returns>An instance of <see cref="FreeImagePlugin"/>.</returns>
24438
public static FreeImagePlugin Plugin(int index)
24440
return (index >= 0) ? plugins[index] : null;
24444
/// Returns an instance of <see cref="FreeImageAPI.Plugins.FreeImagePlugin"/>.
24445
/// <typeparamref name="expression"/> is searched in:
24446
/// <c>Format</c>, <c>RegExpr</c>,
24447
/// <c>ValidExtension</c> and <c>ValidFilename</c>.
24449
/// <param name="expression">The expression to search for.</param>
24450
/// <returns>An instance of <see cref="FreeImageAPI.Plugins.FreeImagePlugin"/>.</returns>
24451
public static FreeImagePlugin Plugin(string expression)
24453
FreeImagePlugin result = null;
24454
expression = expression.ToLower();
24456
foreach (FreeImagePlugin plugin in plugins)
24458
if (plugin.Format.ToLower().Contains(expression) ||
24459
plugin.RegExpr.ToLower().Contains(expression) ||
24460
plugin.ValidExtension(expression, StringComparison.CurrentCultureIgnoreCase) ||
24461
plugin.ValidFilename(expression, StringComparison.CurrentCultureIgnoreCase))
24472
/// Returns an instance of <see cref="FreeImageAPI.Plugins.FreeImagePlugin"/> for the given format.
24474
/// <param name="format">The format of the Plugin.</param>
24475
/// <returns>An instance of <see cref="FreeImageAPI.Plugins.FreeImagePlugin"/>.</returns>
24476
public static FreeImagePlugin PluginFromFormat(string format)
24478
return Plugin(FreeImage.GetFIFFromFormat(format));
24482
/// Returns an instance of <see cref="FreeImageAPI.Plugins.FreeImagePlugin"/> for the given filename.
24484
/// <param name="filename">The valid filename for the plugin.</param>
24485
/// <returns>An instance of <see cref="FreeImageAPI.Plugins.FreeImagePlugin"/>.</returns>
24486
public static FreeImagePlugin PluginFromFilename(string filename)
24488
return Plugin(FreeImage.GetFIFFromFilename(filename));
24492
/// Returns an instance of <see cref="FreeImageAPI.Plugins.FreeImagePlugin"/> for the given mime.
24494
/// <param name="mime">The valid mime for the plugin.</param>
24495
/// <returns>An instance of <see cref="FreeImageAPI.Plugins.FreeImagePlugin"/>.</returns>
24496
public static FreeImagePlugin PluginFromMime(string mime)
24498
return Plugin(FreeImage.GetFIFFromMime(mime));
24502
/// Gets the number of registered plugins.
24504
public static int FIFCount
24508
return FreeImage.GetFIFCount();
24513
/// Gets a readonly collection of all plugins.
24515
public static ReadOnlyCollection<FreeImagePlugin> PluginList
24519
return plugins.AsReadOnly();
24524
/// Gets a list of plugins that are only able to
24525
/// read but not to write.
24527
public static List<FreeImagePlugin> ReadOnlyPlugins
24531
List<FreeImagePlugin> list = new List<FreeImagePlugin>();
24532
foreach (FreeImagePlugin p in plugins)
24534
if (p.SupportsReading && !p.SupportsWriting)
24544
/// Gets a list of plugins that are only able to
24545
/// write but not to read.
24547
public static List<FreeImagePlugin> WriteOnlyPlugins
24551
List<FreeImagePlugin> list = new List<FreeImagePlugin>();
24552
foreach (FreeImagePlugin p in plugins)
24554
if (!p.SupportsReading && p.SupportsWriting)
24564
/// Gets a list of plugins that are not able to
24567
public static List<FreeImagePlugin> StupidPlugins
24571
List<FreeImagePlugin> list = new List<FreeImagePlugin>();
24572
foreach (FreeImagePlugin p in plugins)
24574
if (!p.SupportsReading && !p.SupportsWriting)
24584
/// Gets a list of plugins that are able to read.
24586
public static List<FreeImagePlugin> ReadablePlugins
24590
List<FreeImagePlugin> list = new List<FreeImagePlugin>();
24591
foreach (FreeImagePlugin p in plugins)
24593
if (p.SupportsReading)
24603
/// Gets a list of plugins that are able to write.
24605
public static List<FreeImagePlugin> WriteablePlugins
24609
List<FreeImagePlugin> list = new List<FreeImagePlugin>();
24610
foreach (FreeImagePlugin p in plugins)
24612
if (p.SupportsWriting)
24622
/// Gets a list of local plugins.
24624
public static ReadOnlyCollection<FreeImagePlugin> LocalPlugins
24628
return localPlugins.AsReadOnly();
24633
/// Gets a list of built-in plugins.
24635
public static List<FreeImagePlugin> BuiltInPlugins
24639
List<FreeImagePlugin> list = new List<FreeImagePlugin>();
24640
foreach (FreeImagePlugin p in plugins)
24642
if (!localPlugins.Contains(p))
24652
/// Windows or OS/2 Bitmap File (*.BMP)
24654
public static FreeImagePlugin BMP { get { return plugins[0]; } }
24657
/// Independent JPEG Group (*.JPG, *.JIF, *.JPEG, *.JPE)
24659
public static FreeImagePlugin ICO { get { return plugins[1]; } }
24662
/// Independent JPEG Group (*.JPG, *.JIF, *.JPEG, *.JPE)
24664
public static FreeImagePlugin JPEG { get { return plugins[2]; } }
24667
/// JPEG Network Graphics (*.JNG)
24669
public static FreeImagePlugin JNG { get { return plugins[3]; } }
24672
/// Commodore 64 Koala format (*.KOA)
24674
public static FreeImagePlugin KOALA { get { return plugins[4]; } }
24677
/// Amiga IFF (*.IFF, *.LBM)
24679
public static FreeImagePlugin LBM { get { return plugins[5]; } }
24682
/// Amiga IFF (*.IFF, *.LBM)
24684
public static FreeImagePlugin IFF { get { return plugins[5]; } }
24687
/// Multiple Network Graphics (*.MNG)
24689
public static FreeImagePlugin MNG { get { return plugins[6]; } }
24692
/// Portable Bitmap (ASCII) (*.PBM)
24694
public static FreeImagePlugin PBM { get { return plugins[7]; } }
24697
/// Portable Bitmap (BINARY) (*.PBM)
24699
public static FreeImagePlugin PBMRAW { get { return plugins[8]; } }
24702
/// Kodak PhotoCD (*.PCD)
24704
public static FreeImagePlugin PCD { get { return plugins[9]; } }
24707
/// Zsoft Paintbrush PCX bitmap format (*.PCX)
24709
public static FreeImagePlugin PCX { get { return plugins[10]; } }
24712
/// Portable Graymap (ASCII) (*.PGM)
24714
public static FreeImagePlugin PGM { get { return plugins[11]; } }
24717
/// Portable Graymap (BINARY) (*.PGM)
24719
public static FreeImagePlugin PGMRAW { get { return plugins[12]; } }
24722
/// Portable Network Graphics (*.PNG)
24724
public static FreeImagePlugin PNG { get { return plugins[13]; } }
24727
/// Portable Pixelmap (ASCII) (*.PPM)
24729
public static FreeImagePlugin PPM { get { return plugins[14]; } }
24732
/// Portable Pixelmap (BINARY) (*.PPM)
24734
public static FreeImagePlugin PPMRAW { get { return plugins[15]; } }
24737
/// Sun Rasterfile (*.RAS)
24739
public static FreeImagePlugin RAS { get { return plugins[16]; } }
24742
/// truevision Targa files (*.TGA, *.TARGA)
24744
public static FreeImagePlugin TARGA { get { return plugins[17]; } }
24747
/// Tagged Image File Format (*.TIF, *.TIFF)
24749
public static FreeImagePlugin TIFF { get { return plugins[18]; } }
24752
/// Wireless Bitmap (*.WBMP)
24754
public static FreeImagePlugin WBMP { get { return plugins[19]; } }
24757
/// Adobe Photoshop (*.PSD)
24759
public static FreeImagePlugin PSD { get { return plugins[20]; } }
24762
/// Dr. Halo (*.CUT)
24764
public static FreeImagePlugin CUT { get { return plugins[21]; } }
24767
/// X11 Bitmap Format (*.XBM)
24769
public static FreeImagePlugin XBM { get { return plugins[22]; } }
24772
/// X11 Pixmap Format (*.XPM)
24774
public static FreeImagePlugin XPM { get { return plugins[23]; } }
24777
/// DirectDraw Surface (*.DDS)
24779
public static FreeImagePlugin DDS { get { return plugins[24]; } }
24782
/// Graphics Interchange Format (*.GIF)
24784
public static FreeImagePlugin GIF { get { return plugins[25]; } }
24787
/// High Dynamic Range (*.HDR)
24789
public static FreeImagePlugin HDR { get { return plugins[26]; } }
24792
/// Raw Fax format CCITT G3 (*.G3)
24794
public static FreeImagePlugin FAXG3 { get { return plugins[27]; } }
24797
/// Silicon Graphics SGI image format (*.SGI)
24799
public static FreeImagePlugin SGI { get { return plugins[28]; } }
24802
/// OpenEXR format (*.EXR)
24804
public static FreeImagePlugin EXR { get { return plugins[29]; } }
24807
/// JPEG-2000 format (*.J2K, *.J2C)
24809
public static FreeImagePlugin J2K { get { return plugins[30]; } }
24812
/// JPEG-2000 format (*.JP2)
24814
public static FreeImagePlugin JP2 { get { return plugins[31]; } }
24817
/// Portable FloatMap (*.PFM)
24819
public static FreeImagePlugin PFM { get { return plugins[32]; } }
24822
/// Macintosh PICT (*.PICT)
24824
public static FreeImagePlugin PICT { get { return plugins[33]; } }
24827
/// RAW camera image (*.*)
24829
public static FreeImagePlugin RAW { get { return plugins[34]; } }
24833
namespace FreeImageAPI
24836
/// Provides methods for working with generic bitmap scanlines.
24838
/// <typeparam name="T">Type of the bitmaps' scanlines.</typeparam>
24839
public sealed class Scanline<T> : MemoryArray<T> where T : struct
24842
/// Initializes a new instance based on the specified FreeImage bitmap.
24844
/// <param name="dib">Handle to a FreeImage bitmap.</param>
24845
public Scanline(FIBITMAP dib)
24851
/// Initializes a new instance based on the specified FreeImage bitmap.
24853
/// <param name="dib">Handle to a FreeImage bitmap.</param>
24854
/// <param name="scanline">Index of the zero based scanline.</param>
24855
public Scanline(FIBITMAP dib, int scanline)
24856
: this(dib, scanline, (int)(typeof(T) == typeof(FI1BIT) ?
24857
FreeImage.GetBPP(dib) * FreeImage.GetWidth(dib) :
24858
typeof(T) == typeof(FI4BIT) ?
24859
FreeImage.GetBPP(dib) * FreeImage.GetWidth(dib) / 4 :
24860
(FreeImage.GetBPP(dib) * FreeImage.GetWidth(dib)) / (Marshal.SizeOf(typeof(T)) * 8)))
24864
internal Scanline(FIBITMAP dib, int scanline, int length)
24865
: base(FreeImage.GetScanLine(dib, scanline), length)
24869
throw new ArgumentNullException("dib");
24871
if ((scanline < 0) || (scanline >= FreeImage.GetHeight(dib)))
24873
throw new ArgumentOutOfRangeException("scanline");
24879
namespace FreeImageAPI.IO
24882
/// Class wrapping streams, implementing a buffer for read data,
24883
/// so that seek operations can be made.
24886
/// FreeImage can load bitmaps from arbitrary sources.
24887
/// .NET works with different streams like File- or NetConnection-strams.
24888
/// NetConnection streams, which are used to load files from web servers,
24889
/// for example cannot seek.
24890
/// But FreeImage frequently uses the seek operation when loading bitmaps.
24891
/// <b>StreamWrapper</b> wrapps a stream and makes it seekable by caching all read
24892
/// data into an internal MemoryStream to jump back- and forward.
24893
/// StreamWapper is for internal use and only for loading from streams.
24895
internal class StreamWrapper : Stream
24898
/// The stream to wrap
24900
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
24901
private readonly Stream stream;
24904
/// The caching stream
24906
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
24907
private MemoryStream memoryStream = new MemoryStream();
24910
/// Indicates if the wrapped stream reached its end
24912
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
24913
private bool eos = false;
24916
/// Tells the wrapper to block readings or not
24918
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
24919
private bool blocking = false;
24922
/// Indicates if the wrapped stream is disposed or not
24924
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
24925
private bool disposed = false;
24928
/// Initializes a new instance based on the specified <see cref="Stream"/>.
24930
/// <param name="stream">The stream to wrap.</param>
24931
/// <param name="blocking">When true the wrapper always tries to read the requested
24932
/// amount of data from the wrapped stream.</param>
24933
public StreamWrapper(Stream stream, bool blocking)
24935
if (!stream.CanRead)
24937
throw new ArgumentException("stream is not capable of reading.");
24939
this.stream = stream;
24940
this.blocking = blocking;
24944
/// Releases all resources used by the instance.
24951
// The wrapper only accepts readable streams
24952
public override bool CanRead
24954
get { checkDisposed(); return true; }
24957
// We implement that feature
24958
public override bool CanSeek
24960
get { checkDisposed(); return true; }
24963
// The wrapper is readonly
24964
public override bool CanWrite
24966
get { checkDisposed(); return false; }
24970
public override void Flush()
24976
// Calling this property will cause the wrapper to read the stream
24977
// to its end and cache it completely.
24978
public override long Length
24987
return memoryStream.Length;
24991
// Gets or sets the current position
24992
public override long Position
24997
return memoryStream.Position;
25002
Seek(value, SeekOrigin.Begin);
25006
// Implements the reading feature
25007
public override int Read(byte[] buffer, int offset, int count)
25010
// total bytes read from memory-stream
25011
int memoryBytes = 0;
25012
// total bytes read from the original stream
25013
int streamBytes = 0;
25014
memoryBytes = memoryStream.Read(buffer, offset, count);
25015
if ((count > memoryBytes) && (!eos))
25017
// read the rest from the original stream (can be 0 bytes)
25020
int read = stream.Read(
25022
offset + memoryBytes + streamBytes,
25023
count - memoryBytes - streamBytes);
25024
streamBytes += read;
25034
} while ((memoryBytes + streamBytes) < count);
25035
// copy the bytes from the original stream into the memory stream
25036
// if 0 bytes were read we write 0 so the memory-stream is not changed
25037
memoryStream.Write(buffer, offset + memoryBytes, streamBytes);
25039
return memoryBytes + streamBytes;
25042
// Implements the seeking feature
25043
public override long Seek(long offset, SeekOrigin origin)
25046
long newPosition = 0L;
25047
// get new position
25050
case SeekOrigin.Begin:
25051
newPosition = offset;
25053
case SeekOrigin.Current:
25054
newPosition = memoryStream.Position + offset;
25056
case SeekOrigin.End:
25057
// to seek from the end have have to read to the end first
25062
newPosition = memoryStream.Length + offset;
25065
throw new ArgumentOutOfRangeException("origin");
25067
// in case the new position is beyond the memory-streams end
25068
// and the original streams end hasn't been reached
25069
// the original stream is read until either the stream ends or
25070
// enough bytes have been read
25071
if ((newPosition > memoryStream.Length) && (!eos))
25073
memoryStream.Position = memoryStream.Length;
25074
int bytesToRead = (int)(newPosition - memoryStream.Length);
25075
byte[] buffer = new byte[1024];
25078
bytesToRead -= Read(buffer, 0, (bytesToRead >= buffer.Length) ? buffer.Length : bytesToRead);
25079
} while ((bytesToRead > 0) && (!eos));
25081
memoryStream.Position = (newPosition <= memoryStream.Length) ? newPosition : memoryStream.Length;
25085
// No write-support
25086
public override void SetLength(long value)
25088
throw new Exception("The method or operation is not implemented.");
25091
// No write-support
25092
public override void Write(byte[] buffer, int offset, int count)
25094
throw new Exception("The method or operation is not implemented.");
25097
public void Reset()
25103
// Reads the wrapped stream until its end.
25104
private void Fill()
25108
memoryStream.Position = memoryStream.Length;
25110
byte[] buffer = new byte[1024];
25113
bytesRead = stream.Read(buffer, 0, buffer.Length);
25114
memoryStream.Write(buffer, 0, bytesRead);
25115
} while (bytesRead != 0);
25120
public new void Dispose()
25123
GC.SuppressFinalize(this);
25126
private new void Dispose(bool disposing)
25133
if (memoryStream != null)
25135
memoryStream.Dispose();
25141
public bool Disposed
25143
get { return disposed; }
25146
private void checkDisposed()
25148
if (disposed) throw new ObjectDisposedException("StreamWrapper");
25157
namespace FreeImageAPI
25160
/// Enumeration used for color conversions.
25161
/// FREE_IMAGE_COLOR_DEPTH contains several colors to convert to.
25162
/// The default value 'FICD_AUTO'.
25165
public enum FREE_IMAGE_COLOR_DEPTH
25172
/// Auto selected by the used algorithm.
25174
FICD_AUTO = FICD_UNKNOWN,
25180
/// 1-bit using dithering.
25182
FICD_01_BPP_DITHER = FICD_01_BPP,
25184
/// 1-bit using threshold.
25186
FICD_01_BPP_THRESHOLD = FICD_01_BPP | 2,
25196
/// 16-bit 555 (1 bit remains unused).
25198
FICD_16_BPP_555 = FICD_16_BPP | 2,
25200
/// 16-bit 565 (all bits are used).
25212
/// Reorder palette (make it linear). Only affects 1-, 4- and 8-bit images.
25213
/// <para>The palette is only reordered in case the image is greyscale
25214
/// (all palette entries have the same red, green and blue value).</para>
25216
FICD_REORDER_PALETTE = 1024,
25218
/// Converts the image to greyscale.
25220
FICD_FORCE_GREYSCALE = 2048,
25222
/// Flag to mask out all non color depth flags.
25224
FICD_COLOR_MASK = FICD_01_BPP | FICD_04_BPP | FICD_08_BPP | FICD_16_BPP | FICD_24_BPP | FICD_32_BPP
25228
namespace FreeImageAPI
25231
/// List of combinable compare modes.
25234
public enum FREE_IMAGE_COMPARE_FLAGS
25237
/// Compare headers.
25241
/// Compare palettes.
25245
/// Compare pixel data.
25249
/// Compare meta data.
25253
/// Compare everything.
25255
COMPLETE = (HEADER | PALETTE | DATA | METADATA)
25259
namespace FreeImageAPI
25262
/// Flags for copying data from a bitmap to another.
25264
public enum FREE_IMAGE_METADATA_COPY
25267
/// Exisiting metadata will remain unchanged.
25269
KEEP_EXISITNG = 0x0,
25271
/// Existing metadata will be cleared.
25273
CLEAR_EXISTING = 0x1,
25275
/// Existing metadata will be overwritten.
25277
REPLACE_EXISTING = 0x2
25281
namespace FreeImageAPI
25284
/// List different search modes.
25287
public enum MD_SEARCH_FLAGS
25290
/// The key of the metadata.
25294
/// The description of the metadata
25298
/// The ToString value of the metadata
25306
namespace FreeImageAPI
25309
/// Static class importing functions from the FreeImage library
25310
/// and providing additional functions.
25312
public static partial class FreeImage
25317
/// Array containing all 'FREE_IMAGE_MDMODEL's.
25319
public static readonly FREE_IMAGE_MDMODEL[] FREE_IMAGE_MDMODELS =
25320
(FREE_IMAGE_MDMODEL[])Enum.GetValues(typeof(FREE_IMAGE_MDMODEL));
25323
/// Stores handles used to read from streams.
25325
private static Dictionary<FIMULTIBITMAP, fi_handle> streamHandles =
25326
new Dictionary<FIMULTIBITMAP, fi_handle>();
25329
/// Version of the wrapper library.
25331
private static Version WrapperVersion;
25333
private const int DIB_RGB_COLORS = 0;
25334
private const int DIB_PAL_COLORS = 1;
25335
private const int CBM_INIT = 0x4;
25338
/// An uncompressed format.
25340
public const int BI_RGB = 0;
25343
/// A run-length encoded (RLE) format for bitmaps with 8 bpp. The compression format is a 2-byte
25344
/// format consisting of a count byte followed by a byte containing a color index.
25346
public const int BI_RLE8 = 1;
25349
/// An RLE format for bitmaps with 4 bpp. The compression format is a 2-byte format consisting
25350
/// of a count byte followed by two word-length color indexes.
25352
public const int BI_RLE4 = 2;
25355
/// Specifies that the bitmap is not compressed and that the color table consists of three
25356
/// <b>DWORD</b> color masks that specify the red, green, and blue components, respectively,
25357
/// of each pixel. This is valid when used with 16- and 32-bpp bitmaps.
25359
public const int BI_BITFIELDS = 3;
25362
/// <b>Windows 98/Me, Windows 2000/XP:</b> Indicates that the image is a JPEG image.
25364
public const int BI_JPEG = 4;
25367
/// <b>Windows 98/Me, Windows 2000/XP:</b> Indicates that the image is a PNG image.
25369
public const int BI_PNG = 5;
25373
#region General functions
25376
/// Returns the internal version of this FreeImage .NET wrapper.
25378
/// <returns>The internal version of this FreeImage .NET wrapper.</returns>
25379
public static Version GetWrapperVersion()
25381
if (WrapperVersion == null)
25385
object[] attributes = Assembly.GetAssembly(typeof(FreeImage))
25386
.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false);
25387
if ((attributes != null) && (attributes.Length != 0))
25389
AssemblyFileVersionAttribute attribute =
25390
attributes[0] as AssemblyFileVersionAttribute;
25391
if ((attribute != null) && (attribute.Version != null))
25393
return (WrapperVersion = new Version(attribute.Version));
25402
WrapperVersion = new Version();
25405
return WrapperVersion;
25409
/// Returns the version of the native FreeImage library.
25411
/// <returns>The version of the native FreeImage library.</returns>
25412
public static Version GetNativeVersion()
25414
return new Version(GetVersion());
25418
/// Returns a value indicating if the FreeImage library is available or not.
25419
/// See remarks for further details.
25421
/// <returns><c>false</c> if the file is not available or out of date;
25422
/// <c>true</c>, otherwise.</returns>
25424
/// The FreeImage.NET library is a wrapper for the native C++ library
25425
/// (FreeImage.dll ... dont mix ist up with this library FreeImageNet.dll).
25426
/// The native library <b>must</b> be either in the same folder as the program's
25427
/// executable or in a folder contained in the envirent variable <i>PATH</i>
25428
/// (for example %WINDIR%\System32).<para/>
25429
/// Further more must both libraries, including the program itself,
25430
/// be the same architecture (x86 or x64).
25432
public static bool IsAvailable()
25436
// Call a static fast executing function
25437
Version nativeVersion = new Version(GetVersion());
25438
Version wrapperVersion = GetWrapperVersion();
25439
// No exception thrown, the library seems to be present
25441
(nativeVersion.Major >= wrapperVersion.Major) &&
25442
(nativeVersion.Minor >= wrapperVersion.Minor) &&
25443
(nativeVersion.Build >= wrapperVersion.Build);
25445
catch (DllNotFoundException)
25449
catch (EntryPointNotFoundException)
25453
catch (BadImageFormatException)
25461
#region Bitmap management functions
25464
/// Creates a new bitmap in memory.
25466
/// <param name="width">Width of the new bitmap.</param>
25467
/// <param name="height">Height of the new bitmap.</param>
25468
/// <param name="bpp">Bit depth of the new Bitmap.
25469
/// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap</param>
25470
/// <returns>Handle to a FreeImage bitmap.</returns>
25471
public static FIBITMAP Allocate(int width, int height, int bpp)
25473
return Allocate(width, height, bpp, 0, 0, 0);
25477
/// Creates a new bitmap in memory.
25479
/// <param name="type">Type of the image.</param>
25480
/// <param name="width">Width of the new bitmap.</param>
25481
/// <param name="height">Height of the new bitmap.</param>
25482
/// <param name="bpp">Bit depth of the new Bitmap.
25483
/// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap</param>
25484
/// <returns>Handle to a FreeImage bitmap.</returns>
25485
public static FIBITMAP AllocateT(FREE_IMAGE_TYPE type, int width, int height, int bpp)
25487
return AllocateT(type, width, height, bpp, 0, 0, 0);
25491
/// Allocates a new image of the specified width, height and bit depth and optionally
25492
/// fills it with the specified color. See remarks for further details.
25494
/// <param name="width">Width of the new bitmap.</param>
25495
/// <param name="height">Height of the new bitmap.</param>
25496
/// <param name="bpp">Bit depth of the new bitmap.
25497
/// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmaps.</param>
25498
/// <param name="color">The color to fill the bitmap with or <c>null</c>.</param>
25499
/// <param name="options">Options to enable or disable function-features.</param>
25500
/// <param name="palette">The palette of the bitmap or <c>null</c>.</param>
25501
/// <returns>Handle to a FreeImage bitmap.</returns>
25503
/// This function is an extension to <see cref="Allocate"/>, which additionally supports
25504
/// specifying a palette to be set for the newly create image, as well as specifying a
25505
/// background color, the newly created image should initially be filled with.
25507
/// Basically, this function internally relies on function <see cref="Allocate"/>, followed by a
25508
/// call to <see cref="FillBackground<T>"/>. This is why both parameters
25509
/// <paramref name="color"/> and <paramref name="options"/> behave the same as it is
25510
/// documented for function <see cref="FillBackground<T>"/>.
25511
/// So, please refer to the documentation of <see cref="FillBackground<T>"/> to
25512
/// learn more about parameters <paramref name="color"/> and <paramref name="options"/>.
25514
/// The palette specified through parameter <paramref name="palette"/> is only copied to the
25515
/// newly created image, if the desired bit depth is smaller than or equal to 8 bits per pixel.
25516
/// In other words, the <paramref name="palette"/> parameter is only taken into account for
25517
/// palletized images. So, for an 8-bit image, the length is 256, for an 4-bit image it is 16
25518
/// and it is 2 for a 1-bit image. In other words, this function does not support partial palettes.
25520
/// However, specifying a palette is not necesarily needed, even for palletized images. This
25521
/// function is capable of implicitly creating a palette, if <paramref name="palette"/> is <c>null</c>.
25522
/// If the specified background color is a greyscale value (red = green = blue) or if option
25523
/// <see cref="FREE_IMAGE_COLOR_OPTIONS.FICO_ALPHA_IS_INDEX"/> is specified, a greyscale palette
25524
/// is created. For a 1-bit image, only if the specified background color is either black or white,
25525
/// a monochrome palette, consisting of black and white only is created. In any case, the darker
25526
/// colors are stored at the smaller palette indices.
25528
/// If the specified background color is not a greyscale value, or is neither black nor white
25529
/// for a 1-bit image, solely this specified color is injected into the otherwise black-initialized
25530
/// palette. For this operation, option <see cref="FREE_IMAGE_COLOR_OPTIONS.FICO_ALPHA_IS_INDEX"/>
25531
/// is implicit, so the specified <paramref name="color"/> is applied to the palette entry,
25532
/// specified by the background color's <see cref="RGBQUAD.rgbReserved"/> field.
25533
/// The image is then filled with this palette index.
25535
/// This function returns a newly created image as function <see cref="Allocate"/> does, if both
25536
/// parameters <paramref name="color"/> and <paramref name="palette"/> are <c>null</c>.
25537
/// If only <paramref name="color"/> is <c>null</c>, the palette pointed to by
25538
/// parameter <paramref name="palette"/> is initially set for the new image, if a palletized
25539
/// image of type <see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/> is created.
25540
/// However, in the latter case, this function returns an image, whose
25541
/// pixels are all initialized with zeros so, the image will be filled with the color of the
25542
/// first palette entry.
25544
public static FIBITMAP AllocateEx(int width, int height, int bpp,
25545
RGBQUAD? color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette)
25547
return AllocateEx(width, height, bpp, color, options, palette, 0, 0, 0);
25551
/// Allocates a new image of the specified width, height and bit depth and optionally
25552
/// fills it with the specified color. See remarks for further details.
25554
/// <param name="width">Width of the new bitmap.</param>
25555
/// <param name="height">Height of the new bitmap.</param>
25556
/// <param name="bpp">Bit depth of the new bitmap.
25557
/// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmaps.</param>
25558
/// <param name="color">The color to fill the bitmap with or <c>null</c>.</param>
25559
/// <param name="options">Options to enable or disable function-features.</param>
25560
/// <param name="palette">The palette of the bitmap or <c>null</c>.</param>
25561
/// <param name="red_mask">Red part of the color layout.
25562
/// eg: 0xFF0000</param>
25563
/// <param name="green_mask">Green part of the color layout.
25564
/// eg: 0x00FF00</param>
25565
/// <param name="blue_mask">Blue part of the color layout.
25566
/// eg: 0x0000FF</param>
25567
/// <returns>Handle to a FreeImage bitmap.</returns>
25569
/// This function is an extension to <see cref="Allocate"/>, which additionally supports
25570
/// specifying a palette to be set for the newly create image, as well as specifying a
25571
/// background color, the newly created image should initially be filled with.
25573
/// Basically, this function internally relies on function <see cref="Allocate"/>, followed by a
25574
/// call to <see cref="FillBackground<T>"/>. This is why both parameters
25575
/// <paramref name="color"/> and <paramref name="options"/> behave the same as it is
25576
/// documented for function <see cref="FillBackground<T>"/>.
25577
/// So, please refer to the documentation of <see cref="FillBackground<T>"/> to
25578
/// learn more about parameters <paramref name="color"/> and <paramref name="options"/>.
25580
/// The palette specified through parameter <paramref name="palette"/> is only copied to the
25581
/// newly created image, if the desired bit depth is smaller than or equal to 8 bits per pixel.
25582
/// In other words, the <paramref name="palette"/> parameter is only taken into account for
25583
/// palletized images. So, for an 8-bit image, the length is 256, for an 4-bit image it is 16
25584
/// and it is 2 for a 1-bit image. In other words, this function does not support partial palettes.
25586
/// However, specifying a palette is not necesarily needed, even for palletized images. This
25587
/// function is capable of implicitly creating a palette, if <paramref name="palette"/> is <c>null</c>.
25588
/// If the specified background color is a greyscale value (red = green = blue) or if option
25589
/// <see cref="FREE_IMAGE_COLOR_OPTIONS.FICO_ALPHA_IS_INDEX"/> is specified, a greyscale palette
25590
/// is created. For a 1-bit image, only if the specified background color is either black or white,
25591
/// a monochrome palette, consisting of black and white only is created. In any case, the darker
25592
/// colors are stored at the smaller palette indices.
25594
/// If the specified background color is not a greyscale value, or is neither black nor white
25595
/// for a 1-bit image, solely this specified color is injected into the otherwise black-initialized
25596
/// palette. For this operation, option <see cref="FREE_IMAGE_COLOR_OPTIONS.FICO_ALPHA_IS_INDEX"/>
25597
/// is implicit, so the specified <paramref name="color"/> is applied to the palette entry,
25598
/// specified by the background color's <see cref="RGBQUAD.rgbReserved"/> field.
25599
/// The image is then filled with this palette index.
25601
/// This function returns a newly created image as function <see cref="Allocate"/> does, if both
25602
/// parameters <paramref name="color"/> and <paramref name="palette"/> are <c>null</c>.
25603
/// If only <paramref name="color"/> is <c>null</c>, the palette pointed to by
25604
/// parameter <paramref name="palette"/> is initially set for the new image, if a palletized
25605
/// image of type <see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/> is created.
25606
/// However, in the latter case, this function returns an image, whose
25607
/// pixels are all initialized with zeros so, the image will be filled with the color of the
25608
/// first palette entry.
25610
public static FIBITMAP AllocateEx(int width, int height, int bpp,
25611
RGBQUAD? color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette,
25612
uint red_mask, uint green_mask, uint blue_mask)
25614
if ((palette != null) && (bpp <= 8) && (palette.Length < (1 << bpp)))
25615
return FIBITMAP.Zero;
25617
if (color.HasValue)
25619
GCHandle handle = new GCHandle();
25622
RGBQUAD[] buffer = new RGBQUAD[] { color.Value };
25623
handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
25624
return AllocateEx(width, height, bpp, handle.AddrOfPinnedObject(),
25625
options, palette, red_mask, green_mask, blue_mask);
25629
if (handle.IsAllocated)
25635
return AllocateEx(width, height, bpp, IntPtr.Zero,
25636
options, palette, red_mask, green_mask, blue_mask);
25641
/// Allocates a new image of the specified type, width, height and bit depth and optionally
25642
/// fills it with the specified color. See remarks for further details.
25644
/// <typeparam name="T">The type of the specified color.</typeparam>
25645
/// <param name="type">Type of the image.</param>
25646
/// <param name="width">Width of the new bitmap.</param>
25647
/// <param name="height">Height of the new bitmap.</param>
25648
/// <param name="bpp">Bit depth of the new bitmap.
25649
/// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap</param>
25650
/// <param name="color">The color to fill the bitmap with or <c>null</c>.</param>
25651
/// <param name="options">Options to enable or disable function-features.</param>
25652
/// <param name="palette">The palette of the bitmap or <c>null</c>.</param>
25653
/// <returns>Handle to a FreeImage bitmap.</returns>
25655
/// This function is an extension to <see cref="AllocateT"/>, which additionally supports
25656
/// specifying a palette to be set for the newly create image, as well as specifying a
25657
/// background color, the newly created image should initially be filled with.
25659
/// Basically, this function internally relies on function <see cref="AllocateT"/>, followed by a
25660
/// call to <see cref="FillBackground<T>"/>. This is why both parameters
25661
/// <paramref name="color"/> and <paramref name="options"/> behave the same as it is
25662
/// documented for function <see cref="FillBackground<T>"/>. So, please refer to the
25663
/// documentation of <see cref="FillBackground<T>"/> to learn more about parameters color and options.
25665
/// The palette specified through parameter palette is only copied to the newly created
25666
/// image, if its image type is <see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/> and the desired bit
25667
/// depth is smaller than or equal to 8 bits per pixel. In other words, the <paramref name="palette"/>
25668
/// palette is only taken into account for palletized images. However, if the preceding conditions
25669
/// match and if <paramref name="palette"/> is not <c>null</c>, the palette is assumed to be at
25670
/// least as large as the size of a fully populated palette for the desired bit depth.
25671
/// So, for an 8-bit image, this length is 256, for an 4-bit image it is 16 and it is
25672
/// 2 for a 1-bit image. In other words, this function does not support partial palettes.
25674
/// However, specifying a palette is not necesarily needed, even for palletized images. This
25675
/// function is capable of implicitly creating a palette, if <paramref name="palette"/> is <c>null</c>.
25676
/// If the specified background color is a greyscale value (red = green = blue) or if option
25677
/// <see cref="FREE_IMAGE_COLOR_OPTIONS.FICO_ALPHA_IS_INDEX"/> is specified, a greyscale palette
25678
/// is created. For a 1-bit image, only if the specified background color is either black or white,
25679
/// a monochrome palette, consisting of black and white only is created. In any case, the darker
25680
/// colors are stored at the smaller palette indices.
25682
/// If the specified background color is not a greyscale value, or is neither black nor white
25683
/// for a 1-bit image, solely this specified color is injected into the otherwise black-initialized
25684
/// palette. For this operation, option <see cref="FREE_IMAGE_COLOR_OPTIONS.FICO_ALPHA_IS_INDEX"/>
25685
/// is implicit, so the specified color is applied to the palette entry, specified by the
25686
/// background color's <see cref="RGBQUAD.rgbReserved"/> field. The image is then filled with
25687
/// this palette index.
25689
/// This function returns a newly created image as function <see cref="AllocateT"/> does, if both
25690
/// parameters <paramref name="color"/> and <paramref name="palette"/> are <c>null</c>.
25691
/// If only <paramref name="color"/> is <c>null</c>, the palette pointed to by
25692
/// parameter <paramref name="palette"/> is initially set for the new image, if a palletized
25693
/// image of type <see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/> is created.
25694
/// However, in the latter case, this function returns an image, whose
25695
/// pixels are all initialized with zeros so, the image will be filled with the color of the
25696
/// first palette entry.
25698
public static FIBITMAP AllocateExT<T>(FREE_IMAGE_TYPE type, int width, int height, int bpp,
25699
T? color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette) where T : struct
25701
return AllocateExT(type, width, height, bpp, color, options, palette, 0, 0, 0);
25705
/// Allocates a new image of the specified type, width, height and bit depth and optionally
25706
/// fills it with the specified color. See remarks for further details.
25708
/// <typeparam name="T">The type of the specified color.</typeparam>
25709
/// <param name="type">Type of the image.</param>
25710
/// <param name="width">Width of the new bitmap.</param>
25711
/// <param name="height">Height of the new bitmap.</param>
25712
/// <param name="bpp">Bit depth of the new bitmap.
25713
/// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap</param>
25714
/// <param name="color">The color to fill the bitmap with or <c>null</c>.</param>
25715
/// <param name="options">Options to enable or disable function-features.</param>
25716
/// <param name="palette">The palette of the bitmap or <c>null</c>.</param>
25717
/// <param name="red_mask">Red part of the color layout.
25718
/// eg: 0xFF0000</param>
25719
/// <param name="green_mask">Green part of the color layout.
25720
/// eg: 0x00FF00</param>
25721
/// <param name="blue_mask">Blue part of the color layout.
25722
/// eg: 0x0000FF</param>
25723
/// <returns>Handle to a FreeImage bitmap.</returns>
25725
/// This function is an extension to <see cref="AllocateT"/>, which additionally supports
25726
/// specifying a palette to be set for the newly create image, as well as specifying a
25727
/// background color, the newly created image should initially be filled with.
25729
/// Basically, this function internally relies on function <see cref="AllocateT"/>, followed by a
25730
/// call to <see cref="FillBackground<T>"/>. This is why both parameters
25731
/// <paramref name="color"/> and <paramref name="options"/> behave the same as it is
25732
/// documented for function <see cref="FillBackground<T>"/>. So, please refer to the
25733
/// documentation of <see cref="FillBackground<T>"/> to learn more about parameters color and options.
25735
/// The palette specified through parameter palette is only copied to the newly created
25736
/// image, if its image type is <see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/> and the desired bit
25737
/// depth is smaller than or equal to 8 bits per pixel. In other words, the <paramref name="palette"/>
25738
/// palette is only taken into account for palletized images. However, if the preceding conditions
25739
/// match and if <paramref name="palette"/> is not <c>null</c>, the palette is assumed to be at
25740
/// least as large as the size of a fully populated palette for the desired bit depth.
25741
/// So, for an 8-bit image, this length is 256, for an 4-bit image it is 16 and it is
25742
/// 2 for a 1-bit image. In other words, this function does not support partial palettes.
25744
/// However, specifying a palette is not necesarily needed, even for palletized images. This
25745
/// function is capable of implicitly creating a palette, if <paramref name="palette"/> is <c>null</c>.
25746
/// If the specified background color is a greyscale value (red = green = blue) or if option
25747
/// <see cref="FREE_IMAGE_COLOR_OPTIONS.FICO_ALPHA_IS_INDEX"/> is specified, a greyscale palette
25748
/// is created. For a 1-bit image, only if the specified background color is either black or white,
25749
/// a monochrome palette, consisting of black and white only is created. In any case, the darker
25750
/// colors are stored at the smaller palette indices.
25752
/// If the specified background color is not a greyscale value, or is neither black nor white
25753
/// for a 1-bit image, solely this specified color is injected into the otherwise black-initialized
25754
/// palette. For this operation, option <see cref="FREE_IMAGE_COLOR_OPTIONS.FICO_ALPHA_IS_INDEX"/>
25755
/// is implicit, so the specified color is applied to the palette entry, specified by the
25756
/// background color's <see cref="RGBQUAD.rgbReserved"/> field. The image is then filled with
25757
/// this palette index.
25759
/// This function returns a newly created image as function <see cref="AllocateT"/> does, if both
25760
/// parameters <paramref name="color"/> and <paramref name="palette"/> are <c>null</c>.
25761
/// If only <paramref name="color"/> is <c>null</c>, the palette pointed to by
25762
/// parameter <paramref name="palette"/> is initially set for the new image, if a palletized
25763
/// image of type <see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/> is created.
25764
/// However, in the latter case, this function returns an image, whose
25765
/// pixels are all initialized with zeros so, the image will be filled with the color of the
25766
/// first palette entry.
25768
public static FIBITMAP AllocateExT<T>(FREE_IMAGE_TYPE type, int width, int height, int bpp,
25769
T? color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette,
25770
uint red_mask, uint green_mask, uint blue_mask) where T : struct
25772
if ((palette != null) && (bpp <= 8) && (palette.Length < (1 << bpp)))
25773
return FIBITMAP.Zero;
25775
if (!CheckColorType(type, color))
25776
return FIBITMAP.Zero;
25778
if (color.HasValue)
25780
GCHandle handle = new GCHandle();
25783
T[] buffer = new T[] { color.Value };
25784
handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
25785
return AllocateExT(type, width, height, bpp, handle.AddrOfPinnedObject(),
25786
options, palette, red_mask, green_mask, blue_mask);
25790
if (handle.IsAllocated)
25796
return AllocateExT(type, width, height, bpp, IntPtr.Zero,
25797
options, palette, red_mask, green_mask, blue_mask);
25802
/// Converts a FreeImage bitmap to a .NET <see cref="System.Drawing.Bitmap"/>.
25804
/// <param name="dib">Handle to a FreeImage bitmap.</param>
25805
/// <returns>The converted .NET <see cref="System.Drawing.Bitmap"/>.</returns>
25806
/// <remarks>Copying metadata has been disabled until a proper way
25807
/// of reading and storing metadata in a .NET bitmap is found.</remarks>
25808
/// <exception cref="ArgumentNullException">
25809
/// <paramref name="dib"/> is null.</exception>
25810
/// <exception cref="ArgumentException">
25811
/// The image type of <paramref name="dib"/> is not FIT_BITMAP.</exception>
25812
public static Bitmap GetBitmap(FIBITMAP dib)
25814
return GetBitmap(dib, true);
25818
/// Converts a FreeImage bitmap to a .NET <see cref="System.Drawing.Bitmap"/>.
25820
/// <param name="dib">Handle to a FreeImage bitmap.</param>
25821
/// <param name="copyMetadata">When true existing metadata will be copied.</param>
25822
/// <returns>The converted .NET <see cref="System.Drawing.Bitmap"/>.</returns>
25823
/// <remarks>Copying metadata has been disabled until a proper way
25824
/// of reading and storing metadata in a .NET bitmap is found.</remarks>
25825
/// <exception cref="ArgumentNullException">
25826
/// <paramref name="dib"/> is null.</exception>
25827
/// <exception cref="ArgumentException">
25828
/// The image type of <paramref name="dib"/> is not FIT_BITMAP.</exception>
25829
internal static Bitmap GetBitmap(FIBITMAP dib, bool copyMetadata)
25833
throw new ArgumentNullException("dib");
25835
if (GetImageType(dib) != FREE_IMAGE_TYPE.FIT_BITMAP)
25837
throw new ArgumentException("Only bitmaps with type of FIT_BITMAP can be converted.");
25840
PixelFormat format = GetPixelFormat(dib);
25842
if ((format == PixelFormat.Undefined) && (GetBPP(dib) == 16u))
25844
throw new ArgumentException("Only 16bit 555 and 565 are supported.");
25847
int height = (int)GetHeight(dib);
25848
int width = (int)GetWidth(dib);
25849
int pitch = (int)GetPitch(dib);
25851
Bitmap result = new Bitmap(width, height, format);
25853
// Locking the complete bitmap in writeonly mode
25854
data = result.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, format);
25855
// Writing the bitmap data directly into the new created .NET bitmap.
25856
ConvertToRawBits(data.Scan0, dib, pitch, GetBPP(dib),
25857
GetRedMask(dib), GetGreenMask(dib), GetBlueMask(dib), true);
25858
// Unlock the bitmap
25859
result.UnlockBits(data);
25860
// Apply the bitmaps resolution
25861
result.SetResolution(GetResolutionX(dib), GetResolutionY(dib));
25862
// Check whether the bitmap has a palette
25863
if (GetPalette(dib) != IntPtr.Zero)
25865
// Get the bitmaps palette to apply changes
25866
ColorPalette palette = result.Palette;
25867
// Get the orgininal palette
25868
Color[] colorPalette = new Palette(dib).ColorData;
25869
// Get the maximum number of palette entries to copy
25870
int entriesToCopy = Math.Min(colorPalette.Length, palette.Entries.Length);
25872
// Check whether the bitmap is transparent
25873
if (IsTransparent(dib))
25875
byte[] transTable = GetTransparencyTableEx(dib);
25877
int maxEntriesWithTrans = Math.Min(entriesToCopy, transTable.Length);
25878
// Copy palette entries and include transparency
25879
for (; i < maxEntriesWithTrans; i++)
25881
palette.Entries[i] = Color.FromArgb(transTable[i], colorPalette[i]);
25883
// Copy palette entries and that have no transparancy
25884
for (; i < entriesToCopy; i++)
25886
palette.Entries[i] = Color.FromArgb(0xFF, colorPalette[i]);
25891
for (int i = 0; i < entriesToCopy; i++)
25893
palette.Entries[i] = colorPalette[i];
25897
// Set the bitmaps palette
25898
result.Palette = palette;
25905
List<PropertyItem> list = new List<PropertyItem>();
25906
// Get a list of all types
25909
foreach (FREE_IMAGE_MDMODEL model in FREE_IMAGE_MDMODELS)
25911
// Get a unique search handle
25912
mData = FindFirstMetadata(model, dib, out tag);
25913
// Check if metadata exists for this type
25914
if (mData.IsNull) continue;
25917
PropertyItem propItem = CreatePropertyItem();
25918
propItem.Len = (int)GetTagLength(tag);
25919
propItem.Id = (int)GetTagID(tag);
25920
propItem.Type = (short)GetTagType(tag);
25921
byte[] buffer = new byte[propItem.Len];
25925
byte* src = (byte*)GetTagValue(tag);
25926
fixed (byte* dst = buffer)
25928
CopyMemory(dst, src, (uint)propItem.Len);
25932
propItem.Value = buffer;
25933
list.Add(propItem);
25935
while (FindNextMetadata(mData, out tag));
25936
FindCloseMetadata(mData);
25938
foreach (PropertyItem propItem in list)
25940
result.SetPropertyItem(propItem);
25951
/// Converts an .NET <see cref="System.Drawing.Bitmap"/> into a FreeImage bitmap.
25953
/// <param name="bitmap">The <see cref="System.Drawing.Bitmap"/> to convert.</param>
25954
/// <returns>Handle to a FreeImage bitmap.</returns>
25955
/// <remarks>Copying metadata has been disabled until a proper way
25956
/// of reading and storing metadata in a .NET bitmap is found.</remarks>
25957
/// <exception cref="ArgumentNullException">
25958
/// <paramref name="bitmap"/> is null.</exception>
25959
/// <exception cref="ArgumentException">
25960
/// The bitmaps pixelformat is invalid.</exception>
25961
public static FIBITMAP CreateFromBitmap(Bitmap bitmap)
25963
return CreateFromBitmap(bitmap, false);
25967
/// Converts an .NET <see cref="System.Drawing.Bitmap"/> into a FreeImage bitmap.
25969
/// <param name="bitmap">The <see cref="System.Drawing.Bitmap"/> to convert.</param>
25970
/// <param name="copyMetadata">When true existing metadata will be copied.</param>
25971
/// <returns>Handle to a FreeImage bitmap.</returns>
25972
/// <remarks>Copying metadata has been disabled until a proper way
25973
/// of reading and storing metadata in a .NET bitmap is found.</remarks>
25974
/// <exception cref="ArgumentNullException">
25975
/// <paramref name="bitmap"/> is null.</exception>
25976
/// <exception cref="ArgumentException">
25977
/// The bitmaps pixelformat is invalid.</exception>
25978
internal static FIBITMAP CreateFromBitmap(Bitmap bitmap, bool copyMetadata)
25980
if (bitmap == null)
25982
throw new ArgumentNullException("bitmap");
25984
uint bpp, red_mask, green_mask, blue_mask;
25985
FREE_IMAGE_TYPE type;
25986
if (!GetFormatParameters(bitmap.PixelFormat, out type, out bpp, out red_mask, out green_mask, out blue_mask))
25988
throw new ArgumentException("The bitmaps pixelformat is invalid.");
25991
// Locking the complete bitmap in readonly mode
25992
BitmapData data = bitmap.LockBits(
25993
new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat);
25994
// Copying the bitmap data directly from the .NET bitmap
25995
FIBITMAP result = ConvertFromRawBits(
26006
bitmap.UnlockBits(data);
26008
if (GetPalette(result) != IntPtr.Zero)
26010
Palette palette = new Palette(result);
26011
Color[] colors = bitmap.Palette.Entries;
26012
// Only copy available palette entries
26013
int entriesToCopy = Math.Min(palette.Length, colors.Length);
26014
byte[] transTable = new byte[entriesToCopy];
26015
for (int i = 0; i < entriesToCopy; i++)
26017
RGBQUAD color = (RGBQUAD)colors[i];
26018
color.rgbReserved = 0x00;
26019
palette[i] = color;
26020
transTable[i] = colors[i].A;
26022
if ((bitmap.Flags & (int)ImageFlags.HasAlpha) != 0)
26024
FreeImage.SetTransparencyTable(result, transTable);
26027
// Handle meta data
26029
//if (copyMetadata)
26031
// foreach (PropertyItem propItem in bitmap.PropertyItems)
26033
// FITAG tag = CreateTag();
26034
// SetTagLength(tag, (uint)propItem.Len);
26035
// SetTagID(tag, (ushort)propItem.Id);
26036
// SetTagType(tag, (FREE_IMAGE_MDTYPE)propItem.Type);
26037
// SetTagValue(tag, propItem.Value);
26038
// SetMetadata(FREE_IMAGE_MDMODEL.FIMD_EXIF_EXIF, result, "", tag);
26045
/// Converts a raw bitmap to a FreeImage bitmap.
26047
/// <param name="bits">Array of bytes containing the raw bitmap.</param>
26048
/// <param name="type">The type of the raw bitmap.</param>
26049
/// <param name="width">The width in pixels of the raw bitmap.</param>
26050
/// <param name="height">The height in pixels of the raw bitmap.</param>
26051
/// <param name="pitch">Defines the total width of a scanline in the raw bitmap,
26052
/// including padding bytes.</param>
26053
/// <param name="bpp">The bit depth (bits per pixel) of the raw bitmap.</param>
26054
/// <param name="red_mask">The bit mask describing the bits used to store a single
26055
/// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.</param>
26056
/// <param name="green_mask">The bit mask describing the bits used to store a single
26057
/// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.</param>
26058
/// <param name="blue_mask">The bit mask describing the bits used to store a single
26059
/// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.</param>
26060
/// <param name="topdown">If true, the raw bitmap is stored in top-down order (top-left pixel first)
26061
/// and in bottom-up order (bottom-left pixel first) otherwise.</param>
26062
/// <returns>Handle to a FreeImage bitmap.</returns>
26063
public static unsafe FIBITMAP ConvertFromRawBits(
26065
FREE_IMAGE_TYPE type,
26075
fixed (byte* ptr = bits)
26077
return ConvertFromRawBits(
26092
/// Converts a raw bitmap to a FreeImage bitmap.
26094
/// <param name="bits">Pointer to the memory block containing the raw bitmap.</param>
26095
/// <param name="type">The type of the raw bitmap.</param>
26096
/// <param name="width">The width in pixels of the raw bitmap.</param>
26097
/// <param name="height">The height in pixels of the raw bitmap.</param>
26098
/// <param name="pitch">Defines the total width of a scanline in the raw bitmap,
26099
/// including padding bytes.</param>
26100
/// <param name="bpp">The bit depth (bits per pixel) of the raw bitmap.</param>
26101
/// <param name="red_mask">The bit mask describing the bits used to store a single
26102
/// pixel's red component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.</param>
26103
/// <param name="green_mask">The bit mask describing the bits used to store a single
26104
/// pixel's green component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.</param>
26105
/// <param name="blue_mask">The bit mask describing the bits used to store a single
26106
/// pixel's blue component in the raw bitmap. This is only applied to 16-bpp raw bitmaps.</param>
26107
/// <param name="topdown">If true, the raw bitmap is stored in top-down order (top-left pixel first)
26108
/// and in bottom-up order (bottom-left pixel first) otherwise.</param>
26109
/// <returns>Handle to a FreeImage bitmap.</returns>
26110
public static unsafe FIBITMAP ConvertFromRawBits(
26112
FREE_IMAGE_TYPE type,
26122
byte* addr = (byte*)bits;
26123
if ((addr == null) || (width <= 0) || (height <= 0))
26125
return FIBITMAP.Zero;
26128
FIBITMAP dib = AllocateT(type, width, height, (int)bpp, red_mask, green_mask, blue_mask);
26129
if (dib != FIBITMAP.Zero)
26133
for (int i = height - 1; i >= 0; --i)
26135
CopyMemory((byte*)GetScanLine(dib, i), addr, (int)GetLine(dib));
26141
for (int i = 0; i < height; ++i)
26143
CopyMemory((byte*)GetScanLine(dib, i), addr, (int)GetLine(dib));
26152
/// Saves a .NET <see cref="System.Drawing.Bitmap"/> to a file.
26154
/// <param name="bitmap">The .NET <see cref="System.Drawing.Bitmap"/> to save.</param>
26155
/// <param name="filename">Name of the file to save to.</param>
26156
/// <returns>Returns true on success, false on failure.</returns>
26157
/// <exception cref="ArgumentNullException">
26158
/// <paramref name="bitmap"/> or <paramref name="filename"/> is null.</exception>
26159
/// <exception cref="ArgumentException">
26160
/// The bitmaps pixelformat is invalid.</exception>
26161
public static bool SaveBitmap(Bitmap bitmap, string filename)
26166
FREE_IMAGE_FORMAT.FIF_UNKNOWN,
26167
FREE_IMAGE_SAVE_FLAGS.DEFAULT);
26171
/// Saves a .NET <see cref="System.Drawing.Bitmap"/> to a file.
26173
/// <param name="bitmap">The .NET <see cref="System.Drawing.Bitmap"/> to save.</param>
26174
/// <param name="filename">Name of the file to save to.</param>
26175
/// <param name="flags">Flags to enable or disable plugin-features.</param>
26176
/// <returns>Returns true on success, false on failure.</returns>
26177
/// <exception cref="ArgumentNullException">
26178
/// <paramref name="bitmap"/> or <paramref name="filename"/> is null.</exception>
26179
/// <exception cref="ArgumentException">
26180
/// The bitmaps pixelformat is invalid.</exception>
26181
public static bool SaveBitmap(Bitmap bitmap, string filename, FREE_IMAGE_SAVE_FLAGS flags)
26186
FREE_IMAGE_FORMAT.FIF_UNKNOWN,
26191
/// Saves a .NET <see cref="System.Drawing.Bitmap"/> to a file.
26193
/// <param name="bitmap">The .NET <see cref="System.Drawing.Bitmap"/> to save.</param>
26194
/// <param name="filename">Name of the file to save to.</param>
26195
/// <param name="format">Format of the bitmap. If the format should be taken from the
26196
/// filename use <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/>.</param>
26197
/// <param name="flags">Flags to enable or disable plugin-features.</param>
26198
/// <returns>Returns true on success, false on failure.</returns>
26199
/// <exception cref="ArgumentNullException">
26200
/// <paramref name="bitmap"/> or <paramref name="filename"/> is null.</exception>
26201
/// <exception cref="ArgumentException">
26202
/// The bitmaps pixelformat is invalid.</exception>
26203
public static bool SaveBitmap(
26206
FREE_IMAGE_FORMAT format,
26207
FREE_IMAGE_SAVE_FLAGS flags)
26209
FIBITMAP dib = CreateFromBitmap(bitmap);
26210
bool result = SaveEx(dib, filename, format, flags);
26216
/// Loads a FreeImage bitmap.
26217
/// The file will be loaded with default loading flags.
26219
/// <param name="filename">The complete name of the file to load.</param>
26220
/// <returns>Handle to a FreeImage bitmap.</returns>
26221
/// <exception cref="FileNotFoundException">
26222
/// <paramref name="filename"/> does not exists.</exception>
26223
public static FIBITMAP LoadEx(string filename)
26225
FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN;
26226
return LoadEx(filename, FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format);
26230
/// Loads a FreeImage bitmap.
26231
/// Load flags can be provided by the flags parameter.
26233
/// <param name="filename">The complete name of the file to load.</param>
26234
/// <param name="flags">Flags to enable or disable plugin-features.</param>
26235
/// <returns>Handle to a FreeImage bitmap.</returns>
26236
/// <exception cref="FileNotFoundException">
26237
/// <paramref name="filename"/> does not exists.</exception>
26238
public static FIBITMAP LoadEx(string filename, FREE_IMAGE_LOAD_FLAGS flags)
26240
FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN;
26241
return LoadEx(filename, flags, ref format);
26245
/// Loads a FreeImage bitmap.
26246
/// In case the loading format is <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/> the files
26247
/// real format is being analysed. If no plugin can read the file, format remains
26248
/// <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/> and 0 is returned.
26249
/// The file will be loaded with default loading flags.
26251
/// <param name="filename">The complete name of the file to load.</param>
26252
/// <param name="format">Format of the image. If the format is unknown use
26253
/// <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/>.
26254
/// In case a suitable format was found by LoadEx it will be returned in format.</param>
26255
/// <returns>Handle to a FreeImage bitmap.</returns>
26256
/// <exception cref="FileNotFoundException">
26257
/// <paramref name="filename"/> does not exists.</exception>
26258
public static FIBITMAP LoadEx(string filename, ref FREE_IMAGE_FORMAT format)
26260
return LoadEx(filename, FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format);
26264
/// Loads a FreeImage bitmap.
26265
/// In case the loading format is <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/> the files
26266
/// real format is being analysed. If no plugin can read the file, format remains
26267
/// <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/> and 0 is returned.
26268
/// Load flags can be provided by the flags parameter.
26270
/// <param name="filename">The complete name of the file to load.</param>
26271
/// <param name="flags">Flags to enable or disable plugin-features.</param>
26272
/// <param name="format">Format of the image. If the format is unknown use
26273
/// <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/>.
26274
/// In case a suitable format was found by LoadEx it will be returned in format.
26276
/// <returns>Handle to a FreeImage bitmap.</returns>
26277
/// <exception cref="FileNotFoundException">
26278
/// <paramref name="filename"/> does not exists.</exception>
26279
public static FIBITMAP LoadEx(string filename, FREE_IMAGE_LOAD_FLAGS flags, ref FREE_IMAGE_FORMAT format)
26281
// check if file exists
26282
if (!File.Exists(filename))
26284
throw new FileNotFoundException(filename + " could not be found.");
26286
FIBITMAP dib = new FIBITMAP();
26287
if (format == FREE_IMAGE_FORMAT.FIF_UNKNOWN)
26289
// query all plugins to see if one can read the file
26290
format = GetFileType(filename, 0);
26292
// check if the plugin is capable of loading files
26293
if (FIFSupportsReading(format))
26295
dib = Load(format, filename, flags);
26301
/// Loads a .NET <see cref="System.Drawing.Bitmap"/> from a file.
26303
/// <param name="filename">Name of the file to be loaded.</param>
26304
/// <param name="format">Format of the image. If the format should be taken from the
26305
/// filename use <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/>.</param>
26306
/// <param name="flags">Flags to enable or disable plugin-features.</param>
26307
/// <returns>The loaded .NET <see cref="System.Drawing.Bitmap"/>.</returns>
26308
/// <exception cref="FileNotFoundException">
26309
/// <paramref name="filename"/> does not exists.</exception>
26310
/// <exception cref="ArgumentException">
26311
/// The image type of the image is not <see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>.</exception>
26312
public static Bitmap LoadBitmap(string filename, FREE_IMAGE_LOAD_FLAGS flags, ref FREE_IMAGE_FORMAT format)
26314
FIBITMAP dib = LoadEx(filename, flags, ref format);
26315
Bitmap result = GetBitmap(dib, true);
26321
/// Deletes a previously loaded FreeImage bitmap from memory and resets the handle to 0.
26323
/// <param name="dib">Handle to a FreeImage bitmap.</param>
26324
public static void UnloadEx(ref FIBITMAP dib)
26334
/// Saves a previously loaded FreeImage bitmap to a file.
26335
/// The format is taken off the filename.
26336
/// If no suitable format was found false will be returned.
26338
/// <param name="dib">Handle to a FreeImage bitmap.</param>
26339
/// <param name="filename">The complete name of the file to save to.
26340
/// The extension will be corrected if it is no valid extension for the
26341
/// selected format or if no extension was specified.</param>
26342
/// <returns>Returns true on success, false on failure.</returns>
26343
/// <exception cref="ArgumentNullException">
26344
/// <paramref name="dib"/> or <paramref name="filename"/> is null.</exception>
26345
public static bool SaveEx(FIBITMAP dib, string filename)
26350
FREE_IMAGE_FORMAT.FIF_UNKNOWN,
26351
FREE_IMAGE_SAVE_FLAGS.DEFAULT,
26352
FREE_IMAGE_COLOR_DEPTH.FICD_AUTO,
26357
/// Saves a previously loaded FreeImage bitmap to a file.
26358
/// In case the loading format is <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/>
26359
/// the format is taken off the filename.
26360
/// If no suitable format was found false will be returned.
26362
/// <param name="dib">Handle to a FreeImage bitmap.</param>
26363
/// <param name="filename">The complete name of the file to save to.
26364
/// The extension will be corrected if it is no valid extension for the
26365
/// selected format or if no extension was specified.</param>
26366
/// <param name="format">Format of the image. If the format should be taken from the
26367
/// filename use <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/>.</param>
26368
/// <returns>Returns true on success, false on failure.</returns>
26369
/// <exception cref="ArgumentNullException">
26370
/// <paramref name="dib"/> or <paramref name="filename"/> is null.</exception>
26371
public static bool SaveEx(
26374
FREE_IMAGE_FORMAT format)
26380
FREE_IMAGE_SAVE_FLAGS.DEFAULT,
26381
FREE_IMAGE_COLOR_DEPTH.FICD_AUTO,
26386
/// Saves a previously loaded FreeImage bitmap to a file.
26387
/// The format is taken off the filename.
26388
/// If no suitable format was found false will be returned.
26390
/// <param name="dib">Handle to a FreeImage bitmap.</param>
26391
/// <param name="filename">The complete name of the file to save to.
26392
/// The extension will be corrected if it is no valid extension for the
26393
/// selected format or if no extension was specified.</param>
26394
/// <param name="unloadSource">When true the structure will be unloaded on success.
26395
/// If the function failed and returned false, the bitmap was not unloaded.</param>
26396
/// <returns>Returns true on success, false on failure.</returns>
26397
/// <exception cref="ArgumentNullException">
26398
/// <paramref name="dib"/> or <paramref name="filename"/> is null.</exception>
26399
public static bool SaveEx(
26407
FREE_IMAGE_FORMAT.FIF_UNKNOWN,
26408
FREE_IMAGE_SAVE_FLAGS.DEFAULT,
26409
FREE_IMAGE_COLOR_DEPTH.FICD_AUTO,
26414
/// Saves a previously loaded FreeImage bitmap to a file.
26415
/// The format is taken off the filename.
26416
/// If no suitable format was found false will be returned.
26417
/// Save flags can be provided by the flags parameter.
26419
/// <param name="dib">Handle to a FreeImage bitmap.</param>
26420
/// <param name="filename">The complete name of the file to save to.
26421
/// The extension will be corrected if it is no valid extension for the
26422
/// selected format or if no extension was specified</param>
26423
/// <param name="flags">Flags to enable or disable plugin-features.</param>
26424
/// <returns>Returns true on success, false on failure.</returns>
26425
/// <exception cref="ArgumentNullException">
26426
/// <paramref name="dib"/> or <paramref name="filename"/> is null.</exception>
26427
public static bool SaveEx(
26430
FREE_IMAGE_SAVE_FLAGS flags)
26435
FREE_IMAGE_FORMAT.FIF_UNKNOWN,
26437
FREE_IMAGE_COLOR_DEPTH.FICD_AUTO,
26442
/// Saves a previously loaded FreeImage bitmap to a file.
26443
/// The format is taken off the filename.
26444
/// If no suitable format was found false will be returned.
26445
/// Save flags can be provided by the flags parameter.
26447
/// <param name="dib">Handle to a FreeImage bitmap.</param>
26448
/// <param name="filename">The complete name of the file to save to.
26449
/// The extension will be corrected if it is no valid extension for the
26450
/// selected format or if no extension was specified.</param>
26451
/// <param name="flags">Flags to enable or disable plugin-features.</param>
26452
/// <param name="unloadSource">When true the structure will be unloaded on success.
26453
/// If the function failed and returned false, the bitmap was not unloaded.</param>
26454
/// <returns>Returns true on success, false on failure.</returns>
26455
/// <exception cref="ArgumentNullException">
26456
/// <paramref name="dib"/> or <paramref name="filename"/> is null.</exception>
26457
public static bool SaveEx(
26460
FREE_IMAGE_SAVE_FLAGS flags,
26466
FREE_IMAGE_FORMAT.FIF_UNKNOWN,
26468
FREE_IMAGE_COLOR_DEPTH.FICD_AUTO,
26473
/// Saves a previously loaded FreeImage bitmap to a file.
26474
/// In case the loading format is <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/>
26475
/// the format is taken off the filename.
26476
/// If no suitable format was found false will be returned.
26478
/// <param name="dib">Handle to a FreeImage bitmap.</param>
26479
/// <param name="filename">The complete name of the file to save to.
26480
/// The extension will be corrected if it is no valid extension for the
26481
/// selected format or if no extension was specified.</param>
26482
/// <param name="format">Format of the image. If the format should be taken from the
26483
/// filename use <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/>.</param>
26484
/// <param name="unloadSource">When true the structure will be unloaded on success.
26485
/// If the function failed and returned false, the bitmap was not unloaded.</param>
26486
/// <returns>Returns true on success, false on failure.</returns>
26487
/// <exception cref="ArgumentNullException">
26488
/// <paramref name="dib"/> or <paramref name="filename"/> is null.</exception>
26489
public static bool SaveEx(
26492
FREE_IMAGE_FORMAT format,
26499
FREE_IMAGE_SAVE_FLAGS.DEFAULT,
26500
FREE_IMAGE_COLOR_DEPTH.FICD_AUTO,
26505
/// Saves a previously loaded FreeImage bitmap to a file.
26506
/// In case the loading format is <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/>
26507
/// the format is taken off the filename.
26508
/// If no suitable format was found false will be returned.
26509
/// Save flags can be provided by the flags parameter.
26511
/// <param name="dib">Handle to a FreeImage bitmap.</param>
26512
/// <param name="filename">The complete name of the file to save to.
26513
/// The extension will be corrected if it is no valid extension for the
26514
/// selected format or if no extension was specified.</param>
26515
/// <param name="format">Format of the image. If the format should be taken from the
26516
/// filename use <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/>.</param>
26517
/// <param name="flags">Flags to enable or disable plugin-features.</param>
26518
/// <returns>Returns true on success, false on failure.</returns>
26519
/// <exception cref="ArgumentNullException">
26520
/// <paramref name="dib"/> or <paramref name="filename"/> is null.</exception>
26521
public static bool SaveEx(
26524
FREE_IMAGE_FORMAT format,
26525
FREE_IMAGE_SAVE_FLAGS flags)
26532
FREE_IMAGE_COLOR_DEPTH.FICD_AUTO,
26537
/// Saves a previously loaded FreeImage bitmap to a file.
26538
/// In case the loading format is <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/>
26539
/// the format is taken off the filename.
26540
/// If no suitable format was found false will be returned.
26541
/// Save flags can be provided by the flags parameter.
26542
/// The bitmaps color depth can be set by 'colorDepth'.
26543
/// If set to <see cref="FREE_IMAGE_COLOR_DEPTH.FICD_AUTO"/> a suitable color depth
26544
/// will be taken if available.
26546
/// <param name="dib">Handle to a FreeImage bitmap.</param>
26547
/// <param name="filename">The complete name of the file to save to.
26548
/// The extension will be corrected if it is no valid extension for the
26549
/// selected format or if no extension was specified.</param>
26550
/// <param name="format">Format of the image. If the format should be taken from the
26551
/// filename use <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/>.</param>
26552
/// <param name="flags">Flags to enable or disable plugin-features.</param>
26553
/// <param name="colorDepth">The new color depth of the bitmap.
26554
/// Set to <see cref="FREE_IMAGE_COLOR_DEPTH.FICD_AUTO"/> if Save should take the
26555
/// best suitable color depth.
26556
/// If a color depth is selected that the provided format cannot write an
26557
/// error-message will be thrown.</param>
26558
/// <param name="unloadSource">When true the structure will be unloaded on success.
26559
/// If the function failed and returned false, the bitmap was not unloaded.</param>
26560
/// <returns>Returns true on success, false on failure.</returns>
26561
/// <exception cref="ArgumentException">
26562
/// A direct color conversion failed.</exception>
26563
/// <exception cref="ArgumentNullException">
26564
/// <paramref name="dib"/> or <paramref name="filename"/> is null.</exception>
26565
public static bool SaveEx(
26568
FREE_IMAGE_FORMAT format,
26569
FREE_IMAGE_SAVE_FLAGS flags,
26570
FREE_IMAGE_COLOR_DEPTH colorDepth,
26575
throw new ArgumentNullException("dib");
26577
if (filename == null)
26579
throw new ArgumentNullException("filename");
26581
bool result = false;
26582
// Gets format from filename if the format is unknown
26583
if (format == FREE_IMAGE_FORMAT.FIF_UNKNOWN)
26585
format = GetFIFFromFilename(filename);
26587
if (format != FREE_IMAGE_FORMAT.FIF_UNKNOWN)
26589
// Checks writing support
26590
if (FIFSupportsWriting(format) && FIFSupportsExportType(format, GetImageType(dib)))
26592
// Check valid filename and correct it if needed
26593
if (!IsFilenameValidForFIF(format, filename))
26595
string extension = GetPrimaryExtensionFromFIF(format);
26596
filename = Path.ChangeExtension(filename, extension);
26599
FIBITMAP dibToSave = PrepareBitmapColorDepth(dib, format, colorDepth);
26602
result = Save(format, dibToSave, filename, flags);
26606
// Always unload a temporary created bitmap.
26607
if (dibToSave != dib)
26609
UnloadEx(ref dibToSave);
26611
// On success unload the bitmap
26612
if (result && unloadSource)
26623
/// Loads a FreeImage bitmap.
26624
/// The stream must be set to the correct position before calling LoadFromStream.
26626
/// <param name="stream">The stream to read from.</param>
26627
/// <returns>Handle to a FreeImage bitmap.</returns>
26628
/// <exception cref="ArgumentNullException">
26629
/// <paramref name="stream"/> is null.</exception>
26630
/// <exception cref="ArgumentException">
26631
/// <paramref name="stream"/> is not capable of reading.</exception>
26632
public static FIBITMAP LoadFromStream(Stream stream)
26634
FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN;
26635
return LoadFromStream(stream, FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format);
26639
/// Loads a FreeImage bitmap.
26640
/// The stream must be set to the correct position before calling LoadFromStream.
26642
/// <param name="stream">The stream to read from.</param>
26643
/// <param name="flags">Flags to enable or disable plugin-features.</param>
26644
/// <returns>Handle to a FreeImage bitmap.</returns>
26645
/// <exception cref="ArgumentNullException">
26646
/// <paramref name="stream"/> is null.</exception>
26647
/// <exception cref="ArgumentException">
26648
/// <paramref name="stream"/> is not capable of reading.</exception>
26649
public static FIBITMAP LoadFromStream(Stream stream, FREE_IMAGE_LOAD_FLAGS flags)
26651
FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN;
26652
return LoadFromStream(stream, flags, ref format);
26656
/// Loads a FreeImage bitmap.
26657
/// In case the loading format is <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/> the
26658
/// bitmaps real format is being analysed.
26659
/// The stream must be set to the correct position before calling LoadFromStream.
26661
/// <param name="stream">The stream to read from.</param>
26662
/// <param name="format">Format of the image. If the format is unknown use
26663
/// <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/>.
26664
/// In case a suitable format was found by LoadFromStream it will be returned in format.</param>
26665
/// <returns>Handle to a FreeImage bitmap.</returns>
26666
/// <exception cref="ArgumentNullException">
26667
/// <paramref name="stream"/> is null.</exception>
26668
/// <exception cref="ArgumentException">
26669
/// <paramref name="stream"/> is not capable of reading.</exception>
26670
public static FIBITMAP LoadFromStream(Stream stream, ref FREE_IMAGE_FORMAT format)
26672
return LoadFromStream(stream, FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref format);
26676
/// Loads a FreeImage bitmap.
26677
/// In case the loading format is <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/>
26678
/// the bitmaps real format is being analysed.
26679
/// The stream must be set to the correct position before calling LoadFromStream.
26681
/// <param name="stream">The stream to read from.</param>
26682
/// <param name="flags">Flags to enable or disable plugin-features.</param>
26683
/// <param name="format">Format of the image. If the format is unknown use
26684
/// <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/>.
26685
/// In case a suitable format was found by LoadFromStream it will be returned in format.</param>
26686
/// <returns>Handle to a FreeImage bitmap.</returns>
26687
/// <exception cref="ArgumentNullException">
26688
/// <paramref name="stream"/> is null.</exception>
26689
/// <exception cref="ArgumentException">
26690
/// <paramref name="stream"/> is not capable of reading.</exception>
26691
public static FIBITMAP LoadFromStream(
26693
FREE_IMAGE_LOAD_FLAGS flags,
26694
ref FREE_IMAGE_FORMAT format)
26696
if (stream == null)
26698
throw new ArgumentNullException("stream");
26700
if (!stream.CanRead)
26702
throw new ArgumentException("stream is not capable of reading.");
26704
// Wrap the source stream if it is unable to seek (which is required by FreeImage)
26705
stream = (stream.CanSeek) ? stream : new StreamWrapper(stream, true);
26707
stream.Position = 0L;
26708
if (format == FREE_IMAGE_FORMAT.FIF_UNKNOWN)
26710
// Get the format of the bitmap
26711
format = GetFileTypeFromStream(stream);
26712
// Restore the streams position
26713
stream.Position = 0L;
26715
if (!FIFSupportsReading(format))
26717
return FIBITMAP.Zero;
26719
// Create a 'FreeImageIO' structure for calling 'LoadFromHandle'
26720
// using the internal structure 'FreeImageStreamIO'.
26721
FreeImageIO io = FreeImageStreamIO.io;
26722
using (fi_handle handle = new fi_handle(stream))
26724
return LoadFromHandle(format, ref io, handle, flags);
26729
/// Saves a previously loaded FreeImage bitmap to a stream.
26730
/// The stream must be set to the correct position before calling SaveToStream.
26732
/// <param name="dib">Handle to a FreeImage bitmap.</param>
26733
/// <param name="stream">The stream to write to.</param>
26734
/// <param name="format">Format of the image.</param>
26735
/// <returns>Returns true on success, false on failure.</returns>
26736
/// <exception cref="ArgumentNullException">
26737
/// <paramref name="dib"/> or <paramref name="stream"/> is null.</exception>
26738
/// <exception cref="ArgumentException">
26739
/// <paramref name="stream"/> cannot write.</exception>
26740
public static bool SaveToStream(
26743
FREE_IMAGE_FORMAT format)
26745
return SaveToStream(
26749
FREE_IMAGE_SAVE_FLAGS.DEFAULT,
26750
FREE_IMAGE_COLOR_DEPTH.FICD_AUTO,
26755
/// Saves a previously loaded FreeImage bitmap to a stream.
26756
/// The stream must be set to the correct position before calling SaveToStream.
26758
/// <param name="dib">Handle to a FreeImage bitmap.</param>
26759
/// <param name="stream">The stream to write to.</param>
26760
/// <param name="format">Format of the image.</param>
26761
/// <param name="unloadSource">When true the structure will be unloaded on success.</param>
26762
/// <returns>Returns true on success, false on failure.</returns>
26763
/// <exception cref="ArgumentNullException">
26764
/// <paramref name="dib"/> or <paramref name="stream"/> is null.</exception>
26765
/// <exception cref="ArgumentException">
26766
/// <paramref name="stream"/> cannot write.</exception>
26767
public static bool SaveToStream(
26770
FREE_IMAGE_FORMAT format,
26773
return SaveToStream(
26777
FREE_IMAGE_SAVE_FLAGS.DEFAULT,
26778
FREE_IMAGE_COLOR_DEPTH.FICD_AUTO,
26783
/// Saves a previously loaded FreeImage bitmap to a stream.
26784
/// The stream must be set to the correct position before calling SaveToStream.
26786
/// <param name="dib">Handle to a FreeImage bitmap.</param>
26787
/// <param name="stream">The stream to write to.</param>
26788
/// <param name="format">Format of the image.</param>
26789
/// <param name="flags">Flags to enable or disable plugin-features.</param>
26790
/// <returns>Returns true on success, false on failure.</returns>
26791
/// <exception cref="ArgumentNullException">
26792
/// <paramref name="dib"/> or <paramref name="stream"/> is null.</exception>
26793
/// <exception cref="ArgumentException">
26794
/// <paramref name="stream"/> cannot write.</exception>
26795
public static bool SaveToStream(
26798
FREE_IMAGE_FORMAT format,
26799
FREE_IMAGE_SAVE_FLAGS flags)
26801
return SaveToStream(
26806
FREE_IMAGE_COLOR_DEPTH.FICD_AUTO,
26811
/// Saves a previously loaded FreeImage bitmap to a stream.
26812
/// The stream must be set to the correct position before calling SaveToStream.
26814
/// <param name="dib">Handle to a FreeImage bitmap.</param>
26815
/// <param name="stream">The stream to write to.</param>
26816
/// <param name="format">Format of the image.</param>
26817
/// <param name="flags">Flags to enable or disable plugin-features.</param>
26818
/// <param name="unloadSource">When true the structure will be unloaded on success.</param>
26819
/// <returns>Returns true on success, false on failure.</returns>
26820
/// <exception cref="ArgumentNullException">
26821
/// <paramref name="dib"/> or <paramref name="stream"/> is null.</exception>
26822
/// <exception cref="ArgumentException">
26823
/// <paramref name="stream"/> cannot write.</exception>
26824
public static bool SaveToStream(
26827
FREE_IMAGE_FORMAT format,
26828
FREE_IMAGE_SAVE_FLAGS flags,
26831
return SaveToStream(
26835
FREE_IMAGE_COLOR_DEPTH.FICD_AUTO,
26840
/// Saves a previously loaded FreeImage bitmap to a stream.
26841
/// The stream must be set to the correct position before calling SaveToStream.
26843
/// <param name="dib">Handle to a FreeImage bitmap.</param>
26844
/// <param name="stream">The stream to write to.</param>
26845
/// <param name="format">Format of the image.</param>
26846
/// <param name="flags">Flags to enable or disable plugin-features.</param>
26847
/// <param name="colorDepth">The new color depth of the bitmap.
26848
/// Set to <see cref="FREE_IMAGE_COLOR_DEPTH.FICD_AUTO"/> if SaveToStream should
26849
/// take the best suitable color depth.
26850
/// If a color depth is selected that the provided format cannot write an
26851
/// error-message will be thrown.</param>
26852
/// <returns>Returns true on success, false on failure.</returns>
26853
/// <exception cref="ArgumentNullException">
26854
/// <paramref name="dib"/> or <paramref name="stream"/> is null.</exception>
26855
/// <exception cref="ArgumentException">
26856
/// <paramref name="stream"/> cannot write.</exception>
26857
public static bool SaveToStream(
26860
FREE_IMAGE_FORMAT format,
26861
FREE_IMAGE_SAVE_FLAGS flags,
26862
FREE_IMAGE_COLOR_DEPTH colorDepth)
26864
return SaveToStream(
26874
/// Saves a previously loaded FreeImage bitmap to a stream.
26875
/// The stream must be set to the correct position before calling SaveToStream.
26877
/// <param name="dib">Handle to a FreeImage bitmap.</param>
26878
/// <param name="stream">The stream to write to.</param>
26879
/// <param name="format">Format of the image.</param>
26880
/// <param name="flags">Flags to enable or disable plugin-features.</param>
26881
/// <param name="colorDepth">The new color depth of the bitmap.
26882
/// Set to <see cref="FREE_IMAGE_COLOR_DEPTH.FICD_AUTO"/> if SaveToStream should
26883
/// take the best suitable color depth.
26884
/// If a color depth is selected that the provided format cannot write an
26885
/// error-message will be thrown.</param>
26886
/// <param name="unloadSource">When true the structure will be unloaded on success.</param>
26887
/// <returns>Returns true on success, false on failure.</returns>
26888
/// <exception cref="ArgumentNullException">
26889
/// <paramref name="dib"/> or <paramref name="stream"/> is null.</exception>
26890
/// <exception cref="ArgumentException">
26891
/// <paramref name="stream"/> cannot write.</exception>
26892
public static bool SaveToStream(
26895
FREE_IMAGE_FORMAT format,
26896
FREE_IMAGE_SAVE_FLAGS flags,
26897
FREE_IMAGE_COLOR_DEPTH colorDepth,
26902
throw new ArgumentNullException("dib");
26904
if (stream == null)
26906
throw new ArgumentNullException("stream");
26908
if (!stream.CanWrite)
26910
throw new ArgumentException("stream is not capable of writing.");
26912
if ((!FIFSupportsWriting(format)) || (!FIFSupportsExportType(format, GetImageType(dib))))
26917
FIBITMAP dibToSave = PrepareBitmapColorDepth(dib, format, colorDepth);
26918
bool result = false;
26922
// Create a 'FreeImageIO' structure for calling 'SaveToHandle'
26923
FreeImageIO io = FreeImageStreamIO.io;
26925
using (fi_handle handle = new fi_handle(stream))
26927
result = SaveToHandle(format, dibToSave, ref io, handle, flags);
26932
// Always unload a temporary created bitmap.
26933
if (dibToSave != dib)
26935
UnloadEx(ref dibToSave);
26937
// On success unload the bitmap
26938
if (result && unloadSource)
26949
#region Plugin functions
26952
/// Checks if an extension is valid for a certain format.
26954
/// <param name="fif">The desired format.</param>
26955
/// <param name="extension">The desired extension.</param>
26956
/// <returns>True if the extension is valid for the given format, false otherwise.</returns>
26957
/// <exception cref="ArgumentNullException">
26958
/// <paramref name="extension"/> is null.</exception>
26959
public static bool IsExtensionValidForFIF(FREE_IMAGE_FORMAT fif, string extension)
26961
return IsExtensionValidForFIF(fif, extension, StringComparison.CurrentCultureIgnoreCase);
26965
/// Checks if an extension is valid for a certain format.
26967
/// <param name="fif">The desired format.</param>
26968
/// <param name="extension">The desired extension.</param>
26969
/// <param name="comparisonType">The string comparison type.</param>
26970
/// <returns>True if the extension is valid for the given format, false otherwise.</returns>
26971
/// <exception cref="ArgumentNullException">
26972
/// <paramref name="extension"/> is null.</exception>
26973
public static bool IsExtensionValidForFIF(FREE_IMAGE_FORMAT fif, string extension, StringComparison comparisonType)
26975
if (extension == null)
26977
throw new ArgumentNullException("extension");
26979
bool result = false;
26980
// Split up the string and compare each with the given extension
26981
string tempList = GetFIFExtensionList(fif);
26982
if (tempList != null)
26984
string[] extensionList = tempList.Split(',');
26985
foreach (string ext in extensionList)
26987
if (extension.Equals(ext, comparisonType))
26998
/// Checks if a filename is valid for a certain format.
27000
/// <param name="fif">The desired format.</param>
27001
/// <param name="filename">The desired filename.</param>
27002
/// <returns>True if the filename is valid for the given format, false otherwise.</returns>
27003
/// <exception cref="ArgumentNullException">
27004
/// <paramref name="filename"/> is null.</exception>
27005
public static bool IsFilenameValidForFIF(FREE_IMAGE_FORMAT fif, string filename)
27007
return IsFilenameValidForFIF(fif, filename, StringComparison.CurrentCultureIgnoreCase);
27011
/// Checks if a filename is valid for a certain format.
27013
/// <param name="fif">The desired format.</param>
27014
/// <param name="filename">The desired filename.</param>
27015
/// <param name="comparisonType">The string comparison type.</param>
27016
/// <returns>True if the filename is valid for the given format, false otherwise.</returns>
27017
/// <exception cref="ArgumentNullException">
27018
/// <paramref name="filename"/> is null.</exception>
27019
public static bool IsFilenameValidForFIF(FREE_IMAGE_FORMAT fif, string filename, StringComparison comparisonType)
27021
if (filename == null)
27023
throw new ArgumentNullException("filename");
27025
bool result = false;
27026
// Extract the filenames extension if it exists
27027
string extension = Path.GetExtension(filename);
27028
if (extension.Length != 0)
27030
extension = extension.Remove(0, 1);
27031
result = IsExtensionValidForFIF(fif, extension, comparisonType);
27037
/// This function returns the primary (main or most commonly used?) extension of a certain
27038
/// image format (fif). This is done by returning the first of all possible extensions
27039
/// returned by GetFIFExtensionList().
27040
/// That assumes, that the plugin returns the extensions in ordered form.</summary>
27041
/// <param name="fif">The image format to obtain the primary extension for.</param>
27042
/// <returns>The primary extension of the specified image format.</returns>
27043
public static string GetPrimaryExtensionFromFIF(FREE_IMAGE_FORMAT fif)
27045
string result = null;
27046
string extensions = GetFIFExtensionList(fif);
27047
if (extensions != null)
27049
int position = extensions.IndexOf(',');
27052
result = extensions;
27056
result = extensions.Substring(0, position);
27064
#region Multipage functions
27067
/// Loads a FreeImage multi-paged bitmap.
27069
/// <param name="filename">The complete name of the file to load.</param>
27070
/// <returns>Handle to a FreeImage multi-paged bitmap.</returns>
27071
/// <exception cref="FileNotFoundException">
27072
/// <paramref name="filename"/> does not exists while opening.</exception>
27073
public static FIMULTIBITMAP OpenMultiBitmapEx(string filename)
27075
FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN;
27076
return OpenMultiBitmapEx(
27079
FREE_IMAGE_LOAD_FLAGS.DEFAULT,
27086
/// Loads a FreeImage multi-paged bitmap.
27088
/// <param name="filename">The complete name of the file to load.</param>
27089
/// <param name="keep_cache_in_memory">When true performance is increased at the cost of memory.</param>
27090
/// <returns>Handle to a FreeImage multi-paged bitmap.</returns>
27091
/// <exception cref="FileNotFoundException">
27092
/// <paramref name="filename"/> does not exists while opening.</exception>
27093
public static FIMULTIBITMAP OpenMultiBitmapEx(string filename, bool keep_cache_in_memory)
27095
FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN;
27096
return OpenMultiBitmapEx(
27099
FREE_IMAGE_LOAD_FLAGS.DEFAULT,
27102
keep_cache_in_memory);
27106
/// Loads a FreeImage multi-paged bitmap.
27108
/// <param name="filename">The complete name of the file to load.</param>
27109
/// <param name="read_only">When true the bitmap will be loaded read only.</param>
27110
/// <param name="keep_cache_in_memory">When true performance is increased at the cost of memory.</param>
27111
/// <returns>Handle to a FreeImage multi-paged bitmap.</returns>
27112
/// <exception cref="FileNotFoundException">
27113
/// <paramref name="filename"/> does not exists while opening.</exception>
27114
public static FIMULTIBITMAP OpenMultiBitmapEx(
27117
bool keep_cache_in_memory)
27119
FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN;
27120
return OpenMultiBitmapEx(
27123
FREE_IMAGE_LOAD_FLAGS.DEFAULT,
27126
keep_cache_in_memory);
27130
/// Loads a FreeImage multi-paged bitmap.
27132
/// <param name="filename">The complete name of the file to load.</param>
27133
/// <param name="create_new">When true a new bitmap is created.</param>
27134
/// <param name="read_only">When true the bitmap will be loaded read only.</param>
27135
/// <param name="keep_cache_in_memory">When true performance is increased at the cost of memory.</param>
27136
/// <returns>Handle to a FreeImage multi-paged bitmap.</returns>
27137
/// <exception cref="FileNotFoundException">
27138
/// <paramref name="filename"/> does not exists while opening.</exception>
27139
public static FIMULTIBITMAP OpenMultiBitmapEx(
27143
bool keep_cache_in_memory)
27145
FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN;
27146
return OpenMultiBitmapEx(
27149
FREE_IMAGE_LOAD_FLAGS.DEFAULT,
27152
keep_cache_in_memory);
27156
/// Loads a FreeImage multi-paged bitmap.
27157
/// In case the loading format is <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/> the files real
27158
/// format is being analysed. If no plugin can read the file, format remains
27159
/// <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/> and 0 is returned.
27161
/// <param name="filename">The complete name of the file to load.</param>
27162
/// <param name="format">Format of the image. If the format is unknown use
27163
/// <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/>.
27164
/// In case a suitable format was found by LoadEx it will be returned in format.</param>
27165
/// <param name="create_new">When true a new bitmap is created.</param>
27166
/// <param name="read_only">When true the bitmap will be loaded read only.</param>
27167
/// <param name="keep_cache_in_memory">When true performance is increased at the cost of memory.</param>
27168
/// <returns>Handle to a FreeImage multi-paged bitmap.</returns>
27169
/// <exception cref="FileNotFoundException">
27170
/// <paramref name="filename"/> does not exists while opening.</exception>
27171
public static FIMULTIBITMAP OpenMultiBitmapEx(
27173
ref FREE_IMAGE_FORMAT format,
27176
bool keep_cache_in_memory)
27178
return OpenMultiBitmapEx(
27181
FREE_IMAGE_LOAD_FLAGS.DEFAULT,
27184
keep_cache_in_memory);
27188
/// Loads a FreeImage multi-paged bitmap.
27189
/// In case the loading format is <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/> the files
27190
/// real format is being analysed. If no plugin can read the file, format remains
27191
/// <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/> and 0 is returned.
27192
/// Load flags can be provided by the flags parameter.
27194
/// <param name="filename">The complete name of the file to load.</param>
27195
/// <param name="format">Format of the image. If the format is unknown use
27196
/// <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/>.
27197
/// In case a suitable format was found by LoadEx it will be returned in format.</param>
27198
/// <param name="flags">Flags to enable or disable plugin-features.</param>
27199
/// <param name="create_new">When true a new bitmap is created.</param>
27200
/// <param name="read_only">When true the bitmap will be loaded read only.</param>
27201
/// <param name="keep_cache_in_memory">When true performance is increased at the cost of memory.</param>
27202
/// <returns>Handle to a FreeImage multi-paged bitmap.</returns>
27203
/// <exception cref="FileNotFoundException">
27204
/// <paramref name="filename"/> does not exists while opening.</exception>
27205
public static FIMULTIBITMAP OpenMultiBitmapEx(
27207
ref FREE_IMAGE_FORMAT format,
27208
FREE_IMAGE_LOAD_FLAGS flags,
27211
bool keep_cache_in_memory)
27213
if (!File.Exists(filename) && !create_new)
27215
throw new FileNotFoundException(filename + " could not be found.");
27217
if (format == FREE_IMAGE_FORMAT.FIF_UNKNOWN)
27219
// Check if a plugin can read the data
27220
format = GetFileType(filename, 0);
27222
FIMULTIBITMAP dib = new FIMULTIBITMAP();
27223
if (FIFSupportsReading(format))
27225
dib = OpenMultiBitmap(format, filename, create_new, read_only, keep_cache_in_memory, flags);
27231
/// Loads a FreeImage multi-paged bitmap.
27233
/// <param name="stream">The stream to load the bitmap from.</param>
27234
/// <returns>Handle to a FreeImage multi-paged bitmap.</returns>
27235
public static FIMULTIBITMAP OpenMultiBitmapFromStream(Stream stream)
27237
FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_UNKNOWN;
27238
return OpenMultiBitmapFromStream(stream, ref format, FREE_IMAGE_LOAD_FLAGS.DEFAULT);
27242
/// Loads a FreeImage multi-paged bitmap.
27243
/// In case the loading format is <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/> the files
27244
/// real format is being analysed. If no plugin can read the file, format remains
27245
/// <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/> and 0 is returned.
27246
/// Load flags can be provided by the flags parameter.
27248
/// <param name="stream">The stream to load the bitmap from.</param>
27249
/// <param name="format">Format of the image. If the format is unknown use
27250
/// <see cref="FREE_IMAGE_FORMAT.FIF_UNKNOWN"/></param>.
27251
/// <param name="flags">Flags to enable or disable plugin-features.</param>
27252
/// <returns>Handle to a FreeImage multi-paged bitmap.</returns>
27253
public static FIMULTIBITMAP OpenMultiBitmapFromStream(Stream stream, ref FREE_IMAGE_FORMAT format, FREE_IMAGE_LOAD_FLAGS flags)
27255
if (stream == null)
27256
return FIMULTIBITMAP.Zero;
27258
if (!stream.CanSeek)
27259
stream = new StreamWrapper(stream, true);
27261
FIMULTIBITMAP mdib = FIMULTIBITMAP.Zero;
27262
FreeImageIO io = FreeImageStreamIO.io;
27263
fi_handle handle = new fi_handle(stream);
27267
if (format == FREE_IMAGE_FORMAT.FIF_UNKNOWN)
27269
format = GetFileTypeFromHandle(ref io, handle, checked((int)stream.Length));
27272
mdib = OpenMultiBitmapFromHandle(format, ref io, handle, flags);
27280
lock (streamHandles)
27282
streamHandles.Add(mdib, handle);
27291
CloseMultiBitmap(mdib, FREE_IMAGE_SAVE_FLAGS.DEFAULT);
27293
if (handle != null)
27301
/// Closes a previously opened multi-page bitmap and, when the bitmap was not opened read-only, applies any changes made to it.
27303
/// <param name="bitmap">Handle to a FreeImage multi-paged bitmap.</param>
27304
/// <param name="flags">Flags to enable or disable plugin-features.</param>
27305
/// <returns>Returns true on success, false on failure.</returns>
27306
public static bool CloseMultiBitmap(FIMULTIBITMAP bitmap, FREE_IMAGE_SAVE_FLAGS flags)
27308
if (CloseMultiBitmap_(bitmap, flags))
27311
lock (streamHandles)
27313
if (streamHandles.TryGetValue(bitmap, out handle))
27315
streamHandles.Remove(bitmap);
27325
/// Closes a previously opened multi-page bitmap and, when the bitmap was not opened read-only,
27326
/// applies any changes made to it.
27327
/// On success the handle will be reset to null.
27329
/// <param name="bitmap">Handle to a FreeImage multi-paged bitmap.</param>
27330
/// <returns>Returns true on success, false on failure.</returns>
27331
public static bool CloseMultiBitmapEx(ref FIMULTIBITMAP bitmap)
27333
return CloseMultiBitmapEx(ref bitmap, FREE_IMAGE_SAVE_FLAGS.DEFAULT);
27337
/// Closes a previously opened multi-page bitmap and, when the bitmap was not opened read-only,
27338
/// applies any changes made to it.
27339
/// On success the handle will be reset to null.
27341
/// <param name="bitmap">Handle to a FreeImage multi-paged bitmap.</param>
27342
/// <param name="flags">Flags to enable or disable plugin-features.</param>
27343
/// <returns>Returns true on success, false on failure.</returns>
27344
public static bool CloseMultiBitmapEx(ref FIMULTIBITMAP bitmap, FREE_IMAGE_SAVE_FLAGS flags)
27346
bool result = false;
27347
if (!bitmap.IsNull)
27349
if (CloseMultiBitmap(bitmap, flags))
27359
/// Retrieves the number of pages that are locked in a multi-paged bitmap.
27361
/// <param name="dib">Handle to a FreeImage multi-paged bitmap.</param>
27362
/// <returns>Number of locked pages.</returns>
27363
/// <exception cref="ArgumentNullException">
27364
/// <paramref name="dib"/> is null.</exception>
27365
public static int GetLockedPageCount(FIMULTIBITMAP dib)
27369
throw new ArgumentNullException("dib");
27372
GetLockedPageNumbers(dib, null, ref result);
27377
/// Retrieves a list locked pages of a multi-paged bitmap.
27379
/// <param name="dib">Handle to a FreeImage multi-paged bitmap.</param>
27380
/// <returns>List containing the indexes of the locked pages.</returns>
27381
/// <exception cref="ArgumentNullException">
27382
/// <paramref name="dib"/> is null.</exception>
27383
public static int[] GetLockedPages(FIMULTIBITMAP dib)
27387
throw new ArgumentNullException("dib");
27389
// Get the number of pages and create an array to save the information
27391
int[] result = null;
27393
if (GetLockedPageNumbers(dib, result, ref count))
27395
result = new int[count];
27397
if (!GetLockedPageNumbers(dib, result, ref count))
27406
/// Loads a FreeImage multi-paged bitmap from a stream and returns the
27407
/// FreeImage memory stream used as temporary buffer.
27408
/// The bitmap can not be modified by calling
27409
/// <see cref="FreeImage.AppendPage(FIMULTIBITMAP,FIBITMAP)"/>,
27410
/// <see cref="FreeImage.InsertPage(FIMULTIBITMAP,Int32,FIBITMAP)"/>,
27411
/// <see cref="FreeImage.MovePage(FIMULTIBITMAP,Int32,Int32)"/> or
27412
/// <see cref="FreeImage.DeletePage(FIMULTIBITMAP,Int32)"/>.
27414
/// <param name="stream">The stream to read from.</param>
27415
/// <param name="format">Format of the image.</param>
27416
/// <param name="flags">Flags to enable or disable plugin-features.</param>
27417
/// <param name="memory">The temporary memory buffer used to load the bitmap.</param>
27418
/// <returns>Handle to a FreeImage multi-paged bitmap.</returns>
27419
/// <exception cref="ArgumentNullException">
27420
/// <paramref name="stream"/> is null.</exception>
27421
/// <exception cref="ArgumentException">
27422
/// <paramref name="stream"/> can not read.</exception>
27423
public static FIMULTIBITMAP LoadMultiBitmapFromStream(
27425
FREE_IMAGE_FORMAT format,
27426
FREE_IMAGE_LOAD_FLAGS flags,
27427
out FIMEMORY memory)
27429
if (stream == null)
27431
throw new ArgumentNullException("stream");
27433
if (!stream.CanRead)
27435
throw new ArgumentException("stream");
27437
const int blockSize = 1024;
27439
byte[] buffer = new byte[blockSize];
27441
stream = stream.CanSeek ? stream : new StreamWrapper(stream, true);
27442
memory = OpenMemory(IntPtr.Zero, 0);
27446
bytesRead = stream.Read(buffer, 0, blockSize);
27447
WriteMemory(buffer, (uint)blockSize, (uint)1, memory);
27449
while (bytesRead == blockSize);
27451
return LoadMultiBitmapFromMemory(format, memory, flags);
27456
#region Filetype functions
27459
/// Orders FreeImage to analyze the bitmap signature.
27460
/// In case the stream is not seekable, the stream will have been used
27461
/// and must be recreated for loading.
27463
/// <param name="stream">Name of the stream to analyze.</param>
27464
/// <returns>Type of the bitmap.</returns>
27465
/// <exception cref="ArgumentNullException">
27466
/// <paramref name="stream"/> is null.</exception>
27467
/// <exception cref="ArgumentException">
27468
/// <paramref name="stream"/> can not read.</exception>
27469
public static FREE_IMAGE_FORMAT GetFileTypeFromStream(Stream stream)
27471
if (stream == null)
27473
throw new ArgumentNullException("stream");
27475
if (!stream.CanRead)
27477
throw new ArgumentException("stream is not capable of reading.");
27479
// Wrap the stream if it cannot seek
27480
stream = (stream.CanSeek) ? stream : new StreamWrapper(stream, true);
27481
// Create a 'FreeImageIO' structure for the stream
27482
FreeImageIO io = FreeImageStreamIO.io;
27483
using (fi_handle handle = new fi_handle(stream))
27485
return GetFileTypeFromHandle(ref io, handle, 0);
27491
#region Pixel access functions
27494
/// Retrieves an hBitmap for a FreeImage bitmap.
27495
/// Call FreeHbitmap(IntPtr) to free the handle.
27497
/// <param name="dib">Handle to a FreeImage bitmap.</param>
27498
/// <param name="hdc">A reference device context.
27499
/// Use IntPtr.Zero if no reference is available.</param>
27500
/// <param name="unload">When true dib will be unloaded if the function succeeded.</param>
27501
/// <returns>The hBitmap for the FreeImage bitmap.</returns>
27502
/// <exception cref="ArgumentNullException">
27503
/// <paramref name="dib"/> is null.</exception>
27504
public static unsafe IntPtr GetHbitmap(FIBITMAP dib, IntPtr hdc, bool unload)
27508
throw new ArgumentNullException("dib");
27510
IntPtr hBitmap = IntPtr.Zero;
27511
bool release = false;
27512
IntPtr ppvBits = IntPtr.Zero;
27513
// Check if we have destination
27514
if (release = (hdc == IntPtr.Zero))
27516
// We don't so request dc
27517
hdc = GetDC(IntPtr.Zero);
27519
if (hdc != IntPtr.Zero)
27521
// Get pointer to the infoheader of the bitmap
27522
IntPtr info = GetInfo(dib);
27523
// Create a bitmap in the dc
27524
hBitmap = CreateDIBSection(hdc, info, DIB_RGB_COLORS, out ppvBits, IntPtr.Zero, 0);
27525
if (hBitmap != IntPtr.Zero && ppvBits != IntPtr.Zero)
27527
// Copy the data into the dc
27528
CopyMemory(ppvBits, GetBits(dib), (GetHeight(dib) * GetPitch(dib)));
27529
// Success: we unload the bitmap
27535
// We have to release the dc
27538
ReleaseDC(IntPtr.Zero, hdc);
27545
/// Returns an HBITMAP created by the <c>CreateDIBitmap()</c> function which in turn
27546
/// has always the same color depth as the reference DC, which may be provided
27547
/// through <paramref name="hdc"/>. The desktop DC will be used,
27548
/// if <c>IntPtr.Zero</c> DC is specified.
27549
/// Call <see cref="FreeImage.FreeHbitmap(IntPtr)"/> to free the handle.
27551
/// <param name="dib">Handle to a FreeImage bitmap.</param>
27552
/// <param name="hdc">Handle to a device context.</param>
27553
/// <param name="unload">When true the structure will be unloaded on success.
27554
/// If the function failed and returned false, the bitmap was not unloaded.</param>
27555
/// <returns>If the function succeeds, the return value is a handle to the
27556
/// compatible bitmap. If the function fails, the return value is <see cref="IntPtr.Zero"/>.</returns>
27557
/// <exception cref="ArgumentNullException">
27558
/// <paramref name="dib"/> is null.</exception>
27559
public static IntPtr GetBitmapForDevice(FIBITMAP dib, IntPtr hdc, bool unload)
27563
throw new ArgumentNullException("dib");
27565
IntPtr hbitmap = IntPtr.Zero;
27566
bool release = false;
27567
if (release = (hdc == IntPtr.Zero))
27569
hdc = GetDC(IntPtr.Zero);
27571
if (hdc != IntPtr.Zero)
27573
hbitmap = CreateDIBitmap(
27575
GetInfoHeader(dib),
27586
ReleaseDC(IntPtr.Zero, hdc);
27593
/// Creates a FreeImage DIB from a Device Context/Compatible Bitmap.
27595
/// <param name="hbitmap">Handle to the bitmap.</param>
27596
/// <param name="hdc">Handle to a device context.</param>
27597
/// <returns>Handle to a FreeImage bitmap.</returns>
27598
/// <exception cref="ArgumentNullException">
27599
/// <paramref name="hbitmap"/> is null.</exception>
27600
public unsafe static FIBITMAP CreateFromHbitmap(IntPtr hbitmap, IntPtr hdc)
27602
if (hbitmap == IntPtr.Zero)
27604
throw new ArgumentNullException("hbitmap");
27607
FIBITMAP dib = new FIBITMAP();
27612
if (GetObject(hbitmap, sizeof(BITMAP), (IntPtr)(&bm)) != 0)
27614
dib = Allocate(bm.bmWidth, bm.bmHeight, bm.bmBitsPixel, 0, 0, 0);
27617
colors = GetColorsUsed(dib);
27618
if (release = (hdc == IntPtr.Zero))
27620
hdc = GetDC(IntPtr.Zero);
27629
DIB_RGB_COLORS) != 0)
27633
BITMAPINFOHEADER* bmih = (BITMAPINFOHEADER*)GetInfo(dib);
27634
bmih[0].biClrImportant = bmih[0].biClrUsed = colors;
27643
ReleaseDC(IntPtr.Zero, hdc);
27652
/// Frees a bitmap handle.
27654
/// <param name="hbitmap">Handle to a bitmap.</param>
27655
/// <returns>True on success, false on failure.</returns>
27656
public static bool FreeHbitmap(IntPtr hbitmap)
27658
return DeleteObject(hbitmap);
27663
#region Bitmap information functions
27666
/// Retrieves a DIB's resolution in X-direction measured in 'dots per inch' (DPI) and not in
27667
/// 'dots per meter'.
27669
/// <param name="dib">Handle to a FreeImage bitmap.</param>
27670
/// <returns>The resolution in 'dots per inch'.</returns>
27671
/// <exception cref="ArgumentNullException">
27672
/// <paramref name="dib"/> is null.</exception>
27673
public static uint GetResolutionX(FIBITMAP dib)
27677
throw new ArgumentNullException("dib");
27679
return (uint)(0.5d + 0.0254d * GetDotsPerMeterX(dib));
27683
/// Retrieves a DIB's resolution in Y-direction measured in 'dots per inch' (DPI) and not in
27684
/// 'dots per meter'.
27686
/// <param name="dib">Handle to a FreeImage bitmap.</param>
27687
/// <returns>The resolution in 'dots per inch'.</returns>
27688
/// <exception cref="ArgumentNullException">
27689
/// <paramref name="dib"/> is null.</exception>
27690
public static uint GetResolutionY(FIBITMAP dib)
27694
throw new ArgumentNullException("dib");
27696
return (uint)(0.5d + 0.0254d * GetDotsPerMeterY(dib));
27700
/// Sets a DIB's resolution in X-direction measured in 'dots per inch' (DPI) and not in
27701
/// 'dots per meter'.
27703
/// <param name="dib">Handle to a FreeImage bitmap.</param>
27704
/// <param name="res">The new resolution in 'dots per inch'.</param>
27705
/// <exception cref="ArgumentNullException">
27706
/// <paramref name="dib"/> is null.</exception>
27707
public static void SetResolutionX(FIBITMAP dib, uint res)
27711
throw new ArgumentNullException("dib");
27713
SetDotsPerMeterX(dib, (uint)((double)res / 0.0254d + 0.5d));
27717
/// Sets a DIB's resolution in Y-direction measured in 'dots per inch' (DPI) and not in
27718
/// 'dots per meter'.
27720
/// <param name="dib">Handle to a FreeImage bitmap.</param>
27721
/// <param name="res">The new resolution in 'dots per inch'.</param>
27722
/// <exception cref="ArgumentNullException">
27723
/// <paramref name="dib"/> is null.</exception>
27724
public static void SetResolutionY(FIBITMAP dib, uint res)
27728
throw new ArgumentNullException("dib");
27730
SetDotsPerMeterY(dib, (uint)((double)res / 0.0254d + 0.5d));
27734
/// Returns whether the image is a greyscale image or not.
27735
/// The function scans all colors in the bitmaps palette for entries where
27736
/// red, green and blue are not all the same (not a grey color).
27737
/// Supports 1-, 4- and 8-bit bitmaps.
27739
/// <param name="dib">Handle to a FreeImage bitmap.</param>
27740
/// <returns>True if the image is a greyscale image, else false.</returns>
27741
/// <exception cref="ArgumentNullException">
27742
/// <paramref name="dib"/> is null.</exception>
27743
public static unsafe bool IsGreyscaleImage(FIBITMAP dib)
27747
throw new ArgumentNullException("dib");
27749
bool result = true;
27750
uint bpp = GetBPP(dib);
27756
RGBQUAD* palette = (RGBQUAD*)GetPalette(dib);
27757
uint paletteLength = GetColorsUsed(dib);
27758
for (int i = 0; i < paletteLength; i++)
27760
if (palette[i].rgbRed != palette[i].rgbGreen ||
27761
palette[i].rgbRed != palette[i].rgbBlue)
27776
/// Returns a structure that represents the palette of a FreeImage bitmap.
27778
/// <param name="dib">Handle to a FreeImage bitmap.</param>
27779
/// <returns>A structure representing the bitmaps palette.</returns>
27780
/// <exception cref="ArgumentNullException">
27781
/// <paramref name="dib"/> is null.</exception>
27782
public static Palette GetPaletteEx(FIBITMAP dib)
27784
return new Palette(dib);
27788
/// Returns the <see cref="BITMAPINFOHEADER"/> structure of a FreeImage bitmap.
27789
/// The structure is a copy, so changes will have no effect on
27790
/// the bitmap itself.
27792
/// <param name="dib">Handle to a FreeImage bitmap.</param>
27793
/// <returns><see cref="BITMAPINFOHEADER"/> structure of the bitmap.</returns>
27794
/// <exception cref="ArgumentNullException">
27795
/// <paramref name="dib"/> is null.</exception>
27796
public static unsafe BITMAPINFOHEADER GetInfoHeaderEx(FIBITMAP dib)
27800
throw new ArgumentNullException("dib");
27802
return *(BITMAPINFOHEADER*)GetInfoHeader(dib);
27806
/// Returns the <see cref="BITMAPINFO"/> structure of a FreeImage bitmap.
27807
/// The structure is a copy, so changes will have no effect on
27808
/// the bitmap itself.
27810
/// <param name="dib">Handle to a FreeImage bitmap.</param>
27811
/// <returns><see cref="BITMAPINFO"/> structure of the bitmap.</returns>
27812
/// <exception cref="ArgumentNullException">
27813
/// <paramref name="dib"/> is null.</exception>
27814
public static BITMAPINFO GetInfoEx(FIBITMAP dib)
27818
throw new ArgumentNullException("dib");
27820
BITMAPINFO result = new BITMAPINFO();
27821
result.bmiHeader = GetInfoHeaderEx(dib);
27822
IntPtr ptr = GetPalette(dib);
27823
if (ptr == IntPtr.Zero)
27825
result.bmiColors = new RGBQUAD[0];
27829
result.bmiColors = new MemoryArray<RGBQUAD>(ptr, (int)result.bmiHeader.biClrUsed).Data;
27835
/// Returns the pixelformat of the bitmap.
27837
/// <param name="dib">Handle to a FreeImage bitmap.</param>
27838
/// <returns><see cref="System.Drawing.Imaging.PixelFormat"/> of the bitmap.</returns>
27839
/// <exception cref="ArgumentNullException">
27840
/// <paramref name="dib"/> is null.</exception>
27841
public static PixelFormat GetPixelFormat(FIBITMAP dib)
27845
throw new ArgumentNullException("dib");
27848
PixelFormat result = PixelFormat.Undefined;
27850
if (GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP)
27852
switch (GetBPP(dib))
27855
result = PixelFormat.Format1bppIndexed;
27858
result = PixelFormat.Format4bppIndexed;
27861
result = PixelFormat.Format8bppIndexed;
27864
if ((GetBlueMask(dib) == FI16_565_BLUE_MASK) &&
27865
(GetGreenMask(dib) == FI16_565_GREEN_MASK) &&
27866
(GetRedMask(dib) == FI16_565_RED_MASK))
27868
result = PixelFormat.Format16bppRgb565;
27870
if ((GetBlueMask(dib) == FI16_555_BLUE_MASK) &&
27871
(GetGreenMask(dib) == FI16_555_GREEN_MASK) &&
27872
(GetRedMask(dib) == FI16_555_RED_MASK))
27874
result = PixelFormat.Format16bppRgb555;
27878
result = PixelFormat.Format24bppRgb;
27881
result = PixelFormat.Format32bppArgb;
27889
/// Retrieves all parameters needed to create a new FreeImage bitmap from
27890
/// the format of a .NET <see cref="System.Drawing.Image"/>.
27892
/// <param name="format">The <see cref="System.Drawing.Imaging.PixelFormat"/>
27893
/// of the .NET <see cref="System.Drawing.Image"/>.</param>
27894
/// <param name="type">Returns the type used for the new bitmap.</param>
27895
/// <param name="bpp">Returns the color depth for the new bitmap.</param>
27896
/// <param name="red_mask">Returns the red_mask for the new bitmap.</param>
27897
/// <param name="green_mask">Returns the green_mask for the new bitmap.</param>
27898
/// <param name="blue_mask">Returns the blue_mask for the new bitmap.</param>
27899
/// <returns>True in case a matching conversion exists; else false.
27901
public static bool GetFormatParameters(
27902
PixelFormat format,
27903
out FREE_IMAGE_TYPE type,
27906
out uint green_mask,
27907
out uint blue_mask)
27909
bool result = false;
27910
type = FREE_IMAGE_TYPE.FIT_UNKNOWN;
27917
case PixelFormat.Format1bppIndexed:
27918
type = FREE_IMAGE_TYPE.FIT_BITMAP;
27922
case PixelFormat.Format4bppIndexed:
27923
type = FREE_IMAGE_TYPE.FIT_BITMAP;
27927
case PixelFormat.Format8bppIndexed:
27928
type = FREE_IMAGE_TYPE.FIT_BITMAP;
27932
case PixelFormat.Format16bppRgb565:
27933
type = FREE_IMAGE_TYPE.FIT_BITMAP;
27935
red_mask = FI16_565_RED_MASK;
27936
green_mask = FI16_565_GREEN_MASK;
27937
blue_mask = FI16_565_BLUE_MASK;
27940
case PixelFormat.Format16bppRgb555:
27941
case PixelFormat.Format16bppArgb1555:
27942
type = FREE_IMAGE_TYPE.FIT_BITMAP;
27944
red_mask = FI16_555_RED_MASK;
27945
green_mask = FI16_555_GREEN_MASK;
27946
blue_mask = FI16_555_BLUE_MASK;
27949
case PixelFormat.Format24bppRgb:
27950
type = FREE_IMAGE_TYPE.FIT_BITMAP;
27952
red_mask = FI_RGBA_RED_MASK;
27953
green_mask = FI_RGBA_GREEN_MASK;
27954
blue_mask = FI_RGBA_BLUE_MASK;
27957
case PixelFormat.Format32bppRgb:
27958
case PixelFormat.Format32bppArgb:
27959
case PixelFormat.Format32bppPArgb:
27960
type = FREE_IMAGE_TYPE.FIT_BITMAP;
27962
red_mask = FI_RGBA_RED_MASK;
27963
green_mask = FI_RGBA_GREEN_MASK;
27964
blue_mask = FI_RGBA_BLUE_MASK;
27967
case PixelFormat.Format16bppGrayScale:
27968
type = FREE_IMAGE_TYPE.FIT_UINT16;
27972
case PixelFormat.Format48bppRgb:
27973
type = FREE_IMAGE_TYPE.FIT_RGB16;
27977
case PixelFormat.Format64bppArgb:
27978
case PixelFormat.Format64bppPArgb:
27979
type = FREE_IMAGE_TYPE.FIT_RGBA16;
27988
/// Returns the <see cref="FREE_IMAGE_FORMAT"/> for the specified
27989
/// <see cref="ImageFormat"/>.
27991
/// <param name="imageFormat">The <see cref="ImageFormat"/>
27992
/// for which to return the corresponding <see cref="FREE_IMAGE_FORMAT"/>.</param>
27993
/// <returns>The <see cref="FREE_IMAGE_FORMAT"/> for the specified
27994
/// <see cref="ImageFormat"/></returns>
27995
public static FREE_IMAGE_FORMAT GetFormat(ImageFormat imageFormat)
27997
if (imageFormat != null)
27999
if (imageFormat.Equals(ImageFormat.Bmp))
28000
return FREE_IMAGE_FORMAT.FIF_BMP;
28001
if (imageFormat.Equals(ImageFormat.Gif))
28002
return FREE_IMAGE_FORMAT.FIF_GIF;
28003
if (imageFormat.Equals(ImageFormat.Icon))
28004
return FREE_IMAGE_FORMAT.FIF_ICO;
28005
if (imageFormat.Equals(ImageFormat.Jpeg))
28006
return FREE_IMAGE_FORMAT.FIF_JPEG;
28007
if (imageFormat.Equals(ImageFormat.Png))
28008
return FREE_IMAGE_FORMAT.FIF_PNG;
28009
if (imageFormat.Equals(ImageFormat.Tiff))
28010
return FREE_IMAGE_FORMAT.FIF_TIFF;
28012
return FREE_IMAGE_FORMAT.FIF_UNKNOWN;
28016
/// Retrieves all parameters needed to create a new FreeImage bitmap from
28017
/// raw bits <see cref="System.Drawing.Image"/>.
28019
/// <param name="type">The <see cref="FREE_IMAGE_TYPE"/>
28020
/// of the data in memory.</param>
28021
/// <param name="bpp">The color depth for the data.</param>
28022
/// <param name="red_mask">Returns the red_mask for the data.</param>
28023
/// <param name="green_mask">Returns the green_mask for the data.</param>
28024
/// <param name="blue_mask">Returns the blue_mask for the data.</param>
28025
/// <returns>True in case a matching conversion exists; else false.
28027
public static bool GetTypeParameters(
28028
FREE_IMAGE_TYPE type,
28031
out uint green_mask,
28032
out uint blue_mask)
28034
bool result = false;
28040
case FREE_IMAGE_TYPE.FIT_BITMAP:
28050
red_mask = FI16_555_RED_MASK;
28051
green_mask = FI16_555_GREEN_MASK;
28052
blue_mask = FI16_555_BLUE_MASK;
28057
red_mask = FI_RGBA_RED_MASK;
28058
green_mask = FI_RGBA_GREEN_MASK;
28059
blue_mask = FI_RGBA_BLUE_MASK;
28063
case FREE_IMAGE_TYPE.FIT_UNKNOWN:
28073
/// Compares two FreeImage bitmaps.
28075
/// <param name="dib1">The first bitmap to compare.</param>
28076
/// <param name="dib2">The second bitmap to compare.</param>
28077
/// <param name="flags">Determines which components of the bitmaps will be compared.</param>
28078
/// <returns>True in case both bitmaps match the compare conditions, false otherwise.</returns>
28079
public static bool Compare(FIBITMAP dib1, FIBITMAP dib2, FREE_IMAGE_COMPARE_FLAGS flags)
28081
// Check whether one bitmap is null
28082
if (dib1.IsNull ^ dib2.IsNull)
28086
// Check whether both pointers are the same
28091
if (((flags & FREE_IMAGE_COMPARE_FLAGS.HEADER) > 0) && (!CompareHeader(dib1, dib2)))
28095
if (((flags & FREE_IMAGE_COMPARE_FLAGS.PALETTE) > 0) && (!ComparePalette(dib1, dib2)))
28099
if (((flags & FREE_IMAGE_COMPARE_FLAGS.DATA) > 0) && (!CompareData(dib1, dib2)))
28103
if (((flags & FREE_IMAGE_COMPARE_FLAGS.METADATA) > 0) && (!CompareMetadata(dib1, dib2)))
28110
private static unsafe bool CompareHeader(FIBITMAP dib1, FIBITMAP dib2)
28112
IntPtr i1 = GetInfoHeader(dib1);
28113
IntPtr i2 = GetInfoHeader(dib2);
28114
return CompareMemory((void*)i1, (void*)i2, sizeof(BITMAPINFOHEADER));
28117
private static unsafe bool ComparePalette(FIBITMAP dib1, FIBITMAP dib2)
28119
IntPtr pal1 = GetPalette(dib1), pal2 = GetPalette(dib2);
28120
bool hasPalette1 = pal1 != IntPtr.Zero;
28121
bool hasPalette2 = pal2 != IntPtr.Zero;
28122
if (hasPalette1 ^ hasPalette2)
28130
uint colors = GetColorsUsed(dib1);
28131
if (colors != GetColorsUsed(dib2))
28135
return CompareMemory((void*)pal1, (void*)pal2, sizeof(RGBQUAD) * colors);
28138
private static unsafe bool CompareData(FIBITMAP dib1, FIBITMAP dib2)
28140
uint width = GetWidth(dib1);
28141
if (width != GetWidth(dib2))
28145
uint height = GetHeight(dib1);
28146
if (height != GetHeight(dib2))
28150
uint bpp = GetBPP(dib1);
28151
if (bpp != GetBPP(dib2))
28155
if (GetColorType(dib1) != GetColorType(dib2))
28159
FREE_IMAGE_TYPE type = GetImageType(dib1);
28160
if (type != GetImageType(dib2))
28164
if (GetRedMask(dib1) != GetRedMask(dib2))
28168
if (GetGreenMask(dib1) != GetGreenMask(dib2))
28172
if (GetBlueMask(dib1) != GetBlueMask(dib2))
28180
uint line = GetLine(dib1);
28182
if (type == FREE_IMAGE_TYPE.FIT_BITMAP)
28187
for (int i = 0; i < height; i++)
28189
ptr1 = (byte*)GetScanLine(dib1, i);
28190
ptr2 = (byte*)GetScanLine(dib2, i);
28191
if (!CompareMemory(ptr1, ptr2, line))
28198
for (int i = 0; i < height; i++)
28200
ptr1 = (byte*)GetScanLine(dib1, i);
28201
ptr2 = (byte*)GetScanLine(dib2, i);
28202
if (!CompareMemory(ptr1, ptr2, line))
28209
short* sPtr1, sPtr2;
28210
short mask = (short)(GetRedMask(dib1) | GetGreenMask(dib1) | GetBlueMask(dib1));
28213
for (int i = 0; i < height; i++)
28215
sPtr1 = (short*)GetScanLine(dib1, i);
28216
sPtr2 = (short*)GetScanLine(dib2, i);
28217
if (!CompareMemory(sPtr1, sPtr1, line))
28225
for (int i = 0; i < height; i++)
28227
sPtr1 = (short*)GetScanLine(dib1, i);
28228
sPtr2 = (short*)GetScanLine(dib2, i);
28229
for (int x = 0; x < width; x++)
28231
if ((sPtr1[x] & mask) != (sPtr2[x] & mask))
28240
for (int i = 0; i < height; i++)
28242
ptr1 = (byte*)GetScanLine(dib1, i);
28243
ptr2 = (byte*)GetScanLine(dib2, i);
28244
if (!CompareMemory(ptr1, ptr2, line))
28251
fullBytes = (int)width / 2;
28252
shift = (width % 2) == 0 ? 8 : 4;
28253
for (int i = 0; i < height; i++)
28255
ptr1 = (byte*)GetScanLine(dib1, i);
28256
ptr2 = (byte*)GetScanLine(dib2, i);
28257
if (fullBytes != 0)
28259
if (!CompareMemory(ptr1, ptr2, fullBytes))
28268
if ((ptr1[0] >> shift) != (ptr2[0] >> shift))
28276
fullBytes = (int)width / 8;
28277
shift = 8 - ((int)width % 8);
28278
for (int i = 0; i < height; i++)
28280
ptr1 = (byte*)GetScanLine(dib1, i);
28281
ptr2 = (byte*)GetScanLine(dib2, i);
28282
if (fullBytes != 0)
28284
if (!CompareMemory(ptr1, ptr2, fullBytes))
28293
if ((ptr1[0] >> shift) != (ptr2[0] >> shift))
28301
throw new NotSupportedException("Only 1, 4, 8, 16, 24 and 32 bpp bitmaps are supported.");
28306
for (int i = 0; i < height; i++)
28308
ptr1 = (byte*)GetScanLine(dib1, i);
28309
ptr2 = (byte*)GetScanLine(dib2, i);
28310
if (!CompareMemory(ptr1, ptr2, line))
28319
private static bool CompareMetadata(FIBITMAP dib1, FIBITMAP dib2)
28321
MetadataTag tag1, tag2;
28323
foreach (FREE_IMAGE_MDMODEL metadataModel in FREE_IMAGE_MDMODELS)
28325
if (GetMetadataCount(metadataModel, dib1) !=
28326
GetMetadataCount(metadataModel, dib2))
28330
if (GetMetadataCount(metadataModel, dib1) == 0)
28335
FIMETADATA mdHandle = FindFirstMetadata(metadataModel, dib1, out tag1);
28336
if (mdHandle.IsNull)
28342
if ((!GetMetadata(metadataModel, dib2, tag1.Key, out tag2)) || (tag1 != tag2))
28344
FindCloseMetadata(mdHandle);
28348
while (FindNextMetadata(mdHandle, out tag1));
28349
FindCloseMetadata(mdHandle);
28356
/// Returns the FreeImage bitmap's transparency table.
28357
/// The array is empty in case the bitmap has no transparency table.
28359
/// <param name="dib">Handle to a FreeImage bitmap.</param>
28360
/// <returns>The FreeImage bitmap's transparency table.</returns>
28361
/// <exception cref="ArgumentNullException">
28362
/// <paramref name="dib"/> is null.</exception>
28363
public static unsafe byte[] GetTransparencyTableEx(FIBITMAP dib)
28367
throw new ArgumentNullException("dib");
28369
uint count = GetTransparencyCount(dib);
28370
byte[] result = new byte[count];
28371
byte* ptr = (byte*)GetTransparencyTable(dib);
28372
fixed (byte* dst = result)
28374
CopyMemory(dst, ptr, count);
28380
/// Set the FreeImage bitmap's transparency table. Only affects palletised bitmaps.
28382
/// <param name="dib">Handle to a FreeImage bitmap.</param>
28383
/// <param name="table">The FreeImage bitmap's new transparency table.</param>
28384
/// <exception cref="ArgumentNullException">
28385
/// <paramref name="dib"/> or <paramref name="table"/> is null.</exception>
28386
public static void SetTransparencyTable(FIBITMAP dib, byte[] table)
28390
throw new ArgumentNullException("dib");
28394
throw new ArgumentNullException("table");
28396
SetTransparencyTable(dib, table, table.Length);
28400
/// This function returns the number of unique colors actually used by the
28401
/// specified 1-, 4-, 8-, 16-, 24- or 32-bit image. This might be different from
28402
/// what function FreeImage_GetColorsUsed() returns, which actually returns the
28403
/// palette size for palletised images. Works for
28404
/// <see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/> type images only.
28406
/// <param name="dib">Handle to a FreeImage bitmap.</param>
28407
/// <returns>Returns the number of unique colors used by the image specified or
28408
/// zero, if the image type cannot be handled.</returns>
28409
/// <exception cref="ArgumentNullException">
28410
/// <paramref name="dib"/> is null.</exception>
28411
public static unsafe int GetUniqueColors(FIBITMAP dib)
28415
throw new ArgumentNullException("dib");
28420
if (GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP)
28426
int width = (int)GetWidth(dib);
28427
int height = (int)GetHeight(dib);
28429
switch (GetBPP(dib))
28434
lut = CreateShrunkenPaletteLUT(dib, out uniquePalEnts);
28435
if (uniquePalEnts == 1)
28440
if ((*(byte*)GetScanLine(dib, 0) & 0x80) == 0)
28442
for (int y = 0; y < height; y++)
28444
byte* scanline = (byte*)GetScanLine(dib, y);
28446
for (int x = 0; x < width; x++)
28448
if ((scanline[x / 8] & mask) > 0)
28452
mask = (mask == 0x1) ? 0x80 : (mask >> 1);
28458
for (int y = 0; y < height; y++)
28460
byte* scanline = (byte*)GetScanLine(dib, y);
28462
for (int x = 0; x < width; x++)
28464
if ((scanline[x / 8] & mask) == 0)
28468
mask = (mask == 0x1) ? 0x80 : (mask >> 1);
28476
bitArray = new BitArray(0x10);
28477
lut = CreateShrunkenPaletteLUT(dib, out uniquePalEnts);
28478
if (uniquePalEnts == 1)
28484
for (int y = 0; (y < height) && (result < uniquePalEnts); y++)
28486
byte* scanline = (byte*)GetScanLine(dib, y);
28488
for (int x = 0; (x < width) && (result < uniquePalEnts); x++)
28492
hashcode = lut[scanline[x / 2] >> 4];
28496
hashcode = lut[scanline[x / 2] & 0xF];
28499
if (!bitArray[hashcode])
28501
bitArray[hashcode] = true;
28510
bitArray = new BitArray(0x100);
28511
lut = CreateShrunkenPaletteLUT(dib, out uniquePalEnts);
28512
if (uniquePalEnts == 1)
28518
for (int y = 0; (y < height) && (result < uniquePalEnts); y++)
28520
byte* scanline = (byte*)GetScanLine(dib, y);
28521
for (int x = 0; (x < width) && (result < uniquePalEnts); x++)
28523
hashcode = lut[scanline[x]];
28524
if (!bitArray[hashcode])
28526
bitArray[hashcode] = true;
28535
bitArray = new BitArray(0x10000);
28537
for (int y = 0; y < height; y++)
28539
short* scanline = (short*)GetScanLine(dib, y);
28540
for (int x = 0; x < width; x++, scanline++)
28542
hashcode = *scanline;
28543
if (!bitArray[hashcode])
28545
bitArray[hashcode] = true;
28554
bitArray = new BitArray(0x1000000);
28556
for (int y = 0; y < height; y++)
28558
byte* scanline = (byte*)GetScanLine(dib, y);
28559
for (int x = 0; x < width; x++, scanline += 3)
28561
hashcode = *((int*)scanline) & 0x00FFFFFF;
28562
if (!bitArray[hashcode])
28564
bitArray[hashcode] = true;
28573
bitArray = new BitArray(0x1000000);
28575
for (int y = 0; y < height; y++)
28577
int* scanline = (int*)GetScanLine(dib, y);
28578
for (int x = 0; x < width; x++, scanline++)
28580
hashcode = *scanline & 0x00FFFFFF;
28581
if (!bitArray[hashcode])
28583
bitArray[hashcode] = true;
28595
/// Verifies whether the FreeImage bitmap is 16bit 555.
28597
/// <param name="dib">The FreeImage bitmap to verify.</param>
28598
/// <returns><b>true</b> if the bitmap is RGB16-555; otherwise <b>false</b>.</returns>
28599
public static bool IsRGB555(FIBITMAP dib)
28601
return ((GetRedMask(dib) == FI16_555_RED_MASK) &&
28602
(GetGreenMask(dib) == FI16_555_GREEN_MASK) &&
28603
(GetBlueMask(dib) == FI16_555_BLUE_MASK));
28607
/// Verifies whether the FreeImage bitmap is 16bit 565.
28609
/// <param name="dib">The FreeImage bitmap to verify.</param>
28610
/// <returns><b>true</b> if the bitmap is RGB16-565; otherwise <b>false</b>.</returns>
28611
public static bool IsRGB565(FIBITMAP dib)
28613
return ((GetRedMask(dib) == FI16_565_RED_MASK) &&
28614
(GetGreenMask(dib) == FI16_565_GREEN_MASK) &&
28615
(GetBlueMask(dib) == FI16_565_BLUE_MASK));
28620
#region ICC profile functions
28623
/// Creates a new ICC-Profile for a FreeImage bitmap.
28625
/// <param name="dib">Handle to a FreeImage bitmap.</param>
28626
/// <param name="data">The data of the new ICC-Profile.</param>
28627
/// <returns>The new ICC-Profile of the bitmap.</returns>
28628
/// <exception cref="ArgumentNullException">
28629
/// <paramref name="dib"/> is null.</exception>
28630
public static FIICCPROFILE CreateICCProfileEx(FIBITMAP dib, byte[] data)
28632
return new FIICCPROFILE(dib, data);
28636
/// Creates a new ICC-Profile for a FreeImage bitmap.
28638
/// <param name="dib">Handle to a FreeImage bitmap.</param>
28639
/// <param name="data">The data of the new ICC-Profile.</param>
28640
/// <param name="size">The number of bytes of <paramref name="data"/> to use.</param>
28641
/// <returns>The new ICC-Profile of the FreeImage bitmap.</returns>
28642
/// <exception cref="ArgumentNullException">
28643
/// <paramref name="dib"/> is null.</exception>
28644
public static FIICCPROFILE CreateICCProfileEx(FIBITMAP dib, byte[] data, int size)
28646
return new FIICCPROFILE(dib, data, size);
28651
#region Conversion functions
28654
/// Converts a FreeImage bitmap from one color depth to another.
28655
/// If the conversion fails the original FreeImage bitmap is returned.
28657
/// <param name="dib">Handle to a FreeImage bitmap.</param>
28658
/// <param name="conversion">The desired output format.</param>
28659
/// <returns>Handle to a FreeImage bitmap.</returns>
28660
/// <exception cref="ArgumentNullException">
28661
/// <paramref name="dib"/> is null.</exception>
28662
public static FIBITMAP ConvertColorDepth(
28664
FREE_IMAGE_COLOR_DEPTH conversion)
28666
return ConvertColorDepth(
28670
FREE_IMAGE_DITHER.FID_FS,
28671
FREE_IMAGE_QUANTIZE.FIQ_WUQUANT,
28676
/// Converts a FreeImage bitmap from one color depth to another.
28677
/// If the conversion fails the original FreeImage bitmap is returned.
28679
/// <param name="dib">Handle to a FreeImage bitmap.</param>
28680
/// <param name="conversion">The desired output format.</param>
28681
/// <param name="unloadSource">When true the structure will be unloaded on success.</param>
28682
/// <returns>Handle to a FreeImage bitmap.</returns>
28683
/// <exception cref="ArgumentNullException">
28684
/// <paramref name="dib"/> is null.</exception>
28685
public static FIBITMAP ConvertColorDepth(
28687
FREE_IMAGE_COLOR_DEPTH conversion,
28690
return ConvertColorDepth(
28694
FREE_IMAGE_DITHER.FID_FS,
28695
FREE_IMAGE_QUANTIZE.FIQ_WUQUANT,
28700
/// Converts a FreeImage bitmap from one color depth to another.
28701
/// If the conversion fails the original FreeImage bitmap is returned.
28703
/// <param name="dib">Handle to a FreeImage bitmap.</param>
28704
/// <param name="conversion">The desired output format.</param>
28705
/// <param name="threshold">Threshold value when converting with
28706
/// <see cref="FREE_IMAGE_COLOR_DEPTH.FICD_01_BPP_THRESHOLD"/>.</param>
28707
/// <returns>Handle to a FreeImage bitmap.</returns>
28708
/// <exception cref="ArgumentNullException">
28709
/// <paramref name="dib"/> is null.</exception>
28710
public static FIBITMAP ConvertColorDepth(
28712
FREE_IMAGE_COLOR_DEPTH conversion,
28715
return ConvertColorDepth(
28719
FREE_IMAGE_DITHER.FID_FS,
28720
FREE_IMAGE_QUANTIZE.FIQ_WUQUANT,
28725
/// Converts a FreeImage bitmap from one color depth to another.
28726
/// If the conversion fails the original FreeImage bitmap is returned.
28728
/// <param name="dib">Handle to a FreeImage bitmap.</param>
28729
/// <param name="conversion">The desired output format.</param>
28730
/// <param name="ditherMethod">Dither algorithm when converting
28731
/// with <see cref="FREE_IMAGE_COLOR_DEPTH.FICD_01_BPP_DITHER"/>.</param>
28732
/// <returns>Handle to a FreeImage bitmap.</returns>
28733
/// <exception cref="ArgumentNullException">
28734
/// <paramref name="dib"/> is null.</exception>
28735
public static FIBITMAP ConvertColorDepth(
28737
FREE_IMAGE_COLOR_DEPTH conversion,
28738
FREE_IMAGE_DITHER ditherMethod)
28740
return ConvertColorDepth(
28745
FREE_IMAGE_QUANTIZE.FIQ_WUQUANT,
28751
/// Converts a FreeImage bitmap from one color depth to another.
28752
/// If the conversion fails the original FreeImage bitmap is returned.
28754
/// <param name="dib">Handle to a FreeImage bitmap.</param>
28755
/// <param name="conversion">The desired output format.</param>
28756
/// <param name="quantizationMethod">The quantization algorithm for conversion to 8-bit color depth.</param>
28757
/// <returns>Handle to a FreeImage bitmap.</returns>
28758
/// <exception cref="ArgumentNullException">
28759
/// <paramref name="dib"/> is null.</exception>
28760
public static FIBITMAP ConvertColorDepth(
28762
FREE_IMAGE_COLOR_DEPTH conversion,
28763
FREE_IMAGE_QUANTIZE quantizationMethod)
28765
return ConvertColorDepth(
28769
FREE_IMAGE_DITHER.FID_FS,
28770
quantizationMethod,
28775
/// Converts a FreeImage bitmap from one color depth to another.
28776
/// If the conversion fails the original FreeImage bitmap is returned.
28778
/// <param name="dib">Handle to a FreeImage bitmap.</param>
28779
/// <param name="conversion">The desired output format.</param>
28780
/// <param name="threshold">Threshold value when converting with
28781
/// <see cref="FREE_IMAGE_COLOR_DEPTH.FICD_01_BPP_THRESHOLD"/>.</param>
28782
/// <param name="unloadSource">When true the structure will be unloaded on success.</param>
28783
/// <returns>Handle to a FreeImage bitmap.</returns>
28784
/// <exception cref="ArgumentNullException">
28785
/// <paramref name="dib"/> is null.</exception>
28786
public static FIBITMAP ConvertColorDepth(
28788
FREE_IMAGE_COLOR_DEPTH conversion,
28792
return ConvertColorDepth(
28796
FREE_IMAGE_DITHER.FID_FS,
28797
FREE_IMAGE_QUANTIZE.FIQ_WUQUANT,
28802
/// Converts a FreeImage bitmap from one color depth to another.
28803
/// If the conversion fails the original FreeImage bitmap is returned.
28805
/// <param name="dib">Handle to a FreeImage bitmap.</param>
28806
/// <param name="conversion">The desired output format.</param>
28807
/// <param name="ditherMethod">Dither algorithm when converting with
28808
/// <see cref="FREE_IMAGE_COLOR_DEPTH.FICD_01_BPP_DITHER"/>.</param>
28809
/// <param name="unloadSource">When true the structure will be unloaded on success.</param>
28810
/// <returns>Handle to a FreeImage bitmap.</returns>
28811
/// <exception cref="ArgumentNullException">
28812
/// <paramref name="dib"/> is null.</exception>
28813
public static FIBITMAP ConvertColorDepth(
28815
FREE_IMAGE_COLOR_DEPTH conversion,
28816
FREE_IMAGE_DITHER ditherMethod,
28819
return ConvertColorDepth(
28824
FREE_IMAGE_QUANTIZE.FIQ_WUQUANT,
28830
/// Converts a FreeImage bitmap from one color depth to another.
28831
/// If the conversion fails the original FreeImage bitmap is returned.
28833
/// <param name="dib">Handle to a FreeImage bitmap.</param>
28834
/// <param name="conversion">The desired output format.</param>
28835
/// <param name="quantizationMethod">The quantization algorithm for conversion to 8-bit color depth.</param>
28836
/// <param name="unloadSource">When true the structure will be unloaded on success.</param>
28837
/// <returns>Handle to a FreeImage bitmap.</returns>
28838
/// <exception cref="ArgumentNullException">
28839
/// <paramref name="dib"/> is null.</exception>
28840
public static FIBITMAP ConvertColorDepth(
28842
FREE_IMAGE_COLOR_DEPTH conversion,
28843
FREE_IMAGE_QUANTIZE quantizationMethod,
28846
return ConvertColorDepth(
28850
FREE_IMAGE_DITHER.FID_FS,
28851
quantizationMethod,
28856
/// Converts a FreeImage bitmap from one color depth to another.
28857
/// If the conversion fails the original FreeImage bitmap is returned.
28859
/// <param name="dib">Handle to a FreeImage bitmap.</param>
28860
/// <param name="conversion">The desired output format.</param>
28861
/// <param name="threshold">Threshold value when converting with
28862
/// <see cref="FREE_IMAGE_COLOR_DEPTH.FICD_01_BPP_THRESHOLD"/>.</param>
28863
/// <param name="ditherMethod">Dither algorithm when converting with
28864
/// <see cref="FREE_IMAGE_COLOR_DEPTH.FICD_01_BPP_DITHER"/>.</param>
28865
/// <param name="quantizationMethod">The quantization algorithm for conversion to 8-bit color depth.</param>
28866
/// <param name="unloadSource">When true the structure will be unloaded on success.</param>
28867
/// <returns>Handle to a FreeImage bitmap.</returns>
28868
/// <exception cref="ArgumentNullException">
28869
/// <paramref name="dib"/> is null.</exception>
28870
internal static FIBITMAP ConvertColorDepth(
28872
FREE_IMAGE_COLOR_DEPTH conversion,
28874
FREE_IMAGE_DITHER ditherMethod,
28875
FREE_IMAGE_QUANTIZE quantizationMethod,
28880
throw new ArgumentNullException("dib");
28883
FIBITMAP result = new FIBITMAP();
28884
FIBITMAP dibTemp = new FIBITMAP();
28885
uint bpp = GetBPP(dib);
28886
bool reorderPalette = ((conversion & FREE_IMAGE_COLOR_DEPTH.FICD_REORDER_PALETTE) > 0);
28887
bool forceGreyscale = ((conversion & FREE_IMAGE_COLOR_DEPTH.FICD_FORCE_GREYSCALE) > 0);
28889
if (GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP)
28891
switch (conversion & (FREE_IMAGE_COLOR_DEPTH)0xFF)
28893
case FREE_IMAGE_COLOR_DEPTH.FICD_01_BPP_THRESHOLD:
28897
if (forceGreyscale)
28899
result = Threshold(dib, threshold);
28903
dibTemp = ConvertTo24Bits(dib);
28904
result = ColorQuantizeEx(dibTemp, quantizationMethod, 2, null, 1);
28910
bool isGreyscale = IsGreyscaleImage(dib);
28911
if ((forceGreyscale && (!isGreyscale)) ||
28912
(reorderPalette && isGreyscale))
28914
result = Threshold(dib, threshold);
28919
case FREE_IMAGE_COLOR_DEPTH.FICD_01_BPP_DITHER:
28923
if (forceGreyscale)
28925
result = Dither(dib, ditherMethod);
28929
dibTemp = ConvertTo24Bits(dib);
28930
result = ColorQuantizeEx(dibTemp, quantizationMethod, 2, null, 1);
28936
bool isGreyscale = IsGreyscaleImage(dib);
28937
if ((forceGreyscale && (!isGreyscale)) ||
28938
(reorderPalette && isGreyscale))
28940
result = Dither(dib, ditherMethod);
28945
case FREE_IMAGE_COLOR_DEPTH.FICD_04_BPP:
28949
// Special case when 1bpp and FIC_PALETTE
28950
if (forceGreyscale ||
28951
((bpp == 1) && (GetColorType(dib) == FREE_IMAGE_COLOR_TYPE.FIC_PALETTE)))
28953
dibTemp = ConvertToGreyscale(dib);
28954
result = ConvertTo4Bits(dibTemp);
28959
dibTemp = ConvertTo24Bits(dib);
28960
result = ColorQuantizeEx(dibTemp, quantizationMethod, 16, null, 4);
28966
bool isGreyscale = IsGreyscaleImage(dib);
28967
if ((forceGreyscale && (!isGreyscale)) ||
28968
(reorderPalette && isGreyscale))
28970
dibTemp = ConvertToGreyscale(dib);
28971
result = ConvertTo4Bits(dibTemp);
28978
case FREE_IMAGE_COLOR_DEPTH.FICD_08_BPP:
28982
if (forceGreyscale)
28984
result = ConvertToGreyscale(dib);
28988
dibTemp = ConvertTo24Bits(dib);
28989
result = ColorQuantize(dibTemp, quantizationMethod);
28995
bool isGreyscale = IsGreyscaleImage(dib);
28996
if ((forceGreyscale && (!isGreyscale)) || (reorderPalette && isGreyscale))
28998
result = ConvertToGreyscale(dib);
29003
case FREE_IMAGE_COLOR_DEPTH.FICD_16_BPP_555:
29005
if (forceGreyscale)
29007
dibTemp = ConvertToGreyscale(dib);
29008
result = ConvertTo16Bits555(dibTemp);
29011
else if (bpp != 16 || GetRedMask(dib) != FI16_555_RED_MASK || GetGreenMask(dib) != FI16_555_GREEN_MASK || GetBlueMask(dib) != FI16_555_BLUE_MASK)
29013
result = ConvertTo16Bits555(dib);
29017
case FREE_IMAGE_COLOR_DEPTH.FICD_16_BPP:
29019
if (forceGreyscale)
29021
dibTemp = ConvertToGreyscale(dib);
29022
result = ConvertTo16Bits565(dibTemp);
29025
else if (bpp != 16 || GetRedMask(dib) != FI16_565_RED_MASK || GetGreenMask(dib) != FI16_565_GREEN_MASK || GetBlueMask(dib) != FI16_565_BLUE_MASK)
29027
result = ConvertTo16Bits565(dib);
29031
case FREE_IMAGE_COLOR_DEPTH.FICD_24_BPP:
29033
if (forceGreyscale)
29035
dibTemp = ConvertToGreyscale(dib);
29036
result = ConvertTo24Bits(dibTemp);
29039
else if (bpp != 24)
29041
result = ConvertTo24Bits(dib);
29045
case FREE_IMAGE_COLOR_DEPTH.FICD_32_BPP:
29047
if (forceGreyscale)
29049
dibTemp = ConvertToGreyscale(dib);
29050
result = ConvertTo32Bits(dibTemp);
29053
else if (bpp != 32)
29055
result = ConvertTo32Bits(dib);
29074
/// ColorQuantizeEx is an extension to the <see cref="ColorQuantize(FIBITMAP, FREE_IMAGE_QUANTIZE)"/>
29075
/// method that provides additional options used to quantize a 24-bit image to any
29076
/// number of colors (up to 256), as well as quantize a 24-bit image using a
29077
/// provided palette.
29079
/// <param name="dib">Handle to a FreeImage bitmap.</param>
29080
/// <param name="quantize">Specifies the color reduction algorithm to be used.</param>
29081
/// <param name="PaletteSize">Size of the desired output palette.</param>
29082
/// <param name="ReservePalette">The provided palette.</param>
29083
/// <param name="minColorDepth"><b>true</b> to create a bitmap with the smallest possible
29084
/// color depth for the specified <paramref name="PaletteSize"/>.</param>
29085
/// <returns>Handle to a FreeImage bitmap.</returns>
29086
public static FIBITMAP ColorQuantizeEx(FIBITMAP dib, FREE_IMAGE_QUANTIZE quantize, int PaletteSize, RGBQUAD[] ReservePalette, bool minColorDepth)
29092
if (PaletteSize >= 256)
29094
else if (PaletteSize > 2)
29098
result = ColorQuantizeEx(dib, quantize, PaletteSize, ReservePalette, bpp);
29102
result = ColorQuantizeEx(dib, quantize, PaletteSize, ReservePalette, 8);
29108
/// ColorQuantizeEx is an extension to the <see cref="ColorQuantize(FIBITMAP, FREE_IMAGE_QUANTIZE)"/>
29109
/// method that provides additional options used to quantize a 24-bit image to any
29110
/// number of colors (up to 256), as well as quantize a 24-bit image using a
29111
/// partial or full provided palette.
29113
/// <param name="dib">Handle to a FreeImage bitmap.</param>
29114
/// <param name="quantize">Specifies the color reduction algorithm to be used.</param>
29115
/// <param name="PaletteSize">Size of the desired output palette.</param>
29116
/// <param name="ReservePalette">The provided palette.</param>
29117
/// <param name="bpp">The desired color depth of the created image.</param>
29118
/// <returns>Handle to a FreeImage bitmap.</returns>
29119
public static FIBITMAP ColorQuantizeEx(FIBITMAP dib, FREE_IMAGE_QUANTIZE quantize, int PaletteSize, RGBQUAD[] ReservePalette, int bpp)
29123
FIBITMAP result = FIBITMAP.Zero;
29124
FIBITMAP temp = FIBITMAP.Zero;
29125
int reservedSize = (ReservePalette == null) ? 0 : ReservePalette.Length;
29129
result = ColorQuantizeEx(dib, quantize, PaletteSize, reservedSize, ReservePalette);
29133
temp = ColorQuantizeEx(dib, quantize, Math.Min(16, PaletteSize), reservedSize, ReservePalette);
29136
result = Allocate((int)GetWidth(temp), (int)GetHeight(temp), 4, 0, 0, 0);
29137
CloneMetadata(result, temp);
29138
CopyMemory(GetPalette(result), GetPalette(temp), sizeof(RGBQUAD) * 16);
29140
for (int y = (int)GetHeight(temp) - 1; y >= 0; y--)
29142
Scanline<byte> srcScanline = new Scanline<byte>(temp, y);
29143
Scanline<FI4BIT> dstScanline = new Scanline<FI4BIT>(result, y);
29145
for (int x = (int)GetWidth(temp) - 1; x >= 0; x--)
29147
dstScanline[x] = srcScanline[x];
29154
temp = ColorQuantizeEx(dib, quantize, 2, reservedSize, ReservePalette);
29157
result = Allocate((int)GetWidth(temp), (int)GetHeight(temp), 1, 0, 0, 0);
29158
CloneMetadata(result, temp);
29159
CopyMemory(GetPalette(result), GetPalette(temp), sizeof(RGBQUAD) * 2);
29161
for (int y = (int)GetHeight(temp) - 1; y >= 0; y--)
29163
Scanline<byte> srcScanline = new Scanline<byte>(temp, y);
29164
Scanline<FI1BIT> dstScanline = new Scanline<FI1BIT>(result, y);
29166
for (int x = (int)GetWidth(temp) - 1; x >= 0; x--)
29168
dstScanline[x] = srcScanline[x];
29174
UnloadEx(ref temp);
29184
/// Copies metadata from one FreeImage bitmap to another.
29186
/// <param name="src">Source FreeImage bitmap containing the metadata.</param>
29187
/// <param name="dst">FreeImage bitmap to copy the metadata to.</param>
29188
/// <param name="flags">Flags to switch different copy modes.</param>
29189
/// <returns>Returns -1 on failure else the number of copied tags.</returns>
29190
/// <exception cref="ArgumentNullException">
29191
/// <paramref name="src"/> or <paramref name="dst"/> is null.</exception>
29192
public static int CloneMetadataEx(FIBITMAP src, FIBITMAP dst, FREE_IMAGE_METADATA_COPY flags)
29196
throw new ArgumentNullException("src");
29200
throw new ArgumentNullException("dst");
29203
FITAG tag = new FITAG(), tag2 = new FITAG();
29206
// Clear all existing metadata
29207
if ((flags & FREE_IMAGE_METADATA_COPY.CLEAR_EXISTING) > 0)
29209
foreach (FREE_IMAGE_MDMODEL model in FREE_IMAGE_MDMODELS)
29211
if (!SetMetadata(model, dst, null, tag))
29218
bool keep = !((flags & FREE_IMAGE_METADATA_COPY.REPLACE_EXISTING) > 0);
29220
foreach (FREE_IMAGE_MDMODEL model in FREE_IMAGE_MDMODELS)
29222
FIMETADATA mData = FindFirstMetadata(model, src, out tag);
29223
if (mData.IsNull) continue;
29226
string key = GetTagKey(tag);
29227
if (!(keep && GetMetadata(model, dst, key, out tag2)))
29229
if (SetMetadata(model, dst, key, tag))
29235
while (FindNextMetadata(mData, out tag));
29236
FindCloseMetadata(mData);
29243
/// Returns the comment of a JPEG, PNG or GIF image.
29245
/// <param name="dib">Handle to a FreeImage bitmap.</param>
29246
/// <returns>Comment of the FreeImage bitmp, or null in case no comment exists.</returns>
29247
/// <exception cref="ArgumentNullException">
29248
/// <paramref name="dib"/> is null.</exception>
29249
public static string GetImageComment(FIBITMAP dib)
29251
string result = null;
29254
throw new ArgumentNullException("dib");
29257
if (GetMetadata(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, dib, "Comment", out tag))
29259
MetadataTag metadataTag = new MetadataTag(tag, FREE_IMAGE_MDMODEL.FIMD_COMMENTS);
29260
result = metadataTag.Value as string;
29266
/// Sets the comment of a JPEG, PNG or GIF image.
29268
/// <param name="dib">Handle to a FreeImage bitmap.</param>
29269
/// <param name="comment">New comment of the FreeImage bitmap.
29270
/// Use null to remove the comment.</param>
29271
/// <returns>Returns true on success, false on failure.</returns>
29272
/// <exception cref="ArgumentNullException">
29273
/// <paramref name="dib"/> is null.</exception>
29274
public static bool SetImageComment(FIBITMAP dib, string comment)
29278
throw new ArgumentNullException("dib");
29281
if (comment != null)
29283
FITAG tag = CreateTag();
29284
MetadataTag metadataTag = new MetadataTag(tag, FREE_IMAGE_MDMODEL.FIMD_COMMENTS);
29285
metadataTag.Value = comment;
29286
result = SetMetadata(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, dib, "Comment", tag);
29291
result = SetMetadata(FREE_IMAGE_MDMODEL.FIMD_COMMENTS, dib, "Comment", FITAG.Zero);
29297
/// Retrieve a metadata attached to a FreeImage bitmap.
29299
/// <param name="model">The metadata model to look for.</param>
29300
/// <param name="dib">Handle to a FreeImage bitmap.</param>
29301
/// <param name="key">The metadata field name.</param>
29302
/// <param name="tag">A <see cref="MetadataTag"/> structure returned by the function.</param>
29303
/// <returns>Returns true on success, false on failure.</returns>
29304
/// <exception cref="ArgumentNullException">
29305
/// <paramref name="dib"/> is null.</exception>
29306
public static bool GetMetadata(
29307
FREE_IMAGE_MDMODEL model,
29310
out MetadataTag tag)
29314
throw new ArgumentNullException("dib");
29319
if (GetMetadata(model, dib, key, out _tag))
29321
tag = new MetadataTag(_tag, model);
29333
/// Attach a new metadata tag to a FreeImage bitmap.
29335
/// <param name="model">The metadata model used to store the tag.</param>
29336
/// <param name="dib">Handle to a FreeImage bitmap.</param>
29337
/// <param name="key">The tag field name.</param>
29338
/// <param name="tag">The <see cref="MetadataTag"/> to be attached.</param>
29339
/// <returns>Returns true on success, false on failure.</returns>
29340
/// <exception cref="ArgumentNullException">
29341
/// <paramref name="dib"/> is null.</exception>
29342
public static bool SetMetadata(
29343
FREE_IMAGE_MDMODEL model,
29350
throw new ArgumentNullException("dib");
29352
return SetMetadata(model, dib, key, tag.tag);
29356
/// Provides information about the first instance of a tag that matches the metadata model.
29358
/// <param name="model">The model to match.</param>
29359
/// <param name="dib">Handle to a FreeImage bitmap.</param>
29360
/// <param name="tag">Tag that matches the metadata model.</param>
29361
/// <returns>Unique search handle that can be used to call FindNextMetadata or FindCloseMetadata.
29362
/// Null if the metadata model does not exist.</returns>
29363
/// <exception cref="ArgumentNullException">
29364
/// <paramref name="dib"/> is null.</exception>
29365
public static FIMETADATA FindFirstMetadata(
29366
FREE_IMAGE_MDMODEL model,
29368
out MetadataTag tag)
29372
throw new ArgumentNullException("dib");
29375
FIMETADATA result = FindFirstMetadata(model, dib, out _tag);
29381
tag = new MetadataTag(_tag, model);
29382
if (metaDataSearchHandler.ContainsKey(result))
29384
metaDataSearchHandler[result] = model;
29388
metaDataSearchHandler.Add(result, model);
29394
/// Find the next tag, if any, that matches the metadata model argument in a previous call
29395
/// to FindFirstMetadata, and then alters the tag object contents accordingly.
29397
/// <param name="mdhandle">Unique search handle provided by FindFirstMetadata.</param>
29398
/// <param name="tag">Tag that matches the metadata model.</param>
29399
/// <returns>Returns true on success, false on failure.</returns>
29400
public static bool FindNextMetadata(FIMETADATA mdhandle, out MetadataTag tag)
29404
if (FindNextMetadata(mdhandle, out _tag))
29406
tag = new MetadataTag(_tag, metaDataSearchHandler[mdhandle]);
29418
/// Closes the specified metadata search handle and releases associated resources.
29420
/// <param name="mdhandle">The handle to close.</param>
29421
public static void FindCloseMetadata(FIMETADATA mdhandle)
29423
if (metaDataSearchHandler.ContainsKey(mdhandle))
29425
metaDataSearchHandler.Remove(mdhandle);
29427
FindCloseMetadata_(mdhandle);
29431
/// This dictionary links FIMETADATA handles and FREE_IMAGE_MDMODEL models.
29433
private static Dictionary<FIMETADATA, FREE_IMAGE_MDMODEL> metaDataSearchHandler
29434
= new Dictionary<FIMETADATA, FREE_IMAGE_MDMODEL>(1);
29438
#region Rotation and Flipping
29441
/// This function rotates a 1-, 8-bit greyscale or a 24-, 32-bit color image by means of 3 shears.
29442
/// 1-bit images rotation is limited to integer multiple of 90�.
29443
/// <c>null</c> is returned for other values.
29445
/// <param name="dib">Handle to a FreeImage bitmap.</param>
29446
/// <param name="angle">The angle of rotation.</param>
29447
/// <returns>Handle to a FreeImage bitmap.</returns>
29448
public static FIBITMAP Rotate(FIBITMAP dib, double angle)
29450
return Rotate(dib, angle, IntPtr.Zero);
29454
/// This function rotates a 1-, 8-bit greyscale or a 24-, 32-bit color image by means of 3 shears.
29455
/// 1-bit images rotation is limited to integer multiple of 90�.
29456
/// <c>null</c> is returned for other values.
29458
/// <typeparam name="T">The type of the color to use as background.</typeparam>
29459
/// <param name="dib">Handle to a FreeImage bitmap.</param>
29460
/// <param name="angle">The angle of rotation.</param>
29461
/// <param name="backgroundColor">The color used used to fill the bitmap's background.</param>
29462
/// <returns>Handle to a FreeImage bitmap.</returns>
29463
public static FIBITMAP Rotate<T>(FIBITMAP dib, double angle, T? backgroundColor) where T : struct
29465
if (backgroundColor.HasValue)
29467
GCHandle handle = new GCHandle();
29470
T[] buffer = new T[] { backgroundColor.Value };
29471
handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
29472
return Rotate(dib, angle, handle.AddrOfPinnedObject());
29476
if (handle.IsAllocated)
29482
return Rotate(dib, angle, IntPtr.Zero);
29487
/// Rotates a 4-bit color FreeImage bitmap.
29488
/// Allowed values for <paramref name="angle"/> are 90, 180 and 270.
29489
/// In case <paramref name="angle"/> is 0 or 360 a clone is returned.
29490
/// 0 is returned for other values or in case the rotation fails.
29492
/// <param name="dib">Handle to a FreeImage bitmap.</param>
29493
/// <param name="angle">The angle of rotation.</param>
29494
/// <returns>Handle to a FreeImage bitmap.</returns>
29496
/// This function is kind of temporary due to FreeImage's lack of
29497
/// rotating 4-bit images. It's particularly used by <see cref="FreeImageBitmap"/>'s
29498
/// method RotateFlip. This function will be removed as soon as FreeImage
29499
/// supports rotating 4-bit images.
29501
/// <exception cref="ArgumentNullException">
29502
/// <paramref name="dib"/> is null.</exception>
29503
public static unsafe FIBITMAP Rotate4bit(FIBITMAP dib, double angle)
29507
throw new ArgumentNullException("dib");
29510
FIBITMAP result = new FIBITMAP();
29511
int ang = (int)angle;
29513
if ((GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) &&
29514
(GetBPP(dib) == 4) &&
29517
int width, height, xOrg, yOrg;
29518
Scanline<FI4BIT>[] src, dst;
29519
width = (int)GetWidth(dib);
29520
height = (int)GetHeight(dib);
29525
result = Allocate(height, width, 4, 0, 0, 0);
29530
CopyPalette(dib, result);
29531
src = Get04BitScanlines(dib);
29532
dst = Get04BitScanlines(result);
29533
for (int y = 0; y < width; y++)
29536
for (int x = 0; x < height; x++, yOrg--)
29538
index = src[yOrg][y];
29544
result = Allocate(width, height, 4, 0, 0, 0);
29549
CopyPalette(dib, result);
29550
src = Get04BitScanlines(dib);
29551
dst = Get04BitScanlines(result);
29554
for (int y = 0; y < height; y++, yOrg--)
29557
for (int x = 0; x < width; x++, xOrg--)
29559
index = src[yOrg][xOrg];
29565
result = Allocate(height, width, 4, 0, 0, 0);
29570
CopyPalette(dib, result);
29571
src = Get04BitScanlines(dib);
29572
dst = Get04BitScanlines(result);
29574
for (int y = 0; y < width; y++, xOrg--)
29576
for (int x = 0; x < height; x++)
29578
index = src[x][xOrg];
29585
result = Clone(dib);
29594
#region Upsampling / downsampling
29597
/// Enlarges or shrinks the FreeImage bitmap selectively per side and fills newly added areas
29598
/// with the specified background color. See remarks for further details.
29600
/// <typeparam name="T">The type of the specified color.</typeparam>
29601
/// <param name="dib">Handle to a FreeImage bitmap.</param>
29602
/// <param name="left">The number of pixels, the image should be enlarged on its left side.
29603
/// Negative values shrink the image on its left side.</param>
29604
/// <param name="top">The number of pixels, the image should be enlarged on its top side.
29605
/// Negative values shrink the image on its top side.</param>
29606
/// <param name="right">The number of pixels, the image should be enlarged on its right side.
29607
/// Negative values shrink the image on its right side.</param>
29608
/// <param name="bottom">The number of pixels, the image should be enlarged on its bottom side.
29609
/// Negative values shrink the image on its bottom side.</param>
29610
/// <param name="color">The color, the enlarged sides of the image should be filled with.</param>
29611
/// <param name="options">Options that affect the color search process for palletized images.</param>
29612
/// <returns>Handle to a FreeImage bitmap.</returns>
29614
/// This function enlarges or shrinks an image selectively per side.
29615
/// The main purpose of this function is to add borders to an image.
29616
/// To add a border to any of the image's sides, a positive integer value must be passed in
29617
/// any of the parameters <paramref name="left"/>, <paramref name="top"/>, <paramref name="right"/>
29618
/// or <paramref name="bottom"/>. This value represents the border's
29619
/// width in pixels. Newly created parts of the image (the border areas) are filled with the
29620
/// specified <paramref name="color"/>.
29621
/// Specifying a negative integer value for a certain side, will shrink or crop the image on
29622
/// this side. Consequently, specifying zero for a certain side will not change the image's
29623
/// extension on that side.
29625
/// So, calling this function with all parameters <paramref name="left"/>, <paramref name="top"/>,
29626
/// <paramref name="right"/> and <paramref name="bottom"/> set to zero, is
29627
/// effectively the same as calling function <see cref="Clone"/>; setting all parameters
29628
/// <paramref name="left"/>, <paramref name="top"/>, <paramref name="right"/> and
29629
/// <paramref name="bottom"/> to value equal to or smaller than zero, my easily be substituted
29630
/// by a call to function <see cref="Copy"/>. Both these cases produce a new image, which is
29631
/// guaranteed not to be larger than the input image. Thus, since the specified
29632
/// <paramref name="color"/> is not needed in these cases, <paramref name="color"/>
29633
/// may be <c>null</c>.
29635
/// Both parameters <paramref name="color"/> and <paramref name="options"/> work according to
29636
/// function <see cref="FillBackground<T>"/>. So, please refer to the documentation of
29637
/// <see cref="FillBackground<T>"/> to learn more about parameters <paramref name="color"/>
29638
/// and <paramref name="options"/>. For palletized images, the palette of the input image is
29639
/// transparently copied to the newly created enlarged or shrunken image, so any color look-ups
29640
/// are performed on this palette.
29643
/// // create a white color<br/>
29644
/// RGBQUAD c;<br/>
29645
/// c.rgbRed = 0xFF;<br/>
29646
/// c.rgbGreen = 0xFF;<br/>
29647
/// c.rgbBlue = 0xFF;<br/>
29648
/// c.rgbReserved = 0x00;<br/>
29650
/// // add a white, symmetric 10 pixel wide border to the image<br/>
29651
/// dib2 = FreeImage_EnlargeCanvas(dib, 10, 10, 10, 10, c, FREE_IMAGE_COLOR_OPTIONS.FICO_RGB);<br/>
29653
/// // add white, 20 pixel wide stripes to the top and bottom side of the image<br/>
29654
/// dib3 = FreeImage_EnlargeCanvas(dib, 0, 20, 0, 20, c, FREE_IMAGE_COLOR_OPTIONS.FICO_RGB);<br/>
29656
/// // add white, 30 pixel wide stripes to the right side of the image and<br/>
29657
/// // cut off the 40 leftmost pixel columns<br/>
29658
/// dib3 = FreeImage_EnlargeCanvas(dib, -40, 0, 30, 0, c, FREE_IMAGE_COLOR_OPTIONS.FICO_RGB);<br/>
29660
public static FIBITMAP EnlargeCanvas<T>(FIBITMAP dib, int left, int top, int right, int bottom,
29661
T? color, FREE_IMAGE_COLOR_OPTIONS options) where T : struct
29664
return FIBITMAP.Zero;
29666
if (!CheckColorType(GetImageType(dib), color))
29667
return FIBITMAP.Zero;
29669
if (color.HasValue)
29671
GCHandle handle = new GCHandle();
29674
T[] buffer = new T[] { color.Value };
29675
handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
29676
return EnlargeCanvas(dib, left, top, right, bottom, handle.AddrOfPinnedObject(), options);
29680
if (handle.IsAllocated)
29686
return EnlargeCanvas(dib, left, top, right, bottom, IntPtr.Zero, options);
29695
/// Sets all pixels of the specified image to the color provided through the
29696
/// <paramref name="color"/> parameter. See remarks for further details.
29698
/// <typeparam name="T">The type of the specified color.</typeparam>
29699
/// <param name="dib">Handle to a FreeImage bitmap.</param>
29700
/// <param name="color">The color to fill the bitmap with. See remarks for further details.</param>
29701
/// <param name="options">Options that affect the color search process for palletized images.</param>
29702
/// <returns><c>true</c> on success, <c>false</c> on failure.</returns>
29704
/// This function sets all pixels of an image to the color provided through
29705
/// the <paramref name="color"/> parameter. <see cref="RGBQUAD"/> is used for standard type images.
29706
/// For non standard type images the underlaying structure is used.
29708
/// So, <paramref name="color"/> must be of type <see cref="Double"/>, if the image to be filled is of type
29709
/// <see cref="FREE_IMAGE_TYPE.FIT_DOUBLE"/> and must be a <see cref="FIRGBF"/> structure if the
29710
/// image is of type <see cref="FREE_IMAGE_TYPE.FIT_RGBF"/> and so on.
29712
/// However, the fill color is always specified through a <see cref="RGBQUAD"/> structure
29713
/// for all images of type <see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>.
29714
/// So, for 32- and 24-bit images, the red, green and blue members of the <see cref="RGBQUAD"/>
29715
/// structure are directly used for the image's red, green and blue channel respectively.
29716
/// Although alpha transparent <see cref="RGBQUAD"/> colors are
29717
/// supported, the alpha channel of a 32-bit image never gets modified by this function.
29718
/// A fill color with an alpha value smaller than 255 gets blended with the image's actual
29719
/// background color, which is determined from the image's bottom-left pixel.
29720
/// So, currently using alpha enabled colors, assumes the image to be unicolor before the
29721
/// fill operation. However, the <see cref="RGBQUAD.rgbReserved"/> field is only taken into account,
29722
/// if option <see cref="FREE_IMAGE_COLOR_OPTIONS.FICO_RGBA"/> has been specified.
29724
/// For 16-bit images, the red-, green- and blue components of the specified color are
29725
/// transparently translated into either the 16-bit 555 or 565 representation. This depends
29726
/// on the image's actual red- green- and blue masks.
29728
/// Special attention must be payed for palletized images. Generally, the RGB color specified
29729
/// is looked up in the image's palette. The found palette index is then used to fill the image.
29730
/// There are some option flags, that affect this lookup process:
29731
/// <list type="table">
29733
/// <term>Value</term>
29734
/// <description>Meaning</description>
29737
/// <term><see cref="FREE_IMAGE_COLOR_OPTIONS.FICO_DEFAULT"/></term>
29739
/// Uses the color, that is nearest to the specified color.
29740
/// This is the default behavior and should always find a
29741
/// color in the palette. However, the visual result may
29742
/// far from what was expected and mainly depends on the
29743
/// image's palette.
29747
/// <term><see cref="FREE_IMAGE_COLOR_OPTIONS.FICO_EQUAL_COLOR"/></term>
29749
/// Searches the image's palette for the specified color
29750
/// but only uses the returned palette index, if the specified
29751
/// color exactly matches the palette entry. Of course,
29752
/// depending on the image's actual palette entries, this
29753
/// operation may fail. In this case, the function falls back
29754
/// to option <see cref="FREE_IMAGE_COLOR_OPTIONS.FICO_ALPHA_IS_INDEX"/>
29755
/// and uses the RGBQUAD's rgbReserved member (or its low nibble for 4-bit images
29756
/// or its least significant bit (LSB) for 1-bit images) as
29757
/// the palette index used for the fill operation.
29761
/// <term><see cref="FREE_IMAGE_COLOR_OPTIONS.FICO_ALPHA_IS_INDEX"/></term>
29763
/// Does not perform any color lookup from the palette, but
29764
/// uses the RGBQUAD's alpha channel member rgbReserved as
29765
/// the palette index to be used for the fill operation.
29766
/// However, for 4-bit images, only the low nibble of the
29767
/// rgbReserved member are used and for 1-bit images, only
29768
/// the least significant bit (LSB) is used.
29773
public static bool FillBackground<T>(FIBITMAP dib, T color, FREE_IMAGE_COLOR_OPTIONS options)
29779
if (!CheckColorType(GetImageType(dib), color))
29782
GCHandle handle = new GCHandle();
29785
T[] buffer = new T[] { color };
29786
handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
29787
return FillBackground(dib, handle.AddrOfPinnedObject(), options);
29791
if (handle.IsAllocated)
29798
#region Wrapper functions
29801
/// Returns the next higher possible color depth.
29803
/// <param name="bpp">Color depth to increase.</param>
29804
/// <returns>The next higher color depth or 0 if there is no valid color depth.</returns>
29805
internal static int GetNextColorDepth(int bpp)
29830
/// Returns the next lower possible color depth.
29832
/// <param name="bpp">Color depth to decrease.</param>
29833
/// <returns>The next lower color depth or 0 if there is no valid color depth.</returns>
29834
internal static int GetPrevousColorDepth(int bpp)
29859
/// Reads a null-terminated c-string.
29861
/// <param name="ptr">Pointer to the first char of the string.</param>
29862
/// <returns>The converted string.</returns>
29863
internal static unsafe string PtrToStr(byte* ptr)
29865
string result = null;
29868
System.Text.StringBuilder sb = new System.Text.StringBuilder();
29872
sb.Append((char)(*(ptr++)));
29874
result = sb.ToString();
29879
internal static unsafe byte[] CreateShrunkenPaletteLUT(FIBITMAP dib, out int uniqueColors)
29881
byte[] result = null;
29884
if ((!dib.IsNull) && (GetImageType(dib) == FREE_IMAGE_TYPE.FIT_BITMAP) && (GetBPP(dib) <= 8))
29886
int size = (int)GetColorsUsed(dib);
29887
List<RGBQUAD> newPalette = new List<RGBQUAD>(size);
29888
List<byte> lut = new List<byte>(size);
29889
RGBQUAD* palette = (RGBQUAD*)GetPalette(dib);
29893
for (int i = 0; i < size; i++)
29895
color = palette[i];
29896
color.rgbReserved = 255; // ignore alpha
29898
index = newPalette.IndexOf(color);
29901
newPalette.Add(color);
29902
lut.Add((byte)(newPalette.Count - 1));
29906
lut.Add((byte)index);
29909
result = lut.ToArray();
29910
uniqueColors = newPalette.Count;
29915
internal static PropertyItem CreatePropertyItem()
29917
return (PropertyItem)Activator.CreateInstance(typeof(PropertyItem), true);
29920
private static unsafe void CopyPalette(FIBITMAP src, FIBITMAP dst)
29922
RGBQUAD* orgPal = (RGBQUAD*)GetPalette(src);
29923
RGBQUAD* newPal = (RGBQUAD*)GetPalette(dst);
29924
uint size = (uint)(sizeof(RGBQUAD) * GetColorsUsed(src));
29925
CopyMemory(newPal, orgPal, size);
29928
private static unsafe Scanline<FI4BIT>[] Get04BitScanlines(FIBITMAP dib)
29930
int height = (int)GetHeight(dib);
29931
Scanline<FI4BIT>[] array = new Scanline<FI4BIT>[height];
29932
for (int i = 0; i < height; i++)
29934
array[i] = new Scanline<FI4BIT>(dib, i);
29940
/// Changes a bitmaps color depth.
29941
/// Used by SaveEx and SaveToStream.
29943
private static FIBITMAP PrepareBitmapColorDepth(FIBITMAP dibToSave, FREE_IMAGE_FORMAT format, FREE_IMAGE_COLOR_DEPTH colorDepth)
29945
FREE_IMAGE_TYPE type = GetImageType(dibToSave);
29946
if (type == FREE_IMAGE_TYPE.FIT_BITMAP)
29948
int bpp = (int)GetBPP(dibToSave);
29949
int targetBpp = (int)(colorDepth & FREE_IMAGE_COLOR_DEPTH.FICD_COLOR_MASK);
29951
if (colorDepth != FREE_IMAGE_COLOR_DEPTH.FICD_AUTO)
29953
// A fix colordepth was chosen
29954
if (FIFSupportsExportBPP(format, targetBpp))
29956
dibToSave = ConvertColorDepth(dibToSave, colorDepth, false);
29960
throw new ArgumentException("FreeImage\n\nFreeImage Library plugin " +
29961
GetFormatFromFIF(format) + " is unable to write images with a color depth of " +
29962
targetBpp + " bpp.");
29967
// Auto selection was chosen
29968
if (!FIFSupportsExportBPP(format, bpp))
29970
// The color depth is not supported
29971
int bppUpper = bpp;
29972
int bppLower = bpp;
29973
// Check from the bitmaps current color depth in both directions
29976
bppUpper = GetNextColorDepth(bppUpper);
29977
if (FIFSupportsExportBPP(format, bppUpper))
29979
dibToSave = ConvertColorDepth(dibToSave, (FREE_IMAGE_COLOR_DEPTH)bppUpper, false);
29982
bppLower = GetPrevousColorDepth(bppLower);
29983
if (FIFSupportsExportBPP(format, bppLower))
29985
dibToSave = ConvertColorDepth(dibToSave, (FREE_IMAGE_COLOR_DEPTH)bppLower, false);
29988
} while (!((bppLower == 0) && (bppUpper == 0)));
29996
/// Compares blocks of memory.
29998
/// <param name="buf1">A pointer to a block of memory to compare.</param>
29999
/// <param name="buf2">A pointer to a block of memory to compare.</param>
30000
/// <param name="length">Specifies the number of bytes to be compared.</param>
30001
/// <returns>true, if all bytes compare as equal, false otherwise.</returns>
30002
public static unsafe bool CompareMemory(void* buf1, void* buf2, uint length)
30004
return (length == RtlCompareMemory(buf1, buf2, length));
30008
/// Compares blocks of memory.
30010
/// <param name="buf1">A pointer to a block of memory to compare.</param>
30011
/// <param name="buf2">A pointer to a block of memory to compare.</param>
30012
/// <param name="length">Specifies the number of bytes to be compared.</param>
30013
/// <returns>true, if all bytes compare as equal, false otherwise.</returns>
30014
public static unsafe bool CompareMemory(void* buf1, void* buf2, long length)
30016
return (length == RtlCompareMemory(buf1, buf2, checked((uint)length)));
30020
/// Compares blocks of memory.
30022
/// <param name="buf1">A pointer to a block of memory to compare.</param>
30023
/// <param name="buf2">A pointer to a block of memory to compare.</param>
30024
/// <param name="length">Specifies the number of bytes to be compared.</param>
30025
/// <returns>true, if all bytes compare as equal, false otherwise.</returns>
30026
public static unsafe bool CompareMemory(IntPtr buf1, IntPtr buf2, uint length)
30028
return (length == RtlCompareMemory(buf1.ToPointer(), buf2.ToPointer(), length));
30032
/// Compares blocks of memory.
30034
/// <param name="buf1">A pointer to a block of memory to compare.</param>
30035
/// <param name="buf2">A pointer to a block of memory to compare.</param>
30036
/// <param name="length">Specifies the number of bytes to be compared.</param>
30037
/// <returns>true, if all bytes compare as equal, false otherwise.</returns>
30038
public static unsafe bool CompareMemory(IntPtr buf1, IntPtr buf2, long length)
30040
return (length == RtlCompareMemory(buf1.ToPointer(), buf2.ToPointer(), checked((uint)length)));
30044
/// Moves a block of memory from one location to another.
30046
/// <param name="dst">A pointer to the starting address of the move destination.</param>
30047
/// <param name="src">A pointer to the starting address of the block of memory to be moved.</param>
30048
/// <param name="size">The size of the block of memory to move, in bytes.</param>
30049
public static unsafe void MoveMemory(void* dst, void* src, long size)
30051
MoveMemory(dst, src, checked((uint)size));
30055
/// Moves a block of memory from one location to another.
30057
/// <param name="dst">A pointer to the starting address of the move destination.</param>
30058
/// <param name="src">A pointer to the starting address of the block of memory to be moved.</param>
30059
/// <param name="size">The size of the block of memory to move, in bytes.</param>
30060
public static unsafe void MoveMemory(IntPtr dst, IntPtr src, uint size)
30062
MoveMemory(dst.ToPointer(), src.ToPointer(), size);
30066
/// Moves a block of memory from one location to another.
30068
/// <param name="dst">A pointer to the starting address of the move destination.</param>
30069
/// <param name="src">A pointer to the starting address of the block of memory to be moved.</param>
30070
/// <param name="size">The size of the block of memory to move, in bytes.</param>
30071
public static unsafe void MoveMemory(IntPtr dst, IntPtr src, long size)
30073
MoveMemory(dst.ToPointer(), src.ToPointer(), checked((uint)size));
30077
/// Copies a block of memory from one location to another.
30079
/// <param name="dest">A pointer to the starting address of the copied block's destination.</param>
30080
/// <param name="src">A pointer to the starting address of the block of memory to copy.</param>
30081
/// <param name="len">The size of the block of memory to copy, in bytes.</param>
30083
/// <b>CopyMemory</b> runs faster than <see cref="MoveMemory(void*, void*, uint)"/>.
30084
/// However, if both blocks overlap the result is undefined.
30086
public static unsafe void CopyMemory(byte* dest, byte* src, int len)
30092
*((int*)dest) = *((int*)src);
30093
*((int*)(dest + 4)) = *((int*)(src + 4));
30094
*((int*)(dest + 8)) = *((int*)(src + 8));
30095
*((int*)(dest + 12)) = *((int*)(src + 12));
30099
while ((len -= 0x10) >= 0x10);
30103
if ((len & 8) != 0)
30105
*((int*)dest) = *((int*)src);
30106
*((int*)(dest + 4)) = *((int*)(src + 4));
30110
if ((len & 4) != 0)
30112
*((int*)dest) = *((int*)src);
30116
if ((len & 2) != 0)
30118
*((short*)dest) = *((short*)src);
30122
if ((len & 1) != 0)
30130
/// Copies a block of memory from one location to another.
30132
/// <param name="dest">A pointer to the starting address of the copied block's destination.</param>
30133
/// <param name="src">A pointer to the starting address of the block of memory to copy.</param>
30134
/// <param name="len">The size of the block of memory to copy, in bytes.</param>
30136
/// <b>CopyMemory</b> runs faster than <see cref="MoveMemory(void*, void*, long)"/>.
30137
/// However, if both blocks overlap the result is undefined.
30139
public static unsafe void CopyMemory(byte* dest, byte* src, long len)
30141
CopyMemory(dest, src, checked((int)len));
30145
/// Copies a block of memory from one location to another.
30147
/// <param name="dest">A pointer to the starting address of the copied block's destination.</param>
30148
/// <param name="src">A pointer to the starting address of the block of memory to copy.</param>
30149
/// <param name="len">The size of the block of memory to copy, in bytes.</param>
30151
/// <b>CopyMemory</b> runs faster than <see cref="MoveMemory(void*, void*, long)"/>.
30152
/// However, if both blocks overlap the result is undefined.
30154
public static unsafe void CopyMemory(void* dest, void* src, long len)
30156
CopyMemory((byte*)dest, (byte*)src, checked((int)len));
30160
/// Copies a block of memory from one location to another.
30162
/// <param name="dest">A pointer to the starting address of the copied block's destination.</param>
30163
/// <param name="src">A pointer to the starting address of the block of memory to copy.</param>
30164
/// <param name="len">The size of the block of memory to copy, in bytes.</param>
30166
/// <b>CopyMemory</b> runs faster than <see cref="MoveMemory(void*, void*, uint)"/>.
30167
/// However, if both blocks overlap the result is undefined.
30169
public static unsafe void CopyMemory(void* dest, void* src, int len)
30171
CopyMemory((byte*)dest, (byte*)src, len);
30175
/// Copies a block of memory from one location to another.
30177
/// <param name="dest">A pointer to the starting address of the copied block's destination.</param>
30178
/// <param name="src">A pointer to the starting address of the block of memory to copy.</param>
30179
/// <param name="len">The size of the block of memory to copy, in bytes.</param>
30181
/// <b>CopyMemory</b> runs faster than <see cref="MoveMemory(IntPtr, IntPtr, uint)"/>.
30182
/// However, if both blocks overlap the result is undefined.
30184
public static unsafe void CopyMemory(IntPtr dest, IntPtr src, int len)
30186
CopyMemory((byte*)dest, (byte*)src, len);
30190
/// Copies a block of memory from one location to another.
30192
/// <param name="dest">A pointer to the starting address of the copied block's destination.</param>
30193
/// <param name="src">A pointer to the starting address of the block of memory to copy.</param>
30194
/// <param name="len">The size of the block of memory to copy, in bytes.</param>
30196
/// <b>CopyMemory</b> runs faster than <see cref="MoveMemory(IntPtr, IntPtr, long)"/>.
30197
/// However, if both blocks overlap the result is undefined.
30199
public static unsafe void CopyMemory(IntPtr dest, IntPtr src, long len)
30201
CopyMemory((byte*)dest, (byte*)src, checked((int)len));
30205
/// Copies a block of memory into an array.
30207
/// <param name="dest">An array used as the destination of the copy process.</param>
30208
/// <param name="src">A pointer to the starting address of the block of memory to copy.</param>
30209
/// <param name="len">The size of the block of memory to copy, in bytes.</param>
30210
public static unsafe void CopyMemory(Array dest, void* src, int len)
30212
GCHandle handle = GCHandle.Alloc(dest, GCHandleType.Pinned);
30215
CopyMemory((byte*)handle.AddrOfPinnedObject(), (byte*)src, len);
30224
/// Copies a block of memory into an array.
30226
/// <param name="dest">An array used as the destination of the copy process.</param>
30227
/// <param name="src">A pointer to the starting address of the block of memory to copy.</param>
30228
/// <param name="len">The size of the block of memory to copy, in bytes.</param>
30229
public static unsafe void CopyMemory(Array dest, void* src, long len)
30231
CopyMemory(dest, (byte*)src, checked((int)len));
30235
/// Copies a block of memory into an array.
30237
/// <param name="dest">An array used as the destination of the copy process.</param>
30238
/// <param name="src">A pointer to the starting address of the block of memory to copy.</param>
30239
/// <param name="len">The size of the block of memory to copy, in bytes.</param>
30240
public static unsafe void CopyMemory(Array dest, IntPtr src, int len)
30242
CopyMemory(dest, (byte*)src, len);
30246
/// Copies a block of memory into an array.
30248
/// <param name="dest">An array used as the destination of the copy process.</param>
30249
/// <param name="src">A pointer to the starting address of the block of memory to copy.</param>
30250
/// <param name="len">The size of the block of memory to copy, in bytes.</param>
30251
public static unsafe void CopyMemory(Array dest, IntPtr src, long len)
30253
CopyMemory(dest, (byte*)src, checked((int)len));
30257
/// Copies the content of an array to a memory location.
30259
/// <param name="dest">A pointer to the starting address of the copied block's destination.</param>
30260
/// <param name="src">An array used as the source of the copy process.</param>
30261
/// <param name="len">The size of the block of memory to copy, in bytes.</param>
30262
public static unsafe void CopyMemory(void* dest, Array src, int len)
30264
GCHandle handle = GCHandle.Alloc(src, GCHandleType.Pinned);
30267
CopyMemory((byte*)dest, (byte*)handle.AddrOfPinnedObject(), len);
30276
/// Copies the content of an array to a memory location.
30278
/// <param name="dest">A pointer to the starting address of the copied block's destination.</param>
30279
/// <param name="src">An array used as the source of the copy process.</param>
30280
/// <param name="len">The size of the block of memory to copy, in bytes.</param>
30281
public static unsafe void CopyMemory(void* dest, Array src, long len)
30283
CopyMemory((byte*)dest, src, checked((int)len));
30287
/// Copies the content of an array to a memory location.
30289
/// <param name="dest">A pointer to the starting address of the copied block's destination.</param>
30290
/// <param name="src">An array used as the source of the copy process.</param>
30291
/// <param name="len">The size of the block of memory to copy, in bytes.</param>
30292
public static unsafe void CopyMemory(IntPtr dest, Array src, int len)
30294
CopyMemory((byte*)dest, src, len);
30298
/// Copies the content of an array to a memory location.
30300
/// <param name="dest">A pointer to the starting address of the copied block's destination.</param>
30301
/// <param name="src">An array used as the source of the copy process.</param>
30302
/// <param name="len">The size of the block of memory to copy, in bytes.</param>
30303
public static unsafe void CopyMemory(IntPtr dest, Array src, long len)
30305
CopyMemory((byte*)dest, src, checked((int)len));
30309
/// Copies the content of one array into another array.
30311
/// <param name="dest">An array used as the destination of the copy process.</param>
30312
/// <param name="src">An array used as the source of the copy process.</param>
30313
/// <param name="len">The size of the content to copy, in bytes.</param>
30314
public static unsafe void CopyMemory(Array dest, Array src, int len)
30316
GCHandle dHandle = GCHandle.Alloc(dest, GCHandleType.Pinned);
30319
GCHandle sHandle = GCHandle.Alloc(src, GCHandleType.Pinned);
30322
CopyMemory((byte*)dHandle.AddrOfPinnedObject(), (byte*)sHandle.AddrOfPinnedObject(), len);
30336
/// Copies the content of one array into another array.
30338
/// <param name="dest">An array used as the destination of the copy process.</param>
30339
/// <param name="src">An array used as the source of the copy process.</param>
30340
/// <param name="len">The size of the content to copy, in bytes.</param>
30341
public static unsafe void CopyMemory(Array dest, Array src, long len)
30343
CopyMemory(dest, src, checked((int)len));
30346
internal static string ColorToString(Color color)
30348
return string.Format(
30349
System.Globalization.CultureInfo.CurrentCulture,
30350
"{{Name={0}, ARGB=({1}, {2}, {3}, {4})}}",
30351
new object[] { color.Name, color.A, color.R, color.G, color.B });
30354
internal static void Resize(ref string str, int length)
30356
if ((str != null) && (length >= 0) && (str.Length != length))
30358
char[] chars = str.ToCharArray();
30359
Array.Resize(ref chars, length);
30360
str = new string(chars);
30364
internal static void Resize(ref string str, int min, int max)
30366
if ((str != null) && (min >= 0) && (max >= 0) && (min <= max))
30368
if (str.Length < min)
30370
char[] chars = str.ToCharArray();
30371
Array.Resize(ref chars, min);
30372
str = new string(chars);
30374
else if (str.Length > max)
30376
char[] chars = str.ToCharArray();
30377
Array.Resize(ref chars, max);
30378
str = new string(chars);
30383
internal static void Resize<T>(ref T[] array, int length)
30385
if ((array != null) && (length >= 0) && (array.Length != length))
30387
Array.Resize(ref array, length);
30391
internal static void Resize<T>(ref T[] array, int min, int max)
30393
if ((array != null) && (min >= 0) && (max >= 0) && (min <= max))
30395
if (array.Length < min)
30397
Array.Resize(ref array, min);
30399
else if (array.Length > max)
30401
Array.Resize(ref array, max);
30406
internal static bool CheckColorType<T>(FREE_IMAGE_TYPE imageType, T color)
30408
Type type = typeof(T);
30412
case FREE_IMAGE_TYPE.FIT_BITMAP:
30413
result = (type == typeof(RGBQUAD)); break;
30414
case FREE_IMAGE_TYPE.FIT_COMPLEX:
30415
result = (type == typeof(FICOMPLEX)); break;
30416
case FREE_IMAGE_TYPE.FIT_DOUBLE:
30417
result = (type == typeof(double)); break;
30418
case FREE_IMAGE_TYPE.FIT_FLOAT:
30419
result = (type == typeof(float)); break;
30420
case FREE_IMAGE_TYPE.FIT_INT16:
30421
result = (type == typeof(Int16)); break;
30422
case FREE_IMAGE_TYPE.FIT_INT32:
30423
result = (type == typeof(Int32)); break;
30424
case FREE_IMAGE_TYPE.FIT_RGB16:
30425
result = (type == typeof(FIRGB16)); break;
30426
case FREE_IMAGE_TYPE.FIT_RGBA16:
30427
result = (type == typeof(FIRGBA16)); break;
30428
case FREE_IMAGE_TYPE.FIT_RGBAF:
30429
result = (type == typeof(FIRGBAF)); break;
30430
case FREE_IMAGE_TYPE.FIT_RGBF:
30431
result = (type == typeof(FIRGBF)); break;
30432
case FREE_IMAGE_TYPE.FIT_UINT16:
30433
result = (type == typeof(UInt16)); break;
30434
case FREE_IMAGE_TYPE.FIT_UINT32:
30435
result = (type == typeof(UInt32)); break;
30437
result = false; break;
30444
#region Dll-Imports
30447
/// Retrieves a handle to a display device context (DC) for the client area of a specified window
30448
/// or for the entire screen. You can use the returned handle in subsequent GDI functions to draw in the DC.
30450
/// <param name="hWnd">Handle to the window whose DC is to be retrieved.
30451
/// If this value is IntPtr.Zero, GetDC retrieves the DC for the entire screen. </param>
30452
/// <returns>If the function succeeds, the return value is a handle to the DC for the specified window's client area.
30453
/// If the function fails, the return value is NULL.</returns>
30454
[DllImport("user32.dll")]
30455
private static extern IntPtr GetDC(IntPtr hWnd);
30458
/// Releases a device context (DC), freeing it for use by other applications.
30459
/// The effect of the ReleaseDC function depends on the type of DC. It frees only common and window DCs.
30460
/// It has no effect on class or private DCs.
30462
/// <param name="hWnd">Handle to the window whose DC is to be released.</param>
30463
/// <param name="hDC">Handle to the DC to be released.</param>
30464
/// <returns>Returns true on success, false on failure.</returns>
30465
[DllImport("user32.dll")]
30466
private static extern bool ReleaseDC(IntPtr hWnd, IntPtr hDC);
30469
/// Creates a DIB that applications can write to directly.
30470
/// The function gives you a pointer to the location of the bitmap bit values.
30471
/// You can supply a handle to a file-mapping object that the function will use to create the bitmap,
30472
/// or you can let the system allocate the memory for the bitmap.
30474
/// <param name="hdc">Handle to a device context.</param>
30475
/// <param name="pbmi">Pointer to a BITMAPINFO structure that specifies various attributes of the DIB,
30476
/// including the bitmap dimensions and colors.</param>
30477
/// <param name="iUsage">Specifies the type of data contained in the bmiColors array member of the BITMAPINFO structure
30478
/// pointed to by pbmi (either logical palette indexes or literal RGB values).</param>
30479
/// <param name="ppvBits">Pointer to a variable that receives a pointer to the location of the DIB bit values.</param>
30480
/// <param name="hSection">Handle to a file-mapping object that the function will use to create the DIB.
30481
/// This parameter can be NULL.</param>
30482
/// <param name="dwOffset">Specifies the offset from the beginning of the file-mapping object referenced by hSection
30483
/// where storage for the bitmap bit values is to begin. This value is ignored if hSection is NULL.</param>
30484
/// <returns>If the function succeeds, the return value is a handle to the newly created DIB,
30485
/// and *ppvBits points to the bitmap bit values. If the function fails, the return value is NULL, and *ppvBits is NULL.</returns>
30486
[DllImport("gdi32.dll")]
30487
private static extern IntPtr CreateDIBSection(
30491
out IntPtr ppvBits,
30496
/// Deletes a logical pen, brush, font, bitmap, region, or palette, freeing all system resources associated with the object.
30497
/// After the object is deleted, the specified handle is no longer valid.
30499
/// <param name="hObject">Handle to a logical pen, brush, font, bitmap, region, or palette.</param>
30500
/// <returns>Returns true on success, false on failure.</returns>
30501
[DllImport("gdi32.dll")]
30502
private static extern bool DeleteObject(IntPtr hObject);
30505
/// Creates a compatible bitmap (DDB) from a DIB and, optionally, sets the bitmap bits.
30507
/// <param name="hdc">Handle to a device context.</param>
30508
/// <param name="lpbmih">Pointer to a bitmap information header structure.</param>
30509
/// <param name="fdwInit">Specifies how the system initializes the bitmap bits - (use 4).</param>
30510
/// <param name="lpbInit">Pointer to an array of bytes containing the initial bitmap data.</param>
30511
/// <param name="lpbmi">Pointer to a BITMAPINFO structure that describes the dimensions
30512
/// and color format of the array pointed to by the lpbInit parameter.</param>
30513
/// <param name="fuUsage">Specifies whether the bmiColors member of the BITMAPINFO structure
30514
/// was initialized - (use 0).</param>
30515
/// <returns>Handle to a DIB or null on failure.</returns>
30516
[DllImport("gdi32.dll")]
30517
private static extern IntPtr CreateDIBitmap(
30526
/// Retrieves information for the specified graphics object.
30528
/// <param name="hgdiobj">Handle to the graphics object of interest.</param>
30529
/// <param name="cbBuffer">Specifies the number of bytes of information to
30530
/// be written to the buffer.</param>
30531
/// <param name="lpvObject">Pointer to a buffer that receives the information
30532
/// about the specified graphics object.</param>
30533
/// <returns>0 on failure.</returns>
30534
[DllImport("gdi32.dll")]
30535
private static extern int GetObject(IntPtr hgdiobj, int cbBuffer, IntPtr lpvObject);
30538
/// Retrieves the bits of the specified compatible bitmap and copies them into a buffer
30539
/// as a DIB using the specified format.
30541
/// <param name="hdc">Handle to the device context.</param>
30542
/// <param name="hbmp">Handle to the bitmap. This must be a compatible bitmap (DDB).</param>
30543
/// <param name="uStartScan">Specifies the first scan line to retrieve.</param>
30544
/// <param name="cScanLines">Specifies the number of scan lines to retrieve.</param>
30545
/// <param name="lpvBits">Pointer to a buffer to receive the bitmap data.</param>
30546
/// <param name="lpbmi">Pointer to a BITMAPINFO structure that specifies the desired
30547
/// format for the DIB data.</param>
30548
/// <param name="uUsage">Specifies the format of the bmiColors member of the
30549
/// BITMAPINFO structure - (use 0).</param>
30550
/// <returns>0 on failure.</returns>
30551
[DllImport("gdi32.dll")]
30552
private static extern unsafe int GetDIBits(
30562
/// Moves a block of memory from one location to another.
30564
/// <param name="dst">Pointer to the starting address of the move destination.</param>
30565
/// <param name="src">Pointer to the starting address of the block of memory to be moved.</param>
30566
/// <param name="size">Size of the block of memory to move, in bytes.</param>
30567
[DllImport("Kernel32.dll", EntryPoint = "RtlMoveMemory", SetLastError = false)]
30568
public static unsafe extern void MoveMemory(void* dst, void* src, uint size);
30571
/// The RtlCompareMemory routine compares blocks of memory
30572
/// and returns the number of bytes that are equivalent.
30574
/// <param name="buf1">A pointer to a block of memory to compare.</param>
30575
/// <param name="buf2">A pointer to a block of memory to compare.</param>
30576
/// <param name="count">Specifies the number of bytes to be compared.</param>
30577
/// <returns>RtlCompareMemory returns the number of bytes that compare as equal.
30578
/// If all bytes compare as equal, the input Length is returned.</returns>
30579
[DllImport("ntdll.dll", EntryPoint = "RtlCompareMemory", SetLastError = false)]
30580
internal static unsafe extern uint RtlCompareMemory(void* buf1, void* buf2, uint count);