4 messages in net.java.dev.jna.usersRe: [jna-users] Arrays offset
FromSent OnAttachments
Cyril DelmasMar 4, 2009 8:26 am 
Timothy WallMar 4, 2009 8:40 am 
Cyril DelmasMar 4, 2009 8:50 am 
Timothy WallMar 4, 2009 9:35 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] Arrays offsetActions...
From:Timothy Wall (twal@dev.java.net)
Date:Mar 4, 2009 9:35:52 am
List:net.java.dev.jna.users

On Mar 4, 2009, at 11:50 AM, Cyril Delmas wrote:

Ok for the array of pointers. The matter now is to translate this part : ==== LPBYTE lpImage = (LPBYTE) malloc ( sizeof(BYTE) * 3 * width * height );

Memory lpImage = new Memory(3 * width * height)

//// IT.data[0] = lpImage+2; // red channel IT.data[1] = lpImage+1; // green channel IT.data[2] = lpImage; // blue channel ==== I guess LPBYTE may be transformed in byte[], but how can I translate the last three lines ? I don't think it is possible in Java, as we can't access addresses...

data[0] = lpImage.share(2); data[1] = lpImage.share(1); data[2] = lpImage;

However, the offsets should probably be multiples of size (width* height), not single bytes, unless your RGB values are interleaved.

Timothy Wall a écrit :

It's an array of pointers, so use Pointer[] data = new Pointer[3]; what you assign to each pointer depends on your application. On Mar 4, 2009, at 11:27 AM, Cyril Delmas wrote:

Hi list, I want to transform this C code :

========== LPBYTE lpImage = (LPBYTE) malloc ( sizeof(BYTE) * 3 * width * height ); // initialize lpImage correctly

ImageTransfer IT; IT.columnBytes = 3; IT.rowBytes = 3 * width; IT.height = height; IT.width = width; IT.data[0] = lpImage+2; // red channel IT.data[1] = lpImage+1; // green channel IT.data[2] = lpImage; // blue channel

// use IT ==========

into the equivalent in Java using JNA.

I don't know which type I must use for "data" in the ImageTransfer structure :

typedef struct { int width; int height; int rowBytes; int columnBytes; unsigned char *data[3]; } ImageTransfer;

and don't know how to initialize the structure in Java (using Pointer, PointerByReference, ByteByReference or ByteBuffer ?). I tried some combinations, without success (access violation).