From 4c68153c4a8824f4c4a4222856d503abc4115d39 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sun, 25 Nov 2007 17:12:59 +0000 Subject: [PATCH] * Implemented C# bindings for ditherBitmap() and added it to the C# test. --- csharp/AssemblyInfo.cs | 2 +- csharp/Caca.cs | 3 +- csharp/Cucul.cs | 115 ++++++++++++++++++++++------------------- csharp/test.cs | 15 +++++- 4 files changed, 79 insertions(+), 56 deletions(-) diff --git a/csharp/AssemblyInfo.cs b/csharp/AssemblyInfo.cs index 5d426c6..0fc34d2 100644 --- a/csharp/AssemblyInfo.cs +++ b/csharp/AssemblyInfo.cs @@ -1,5 +1,5 @@ /* - * AssemblyInfo .NET bindings for libcaca + * AssemblyInfo .NET bindings for libcaca * Copyright (c) 2006 Jean-Yves Lamoureux * All Rights Reserved * diff --git a/csharp/Caca.cs b/csharp/Caca.cs index 75d868b..29f99de 100644 --- a/csharp/Caca.cs +++ b/csharp/Caca.cs @@ -1,6 +1,7 @@ /* - * libcaca .NET bindings for libcaca + * libcaca .NET bindings for libcaca * Copyright (c) 2006 Jean-Yves Lamoureux + * 2007 Sam Hocevar * All Rights Reserved * * $Id$ diff --git a/csharp/Cucul.cs b/csharp/Cucul.cs index 4929cf8..2f0be9b 100644 --- a/csharp/Cucul.cs +++ b/csharp/Cucul.cs @@ -1,6 +1,7 @@ /* - * libcucul .NET bindings for libcucul + * libcucul .NET bindings for libcucul * Copyright (c) 2006 Jean-Yves Lamoureux + * 2007 Sam Hocevar * All Rights Reserved * * $Id$ @@ -347,56 +348,67 @@ namespace Cucul private static extern int cucul_draw_thin_polyline(IntPtr cv, int[] x, int[] y, int n); /* frame handling */ - /* FIXME: clean up this shit */ [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern int cucul_get_frame_count(IntPtr cv); - [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), - SuppressUnmanagedCodeSecurity] - private static extern int cucul_set_frame(IntPtr cv, int f); - [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), - SuppressUnmanagedCodeSecurity] - private static extern string cucul_get_frame_name(IntPtr cv); - [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), - SuppressUnmanagedCodeSecurity] - private static extern int cucul_set_frame_name(IntPtr cv, string n); - [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), - SuppressUnmanagedCodeSecurity] - private static extern int cucul_create_frame(IntPtr cv, int f); - [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), - SuppressUnmanagedCodeSecurity] - private static extern int cucul_free_frame(IntPtr cv, int f); - public int getFrameCount() { return cucul_get_frame_count(_cv); } + [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), + SuppressUnmanagedCodeSecurity] + private static extern int cucul_set_frame(IntPtr cv, int f); public int setFrame(int f) { return cucul_set_frame(_cv, f); } - public string getFrameName() - { - return cucul_get_frame_name(_cv); - } - - public int setFrameName(string n) + [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), + SuppressUnmanagedCodeSecurity] + private static extern string cucul_get_frame_name(IntPtr cv); + [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), + SuppressUnmanagedCodeSecurity] + private static extern int cucul_set_frame_name(IntPtr cv, string n); + public string frameName { - return cucul_set_frame_name(_cv, n); + get { return cucul_get_frame_name(_cv); } + set { cucul_set_frame_name(_cv, value); } } + [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), + SuppressUnmanagedCodeSecurity] + private static extern int cucul_create_frame(IntPtr cv, int f); public int createFrame(int f) { return cucul_create_frame(_cv, f); } + [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), + SuppressUnmanagedCodeSecurity] + private static extern int cucul_free_frame(IntPtr cv, int f); public int freeFrame(int f) { return cucul_free_frame(_cv, f); } + + /* bitmap dithering */ + + [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), + SuppressUnmanagedCodeSecurity] + private static extern int cucul_dither_bitmap(IntPtr c, int x, int y, + int w, int h, + IntPtr d, IntPtr data); + public int ditherBitmap(int x, int y, int w, int h, CuculDither d, + object data) + { + GCHandle gch = GCHandle.Alloc(data); + int ret = cucul_dither_bitmap(_cv, x, y, w, h, d._dither, + gch.AddrOfPinnedObject()); + gch.Free(); + return ret; + } } public unsafe class CuculAttr @@ -435,15 +447,33 @@ namespace Cucul public unsafe class CuculDither : IDisposable { - [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), + public readonly IntPtr _dither; + + [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] - private static extern IntPtr cucul_create_dither(int bpp, int w, - int h, int pitch, - Int64 rmask, - Int64 gmask, - Int64 bmask, - Int64 amask); + private static extern IntPtr cucul_create_dither(int bpp, int w, + int h, int pitch, + ulong rmask, + ulong gmask, + ulong bmask, + ulong amask); + public CuculDither(int bpp, int w,int h, int pitch, + uint rmask, uint gmask, uint bmask, uint amask) + { + _dither = cucul_create_dither(bpp, w, h, pitch, + rmask, gmask, bmask, amask); + } + + [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), + SuppressUnmanagedCodeSecurity] + private static extern int cucul_free_dither(IntPtr d); + public void Dispose() + { + cucul_free_dither(_dither); + GC.SuppressFinalize(this); + } + /* TODO: fix this shit */ [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] @@ -486,28 +516,7 @@ namespace Cucul [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern string[] cucul_get_dither_mode_list(IntPtr d); - [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), - SuppressUnmanagedCodeSecurity] - private static extern int cucul_free_dither(IntPtr d); - /* FIXME [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), - SuppressUnmanagedCodeSecurity] - int cucul_dither_bitmap(Canvas c, int x, int y, int w , int y, - IntPtr d2, void *);*/ - - IntPtr _dither; - - public CuculDither(int bpp, int w,int h, int pitch, - Int64 rmask, Int64 gmask,Int64 bmask, Int64 amask) - { - _dither = cucul_create_dither(bpp, w, h, pitch, rmask, gmask, bmask, amask); - } - - public void Dispose() - { - cucul_free_dither(_dither); - GC.SuppressFinalize(this); - } public int setBrightness(float b) { diff --git a/csharp/test.cs b/csharp/test.cs index 15a63da..c699b54 100644 --- a/csharp/test.cs +++ b/csharp/test.cs @@ -1,6 +1,7 @@ /* - * Test .NET bindings test program + * Test .NET bindings test program * Copyright (c) 2006 Jean-Yves Lamoureux + * 2007 Sam Hocevar * All Rights Reserved * * $Id$ @@ -14,17 +15,27 @@ using System; +using System.Runtime.InteropServices; using Cucul; using Caca; class DemoCanvas : CuculCanvas { + private uint[,] table; + private DateTime startTime; + private CuculDither d; public DemoCanvas() { startTime = DateTime.Now; + + table = new uint[16,16]; + d = new CuculDither(32, 16, 16, 16 * 4, 0xff0000, 0xff00, 0xff, 0x0); + for(int y = 0; y < 16; y++) + for(int x = 0; x < 16; x++) + table[x,y] = (uint)((x + y) << 16) | (uint)(x << 8) | (uint)(y); } public void Draw() @@ -34,6 +45,8 @@ class DemoCanvas : CuculCanvas Clear(); + ditherBitmap(0, 0, width, height, d, table); + setColorAnsi(Libcucul.WHITE, Libcucul.BLACK); for(int i = 0; i < barCount; i++) {