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

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

Large source code cleanup, getting rid of spaces, tabs, and svn keywords.

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 *  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
14using System;
15using System.Runtime.InteropServices;
16using System.Security;
17using System.Drawing;
18
19namespace 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        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
52         SuppressUnmanagedCodeSecurity]
53        private static extern int caca_set_dither_palette(IntPtr d,
54                               uint[] r, uint[] g,
55                               uint[] b, uint[] a);
56        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
57         SuppressUnmanagedCodeSecurity]
58        private static extern int caca_set_dither_brightness(IntPtr d, float b);
59        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
60         SuppressUnmanagedCodeSecurity]
61        private static extern int caca_set_dither_gamma(IntPtr d, float g);
62        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
63         SuppressUnmanagedCodeSecurity]
64        private static extern int caca_set_dither_contrast(IntPtr d, float c);
65        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
66         SuppressUnmanagedCodeSecurity]
67        private static extern int caca_set_dither_invert(IntPtr d, int i);
68        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
69         SuppressUnmanagedCodeSecurity]
70        private static extern int caca_set_dither_antialias(IntPtr d, string s);
71        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
72         SuppressUnmanagedCodeSecurity]
73        private static extern string[] caca_get_dither_antialias_list(IntPtr d);
74        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
75         SuppressUnmanagedCodeSecurity]
76        private static extern int caca_set_dither_color(IntPtr d, string s);
77        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
78         SuppressUnmanagedCodeSecurity]
79        private static extern string[] caca_get_dither_color_list(IntPtr d);
80        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
81         SuppressUnmanagedCodeSecurity]
82        private static extern int caca_set_dither_charset(IntPtr d, string s);
83        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
84         SuppressUnmanagedCodeSecurity]
85        private static extern string[] caca_get_dither_charset_list(IntPtr d);
86        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
87         SuppressUnmanagedCodeSecurity]
88        private static extern int caca_set_dither_mode(IntPtr d, string s);
89        [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
90         SuppressUnmanagedCodeSecurity]
91        private static extern string[] caca_get_dither_mode_list(IntPtr d);
92
93
94        public int setBrightness(float b)
95        {
96            return caca_set_dither_brightness(_dither, b);
97        }
98
99        public int setGamma(float g)
100        {
101            return caca_set_dither_gamma(_dither, g);
102        }
103
104        public int setContrast(float c)
105        {
106            return caca_set_dither_contrast(_dither, c);
107        }
108
109        public int setInvert(int i)
110        {
111            return caca_set_dither_invert(_dither, i);
112        }
113
114        public int setAntialias(string s)
115        {
116            return caca_set_dither_antialias(_dither, s);
117        }
118
119        public int setColor(string s)
120        {
121            return caca_set_dither_color(_dither, s);
122        }
123
124        public int setCharset(string s)
125        {
126            return caca_set_dither_charset(_dither, s);
127        }
128
129        public int setMode(string s)
130        {
131            return caca_set_dither_mode(_dither, s);
132        }
133
134        /* <FIXME> */
135        public string[] getAntialiasList()
136        {
137            return caca_get_dither_antialias_list(_dither);
138        }
139
140        public string[] getColorList()
141        {
142            return caca_get_dither_color_list(_dither);
143        }
144
145        public string[] getCharsetList()
146        {
147            return caca_get_dither_charset_list(_dither);
148        }
149
150        public string[] getModeList()
151        {
152            return caca_get_dither_mode_list(_dither);
153        }
154
155        /* </FIXME> */
156    }
157}
158
Note: See TracBrowser for help on using the repository browser.