Re: [GD-DEVEL] [proposal] Attach DIB section buffer to gdImage
[email protected] (Pierre)
| Newsgroups | php.gd.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi Mateusz, On 8/13/07, Mateusz Loskot <[email protected]> wrote: > Hi, > > Some (quite long) time ago, I was asking about how to use libgd > as GDI replacement and how to use it to draw on Windows device-context. > Here, I'd like to introduce simple single-function extension to libgd > that solves this task. > > I created new function called gdImageTrueColorAttachBuffer. > This function does not use any elements specific to Windows > and perhaps it could be used on other purposes, not only under Windows. > > The idea behind the gdImageTrueColorAttachBuffer is simple. > In Windows, CreateDIBSection allocates linear buffer for pixels > but libgd uses 2-dim buffer, so my function attaches chunks of the > linear buffer as separate rows to gdImage object. > It's also possible to control orientation of pixel rows, normal or > up-side-down by using negative value of 'stride' parameter. > > > Here is the gdImageTrueColorAttachBuffer function code: > > ////////////////////////////////////////////////////////////////////// > BGD_DECLARE(gdImagePtr) > gdImageTrueColorAttachBuffer(int* buffer, int sx, int sy, int stride) It is a very good idea. Such function is required for not only windows bmp but almost all other upcoming formats like cairo, agg, X or whatever we may need. About the implementation, I'm not sure we can accept any format. We may need an additional argument to define the buffer format (rgb, rgba, argb, etc.). The problem is not how to initialize the buffer but how to work with it with the other GD functions (drawing functions, load/save, etc.). We will need an efficient way to access it. It may be better to share the buffer instead of copying it. It'll faster and more flexible (the buffer can still be used by another API (gdi, dx, gl..). I would also like to have a generic image format. The primitives functions can be customized and used by the other GD functions. It will be slow (not much slower that what we have now) but it can be amazingly useful. A last solution is to create a Win32 internal format. It can be done independently of the other image formats. Would it help for the CE platform? Cheers, --Pierre