Re: [GD-DEVEL] allocation of pixel buffer

[email protected] (Pierre Joye) Thu, 20 Jun 2013 06:30:03 +0200
Newsgroups php.gd.devel
Message-ID <CAEZPtU4e1TJY3tVJu48BTBaUZjANpN-cwNLmB0T-kFDKHp4a8g@mail.gmail.com>
hi Chris,

On Wed, Jun 19, 2013 at 9:31 PM, Chris Barker - NOAA Federal
<[email protected]> wrote:
> Folks,
>
> I'm working on some new bindings of GD for Python.

Very nice, let us know if we can help in any way!

> One of the things
> I'd hoped to do is wrap the pixel buffer in a numpy array, so that
> users could manipulate it with numpy functions (and nifty tools like
> the nd-image package) and not have to copy the data back-and forthc
> between gd and numpy.
>
> However, I've noticed that the pixel buffer is allocated row-by-row,
> rather than as oen big block of data. This make it impossible to share
> the buffer with numpy, as numpy requires a single block of contiguous
> memory.
>
> It there a compelling reason for it to be allocated this way? or could
> I re-write the allocation routines to allocate a single block of
> memory? (still casting it to a **, so it would still be able to be
> used in the same way in the rest of the code.

It was done like that in all the 2.x serie and we can't really change
that at this point. That's not the best way but it is how it is :)

2.2+ will allow custom buffer to be used, allocated by gd or 3rd
parties, with more buffer formats. Something like what is done in
pixmap (freedesktop) if you know it.

> Honestly, I'm not sure I'd ever get around to it -- copying data isn't
> all THAT expensive, but I was wondering if it's done this way for a
> godo reason I'm not thinking of at the moment.


Cheers,
--
Pierre

@pierrejoye | http://www.libgd.org