|
From: Alan W. I. <ir...@be...> - 2007-03-10 04:55:47
|
On 2007-03-09 17:53-0500 Raul Perez-alejo Neyra wrote:
>
> thanks to allan for forwarding my message to this mailing list, unfortunately we still have problems with the plplot mem driver. We want plplot to compose a graphic in memory and then pass it to another vector graphic library (cairo).
> In our testing it seems that plplot does not write in the defined buffer, the problem doesn't seems to be cairo because when we force the values of the buffer cairo outputs fine.
> we are using plplot-5.7.2 with xwin and mem drivers only.
>
> here is our test code.
> this example is an hybrid of some code found on sourceforge, and sent to us by Hazen.
> any help will be appreciated.
> gratings Raul.
>
>
>
> #include <plplot.h>
> #include <memory.h>
> #include <iostream>
> #include <cairo.h>
>
> using namespace std;
>
>
> int main(int argc, char **argv) {
>
> int width = 200;
> int height = 200;
>
> char *buffer;
> buffer = (char *)malloc(width * height * 3 * sizeof(char));
> for(int ii=0;ii<(width*height*3);ii++) { buffer[ii] = 0; }
>
> plsdev("mem");
> plsmem(width, height, buffer);
> plscolbg (255, 255, 255);
> plinit();
> plenv(0, 10.0, 0, 10.0, 0, 0);
> pljoin(1.0, 2.0, 7.0, 8.0);
> plend();
>
> cairo_surface_t *surface;
> unsigned char *cairo_buffer;
> cairo_buffer = (unsigned char *)malloc(width * height * 4 * sizeof(char));
>
> for (int i = 0, j = 0; i < (width * height * 3); i+=3)
> {
> cairo_buffer[j++] = buffer[i+2]; //blue
> cairo_buffer[j++] = buffer[i + 1]; //green
> cairo_buffer[j++] = buffer[i]; //red
> cairo_buffer[j++] = 0;
> }
>
> surface = cairo_image_surface_create_for_data
> (cairo_buffer,
> CAIRO_FORMAT_RGB24,
> width, height, 0);
>
> cairo_surface_write_to_png(surface, "plplot1.png");
> cairo_surface_destroy (surface);
> return 0;
> }
>
Raul, I am not really expert in this area, but I do know that plend closes
_everything_ having to do with plplot. I doubt it would also free the
buffer area, but just to be sure, I would suggest putting the plend call
after the cairo_surface_destroy call.
Alan
__________________________
Alan W. Irwin
Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).
Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the Yorick front-end to PLplot (yplot.sf.net); the
Loads of Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________
Linux-powered Science
__________________________
|