-
Notifications
You must be signed in to change notification settings - Fork 2
/
TestUCI.cs
53 lines (47 loc) · 1.31 KB
/
TestUCI.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace TestUCI
{
class Program
{
[DllImport("ucidec.dll")]
public static extern int UCIDecode(byte[] src, int srclen, out IntPtr dst, out int stride, out int w, out int h, out int b);
[DllImport("ucidec.dll")]
public static extern int UCIFree(IntPtr p);
[DllImport("ucidec.dll")]
public static extern int UCIDebug(int level);
private static void Main(string[] args)
{
byte[] src;
IntPtr dst;
int w, h, b, stride, r;
FileStream fs;
using(fs = new FileStream("test.uci", FileMode.Open))
{
src = new byte[fs.Length];
fs.Read(src, 0, (int) fs.Length);
fs.Close();
}
UCIDebug(0x7fffffff);
r = UCIDecode(src, src.Length, out dst, out stride, out w, out h, out b);
if(r < 0)
{
Console.WriteLine("ERROR: DecodeUCI failed (return " + r + ")");
return;
}
Console.WriteLine("INFO: width x height x bit : " + w + " x " + h + " x " + b);
using(fs = new FileStream("test.rgb", FileMode.OpenOrCreate))
{
src = new byte[w * (b/8)];
for(int i = 0; i < h; ++i)
{
Marshal.Copy(new IntPtr(dst.ToInt32() + i * stride), src, 0, src.Length);
fs.Write(src, 0, src.Length);
}
fs.Close();
}
UCIFree(dst);
}
}
}