Subversion Repositories AndroidProjects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
244 chris 1
using System;
2
using System.Runtime.InteropServices;
3
using System.Text;
4
 
5
// Application namespace - change this to match your application if needed
6
namespace J2K_CodecPrj
7
{
8
        public abstract class J2KCodec
9
        {
10
                // Returns codec version and build number in the 0x105678 form, where 
11
                // 10 is a version (1.0) and 5678 is a build number.
12
                [DllImport("j2k-codec", EntryPoint="_J2K_getVersion@0")]
13
                public static extern uint GetVersion();
14
 
15
                // Returns the code of last error. Use GetErrorString() to get 
16
                // textual description of the error.
17
                [DllImport("j2k-codec", EntryPoint="_J2K_getLastError@0")]
18
                public static extern J2KError GetLastError();
19
 
20
                [DllImport("j2k-codec", EntryPoint="_J2K_getErrorStrVB@8")]
21
                private static extern void _GetErrorString(J2KError errCode, StringBuilder errStr);
22
 
23
                // Returns the textual description of an error by the error code 
24
                // obtained from getLastError().
25
                public static string GetErrorString(J2KError errCode)
26
                {
27
                        StringBuilder sb = new StringBuilder(2048);
28
                        _GetErrorString(errCode, sb);
29
                        return sb.ToString();
30
                }
31
 
32
                // Returns the textual description of the last error.
33
                public static string GetLastErrorString()
34
                {
35
                        return GetErrorString(GetLastError());
36
                }
37
 
38
                // This function unlocks the full functionality of J2K-Codec. After you
39
                // have purchased your personal registration key, you need to pass it 
40
                // to this function.
41
                [DllImport("j2k-codec", EntryPoint="_J2K_Unlock@4")]
42
                public static extern void Unlock(string key);
43
 
44
 
45
                // This function creates a log-file and starts logging debug messages of J2K-Codec.
46
                // 'level' can be Normal or Detailed.
47
                // Passing append as true will append the log session to existing log-file.
48
                // Returns 0 if there was no error.
49
                // NOTES: 
50
                //  1. Log-file name is 'j2k-codec.log'
51
                //  2. The performance will degrade significantly if the logging is on.
52
                [DllImport("j2k-codec", EntryPoint="_J2K_StartLogging@8")]
53
                public static extern J2KError StartLogging(J2KLogLevel level, bool append);
54
 
55
                // Use this function to stop logging, initiated by StartLogging().
56
                [DllImport("j2k-codec", EntryPoint="_J2K_StopLogging@0")]
57
                public static extern void StopLogging(int level, bool append);
58
 
59
                // Open an image from a file with given name.
60
                [DllImport("j2k-codec", EntryPoint="_J2K_OpenFile@4")]
61
                public static extern IntPtr OpenFile(string fileName);
62
 
63
                // Open the image from a buffer with 'size' length
64
                [DllImport("j2k-codec", EntryPoint="_J2K_OpenFile@4")]
65
                public static extern IntPtr OpenMemory(byte[] buffer, uint size);
66
 
67
                // Get size information from the image
68
                [DllImport("j2k-codec", EntryPoint="_J2K_GetInfo@16")]
69
                public static extern J2KError GetInfo(IntPtr image, out int width, out int height, out int components);
70
 
71
                // Get more detailed information from the image
72
                [DllImport("j2k-codec", EntryPoint="_J2K_GetInfoEx@8")]
73
                public static extern J2KError GetInfoEx(IntPtr image, out J2KInfo info);
74
 
75
 
76
                // Get meta data, embedded into the JP2 image. See help file for parameter explanation
77
                [DllImport("j2k-codec", EntryPoint="_J2K_GetInfoEx@8")]
78
                public static extern J2KError GetMetaData(IntPtr image, ref int no, ref J2KMetadata type, ref IntPtr data, ref int size);
79
 
80
                // Decodes the image, previously created with Open(). If 'buffer' is
81
                // null, then the required amount of memory is allocated and its size
82
                // returned through the 'size' argument. pitch - distance, in bytes, to
83
                // the start of next line. For options see help file.
84
                [DllImport("j2k-codec", EntryPoint="_J2K_Decode@20")]
85
                public static extern J2KError Decode(IntPtr image, ref IntPtr buffer, ref int size, string options, ref int pitch);
86
 
87
                // Selects or unselects a tile or a tile range, depending on 'select'.
88
                // If select is true then the tiles are selected for decoding, 
89
                // otherwise they are unselected. The range is defined by start and end
90
                // tile numbers (inclusive) in the raster order. If end_tile==-1 then
91
                // the max tile number will be used instead.
92
                [DllImport("j2k-codec", EntryPoint="_J2K_SelectTiles@16")]
93
                public static extern J2KError SelectTiles(IntPtr image, int startTile, int endTile, bool select);
94
 
95
                // Gets the number of available resolution levels.
96
                [DllImport("j2k-codec", EntryPoint="_J2K_GetResolutions@8")]
97
                public static extern J2KError GetResolutions(IntPtr image, ref int resolutions);
98
 
99
                // Gets the dimensions of a resolution level.
100
                [DllImport("j2k-codec", EntryPoint="_J2K_GetResolutionDimensions@16")]
101
                public static extern J2KError GetResolutionDimensions(IntPtr image, int resLevel, out int width, out int height);
102
 
103
 
104
                // Cancels Decode() operations.
105
                [DllImport("j2k-codec", EntryPoint="_J2K_Cancel@4")]
106
                public static extern J2KError Cancel(IntPtr image);
107
 
108
                // Destroys the image, previously created by Open(). All images must 
109
                // be closed using this function to avoid memory leaks.
110
                [DllImport("j2k-codec", EntryPoint="_J2K_Close@4")]
111
                public static extern J2KError Close(IntPtr image);
112
        }
113
 
114
        public enum J2KError
115
        {
116
                Success = 0,
117
                NeedMMX,
118
                NotEnoughMemory,
119
                CorruptedData,
120
                PipeFailure,
121
                InvalidArgument,
122
                Canceled,
123
                CantOpenFile,
124
                OptionUnrecognized,
125
                NoSuchTile,
126
                NoSuchResolution,
127
                BppTooSmall,
128
                BufferTooSmall,
129
                NotPart1Format,
130
                ImageIsTooLarge,
131
                TooManyResLevel,
132
                TooLargeCodeblocks,
133
                NoLaziness,
134
                NoVcausal,
135
                TooManyComponents,
136
                Only8BitComponents,
137
                OnlyUnsigComponents,
138
                DownsampledComponents,
139
                RoiNotSupported,
140
                ProgrChangeNotSup,
141
                PacketHeadersNotSup,
142
                No64BitSupport,
143
                InternalError
144
        }
145
 
146
        public enum J2KLogLevel
147
        {
148
                Normal = 0,
149
                Detailed = 1,
150
                All = 1
151
        }
152
 
153
        public enum J2KMetadata
154
        {
155
                CommentStr,
156
                CommentBin,
157
                Geotiff,
158
                Xml,
159
                Url,
160
                Pal,
161
                Icc,
162
                Unknown
163
        }
164
 
165
        [StructLayout(LayoutKind.Sequential)]
166
        public struct J2KInfo
167
        {
168
                public int Version;
169
                public int Width;
170
                public int Height;
171
                public int Components;
172
                public int FileType;
173
                public int HorizontalTiles;
174
                public int VerticalTiles;
175
        }
176
}