Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Trusted Contributor
bbdev12345
Posts: 117
Registered: ‎09-06-2011
My Device: 9900
My Carrier: myself

Re: does img_t have setARGB equivalent

Hi, thanks for your continued support BGmot.

 

All my relevent java stuff is nicely pasted here now if that helps..

 

http://supportforums.blackberry.com/t5/Java-Development/Correct-code-to-get-area-of-image-data/td-p/...

Please use plain text.
Trusted Contributor
bbdev12345
Posts: 117
Registered: ‎09-06-2011
My Device: 9900
My Carrier: myself

Re: does img_t have setARGB equivalent

[ Edited ]

Sorry BGmot, just understood your question.

 

out is the output stream to the socket and dout is the dataoutputstream to the socket. dout writes the size of the bytes to be expected which is converted to toRead in c++.

 

Thanks.

Please use plain text.
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: does img_t have setARGB equivalent

>out is the output stream to the socket and dout is the dataoutputstream to the socket.

Ok, I don't know Java and don't really understand what that means -))) disregard my question, hope you are writing to the socket properly.

let's rewrite your Java this way:

byte[] integersToBytes(int[] values)
{
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   DataOutputStream dos = new DataOutputStream(baos);
   for(int i=0; i < values.length; ++i)
   {
       try
       {
        dos.writeByte((values[i] >> 16) & 0xff); // R
dos.writeByte((values[i] >> 8) & 0xff); // G
dos.writeByte(values[i] & 0xff); // B
dos.writeByte((values[i] >> 24) & 0xff); // A } catch(Exception gg) { } } return baos.toByteArray(); }

And your C code should be something like this:

int w = 50;
int h = 50;
int toRead = w*h*4;
		int pixels[toRead];
int readInt;
     char buf2[4];

while(connected){
  toRead = readImageSize(imagesock, buf2, sizeof(buf2));
  char image_data[toRead];
  bzero(image_data, toRead);
  totalBytes = 0;
  received = 0;
  while (connected && totalBytes < toRead){
    received = read(imagesock, &image_data[totalBytes], sizeof(image_data)-totalBytes);
    if(received > 0){
      totalBytes += received;
    }
}
cout << "\n totalbytes " << totalBytes << "toread=" << toRead;
cout.flush();
for (int i=0; i < h; i++)
memcpy(img.access.direct.data+i*img.access.direct.stride, image_data, w*4);
screen_post_window(screen, bg_buf, 1, rect, 0 ); screen_flush_context(screencontext,0); }
Please use plain text.
Trusted Contributor
bbdev12345
Posts: 117
Registered: ‎09-06-2011
My Device: 9900
My Carrier: myself

Re: does img_t have setARGB equivalent

just a quick update BGmot, the size of the image is a square now (thanks) which is correct but the exact same color issues remain.

 

I have just set my screen to 1024x600 in case that affected things but it didnt at all in terms of color.

 

I wonder what else could be doing this - if I had to speculate what was happening I'd say the image could be display a lot bigger than it actually is so a bit of blue is filling the whole square.

Please use plain text.
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: does img_t have setARGB equivalent

Please send me (via PM) raw output - bytes you are receiving from socket, Several hundreds will be enough.

Please use plain text.
Developer
mreed
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: does img_t have setARGB equivalent

First lets simplify this issue. You probably should elimiate the server/socket from this equation until you have it working on the device first. Take your sample image, get the ARGB byte array and write it to a file. One the device use that file locally for now. If you want others to help test it you could also attach here a zip of the image and the file containing the ARGB bytes. If you attach the zip with both, someone else can also confirm if its correct output.

Please use plain text.
Trusted Contributor
bbdev12345
Posts: 117
Registered: ‎09-06-2011
My Device: 9900
My Carrier: myself

Re: does img_t have setARGB equivalent

BGmot, I'm about to pm you the first few hundrew characters of my file, should I pm it to you to mreed - I can't find an attach zip option when replying?

Please use plain text.
Developer
mreed
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: does img_t have setARGB equivalent

There should be an Attachments option to the right of where you type your reply. Not really interested in a partial file though.

Please use plain text.
Trusted Contributor
bbdev12345
Posts: 117
Registered: ‎09-06-2011
My Device: 9900
My Carrier: myself

Re: does img_t have setARGB equivalent

I really cant see an option to attach - maybe because we're different levels we have different privileges?

 

 

Please use plain text.
Developer
mreed
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: does img_t have setARGB equivalent

[ Edited ]

Interesting. I'm not sure why its not there. Find a file host I guess?

 

I think you can confirm yourself if the ARGB int[] is correct by just converting it back to a Bitmap or PNG and save it to a file. Thats the first thing you should confirm.

Please use plain text.