| 1 |
/* |
| 2 |
* libcaca .NET bindings for libcaca |
| 3 |
* Copyright (c) 2006 Jean-Yves Lamoureux <[email protected]> |
| 4 |
* 2007 Sam Hocevar <[email protected]> |
| 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 |
|
| 14 |
using System; |
| 15 |
using System.Runtime.InteropServices; |
| 16 |
using System.Security; |
| 17 |
using System.Drawing; |
| 18 |
|
| 19 |
namespace Caca |
| 20 |
{ |
| 21 |
public class Dither : IDisposable |
| 22 |
{ |
| 23 |
public readonly IntPtr _dither; |
| 24 |
|
| 25 |
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
| 26 |
SuppressUnmanagedCodeSecurity] |
| 27 |
private static extern IntPtr caca_create_dither(int bpp, int w, |
| 28 |
int h, int pitch, |
| 29 |
uint rmask, |
| 30 |
uint gmask, |
| 31 |
uint bmask, |
| 32 |
uint amask); |
| 33 |
public Dither(int bpp, Size s, int pitch, |
| 34 |
uint rmask, uint gmask, uint bmask, uint amask) |
| 35 |
{ |
| 36 |
_dither = caca_create_dither(bpp, s.Width, s.Height, pitch, |
| 37 |
rmask, gmask, bmask, amask); |
| 38 |
} |
| 39 |
|
| 40 |
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
| 41 |
SuppressUnmanagedCodeSecurity] |
| 42 |
private static extern int caca_free_dither(IntPtr d); |
| 43 |
public void Dispose() |
| 44 |
{ |
| 45 |
caca_free_dither(_dither); |
| 46 |
GC.SuppressFinalize(this); |
| 47 |
} |
| 48 |
|
| 49 |
/* TODO: fix this shit */ |
| 50 |
|
| 51 |
#if false |
| 52 |
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
| 53 |
SuppressUnmanagedCodeSecurity] |
| 54 |
private static extern int caca_set_dither_palette(IntPtr d, |
| 55 |
uint[] r, uint[] g, |
| 56 |
uint[] b, uint[] a); |
| 57 |
#endif |
| 58 |
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
| 59 |
SuppressUnmanagedCodeSecurity] |
| 60 |
private static extern int caca_set_dither_brightness(IntPtr d, float b); |
| 61 |
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
| 62 |
SuppressUnmanagedCodeSecurity] |
| 63 |
private static extern int caca_set_dither_gamma(IntPtr d, float g); |
| 64 |
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
| 65 |
SuppressUnmanagedCodeSecurity] |
| 66 |
private static extern int caca_set_dither_contrast(IntPtr d, float c); |
| 67 |
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
| 68 |
SuppressUnmanagedCodeSecurity] |
| 69 |
private static extern int caca_set_dither_invert(IntPtr d, int i); |
| 70 |
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
| 71 |
SuppressUnmanagedCodeSecurity] |
| 72 |
private static extern int caca_set_dither_antialias(IntPtr d, string s); |
| 73 |
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
| 74 |
SuppressUnmanagedCodeSecurity] |
| 75 |
private static extern string[] caca_get_dither_antialias_list(IntPtr d); |
| 76 |
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
| 77 |
SuppressUnmanagedCodeSecurity] |
| 78 |
private static extern int caca_set_dither_color(IntPtr d, string s); |
| 79 |
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
| 80 |
SuppressUnmanagedCodeSecurity] |
| 81 |
private static extern string[] caca_get_dither_color_list(IntPtr d); |
| 82 |
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
| 83 |
SuppressUnmanagedCodeSecurity] |
| 84 |
private static extern int caca_set_dither_charset(IntPtr d, string s); |
| 85 |
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
| 86 |
SuppressUnmanagedCodeSecurity] |
| 87 |
private static extern string[] caca_get_dither_charset_list(IntPtr d); |
| 88 |
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
| 89 |
SuppressUnmanagedCodeSecurity] |
| 90 |
private static extern int caca_set_dither_mode(IntPtr d, string s); |
| 91 |
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
| 92 |
SuppressUnmanagedCodeSecurity] |
| 93 |
private static extern string[] caca_get_dither_mode_list(IntPtr d); |
| 94 |
|
| 95 |
|
| 96 |
public int setBrightness(float b) |
| 97 |
{ |
| 98 |
return caca_set_dither_brightness(_dither, b); |
| 99 |
} |
| 100 |
|
| 101 |
public int setGamma(float g) |
| 102 |
{ |
| 103 |
return caca_set_dither_gamma(_dither, g); |
| 104 |
} |
| 105 |
|
| 106 |
public int setContrast(float c) |
| 107 |
{ |
| 108 |
return caca_set_dither_contrast(_dither, c); |
| 109 |
} |
| 110 |
|
| 111 |
public int setInvert(int i) |
| 112 |
{ |
| 113 |
return caca_set_dither_invert(_dither, i); |
| 114 |
} |
| 115 |
|
| 116 |
public int setAntialias(string s) |
| 117 |
{ |
| 118 |
return caca_set_dither_antialias(_dither, s); |
| 119 |
} |
| 120 |
|
| 121 |
public int setColor(string s) |
| 122 |
{ |
| 123 |
return caca_set_dither_color(_dither, s); |
| 124 |
} |
| 125 |
|
| 126 |
public int setCharset(string s) |
| 127 |
{ |
| 128 |
return caca_set_dither_charset(_dither, s); |
| 129 |
} |
| 130 |
|
| 131 |
public int setMode(string s) |
| 132 |
{ |
| 133 |
return caca_set_dither_mode(_dither, s); |
| 134 |
} |
| 135 |
|
| 136 |
/* <FIXME> */ |
| 137 |
public string[] getAntialiasList() |
| 138 |
{ |
| 139 |
return caca_get_dither_antialias_list(_dither); |
| 140 |
} |
| 141 |
|
| 142 |
public string[] getColorList() |
| 143 |
{ |
| 144 |
return caca_get_dither_color_list(_dither); |
| 145 |
} |
| 146 |
|
| 147 |
public string[] getCharsetList() |
| 148 |
{ |
| 149 |
return caca_get_dither_charset_list(_dither); |
| 150 |
} |
| 151 |
|
| 152 |
public string[] getModeList() |
| 153 |
{ |
| 154 |
return caca_get_dither_mode_list(_dither); |
| 155 |
} |
| 156 |
|
| 157 |
/* </FIXME> */ |
| 158 |
} |
| 159 |
} |
| 160 |
|