Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

JNI: changing from ARGB to RRRGGGBBB memory problem

Thread view: 
Marcelo - 13 Dec 2005 22:27 GMT
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
Marcelo - 13 Dec 2005 22:43 GMT
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[i] >> 16) & 0xff);
        //pr = &red;               
       
        uchar green = ((body[i] >> 8) & 0xff);
        //pg = &green;
       
        uchar blue = (body[i] & 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);
}
Eric Sosman - 13 Dec 2005 23:01 GMT
Marcelo wrote On 12/13/05 17:43,:
> The error I get is
> segmentation fault.
[quoted text clipped - 11 lines]
>     uchar rgbArr [3 * compSize];
> [...]

   Given the dimensions mentioned in your first message,
this array will require nine megabytes -- somewhat more
than most environments provide for stack space.  You may
be able to run the program with an enormous stack size,
but a better alternative would be to create the array on
the heap instead of on the stack.

Signature

Eric.Sosman@sun.com

Roedy Green - 13 Dec 2005 22:48 GMT
>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:

What would happen if you cut your image into four pieces and processed
them separately?
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Roedy Green - 13 Dec 2005 22:59 GMT
>where len = 3145728 (for a given image The width 2048, the height 1536)

The biggest  square of pixels you can address is 46,340 x 46,340.

You will run out of RAM long before you will run out of address bits.

Have a look at http://mindprod.com/jgloss/javaexe.htm
to increase the size of the virtual RAM space.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.