Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Saving PtRaw "content" as images: (5 Items)
   
Saving PtRaw "content" as images  
I have some code that draws to a PtRaw widget using basic Photon API drawing calls (PgDrawIRect and such), from the draw
 function callback.

We would like to add a feature where we can save the content of these graphs to an image file (.png,.jpg, or pretty much
 anything else). I am not using offscreen contexts.

What would be the simplest/quickest way to tweak my code to make this possible? Note that I keep an internal buffer of 
my pixel values, so worst comes to worst I make a separate function that draws in the same way from this internal buffer
 to an image file -- but even that, I'm not sure what would be the simplest way to do it.

Let me know if you have suggestions,

Thanks,
Simon
Re: Saving PtRaw "content" as images  
It looks like you have an offscreen buffer (except it is not a "Photon" one). Since you have it, and you know what 
format it is in. 
-- You need to allocate/declare a PhImage_t structure. 
-- Fill the structure with, use a matching Photon image format as the format (one of Pg_IMAGE_DIRECT_* for example)
-- size, bpl.
-- set PhImage_t image to your buffer address
-- use PxWriteImage().

Look at the source of the pv app that saves images.

You can also use libimg directly -- img_write_file().

Re: Saving PtRaw "content" as images  
> It looks like you have an offscreen buffer (except it is not a "Photon" one). 

Not exactly: it isn't a buffer of raw image data (that I can just point to from a PhImage_t struct), it's an array of a 
certain struct type that contains the x and y positions of my pixels and a color value. So in the steps that you 
described, I don't know how I would turn this custom "home made" data into actual image data (which is something I 
normally do by calling the Pg(...) functions, which draws onto the screen, not a buffer).

Suppose I change the code to also draw into an offscreen context, how would I access the raw image data that I can point
 to with my PhImage_t ?
Re: Saving PtRaw "content" as images  
In this case you will need to use:
-- PdCreateOffscreenContext()
-- draw into it
-- blit to the screen
-- use PdGetOffscreenContextPtr() to get a pointer to the raw image data
-- use PxWriteImage() to save it.

Here is a link with a sample of setting up and using an offscreen context: http://www.qnx.com/developers/docs/6.4.0/
photon/prog_guide/draw.html#VideoMemoryOffscreen
Re: Saving PtRaw "content" as images  
Or PgReadScreen() might be useful, if you calculate the coordinates to "read from" ...