Skip navigation.
Home
The QNX Community Portal

View topic - Write an Image from raw pixel data

Write an Image from raw pixel data

Isn't the name clear?

Write an Image from raw pixel data

Postby nudels » Mon Sep 12, 2011 5:53 am

Hey Guys :)

i want to write an Image from my ethernet stream.
i get a pointer to the raw pixel data and now i want to write this data into a picture file and save it.
have qnx some functions for my problem?
i found that in the "pxImage.h" are some functions for that, is it right?
now how can i make it ;)

i hope somebody could give me a hint :)

with best regards nudels :)
nudels
Active Member
 
Posts: 22
Joined: Wed Aug 17, 2011 6:27 am

Re: Write an Image from raw pixel data

Postby mario » Mon Sep 12, 2011 3:59 pm

As far as I know there are only fonctions to load images (png, jpg, bmp etc) but for some reasons not to save them.
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Re: Write an Image from raw pixel data

Postby koko » Mon Sep 12, 2011 4:25 pm

Check this out:
error = PxWriteImage( fname, image, NULL,PX_IMAGE_JPG,0 );

where:
char *fname, file name prefixed with the absolute path.
PhImage_t *image,
PX_IMAGE_JPG ---> if you need the file to be saved in JPG format
PX_IMAGE_BMP for BMP format.
PNP does not work.
I use it in my applications successfully. It is not documented but works fine.
Your application needs to be linked with libphexlib,
#add libphexlib for PxWriteImage in your common.mk
LIBS+=phexlib
koko
Senior Member
 
Posts: 100
Joined: Wed Aug 20, 2003 1:31 am

Re: Write an Image from raw pixel data

Postby nudels » Mon Sep 12, 2011 6:20 pm

thanks for replies :)

@koko:
i have seen this function, but my problem is, that i have an const unsigned int Pointer and not a PhImage_t Pointer and i cant cast from const unsigned to PhImage_t.
Or is there any function or structdata that i have to reference with the const unsigned int Pointer?

EDIT 13.09.2011:

okay i tried with PxWriteImage(). My code is the following:
Code: Select all
int Draw::saveImg(const unsigned int* img)
{
   std::cout << "Draw::saveImg()" << std::endl;
   m_img = img;

   int error;
   if((error = PxWriteImage("/home/write.bmp",(PhImage_t*) m_img, NULL ,PX_IMAGE_BMP,0)) == 1)
   {
      perror("ERROR in PxWriteImage");
      exit(1);
   }
   std::cout << "finished" << std::endl;

   return 0;
}


But i get the error, that my core is dumped ("Memory fault (core dumped)")
And sometimes i get the error: "PxWriteImage: No such Process".

Thanks for your interest to help me :)

with best regards
nudels
Active Member
 
Posts: 22
Joined: Wed Aug 17, 2011 6:27 am

Re: Write an Image from raw pixel data

Postby koko » Tue Sep 13, 2011 11:28 pm

Hi nudels,
Your problem is that you try to cast to PhImage_t something what is not.
if((error = PxWriteImage("/home/write.bmp",(PhImage_t*) m_img, NULL ,PX_IMAGE_BMP,0)) == 1)
{
perror("ERROR in PxWriteImage");
exit(1);
}

You should read QNX documentation( Chapter Raw Drawing and Animation ) or look at /usr/include/photon/Pg.h for PhImage_t.
You will see that the structure from type PtImage_t has a field image( char *image ). This is the pointer which has to point to your frame.
I recommend you to read carefully the mentioned chapter - there are some tricks you need to understand before using the function.
Look the section for Images into this chapter. Pay attention to the format of your frame - incoming and the one you need to draw.
Cheers
koko
Senior Member
 
Posts: 100
Joined: Wed Aug 20, 2003 1:31 am

Re: Write an Image from raw pixel data

Postby nudels » Wed Sep 14, 2011 7:22 am

hi koko,

also i have tried it like u described.
my pics are 16bit bmp files.

Code: Select all
int Draw::saveImg(const unsigned int* img)
{
   std::cout << "Draw::saveImg()" << std::endl;
   m_img = img;

   PhImage_t my;

   memset(&my, 0, sizeof(PhImage_t));

   my.image = (char*) m_img;
   my.type = 33;
   my.size.h = 240;
   my.size.w = 320;
   my.alpha = 0;
   my.bpl = 5120;
   my.colors = 0;


   int error;
   if((error = PxWriteImage("/home/write.bmp", &my, NULL ,PX_IMAGE_BMP,0)) == 1)
   {
      perror("ERROR in PxWriteImage");
      exit(1);
   }
   std::cout << "finished()" << std::endl;

   return 0;
}


but i get the same error. "Memory fault (core dumped)".

it creates a file, but the filesize is 0 bytes and i cant open it :/

EDIT:

okay now it works ;)
it was a little mistake ^^

but now i have the problem that the bmp picture has no color :/ even when i set "my.color = 32768".
Attachments
write.rar
write.bmp
(74.65 KiB) Downloaded 887 times
nudels
Active Member
 
Posts: 22
Joined: Wed Aug 17, 2011 6:27 am

Re: Write an Image from raw pixel data

Postby koko » Wed Sep 14, 2011 4:06 pm

Congratulations,
You are step away from the solution.
Where did you get type=33?
I believe your incoming frame format is RGB565, and not RGB888( which is 33 ).
Use defines instead ---> type=Pg_IMAGE_DIRECT_565. They are all defined in Pg.h.
Cheers,
koko
koko
Senior Member
 
Posts: 100
Joined: Wed Aug 20, 2003 1:31 am

Re: Write an Image from raw pixel data

Postby nudels » Thu Sep 15, 2011 7:01 am

huhu :)

okay now i have a bitmpa with color.
i had to set the type to Pg_IMAGE_DIRECT_8888.
The other one didn't worked.
Now i have an Bitmpa, but its some kind of distorted :/
i attach the picture and maybe has somebody an idea how to fix it :)
Attachments
write.rar
(98.65 KiB) Downloaded 893 times
nudels
Active Member
 
Posts: 22
Joined: Wed Aug 17, 2011 6:27 am

Re: Write an Image from raw pixel data

Postby maschoen » Sat Sep 17, 2011 7:57 am

When you get a distorted image, it probably has to do with the difference between bpl (bytes per line) and the pixel width.

Let's say you try to load pixel data in 888 format into an existing image. The first pixel goes in the first three bytes, the next pixel in the next three bytes, and so forth. Let's say you have a width of 100. So the first 100 pixels goes in the first 300 bytes.
But where does the first pixel in the 2nd row go? It's not necessarily in the next byte. You have to look at the image->bpl value.
maschoen
QNX Master
 
Posts: 2644
Joined: Wed Jun 25, 2003 5:18 pm


Return to GUI Programming

Who is online

Users browsing this forum: No registered users and 2 guests