0

I am converting some C code into Java which includes image processing. However, I am stuck in a situation where I have to convert some lines of codes which include pointer calculations:

for(i=xMin[k];i<=xMax[k];i++)
{
        for(j=yMin[k];j<=yMax[k];j++)
        {
             if (Bimg[i][j]== k1)
             {
                /* accessing single channel for r g b  value */   

                b = data[i*step + j*channels + 0];
                g = data[i*step + j*channels + 1];
                r = data[i*step + j*channels + 2];
             }       
       }              
}

Can anybody please tell me how to convert this "data" pointer into java equivalent? Here, "data" is a pointer variable.

1

2 Answers 2

1

What is data pointing at?

It looks like it is pointing to an array of bytes, so just make data a byte[]. Assuming the C array pointed at and the Java array referred to have the same data, the same calculations should work.

Sign up to request clarification or add additional context in comments.

1 Comment

No, the data variable is pointing at BytePointer
1

I assume that the data you specific in the question is actually an array of unsigned char. Like:

unsigned char *data = (unsigned char*)malloc(datasize*sizeof(unsigned char));

I believe the equivalent in java is

byte[] data = new byte[datasize]

And since java don't allow you to operate pointer. You should use index to manipulate the data array.

Note: byte in java is always signed. You can get the unsigned value by:

int v = b & 0xFF

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.