4
4
using System . Runtime . InteropServices ;
5
5
using System . Diagnostics ;
6
6
7
- namespace FreeImageAPI
7
+ namespace FreeImageAPI ;
8
+
9
+ /// <summary>
10
+ /// Class handling non-bitmap related functions.
11
+ /// </summary>
12
+ public static class FreeImageEngine
8
13
{
9
- /// <summary>
10
- /// Class handling non-bitmap related functions.
11
- /// </summary>
12
- public static class FreeImageEngine
13
- {
14
- #region Callback
14
+ #region Callback
15
+
16
+ // Callback delegate
17
+ [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
18
+ private static readonly OutputMessageFunction outputMessageFunction ;
15
19
16
- // Callback delegate
17
- [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
18
- private static readonly OutputMessageFunction outputMessageFunction ;
20
+ static FreeImageEngine ( )
21
+ {
22
+ // Check if FreeImage.dll is present and cancel setting the callbackfuntion if not
23
+ if ( ! IsAvailable )
24
+ {
25
+ return ;
26
+ }
27
+ // Create a delegate (function pointer) to 'OnMessage'
28
+ outputMessageFunction = new OutputMessageFunction ( OnMessage ) ;
29
+ // Set the callback
30
+ FreeImage . SetOutputMessage ( outputMessageFunction ) ;
31
+ }
19
32
20
- static FreeImageEngine ( )
21
- {
22
- // Check if FreeImage.dll is present and cancel setting the callbackfuntion if not
23
- if ( ! IsAvailable )
24
- {
25
- return ;
26
- }
27
- // Create a delegate (function pointer) to 'OnMessage'
28
- outputMessageFunction = new OutputMessageFunction ( OnMessage ) ;
29
- // Set the callback
30
- FreeImage . SetOutputMessage ( outputMessageFunction ) ;
31
- }
33
+ /// <summary>
34
+ /// Internal callback
35
+ /// </summary>
36
+ private static void OnMessage ( FREE_IMAGE_FORMAT fif , string message )
37
+ {
38
+ // Get a local copy of the multicast-delegate
39
+ OutputMessageFunction m = Message ;
32
40
33
- /// <summary>
34
- /// Internal callback
35
- /// </summary>
36
- private static void OnMessage ( FREE_IMAGE_FORMAT fif , string message )
37
- {
38
- // Get a local copy of the multicast-delegate
39
- OutputMessageFunction m = Message ;
41
+ // Check the local copy instead of the static instance
42
+ // to prevent a second thread from setting the delegate
43
+ // to null, which would cause a nullreference exception
44
+ // Invoke the multicast-delegate
45
+ m ? . Invoke ( fif , message ) ;
46
+ }
40
47
41
- // Check the local copy instead of the static instance
42
- // to prevent a second thread from setting the delegate
43
- // to null, which would cause a nullreference exception
44
- // Invoke the multicast-delegate
45
- m ? . Invoke ( fif , message ) ;
48
+ /// <summary>
49
+ /// Gets a value indicating if the FreeImage DLL is available or not.
50
+ /// </summary>
51
+ public static bool IsAvailable
52
+ {
53
+ get
54
+ {
55
+ return FreeImage . IsAvailable ( ) ;
46
56
}
57
+ }
47
58
48
- /// <summary>
49
- /// Gets a value indicating if the FreeImage DLL is available or not.
50
- /// </summary>
51
- public static bool IsAvailable
52
- {
53
- get
54
- {
55
- return FreeImage . IsAvailable ( ) ;
56
- }
57
- }
58
-
59
- /// <summary>
60
- /// Internal errors in FreeImage generate a logstring that can be
61
- /// captured by this event.
62
- /// </summary>
63
- public static event OutputMessageFunction Message ;
59
+ /// <summary>
60
+ /// Internal errors in FreeImage generate a logstring that can be
61
+ /// captured by this event.
62
+ /// </summary>
63
+ public static event OutputMessageFunction Message ;
64
64
65
- #endregion
65
+ #endregion
66
66
67
- /// <summary>
68
- /// Gets a string containing the current version of the library.
69
- /// </summary>
70
- public static string Version
71
- {
72
- get
73
- {
74
- return FreeImage . GetVersion ( ) ;
75
- }
76
- }
67
+ /// <summary>
68
+ /// Gets a string containing the current version of the library.
69
+ /// </summary>
70
+ public static string Version
71
+ {
72
+ get
73
+ {
74
+ return FreeImage . GetVersion ( ) ;
75
+ }
76
+ }
77
77
78
- /// <summary>
79
- /// Gets a string containing a standard copyright message.
80
- /// </summary>
81
- public static string CopyrightMessage
82
- {
83
- get
84
- {
85
- return FreeImage . GetCopyrightMessage ( ) ;
86
- }
87
- }
78
+ /// <summary>
79
+ /// Gets a string containing a standard copyright message.
80
+ /// </summary>
81
+ public static string CopyrightMessage
82
+ {
83
+ get
84
+ {
85
+ return FreeImage . GetCopyrightMessage ( ) ;
86
+ }
87
+ }
88
88
89
- /// <summary>
90
- /// Gets whether the platform is using Little Endian.
91
- /// </summary>
92
- public static bool IsLittleEndian
93
- {
94
- get
95
- {
96
- return FreeImage . IsLittleEndian ( ) ;
97
- }
98
- }
99
- }
100
- }
89
+ /// <summary>
90
+ /// Gets whether the platform is using Little Endian.
91
+ /// </summary>
92
+ public static bool IsLittleEndian
93
+ {
94
+ get
95
+ {
96
+ return FreeImage . IsLittleEndian ( ) ;
97
+ }
98
+ }
99
+ }
0 commit comments