Преглед изворни кода

* Implemented C# bindings for ditherBitmap() and added it to the C# test.

tags/v0.99.beta14
Sam Hocevar sam пре 17 година
родитељ
комит
4c68153c4a
4 измењених фајлова са 79 додато и 56 уклоњено
  1. +1
    -1
      csharp/AssemblyInfo.cs
  2. +2
    -1
      csharp/Caca.cs
  3. +62
    -53
      csharp/Cucul.cs
  4. +14
    -1
      csharp/test.cs

+ 1
- 1
csharp/AssemblyInfo.cs Прегледај датотеку

@@ -1,5 +1,5 @@
/*
* AssemblyInfo .NET bindings for libcaca
* AssemblyInfo .NET bindings for libcaca
* Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
* All Rights Reserved
*


+ 2
- 1
csharp/Caca.cs Прегледај датотеку

@@ -1,6 +1,7 @@
/*
* libcaca .NET bindings for libcaca
* libcaca .NET bindings for libcaca
* Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
* 2007 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
* $Id$


+ 62
- 53
csharp/Cucul.cs Прегледај датотеку

@@ -1,6 +1,7 @@
/*
* libcucul .NET bindings for libcucul
* libcucul .NET bindings for libcucul
* Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
* 2007 Sam Hocevar <sam@zoy.org>
* 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)
{


+ 14
- 1
csharp/test.cs Прегледај датотеку

@@ -1,6 +1,7 @@
/*
* Test .NET bindings test program
* Test .NET bindings test program
* Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
* 2007 Sam Hocevar <sam@zoy.org>
* 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++)
{


Loading…
Откажи
Сачувај