NativeMethods_imgcodecs.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using System.Diagnostics.Contracts;
  2. using System.Runtime.InteropServices;
  3. #pragma warning disable 1591
  4. #pragma warning disable CA2101 // Specify marshaling for P/Invoke string arguments
  5. namespace OpenCvSharp.Internal;
  6. static partial class NativeMethods
  7. {
  8. // imread
  9. [Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true, ExactSpelling = true,
  10. EntryPoint = "imgcodecs_imread")]
  11. public static extern ExceptionStatus imgcodecs_imread_NotWindows(
  12. [MarshalAs(StringUnmanagedTypeNotWindows)] string fileName, int flags, out IntPtr returnValue);
  13. [Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true, ExactSpelling = true,
  14. EntryPoint = "imgcodecs_imread")]
  15. public static extern ExceptionStatus imgcodecs_imread_Windows(
  16. [MarshalAs(StringUnmanagedTypeWindows)] string fileName, int flags, out IntPtr returnValue);
  17. [Pure]
  18. public static ExceptionStatus imgcodecs_imread(string fileName, int flags, out IntPtr returnValue)
  19. {
  20. if (IsWindows())
  21. return imgcodecs_imread_Windows(fileName, flags, out returnValue);
  22. return imgcodecs_imread_NotWindows(fileName, flags, out returnValue);
  23. }
  24. // imreadmulti
  25. [Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true, ExactSpelling = true,
  26. EntryPoint = "imgcodecs_imreadmulti")]
  27. public static extern ExceptionStatus imgcodecs_imreadmulti_NotWindows(
  28. [MarshalAs(StringUnmanagedTypeNotWindows)] string fileName, IntPtr mats, int flags, out int returnValue);
  29. [Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true, ExactSpelling = true,
  30. EntryPoint = "imgcodecs_imreadmulti")]
  31. public static extern ExceptionStatus imgcodecs_imreadmulti_Windows(
  32. [MarshalAs(StringUnmanagedTypeWindows)] string fileName, IntPtr mats, int flags, out int returnValue);
  33. [Pure]
  34. public static ExceptionStatus imgcodecs_imreadmulti(string fileName, IntPtr mats, int flags, out int returnValue)
  35. {
  36. if (IsWindows())
  37. return imgcodecs_imreadmulti_Windows(fileName, mats, flags, out returnValue);
  38. return imgcodecs_imreadmulti_NotWindows(fileName, mats, flags, out returnValue);
  39. }
  40. // imwrite
  41. [Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true, ExactSpelling = true,
  42. EntryPoint = "imgcodecs_imwrite")]
  43. public static extern ExceptionStatus imgcodecs_imwrite_NotWindows(
  44. [MarshalAs(StringUnmanagedTypeNotWindows)] string fileName, IntPtr img, [In] int[] @params, int paramsLength, out int returnValue);
  45. [Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true, ExactSpelling = true,
  46. EntryPoint = "imgcodecs_imwrite")]
  47. public static extern ExceptionStatus imgcodecs_imwrite_Windows(
  48. [MarshalAs(StringUnmanagedTypeWindows)] string fileName, IntPtr img, [In] int[] @params, int paramsLength, out int returnValue);
  49. [Pure]
  50. public static ExceptionStatus imgcodecs_imwrite(string fileName, IntPtr img, int[] @params, int paramsLength, out int returnValue)
  51. {
  52. if (IsWasm()) {
  53. returnValue = default(int);
  54. return ExceptionStatus.Occurred;
  55. }
  56. if (IsWindows())
  57. return imgcodecs_imwrite_Windows(fileName, img, @params, paramsLength, out returnValue);
  58. return imgcodecs_imwrite_NotWindows(fileName, img, @params, paramsLength, out returnValue);
  59. }
  60. // imwrite_multi
  61. [Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true, ExactSpelling = true,
  62. EntryPoint = "imgcodecs_imwrite_multi")]
  63. public static extern ExceptionStatus imgcodecs_imwrite_multi_NotWindows(
  64. [MarshalAs(StringUnmanagedTypeNotWindows)] string fileName, IntPtr img, [In] int[] @params, int paramsLength, out int returnValue);
  65. [Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true, ExactSpelling = true,
  66. EntryPoint = "imgcodecs_imwrite_multi")]
  67. public static extern ExceptionStatus imgcodecs_imwrite_multi_Windows(
  68. [MarshalAs(StringUnmanagedTypeWindows)] string fileName, IntPtr img, [In] int[] @params, int paramsLength, out int returnValue);
  69. [Pure]
  70. public static ExceptionStatus imgcodecs_imwrite_multi(string fileName, IntPtr img, int[] @params, int paramsLength, out int returnValue)
  71. {
  72. if (IsWindows())
  73. return imgcodecs_imwrite_multi_Windows(fileName, img, @params, paramsLength, out returnValue);
  74. return imgcodecs_imwrite_multi_NotWindows(fileName, img, @params, paramsLength, out returnValue);
  75. }
  76. //
  77. [Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
  78. public static extern ExceptionStatus imgcodecs_imdecode_Mat(
  79. IntPtr buf, int flags, out IntPtr returnValue);
  80. [Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
  81. public static extern unsafe ExceptionStatus imgcodecs_imdecode_vector(
  82. byte* buf, int bufLength, int flags, out IntPtr returnValue);
  83. [Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
  84. public static extern ExceptionStatus imgcodecs_imdecode_InputArray(
  85. IntPtr buf, int flags, out IntPtr returnValue);
  86. // Do not consider that "ext" may not be ASCII characters
  87. [Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true, ExactSpelling = true)]
  88. public static extern ExceptionStatus imgcodecs_imencode_vector(
  89. [MarshalAs(UnmanagedType.LPStr)] string ext, IntPtr img, IntPtr buf, [In] int[] @params, int paramsLength, out int returnValue);
  90. // haveImageReader
  91. [Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true, ExactSpelling = true,
  92. EntryPoint = "imgcodecs_imwrite")]
  93. public static extern ExceptionStatus imgcodecs_haveImageReader_NotWindows(
  94. [MarshalAs(StringUnmanagedTypeNotWindows)] string fileName, out int returnValue);
  95. [Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true, ExactSpelling = true,
  96. EntryPoint = "imgcodecs_imwrite")]
  97. public static extern ExceptionStatus imgcodecs_haveImageReader_Windows(
  98. [MarshalAs(StringUnmanagedTypeWindows)] string fileName, out int returnValue);
  99. [Pure]
  100. public static ExceptionStatus imgcodecs_haveImageReader(string fileName, out int returnValue)
  101. {
  102. if (IsWasm()) {
  103. returnValue = default(int);
  104. return ExceptionStatus.Occurred;
  105. }
  106. if (IsWindows())
  107. return imgcodecs_haveImageReader_Windows(fileName, out returnValue);
  108. return imgcodecs_haveImageReader_NotWindows(fileName, out returnValue);
  109. }
  110. // haveImageWriter
  111. [Pure, DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, BestFitMapping = false, ThrowOnUnmappableChar = true, ExactSpelling = true)]
  112. public static extern ExceptionStatus imgcodecs_haveImageWriter(
  113. [MarshalAs(UnmanagedType.LPStr)] string fileName, out int returnValue);
  114. }