You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

161 regels
5.9 KiB

  1. /*
  2. * libcaca .NET bindings for libcaca
  3. * Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
  4. * 2007 Sam Hocevar <sam@hocevar.net>
  5. * All Rights Reserved
  6. *
  7. * This library is free software. It comes without any warranty, to
  8. * the extent permitted by applicable law. You can redistribute it
  9. * and/or modify it under the terms of the Do What the Fuck You Want
  10. * to Public License, Version 2, as published by Sam Hocevar. See
  11. * http://www.wtfpl.net/ for more details.
  12. */
  13. using System;
  14. using System.Runtime.InteropServices;
  15. using System.Security;
  16. using System.Drawing;
  17. namespace Caca
  18. {
  19. public class Dither : IDisposable
  20. {
  21. public readonly IntPtr _dither;
  22. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  23. SuppressUnmanagedCodeSecurity]
  24. private static extern IntPtr caca_create_dither(int bpp, int w,
  25. int h, int pitch,
  26. uint rmask,
  27. uint gmask,
  28. uint bmask,
  29. uint amask);
  30. public Dither(int bpp, Size s, int pitch,
  31. uint rmask, uint gmask, uint bmask, uint amask)
  32. {
  33. _dither = caca_create_dither(bpp, s.Width, s.Height, pitch,
  34. rmask, gmask, bmask, amask);
  35. }
  36. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  37. SuppressUnmanagedCodeSecurity]
  38. private static extern int caca_free_dither(IntPtr d);
  39. public void Dispose()
  40. {
  41. caca_free_dither(_dither);
  42. GC.SuppressFinalize(this);
  43. }
  44. /* TODO: fix this shit */
  45. #if false
  46. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  47. SuppressUnmanagedCodeSecurity]
  48. private static extern int caca_set_dither_palette(IntPtr d,
  49. uint[] r, uint[] g,
  50. uint[] b, uint[] a);
  51. #endif
  52. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  53. SuppressUnmanagedCodeSecurity]
  54. private static extern int caca_set_dither_brightness(IntPtr d, float b);
  55. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  56. SuppressUnmanagedCodeSecurity]
  57. private static extern int caca_set_dither_gamma(IntPtr d, float g);
  58. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  59. SuppressUnmanagedCodeSecurity]
  60. private static extern int caca_set_dither_contrast(IntPtr d, float c);
  61. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  62. SuppressUnmanagedCodeSecurity]
  63. private static extern int caca_set_dither_invert(IntPtr d, int i);
  64. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  65. SuppressUnmanagedCodeSecurity]
  66. private static extern int caca_set_dither_antialias(IntPtr d, string s);
  67. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  68. SuppressUnmanagedCodeSecurity]
  69. private static extern string[] caca_get_dither_antialias_list(IntPtr d);
  70. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  71. SuppressUnmanagedCodeSecurity]
  72. private static extern int caca_set_dither_color(IntPtr d, string s);
  73. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  74. SuppressUnmanagedCodeSecurity]
  75. private static extern string[] caca_get_dither_color_list(IntPtr d);
  76. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  77. SuppressUnmanagedCodeSecurity]
  78. private static extern int caca_set_dither_charset(IntPtr d, string s);
  79. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  80. SuppressUnmanagedCodeSecurity]
  81. private static extern string[] caca_get_dither_charset_list(IntPtr d);
  82. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  83. SuppressUnmanagedCodeSecurity]
  84. private static extern int caca_set_dither_mode(IntPtr d, string s);
  85. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  86. SuppressUnmanagedCodeSecurity]
  87. private static extern string[] caca_get_dither_mode_list(IntPtr d);
  88. public int setBrightness(float b)
  89. {
  90. return caca_set_dither_brightness(_dither, b);
  91. }
  92. public int setGamma(float g)
  93. {
  94. return caca_set_dither_gamma(_dither, g);
  95. }
  96. public int setContrast(float c)
  97. {
  98. return caca_set_dither_contrast(_dither, c);
  99. }
  100. public int setInvert(int i)
  101. {
  102. return caca_set_dither_invert(_dither, i);
  103. }
  104. public int setAntialias(string s)
  105. {
  106. return caca_set_dither_antialias(_dither, s);
  107. }
  108. public int setColor(string s)
  109. {
  110. return caca_set_dither_color(_dither, s);
  111. }
  112. public int setCharset(string s)
  113. {
  114. return caca_set_dither_charset(_dither, s);
  115. }
  116. public int setMode(string s)
  117. {
  118. return caca_set_dither_mode(_dither, s);
  119. }
  120. /* <FIXME> */
  121. public string[] getAntialiasList()
  122. {
  123. return caca_get_dither_antialias_list(_dither);
  124. }
  125. public string[] getColorList()
  126. {
  127. return caca_get_dither_color_list(_dither);
  128. }
  129. public string[] getCharsetList()
  130. {
  131. return caca_get_dither_charset_list(_dither);
  132. }
  133. public string[] getModeList()
  134. {
  135. return caca_get_dither_mode_list(_dither);
  136. }
  137. /* </FIXME> */
  138. }
  139. }