Re: [GD-DEVEL] [proposal] Attach DIB section buffer to gdImage
| From: | Mateusz Loskot | Date: | Sun, 19 Aug 2007 19:58:27 +0000 |
| Subject: | Re: [GD-DEVEL] [proposal] Attach DIB section buffer to gdImage | ||
| References: | 1 2 | Groups: | php.gd.devel |
| Request: | Send a blank email to php-gd-devel+get-244@lists.php.net to get a copy of this message | ||
Pierre wrote:
> On 8/13/07, Mateusz Loskot <mateusz@loskot.net> wrote:
>>
>> 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.
Pierre,
I'm glad you like it too.
Yes, I believe it isn't single purpose code but would be useful
somewhere else.
> About the implementation, I'm not sure we can accept any format.
Understood.
I intentionally use 32-bit image the idea comes from one of my
project where I don't need any other formats.
> 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.
Yes.
> 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..).
Hmm, but I don't copy it but I use shared buffer.
> 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.
Unfortunately, I don't think I'm experienced enough with libgd to give
any better proposal. So, I'd appreciate if we can discuss it here
together or may be you have something in mind already?
> 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?
I *suppose* it would help.
Do you have any properties of such format figured out already?
Cheers
--
Mateusz Loskot
http://mateusz.loskot.net