-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFreeImageStaticImports.cs
More file actions
2369 lines (2097 loc) · 116 KB
/
FreeImageStaticImports.cs
File metadata and controls
2369 lines (2097 loc) · 116 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==========================================================
// FreeImage 3 .NET wrapper
// Original FreeImage 3 functions and .NET compatible derived functions
//
// Design and implementation by
// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net)
// - Carsten Klein (cklein05@users.sourceforge.net)
//
// Contributors:
// - David Boland (davidboland@vodafone.ie)
//
// Main reference : MSDN Knowlede Base
//
// This file is part of FreeImage 3
//
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
// THIS DISCLAIMER.
//
// Use at your own risk!
// ==========================================================
// ==========================================================
// CVS
// $Revision: 1.9 $
// $Date: 2009/09/15 11:41:37 $
// $Id: FreeImageStaticImports.cs,v 1.9 2009/09/15 11:41:37 cklein05 Exp $
// ==========================================================
using System;
using System.Runtime.InteropServices;
using FreeImageAPI.Plugins;
using FreeImageAPI.IO;
namespace FreeImageAPI
{
public static partial class FreeImage
{
#region Constants
/// <summary>
/// Filename of the FreeImage library.
/// </summary>
private const string FreeImageLibrary = "FreeImage";
/// <summary>
/// Number of bytes to shift left within a 4 byte block.
/// </summary>
public const int FI_RGBA_RED = 2;
/// <summary>
/// Number of bytes to shift left within a 4 byte block.
/// </summary>
public const int FI_RGBA_GREEN = 1;
/// <summary>
/// Number of bytes to shift left within a 4 byte block.
/// </summary>
public const int FI_RGBA_BLUE = 0;
/// <summary>
/// Number of bytes to shift left within a 4 byte block.
/// </summary>
public const int FI_RGBA_ALPHA = 3;
/// <summary>
/// Mask indicating the position of the given color.
/// </summary>
public const uint FI_RGBA_RED_MASK = 0x00FF0000;
/// <summary>
/// Mask indicating the position of the given color.
/// </summary>
public const uint FI_RGBA_GREEN_MASK = 0x0000FF00;
/// <summary>
/// Mask indicating the position of the given color.
/// </summary>
public const uint FI_RGBA_BLUE_MASK = 0x000000FF;
/// <summary>
/// Mask indicating the position of the given color.
/// </summary>
public const uint FI_RGBA_ALPHA_MASK = 0xFF000000;
/// <summary>
/// Number of bits to shift left within a 32 bit block.
/// </summary>
public const int FI_RGBA_RED_SHIFT = 16;
/// <summary>
/// Number of bits to shift left within a 32 bit block.
/// </summary>
public const int FI_RGBA_GREEN_SHIFT = 8;
/// <summary>
/// Number of bits to shift left within a 32 bit block.
/// </summary>
public const int FI_RGBA_BLUE_SHIFT = 0;
/// <summary>
/// Number of bits to shift left within a 32 bit block.
/// </summary>
public const int FI_RGBA_ALPHA_SHIFT = 24;
/// <summary>
/// Mask indicating the position of color components of a 32 bit color.
/// </summary>
public const uint FI_RGBA_RGB_MASK = (FI_RGBA_RED_MASK | FI_RGBA_GREEN_MASK | FI_RGBA_BLUE_MASK);
/// <summary>
/// Mask indicating the position of the given color.
/// </summary>
public const int FI16_555_RED_MASK = 0x7C00;
/// <summary>
/// Mask indicating the position of the given color.
/// </summary>
public const int FI16_555_GREEN_MASK = 0x03E0;
/// <summary>
/// Mask indicating the position of the given color.
/// </summary>
public const int FI16_555_BLUE_MASK = 0x001F;
/// <summary>
/// Number of bits to shift left within a 16 bit block.
/// </summary>
public const int FI16_555_RED_SHIFT = 10;
/// <summary>
/// Number of bits to shift left within a 16 bit block.
/// </summary>
public const int FI16_555_GREEN_SHIFT = 5;
/// <summary>
/// Number of bits to shift left within a 16 bit block.
/// </summary>
public const int FI16_555_BLUE_SHIFT = 0;
/// <summary>
/// Mask indicating the position of the given color.
/// </summary>
public const int FI16_565_RED_MASK = 0xF800;
/// <summary>
/// Mask indicating the position of the given color.
/// </summary>
public const int FI16_565_GREEN_MASK = 0x07E0;
/// <summary>
/// Mask indicating the position of the given color.
/// </summary>
public const int FI16_565_BLUE_MASK = 0x001F;
/// <summary>
/// Number of bits to shift left within a 16 bit block.
/// </summary>
public const int FI16_565_RED_SHIFT = 11;
/// <summary>
/// Number of bits to shift left within a 16 bit block.
/// </summary>
public const int FI16_565_GREEN_SHIFT = 5;
/// <summary>
/// Number of bits to shift left within a 16 bit block.
/// </summary>
public const int FI16_565_BLUE_SHIFT = 0;
#endregion
#region General functions
/// <summary>
/// Initialises the library.
/// </summary>
/// <param name="load_local_plugins_only">
/// When the <paramref name="load_local_plugins_only"/> is true, FreeImage won't make use of external plugins.
/// </param>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Initialise")]
private static extern void Initialise(bool load_local_plugins_only);
/// <summary>
/// Deinitialises the library.
/// </summary>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_DeInitialise")]
private static extern void DeInitialise();
/// <summary>
/// Returns a string containing the current version of the library.
/// </summary>
/// <returns>The current version of the library.</returns>
public static unsafe string GetVersion() { return PtrToStr(GetVersion_()); }
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetVersion")]
private static unsafe extern byte* GetVersion_();
/// <summary>
/// Returns a string containing a standard copyright message.
/// </summary>
/// <returns>A standard copyright message.</returns>
public static unsafe string GetCopyrightMessage() { return PtrToStr(GetCopyrightMessage_()); }
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetCopyrightMessage")]
private static unsafe extern byte* GetCopyrightMessage_();
/// <summary>
/// Calls the set error message function in FreeImage.
/// </summary>
/// <param name="fif">Format of the bitmaps.</param>
/// <param name="message">The error message.</param>
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_OutputMessageProc")]
public static extern void OutputMessageProc(FREE_IMAGE_FORMAT fif, string message);
/// <summary>
/// You use the function FreeImage_SetOutputMessage to capture the log string
/// so that you can show it to the user of the program.
/// The callback is implemented in the <see cref="FreeImageEngine.Message"/> event of this class.
/// </summary>
/// <remarks>The function is private because FreeImage can only have a single
/// callback function. To use the callback use the <see cref="FreeImageEngine.Message"/>
/// event of this class.</remarks>
/// <param name="omf">Handler to the callback function.</param>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetOutputMessage")]
internal static extern void SetOutputMessage(OutputMessageFunction omf);
#endregion
#region Bitmap management functions
/// <summary>
/// Creates a new bitmap in memory.
/// </summary>
/// <param name="width">Width of the new bitmap.</param>
/// <param name="height">Height of the new bitmap.</param>
/// <param name="bpp">Bit depth of the new Bitmap.
/// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap</param>
/// <param name="red_mask">Red part of the color layout.
/// eg: 0xFF0000</param>
/// <param name="green_mask">Green part of the color layout.
/// eg: 0x00FF00</param>
/// <param name="blue_mask">Blue part of the color layout.
/// eg: 0x0000FF</param>
/// <returns>Handle to a FreeImage bitmap.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Allocate")]
public static extern FIBITMAP Allocate(int width, int height, int bpp,
uint red_mask, uint green_mask, uint blue_mask);
/// <summary>
/// Creates a new bitmap in memory.
/// </summary>
/// <param name="type">Type of the image.</param>
/// <param name="width">Width of the new bitmap.</param>
/// <param name="height">Height of the new bitmap.</param>
/// <param name="bpp">Bit depth of the new Bitmap.
/// Supported pixel depth: 1-, 4-, 8-, 16-, 24-, 32-bit per pixel for standard bitmap</param>
/// <param name="red_mask">Red part of the color layout.
/// eg: 0xFF0000</param>
/// <param name="green_mask">Green part of the color layout.
/// eg: 0x00FF00</param>
/// <param name="blue_mask">Blue part of the color layout.
/// eg: 0x0000FF</param>
/// <returns>Handle to a FreeImage bitmap.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AllocateT")]
public static extern FIBITMAP AllocateT(FREE_IMAGE_TYPE type, int width, int height, int bpp,
uint red_mask, uint green_mask, uint blue_mask);
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AllocateEx")]
internal static extern FIBITMAP AllocateEx(int width, int height, int bpp,
IntPtr color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette,
uint red_mask, uint green_mask, uint blue_mask);
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AllocateExT")]
internal static extern FIBITMAP AllocateExT(FREE_IMAGE_TYPE type, int width, int height, int bpp,
IntPtr color, FREE_IMAGE_COLOR_OPTIONS options, RGBQUAD[] palette,
uint red_mask, uint green_mask, uint blue_mask);
/// <summary>
/// Makes an exact reproduction of an existing bitmap, including metadata and attached profile if any.
/// </summary>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
/// <returns>Handle to a FreeImage bitmap.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Clone")]
public static extern FIBITMAP Clone(FIBITMAP dib);
/// <summary>
/// Deletes a previously loaded FIBITMAP from memory.
/// </summary>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_Unload")]
public static extern void Unload(FIBITMAP dib);
/// <summary>
/// Decodes a bitmap, allocates memory for it and returns it as a FIBITMAP.
/// </summary>
/// <param name="fif">Type of the bitmap.</param>
/// <param name="filename">Name of the file to decode.</param>
/// <param name="flags">Flags to enable or disable plugin-features.</param>
/// <returns>Handle to a FreeImage bitmap.</returns>
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_LoadU")]
public static extern FIBITMAP Load(FREE_IMAGE_FORMAT fif, string filename, FREE_IMAGE_LOAD_FLAGS flags);
/// <summary>
/// Decodes a bitmap, allocates memory for it and returns it as a FIBITMAP.
/// The filename supports UNICODE.
/// </summary>
/// <param name="fif">Type of the bitmap.</param>
/// <param name="filename">Name of the file to decode.</param>
/// <param name="flags">Flags to enable or disable plugin-features.</param>
/// <returns>Handle to a FreeImage bitmap.</returns>
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_LoadU")]
private static extern FIBITMAP LoadU(FREE_IMAGE_FORMAT fif, string filename, FREE_IMAGE_LOAD_FLAGS flags);
/// <summary>
/// Loads a bitmap from an arbitrary source.
/// </summary>
/// <param name="fif">Type of the bitmap.</param>
/// <param name="io">A FreeImageIO structure with functionpointers to handle the source.</param>
/// <param name="handle">A handle to the source.</param>
/// <param name="flags">Flags to enable or disable plugin-features.</param>
/// <returns>Handle to a FreeImage bitmap.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_LoadFromHandle")]
public static extern FIBITMAP LoadFromHandle(FREE_IMAGE_FORMAT fif, ref FreeImageIO io, fi_handle handle, FREE_IMAGE_LOAD_FLAGS flags);
/// <summary>
/// Saves a previosly loaded FIBITMAP to a file.
/// </summary>
/// <param name="fif">Type of the bitmap.</param>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
/// <param name="filename">Name of the file to save to.</param>
/// <param name="flags">Flags to enable or disable plugin-features.</param>
/// <returns>Returns true on success, false on failure.</returns>
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_SaveU")]
public static extern bool Save(FREE_IMAGE_FORMAT fif, FIBITMAP dib, string filename, FREE_IMAGE_SAVE_FLAGS flags);
/// <summary>
/// Saves a previosly loaded FIBITMAP to a file.
/// The filename supports UNICODE.
/// </summary>
/// <param name="fif">Type of the bitmap.</param>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
/// <param name="filename">Name of the file to save to.</param>
/// <param name="flags">Flags to enable or disable plugin-features.</param>
/// <returns>Returns true on success, false on failure.</returns>
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_SaveU")]
private static extern bool SaveU(FREE_IMAGE_FORMAT fif, FIBITMAP dib, string filename, FREE_IMAGE_SAVE_FLAGS flags);
/// <summary>
/// Saves a bitmap to an arbitrary source.
/// </summary>
/// <param name="fif">Type of the bitmap.</param>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
/// <param name="io">A FreeImageIO structure with functionpointers to handle the source.</param>
/// <param name="handle">A handle to the source.</param>
/// <param name="flags">Flags to enable or disable plugin-features.</param>
/// <returns>Returns true on success, false on failure.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SaveToHandle")]
public static extern bool SaveToHandle(FREE_IMAGE_FORMAT fif, FIBITMAP dib, ref FreeImageIO io, fi_handle handle,
FREE_IMAGE_SAVE_FLAGS flags);
#endregion
#region Memory I/O streams
/// <summary>
/// Open a memory stream.
/// </summary>
/// <param name="data">Pointer to the data in memory.</param>
/// <param name="size_in_bytes">Length of the data in byte.</param>
/// <returns>Handle to a memory stream.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_OpenMemory")]
public static extern FIMEMORY OpenMemory(IntPtr data, uint size_in_bytes);
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_OpenMemory")]
internal static extern FIMEMORY OpenMemoryEx(byte[] data, uint size_in_bytes);
/// <summary>
/// Close and free a memory stream.
/// </summary>
/// <param name="stream">Handle to a memory stream.</param>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CloseMemory")]
public static extern void CloseMemory(FIMEMORY stream);
/// <summary>
/// Decodes a bitmap from a stream, allocates memory for it and returns it as a FIBITMAP.
/// </summary>
/// <param name="fif">Type of the bitmap.</param>
/// <param name="stream">Handle to a memory stream.</param>
/// <param name="flags">Flags to enable or disable plugin-features.</param>
/// <returns>Handle to a FreeImage bitmap.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_LoadFromMemory")]
public static extern FIBITMAP LoadFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY stream, FREE_IMAGE_LOAD_FLAGS flags);
/// <summary>
/// Saves a previosly loaded FIBITMAP to a stream.
/// </summary>
/// <param name="fif">Type of the bitmap.</param>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
/// <param name="stream">Handle to a memory stream.</param>
/// <param name="flags">Flags to enable or disable plugin-features.</param>
/// <returns>Returns true on success, false on failure.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SaveToMemory")]
public static extern bool SaveToMemory(FREE_IMAGE_FORMAT fif, FIBITMAP dib, FIMEMORY stream, FREE_IMAGE_SAVE_FLAGS flags);
/// <summary>
/// Gets the current position of a memory handle.
/// </summary>
/// <param name="stream">Handle to a memory stream.</param>
/// <returns>The current file position if successful, -1 otherwise.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_TellMemory")]
public static extern int TellMemory(FIMEMORY stream);
/// <summary>
/// Moves the memory handle to a specified location.
/// </summary>
/// <param name="stream">Handle to a memory stream.</param>
/// <param name="offset">Number of bytes from origin.</param>
/// <param name="origin">Initial position.</param>
/// <returns>Returns true on success, false on failure.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SeekMemory")]
public static extern bool SeekMemory(FIMEMORY stream, int offset, System.IO.SeekOrigin origin);
/// <summary>
/// Provides a direct buffer access to a memory stream.
/// </summary>
/// <param name="stream">The target memory stream.</param>
/// <param name="data">Pointer to the data in memory.</param>
/// <param name="size_in_bytes">Size of the data in bytes.</param>
/// <returns>Returns true on success, false on failure.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AcquireMemory")]
public static extern bool AcquireMemory(FIMEMORY stream, ref IntPtr data, ref uint size_in_bytes);
/// <summary>
/// Reads data from a memory stream.
/// </summary>
/// <param name="buffer">The buffer to store the data in.</param>
/// <param name="size">Size in bytes of the items.</param>
/// <param name="count">Number of items to read.</param>
/// <param name="stream">The stream to read from.
/// The memory pointer associated with stream is increased by the number of bytes actually read.</param>
/// <returns>The number of full items actually read.
/// May be less than count on error or stream-end.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_ReadMemory")]
public static extern uint ReadMemory(byte[] buffer, uint size, uint count, FIMEMORY stream);
/// <summary>
/// Writes data to a memory stream.
/// </summary>
/// <param name="buffer">The buffer to read the data from.</param>
/// <param name="size">Size in bytes of the items.</param>
/// <param name="count">Number of items to write.</param>
/// <param name="stream">The stream to write to.
/// The memory pointer associated with stream is increased by the number of bytes actually written.</param>
/// <returns>The number of full items actually written.
/// May be less than count on error or stream-end.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_WriteMemory")]
public static extern uint WriteMemory(byte[] buffer, uint size, uint count, FIMEMORY stream);
/// <summary>
/// Open a multi-page bitmap from a memory stream.
/// </summary>
/// <param name="fif">Type of the bitmap.</param>
/// <param name="stream">The stream to decode.</param>
/// <param name="flags">Flags to enable or disable plugin-features.</param>
/// <returns>Handle to a FreeImage multi-paged bitmap.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_LoadMultiBitmapFromMemory")]
public static extern FIMULTIBITMAP LoadMultiBitmapFromMemory(FREE_IMAGE_FORMAT fif, FIMEMORY stream, FREE_IMAGE_LOAD_FLAGS flags);
#endregion
#region Plugin functions
/// <summary>
/// Registers a new plugin to be used in FreeImage.
/// </summary>
/// <param name="proc_address">Pointer to the function that initialises the plugin.</param>
/// <param name="format">A string describing the format of the plugin.</param>
/// <param name="description">A string describing the plugin.</param>
/// <param name="extension">A string witha comma sperated list of extensions. f.e: "pl,pl2,pl4"</param>
/// <param name="regexpr">A regular expression used to identify the bitmap.</param>
/// <returns>The format idientifier assigned by FreeImage.</returns>
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_RegisterLocalPlugin")]
public static extern FREE_IMAGE_FORMAT RegisterLocalPlugin(InitProc proc_address,
string format, string description, string extension, string regexpr);
/// <summary>
/// Registers a new plugin to be used in FreeImage. The plugin is residing in a DLL.
/// The Init function must be called Init and must use the stdcall calling convention.
/// </summary>
/// <param name="path">Complete path to the dll file hosting the plugin.</param>
/// <param name="format">A string describing the format of the plugin.</param>
/// <param name="description">A string describing the plugin.</param>
/// <param name="extension">A string witha comma sperated list of extensions. f.e: "pl,pl2,pl4"</param>
/// <param name="regexpr">A regular expression used to identify the bitmap.</param>
/// <returns>The format idientifier assigned by FreeImage.</returns>
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_RegisterExternalPlugin")]
public static extern FREE_IMAGE_FORMAT RegisterExternalPlugin(string path,
string format, string description, string extension, string regexpr);
/// <summary>
/// Retrieves the number of FREE_IMAGE_FORMAT identifiers being currently registered.
/// </summary>
/// <returns>The number of registered formats.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFCount")]
public static extern int GetFIFCount();
/// <summary>
/// Enables or disables a plugin.
/// </summary>
/// <param name="fif">The plugin to enable or disable.</param>
/// <param name="enable">True: enable the plugin. false: disable the plugin.</param>
/// <returns>The previous state of the plugin.
/// 1 - enabled. 0 - disables. -1 plugin does not exist.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetPluginEnabled")]
public static extern int SetPluginEnabled(FREE_IMAGE_FORMAT fif, bool enable);
/// <summary>
/// Retrieves the state of a plugin.
/// </summary>
/// <param name="fif">The plugin to check.</param>
/// <returns>1 - enabled. 0 - disables. -1 plugin does not exist.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_IsPluginEnabled")]
public static extern int IsPluginEnabled(FREE_IMAGE_FORMAT fif);
/// <summary>
/// Returns a <see cref="FREE_IMAGE_FORMAT"/> identifier from the format string that was used to register the FIF.
/// </summary>
/// <param name="format">The string that was used to register the plugin.</param>
/// <returns>A <see cref="FREE_IMAGE_FORMAT"/> identifier from the format.</returns>
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetFIFFromFormat")]
public static extern FREE_IMAGE_FORMAT GetFIFFromFormat(string format);
/// <summary>
/// Returns a <see cref="FREE_IMAGE_FORMAT"/> identifier from a MIME content type string
/// (MIME stands for Multipurpose Internet Mail Extension).
/// </summary>
/// <param name="mime">A MIME content type.</param>
/// <returns>A <see cref="FREE_IMAGE_FORMAT"/> identifier from the MIME.</returns>
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_GetFIFFromMime")]
public static extern FREE_IMAGE_FORMAT GetFIFFromMime(string mime);
/// <summary>
/// Returns the string that was used to register a plugin from the system assigned <see cref="FREE_IMAGE_FORMAT"/>.
/// </summary>
/// <param name="fif">The assigned <see cref="FREE_IMAGE_FORMAT"/>.</param>
/// <returns>The string that was used to register the plugin.</returns>
public static unsafe string GetFormatFromFIF(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFormatFromFIF_(fif)); }
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFormatFromFIF")]
private static unsafe extern byte* GetFormatFromFIF_(FREE_IMAGE_FORMAT fif);
/// <summary>
/// Returns a comma-delimited file extension list describing the bitmap formats the given plugin can read and/or write.
/// </summary>
/// <param name="fif">The desired <see cref="FREE_IMAGE_FORMAT"/>.</param>
/// <returns>A comma-delimited file extension list.</returns>
public static unsafe string GetFIFExtensionList(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFIFExtensionList_(fif)); }
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFExtensionList")]
private static unsafe extern byte* GetFIFExtensionList_(FREE_IMAGE_FORMAT fif);
/// <summary>
/// Returns a descriptive string that describes the bitmap formats the given plugin can read and/or write.
/// </summary>
/// <param name="fif">The desired <see cref="FREE_IMAGE_FORMAT"/>.</param>
/// <returns>A descriptive string that describes the bitmap formats.</returns>
public static unsafe string GetFIFDescription(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFIFDescription_(fif)); }
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFDescription")]
private static unsafe extern byte* GetFIFDescription_(FREE_IMAGE_FORMAT fif);
/// <summary>
/// Returns a regular expression string that can be used by a regular expression engine to identify the bitmap.
/// FreeImageQt makes use of this function.
/// </summary>
/// <param name="fif">The desired <see cref="FREE_IMAGE_FORMAT"/>.</param>
/// <returns>A regular expression string.</returns>
public static unsafe string GetFIFRegExpr(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFIFRegExpr_(fif)); }
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFRegExpr")]
private static unsafe extern byte* GetFIFRegExpr_(FREE_IMAGE_FORMAT fif);
/// <summary>
/// Given a <see cref="FREE_IMAGE_FORMAT"/> identifier, returns a MIME content type string (MIME stands for Multipurpose Internet Mail Extension).
/// </summary>
/// <param name="fif">The desired <see cref="FREE_IMAGE_FORMAT"/>.</param>
/// <returns>A MIME content type string.</returns>
public static unsafe string GetFIFMimeType(FREE_IMAGE_FORMAT fif) { return PtrToStr(GetFIFMimeType_(fif)); }
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFIFMimeType")]
private static unsafe extern byte* GetFIFMimeType_(FREE_IMAGE_FORMAT fif);
/// <summary>
/// This function takes a filename or a file-extension and returns the plugin that can
/// read/write files with that extension in the form of a <see cref="FREE_IMAGE_FORMAT"/> identifier.
/// </summary>
/// <param name="filename">The filename or -extension.</param>
/// <returns>The <see cref="FREE_IMAGE_FORMAT"/> of the plugin.</returns>
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFIFFromFilenameU")]
public static extern FREE_IMAGE_FORMAT GetFIFFromFilename(string filename);
/// <summary>
/// This function takes a filename or a file-extension and returns the plugin that can
/// read/write files with that extension in the form of a <see cref="FREE_IMAGE_FORMAT"/> identifier.
/// Supports UNICODE filenames.
/// </summary>
/// <param name="filename">The filename or -extension.</param>
/// <returns>The <see cref="FREE_IMAGE_FORMAT"/> of the plugin.</returns>
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFIFFromFilenameU")]
private static extern FREE_IMAGE_FORMAT GetFIFFromFilenameU(string filename);
/// <summary>
/// Checks if a plugin can load bitmaps.
/// </summary>
/// <param name="fif">The <see cref="FREE_IMAGE_FORMAT"/> of the plugin.</param>
/// <returns>True if the plugin can load bitmaps, else false.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsReading")]
public static extern bool FIFSupportsReading(FREE_IMAGE_FORMAT fif);
/// <summary>
/// Checks if a plugin can save bitmaps.
/// </summary>
/// <param name="fif">The <see cref="FREE_IMAGE_FORMAT"/> of the plugin.</param>
/// <returns>True if the plugin can save bitmaps, else false.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsWriting")]
public static extern bool FIFSupportsWriting(FREE_IMAGE_FORMAT fif);
/// <summary>
/// Checks if a plugin can save bitmaps in the desired bit depth.
/// </summary>
/// <param name="fif">The <see cref="FREE_IMAGE_FORMAT"/> of the plugin.</param>
/// <param name="bpp">The desired bit depth.</param>
/// <returns>True if the plugin can save bitmaps in the desired bit depth, else false.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsExportBPP")]
public static extern bool FIFSupportsExportBPP(FREE_IMAGE_FORMAT fif, int bpp);
/// <summary>
/// Checks if a plugin can save a bitmap in the desired data type.
/// </summary>
/// <param name="fif">The <see cref="FREE_IMAGE_FORMAT"/> of the plugin.</param>
/// <param name="type">The desired image type.</param>
/// <returns>True if the plugin can save bitmaps as the desired type, else false.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsExportType")]
public static extern bool FIFSupportsExportType(FREE_IMAGE_FORMAT fif, FREE_IMAGE_TYPE type);
/// <summary>
/// Checks if a plugin can load or save an ICC profile.
/// </summary>
/// <param name="fif">The <see cref="FREE_IMAGE_FORMAT"/> of the plugin.</param>
/// <returns>True if the plugin can load or save an ICC profile, else false.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_FIFSupportsICCProfiles")]
public static extern bool FIFSupportsICCProfiles(FREE_IMAGE_FORMAT fif);
#endregion
#region Multipage functions
/// <summary>
/// Loads a FreeImage multi-paged bitmap.
/// Load flags can be provided by the flags parameter.
/// </summary>
/// <param name="fif">Format of the image.</param>
/// <param name="filename">The complete name of the file to load.</param>
/// <param name="create_new">When true a new bitmap is created.</param>
/// <param name="read_only">When true the bitmap will be loaded read only.</param>
/// <param name="keep_cache_in_memory">When true performance is increased at the cost of memory.</param>
/// <param name="flags">Flags to enable or disable plugin-features.</param>
/// <returns>Handle to a FreeImage multi-paged bitmap.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_OpenMultiBitmap")]
public static extern FIMULTIBITMAP OpenMultiBitmap(FREE_IMAGE_FORMAT fif, string filename, bool create_new,
bool read_only, bool keep_cache_in_memory, FREE_IMAGE_LOAD_FLAGS flags);
/// <summary>
/// Loads a FreeImage multi-pages bitmap from the specified handle
/// using the specified functions.
/// Load flags can be provided by the flags parameter.
/// </summary>
/// <param name="fif">Format of the image.</param>
/// <param name="io">IO functions used to read from the specified handle.</param>
/// <param name="handle">The handle to load the bitmap from.</param>
/// <param name="flags">Flags to enable or disable plugin-features.</param>
/// <returns>Handle to a FreeImage multi-paged bitmap.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_OpenMultiBitmapFromHandle")]
public static extern FIMULTIBITMAP OpenMultiBitmapFromHandle(FREE_IMAGE_FORMAT fif, ref FreeImageIO io,
fi_handle handle, FREE_IMAGE_LOAD_FLAGS flags);
/// <summary>
/// Closes a previously opened multi-page bitmap and, when the bitmap was not opened read-only, applies any changes made to it.
/// </summary>
/// <param name="bitmap">Handle to a FreeImage multi-paged bitmap.</param>
/// <param name="flags">Flags to enable or disable plugin-features.</param>
/// <returns>Returns true on success, false on failure.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_CloseMultiBitmap")]
private static extern bool CloseMultiBitmap_(FIMULTIBITMAP bitmap, FREE_IMAGE_SAVE_FLAGS flags);
/// <summary>
/// Returns the number of pages currently available in the multi-paged bitmap.
/// </summary>
/// <param name="bitmap">Handle to a FreeImage multi-paged bitmap.</param>
/// <returns>Number of pages.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPageCount")]
public static extern int GetPageCount(FIMULTIBITMAP bitmap);
/// <summary>
/// Appends a new page to the end of the bitmap.
/// </summary>
/// <param name="bitmap">Handle to a FreeImage multi-paged bitmap.</param>
/// <param name="data">Handle to a FreeImage bitmap.</param>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_AppendPage")]
public static extern void AppendPage(FIMULTIBITMAP bitmap, FIBITMAP data);
/// <summary>
/// Inserts a new page before the given position in the bitmap.
/// </summary>
/// <param name="bitmap">Handle to a FreeImage multi-paged bitmap.</param>
/// <param name="page">Page has to be a number smaller than the current number of pages available in the bitmap.</param>
/// <param name="data">Handle to a FreeImage bitmap.</param>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_InsertPage")]
public static extern void InsertPage(FIMULTIBITMAP bitmap, int page, FIBITMAP data);
/// <summary>
/// Deletes the page on the given position.
/// </summary>
/// <param name="bitmap">Handle to a FreeImage multi-paged bitmap.</param>
/// <param name="page">Number of the page to delete.</param>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_DeletePage")]
public static extern void DeletePage(FIMULTIBITMAP bitmap, int page);
/// <summary>
/// Locks a page in memory for editing.
/// </summary>
/// <param name="bitmap">Handle to a FreeImage multi-paged bitmap.</param>
/// <param name="page">Number of the page to lock.</param>
/// <returns>Handle to a FreeImage bitmap.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_LockPage")]
public static extern FIBITMAP LockPage(FIMULTIBITMAP bitmap, int page);
/// <summary>
/// Unlocks a previously locked page and gives it back to the multi-page engine.
/// </summary>
/// <param name="bitmap">Handle to a FreeImage multi-paged bitmap.</param>
/// <param name="data">Handle to a FreeImage bitmap.</param>
/// <param name="changed">If true, the page is applied to the multi-page bitmap.</param>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_UnlockPage")]
public static extern void UnlockPage(FIMULTIBITMAP bitmap, FIBITMAP data, bool changed);
/// <summary>
/// Moves the source page to the position of the target page.
/// </summary>
/// <param name="bitmap">Handle to a FreeImage multi-paged bitmap.</param>
/// <param name="target">New position of the page.</param>
/// <param name="source">Old position of the page.</param>
/// <returns>Returns true on success, false on failure.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_MovePage")]
public static extern bool MovePage(FIMULTIBITMAP bitmap, int target, int source);
/// <summary>
/// Returns an array of page-numbers that are currently locked in memory.
/// When the pages parameter is null, the size of the array is returned in the count variable.
/// </summary>
/// <example>
/// <code>
/// int[] lockedPages = null;
/// int count = 0;
/// GetLockedPageNumbers(dib, lockedPages, ref count);
/// lockedPages = new int[count];
/// GetLockedPageNumbers(dib, lockedPages, ref count);
/// </code>
/// </example>
/// <param name="bitmap">Handle to a FreeImage multi-paged bitmap.</param>
/// <param name="pages">The list of locked pages in the multi-pages bitmap.
/// If set to null, count will contain the number of pages.</param>
/// <param name="count">If <paramref name="pages"/> is set to null count will contain the number of locked pages.</param>
/// <returns>Returns true on success, false on failure.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetLockedPageNumbers")]
public static extern bool GetLockedPageNumbers(FIMULTIBITMAP bitmap, int[] pages, ref int count);
#endregion
#region Filetype functions
/// <summary>
/// Orders FreeImage to analyze the bitmap signature.
/// </summary>
/// <param name="filename">Name of the file to analyze.</param>
/// <param name="size">Reserved parameter - use 0.</param>
/// <returns>Type of the bitmap.</returns>
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFileTypeU")]
public static extern FREE_IMAGE_FORMAT GetFileType(string filename, int size);
/// <summary>
/// Orders FreeImage to analyze the bitmap signature.
/// Supports UNICODE filenames.
/// </summary>
/// <param name="filename">Name of the file to analyze.</param>
/// <param name="size">Reserved parameter - use 0.</param>
/// <returns>Type of the bitmap.</returns>
[DllImport(FreeImageLibrary, CharSet = CharSet.Unicode, EntryPoint = "FreeImage_GetFileTypeU")]
private static extern FREE_IMAGE_FORMAT GetFileTypeU(string filename, int size);
/// <summary>
/// Uses the <see cref="FreeImageIO"/> structure as described in the topic bitmap management functions
/// to identify a bitmap type.
/// </summary>
/// <param name="io">A <see cref="FreeImageIO"/> structure with functionpointers to handle the source.</param>
/// <param name="handle">A handle to the source.</param>
/// <param name="size">Size in bytes of the source.</param>
/// <returns>Type of the bitmap.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFileTypeFromHandle")]
public static extern FREE_IMAGE_FORMAT GetFileTypeFromHandle(ref FreeImageIO io, fi_handle handle, int size);
/// <summary>
/// Uses a memory handle to identify a bitmap type.
/// </summary>
/// <param name="stream">Pointer to the stream.</param>
/// <param name="size">Size in bytes of the source.</param>
/// <returns>Type of the bitmap.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetFileTypeFromMemory")]
public static extern FREE_IMAGE_FORMAT GetFileTypeFromMemory(FIMEMORY stream, int size);
#endregion
#region Helper functions
/// <summary>
/// Returns whether the platform is using Little Endian.
/// </summary>
/// <returns>Returns true if the platform is using Litte Endian, else false.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_IsLittleEndian")]
public static extern bool IsLittleEndian();
/// <summary>
/// Converts a X11 color name into a corresponding RGB value.
/// </summary>
/// <param name="szColor">Name of the color to convert.</param>
/// <param name="nRed">Red component.</param>
/// <param name="nGreen">Green component.</param>
/// <param name="nBlue">Blue component.</param>
/// <returns>Returns true on success, false on failure.</returns>
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_LookupX11Color")]
public static extern bool LookupX11Color(string szColor, out byte nRed, out byte nGreen, out byte nBlue);
/// <summary>
/// Converts a SVG color name into a corresponding RGB value.
/// </summary>
/// <param name="szColor">Name of the color to convert.</param>
/// <param name="nRed">Red component.</param>
/// <param name="nGreen">Green component.</param>
/// <param name="nBlue">Blue component.</param>
/// <returns>Returns true on success, false on failure.</returns>
[DllImport(FreeImageLibrary, CharSet = CharSet.Ansi, EntryPoint = "FreeImage_LookupSVGColor")]
public static extern bool LookupSVGColor(string szColor, out byte nRed, out byte nGreen, out byte nBlue);
#endregion
#region Pixel access functions
/// <summary>
/// Returns a pointer to the data-bits of the bitmap.
/// </summary>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
/// <returns>Pointer to the data-bits.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetBits")]
public static extern IntPtr GetBits(FIBITMAP dib);
/// <summary>
/// Returns a pointer to the start of the given scanline in the bitmap's data-bits.
/// </summary>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
/// <param name="scanline">Number of the scanline.</param>
/// <returns>Pointer to the scanline.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetScanLine")]
public static extern IntPtr GetScanLine(FIBITMAP dib, int scanline);
/// <summary>
/// Get the pixel index of a palettized image at position (x, y), including range check (slow access).
/// </summary>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
/// <param name="x">Pixel position in horizontal direction.</param>
/// <param name="y">Pixel position in vertical direction.</param>
/// <param name="value">The pixel index.</param>
/// <returns>Returns true on success, false on failure.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPixelIndex")]
public static extern bool GetPixelIndex(FIBITMAP dib, uint x, uint y, out byte value);
/// <summary>
/// Get the pixel color of a 16-, 24- or 32-bit image at position (x, y), including range check (slow access).
/// </summary>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
/// <param name="x">Pixel position in horizontal direction.</param>
/// <param name="y">Pixel position in vertical direction.</param>
/// <param name="value">The pixel color.</param>
/// <returns>Returns true on success, false on failure.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPixelColor")]
public static extern bool GetPixelColor(FIBITMAP dib, uint x, uint y, out RGBQUAD value);
/// <summary>
/// Set the pixel index of a palettized image at position (x, y), including range check (slow access).
/// </summary>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
/// <param name="x">Pixel position in horizontal direction.</param>
/// <param name="y">Pixel position in vertical direction.</param>
/// <param name="value">The new pixel index.</param>
/// <returns>Returns true on success, false on failure.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetPixelIndex")]
public static extern bool SetPixelIndex(FIBITMAP dib, uint x, uint y, ref byte value);
/// <summary>
/// Set the pixel color of a 16-, 24- or 32-bit image at position (x, y), including range check (slow access).
/// </summary>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
/// <param name="x">Pixel position in horizontal direction.</param>
/// <param name="y">Pixel position in vertical direction.</param>
/// <param name="value">The new pixel color.</param>
/// <returns>Returns true on success, false on failure.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_SetPixelColor")]
public static extern bool SetPixelColor(FIBITMAP dib, uint x, uint y, ref RGBQUAD value);
#endregion
#region Bitmap information functions
/// <summary>
/// Retrieves the type of the bitmap.
/// </summary>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
/// <returns>Type of the bitmap.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetImageType")]
public static extern FREE_IMAGE_TYPE GetImageType(FIBITMAP dib);
/// <summary>
/// Returns the number of colors used in a bitmap.
/// </summary>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
/// <returns>Palette-size for palletised bitmaps, and 0 for high-colour bitmaps.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetColorsUsed")]
public static extern uint GetColorsUsed(FIBITMAP dib);
/// <summary>
/// Returns the size of one pixel in the bitmap in bits.
/// </summary>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
/// <returns>Size of one pixel in the bitmap in bits.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetBPP")]
public static extern uint GetBPP(FIBITMAP dib);
/// <summary>
/// Returns the width of the bitmap in pixel units.
/// </summary>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
/// <returns>With of the bitmap.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetWidth")]
public static extern uint GetWidth(FIBITMAP dib);
/// <summary>
/// Returns the height of the bitmap in pixel units.
/// </summary>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
/// <returns>Height of the bitmap.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetHeight")]
public static extern uint GetHeight(FIBITMAP dib);
/// <summary>
/// Returns the width of the bitmap in bytes.
/// </summary>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
/// <returns>With of the bitmap in bytes.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetLine")]
public static extern uint GetLine(FIBITMAP dib);
/// <summary>
/// Returns the width of the bitmap in bytes, rounded to the next 32-bit boundary,
/// also known as pitch or stride or scan width.
/// </summary>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
/// <returns>With of the bitmap in bytes.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPitch")]
public static extern uint GetPitch(FIBITMAP dib);
/// <summary>
/// Returns the size of the DIB-element of a FIBITMAP in memory.
/// </summary>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
/// <returns>Size of the DIB-element</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetDIBSize")]
public static extern uint GetDIBSize(FIBITMAP dib);
/// <summary>
/// Returns a pointer to the bitmap's palette.
/// </summary>
/// <param name="dib">Handle to a FreeImage bitmap.</param>
/// <returns>Pointer to the bitmap's palette.</returns>
[DllImport(FreeImageLibrary, EntryPoint = "FreeImage_GetPalette")]
public static extern IntPtr GetPalette(FIBITMAP dib);
/// <summary>
/// Returns the horizontal resolution, in pixels-per-meter, of the target device for the bitmap.
/// </summary>
/// <param name="dib">Handle to a FreeImage bitmap.</param>