Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

159 linhas
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://sam.zoy.org/wtfpl/COPYING 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. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  46. SuppressUnmanagedCodeSecurity]
  47. private static extern int caca_set_dither_palette(IntPtr d,
  48. uint[] r, uint[] g,
  49. uint[] b, uint[] a);
  50. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  51. SuppressUnmanagedCodeSecurity]
  52. private static extern int caca_set_dither_brightness(IntPtr d, float b);
  53. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  54. SuppressUnmanagedCodeSecurity]
  55. private static extern int caca_set_dither_gamma(IntPtr d, float g);
  56. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  57. SuppressUnmanagedCodeSecurity]
  58. private static extern int caca_set_dither_contrast(IntPtr d, float c);
  59. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  60. SuppressUnmanagedCodeSecurity]
  61. private static extern int caca_set_dither_invert(IntPtr d, int i);
  62. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  63. SuppressUnmanagedCodeSecurity]
  64. private static extern int caca_set_dither_antialias(IntPtr d, string s);
  65. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  66. SuppressUnmanagedCodeSecurity]
  67. private static extern string[] caca_get_dither_antialias_list(IntPtr d);
  68. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  69. SuppressUnmanagedCodeSecurity]
  70. private static extern int caca_set_dither_color(IntPtr d, string s);
  71. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  72. SuppressUnmanagedCodeSecurity]
  73. private static extern string[] caca_get_dither_color_list(IntPtr d);
  74. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  75. SuppressUnmanagedCodeSecurity]
  76. private static extern int caca_set_dither_charset(IntPtr d, string s);
  77. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  78. SuppressUnmanagedCodeSecurity]
  79. private static extern string[] caca_get_dither_charset_list(IntPtr d);
  80. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  81. SuppressUnmanagedCodeSecurity]
  82. private static extern int caca_set_dither_mode(IntPtr d, string s);
  83. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  84. SuppressUnmanagedCodeSecurity]
  85. private static extern string[] caca_get_dither_mode_list(IntPtr d);
  86. public int setBrightness(float b)
  87. {
  88. return caca_set_dither_brightness(_dither, b);
  89. }
  90. public int setGamma(float g)
  91. {
  92. return caca_set_dither_gamma(_dither, g);
  93. }
  94. public int setContrast(float c)
  95. {
  96. return caca_set_dither_contrast(_dither, c);
  97. }
  98. public int setInvert(int i)
  99. {
  100. return caca_set_dither_invert(_dither, i);
  101. }
  102. public int setAntialias(string s)
  103. {
  104. return caca_set_dither_antialias(_dither, s);
  105. }
  106. public int setColor(string s)
  107. {
  108. return caca_set_dither_color(_dither, s);
  109. }
  110. public int setCharset(string s)
  111. {
  112. return caca_set_dither_charset(_dither, s);
  113. }
  114. public int setMode(string s)
  115. {
  116. return caca_set_dither_mode(_dither, s);
  117. }
  118. /* <FIXME> */
  119. public string[] getAntialiasList()
  120. {
  121. return caca_get_dither_antialias_list(_dither);
  122. }
  123. public string[] getColorList()
  124. {
  125. return caca_get_dither_color_list(_dither);
  126. }
  127. public string[] getCharsetList()
  128. {
  129. return caca_get_dither_charset_list(_dither);
  130. }
  131. public string[] getModeList()
  132. {
  133. return caca_get_dither_mode_list(_dither);
  134. }
  135. /* </FIXME> */
  136. }
  137. }