JNI: changing from ARGB to RRRGGGBBB memory problem

M

Marcelo

Hello,

I am trying to modify some color information from java to C.
I have the information given by java in a format ARGB and I would like to
convert it as:

RRRR...GGGG...BBB....
without the A composant. Separating the A,R,G,B part is not hard. My main
problem is the size of my images.

I have something like
jsize len = env -> GetArrayLength(arr);

where len = 3145728 (for a given image The width 2048, the height 1536)

I have tried to put it inside a unsigned char variable vector, but it doesn't
work well. I seems like that's a lot of memory (Eclipse just stops executing the
jni program).

Do you have an idea in order to bypass this "memory" problem ?

thanks a lot,

Marcelo

The error is segmentation falut, and the code:
The error I get is
segmentation fault.

My code is:

void argb2rgb(JNIEnv *env, jobject obj, jintArray arr)
{
jsize len = env -> GetArrayLength(arr);
int *body = env -> GetIntArrayElements(arr, 0);

int compSize = len / 4 ;
printf("\n%d len:%d\n",compSize,len);

uchar rgbArr [3 * compSize];
uchar* pr = (uchar*) rgbArr;
uchar* pg = pr + compSize;
uchar* pb = pg + compSize;

//pg = pr + compSize;
//pb = pg + compSize;


int i = 0;
for( i = 0 ; i< 1; i++){
uchar red = ((body >> 16) & 0xff);
//pr = &red;

uchar green = ((body >> 8) & 0xff);
//pg = &green;

uchar blue = (body & 0xff);
//pg = &blue;

int result = (red << 16) | (green << 8) | blue;
//printf("red %d pointer: %d result: %x",red, *pr, result);
}

env -> ReleaseIntArrayElements(arr, body, 0);
}
 
V

Victor Bazarov

Marcelo said:
I am trying to modify some color information from java to C.

Neither is topical here. Or did you not know that C is a different
language than C++?
I have the information given by java in a format ARGB and I would like
to convert it as:

RRRR...GGGG...BBB....
without the A composant. Separating the A,R,G,B part is not hard. My
main problem is the size of my images.

What do you mean by that?
I have something like
jsize len = env -> GetArrayLength(arr);

What's "jsize"? What's "env"? What's "arr"?
where len = 3145728 (for a given image The width 2048, the height 1536)

So, your 'GetArrayLength' function retuns you the result of multiplying
the width by the height. Is there a problem? It seems doing it right...
I have tried to put it inside a unsigned char variable vector, but it
doesn't work well.

Read FAQ 5.8.
> I seems like that's a lot of memory (Eclipse just
stops executing the jni program).

You are losing me here... Are we being punk'd here? This is a C++
newsgroup, right? What's a lot of memory? 3 mebibytes?
Do you have an idea in order to bypass this "memory" problem ?

I don't see a memory problem. Perhaps you're being less than clear...
thanks a lot,

Marcelo

The error is segmentation falut, and the code:
The error I get is
segmentation fault.

Have you tried debugging it? You know, running it under a debugger...
My code is:

void argb2rgb(JNIEnv *env, jobject obj, jintArray arr)
{
jsize len = env -> GetArrayLength(arr);
int *body = env -> GetIntArrayElements(arr, 0);

int compSize = len / 4 ;
printf("\n%d len:%d\n",compSize,len);

uchar rgbArr [3 * compSize];

This is not C++. In C++ the expression inside brackets in an array
declaration MUST be compile-time cosntant. Maybe you meant

uchar *rgbArr = new uchar[3 * compSize];

?
uchar* pr = (uchar*) rgbArr;

There is no need to cast here.
uchar* pg = pr + compSize;
uchar* pb = pg + compSize;

//pg = pr + compSize;
//pb = pg + compSize;


int i = 0;
for( i = 0 ; i< 1; i++){
uchar red = ((body >> 16) & 0xff);
//pr = &red;

uchar green = ((body >> 8) & 0xff);
//pg = &green;

uchar blue = (body & 0xff);
//pg = &blue;

int result = (red << 16) | (green << 8) | blue;
//printf("red %d pointer: %d result: %x",red, *pr, result);
}

env -> ReleaseIntArrayElements(arr, body, 0);
}


And where is the segmentation fault?

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,950
Members
47,503
Latest member
supremedee

Latest Threads

Top