Question about importing data from memory
| From: | Jeff Cunningham | Date: | Wed, 28 Nov 2007 14:56:20 +0000 |
| Subject: | Question about importing data from memory | ||
| Groups: | php.gd.devel | ||
| Request: | Send a blank email to php-gd-devel+get-285@lists.php.net to get a copy of this message | ||
Hi,
I am processing some imagery that comes directly from sensors so that I end up with it in an NxM array of unsigned integers of rgb values (for example, array[0][0]=\xff0000 would be a red pixel in the upper-left corner). Some of this imagery wants to end up on web pages with text annotation, which is why I am looking at using the gd library. Currently, I save these images as bmp files using my own code, convert them to jpeg using imagemagick's convert utility, and they have no annotations.
Is there a way to get the data from my arrays directly into a gdImage? I was looking through the API and could only find the function gdImageCreateFromGdPtr:
http://www.libgd.org/OldImageCreation#gdImageCreateFromGdPtr.28int_size.2C_void_.2Adata.29_.28FUNCTION.29
but I couldn't find any description of the format of a GdPtr. I could go to the source code, but in my experience when something isn't described in the API, its often not stable, so I don't want to get off on the wrong track.
I did take a look at a couple of the files like gdxpm.c for guidance, and there it appears that one creates a gdImage and populates it by creating a color table on the fly and writing indices instead of pixels. The problems I can see with this approach are that - unless duplicate color entries are allowed - there will be a significant overhead involved in searching the table for an existing color each time before creating a new one, which with Truecolor could be hugely inefficient.
I didn't see any related discussions in the list archives. How do people handle this kind of problem?
Thanks,
Jeff Cunningham