source: libcaca/trunk/caca-sharp/Dither.cs @ 4148

Last change on this file since 4148 was 4148, checked in by Sam Hocevar, 10 years ago

Update my e-mail address everywhere.

File size: 5.9 KB
Line 
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 *  $Id$
8 *
9 *  This library is free software. It comes without any warranty, to
10 *  the extent permitted by applicable law. You can redistribute it
11 *  and/or modify it under the terms of the Do What The Fuck You Want
12 *  To Public License, Version 2, as published by Sam Hocevar. See
13 *  http://sam.zoy.org/wtfpl/COPYING for more details.
14 */
15
16using System;
17using System.Runtime.InteropServices;
18using System.Security;
19using System.Drawing;
20
21namespace Caca
22{
23    public class Dither : IDisposable
24    {
25        public readonly IntPtr _dither;
26
27        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
28         SuppressUnmanagedCodeSecurity]
29        private static extern IntPtr caca_create_dither(int bpp, int w,
30                                                         int h, int pitch,
31                                                         uint rmask,
32                                                         uint gmask,
33                                                         uint bmask,
34                                                         uint amask);
35        public Dither(int bpp, Size s, int pitch,
36                      uint rmask, uint gmask, uint bmask, uint amask)
37        {
38            _dither = caca_create_dither(bpp, s.Width, s.Height, pitch,
39                                          rmask, gmask, bmask, amask);
40        }
41
42        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
43         SuppressUnmanagedCodeSecurity]
44        private static extern int caca_free_dither(IntPtr d);
45        public void Dispose()
46        {
47            caca_free_dither(_dither);
48            GC.SuppressFinalize(this);
49        }
50
51        /* TODO: fix this shit */
52
53        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
54         SuppressUnmanagedCodeSecurity]
55        private static extern int caca_set_dither_palette(IntPtr d,
56                               uint[] r, uint[] g,
57                               uint[] b, uint[] a);
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
Note: See TracBrowser for help on using the repository browser.