using System; using System.Runtime.InteropServices; // For DllImport(). public struct jas_matrix_t { /* A matrix of pixels (one matrix per component) */ public int flags; /* Additional state information. */ public int xstart; /* The starting horizontal index. */ public int ystart; /* The starting vertical index. */ public int xend; /* The ending horizontal index. */ public int yend; /* The ending vertical index. */ public int numrows; /* The number of rows in the matrix. */ public int numcols; /* The number of columns in the matrix. */ public IntPtr row_ptrs; /* Pointers to the start of each row. */ public int maxrows; /* The allocated size of the rows array. */ public IntPtr data; /* The matrix data buffer. */ public int datasize; /* The allocated size of the data array. */ public static jas_matrix_t fromPtr(IntPtr ptr) { return (jas_matrix_t)Marshal.PtrToStructure(ptr, typeof(jas_matrix_t)); } public int[] get_int_array() { int[] retval=new int[datasize]; Marshal.Copy(data, retval, 0, datasize); /* only the low byte has any meaning */ return retval; } public int get_pixel(int x, int y) { return Marshal.ReadInt32(data, y*numcols+x); } } public struct jas_image_cmpt_t { /* Image component class. */ public int tlx; /* The x-coordinate of the top-left corner of the component. */ public int tly; /* The y-coordinate of the top-left corner of the component. */ public int hstep; /* The horizontal sampling period in units of the reference grid. */ public int vstep; /* The vertical sampling period in units of the reference grid. */ public int width; /* The component width in samples. */ public int height; /* The component height in samples. */ public int prec; /* precision */ public int sgnd; /* signed-ness */ public IntPtr stream; /* The stream containing the component data. */ public int cps; /* The number of characters per sample in the stream. */ public int type; /* The type of component (e.g., opacity, red, green, blue, luma). */ public static jas_image_cmpt_t fromPtr(IntPtr ptr) { return (jas_image_cmpt_t)Marshal.PtrToStructure(ptr, typeof(jas_image_cmpt_t)); } } public struct jas_image_t { public int tlx; /* The x-coordinate of the top-left corner of the image bounding box. */ public int tly; /* The y-coordinate of the top-left corner of the image bounding box. */ public int brx; /* The x-coordinate of the bottom-right corner of the image bounding box (plus one). */ public int bry; /* The y-coordinate of the bottom-right corner of the image bounding box (plus one). */ public int numcmpts; /* The number of components. */ public int maxcmpts; /* The maximum number of components that this image can have (i.e., the allocated size of the components array). */ public IntPtr cmpts; /* array of pointers to jas_image_cmpt_t: Per-component information. */ public int clrspc; public IntPtr cmprof; public bool inmem; public static jas_image_t fromPtr(IntPtr ptr) { return (jas_image_t)Marshal.PtrToStructure(ptr, typeof(jas_image_t)); } public int width { get { return brx-tlx; } } public int height { get { return bry-tly; } } public jas_image_cmpt_t[] get_components() { jas_image_cmpt_t[] retval=new jas_image_cmpt_t[numcmpts]; int i; for(i=0;i4) throw new Exception("order.Length must be <= 4"); jas_image_t image_struct=jas_image_t.fromPtr(image_ptr); IntPtr matrix=jas_matrix_create(image_struct.height, image_struct.width); int [] pixels = new int [image_struct.height*image_struct.width]; for(int c=0;c