Page 1 of 1

Why not allow direct access to underlying pixel array?

Posted: Wed Jun 11, 2008 10:39 am
by howardck
I'm new to gd. I'm trying to do some manipulation of an image's pixels for some special effects, and I'm wondering why there's no api for accessing the underlying pixel array directly? Instead, I have to call imagecolorat and imagesetpixel for every pixel in the image. This seems very inefficient to me.

Why isn't there something like imageGetPixelArray() and imageSetPixelArray() available? Other libraries I've used allow this low-level access, why not gd? I suppose I could write a php extension to provide this capability, but that's a bit beyond my capabilities at the moment.

TIA,
Howard

Re: Why not allow direct access to underlying pixel array?

Posted: Wed Jun 11, 2008 10:57 am
by onion2k
At some point in the process you (or GD) would have to loop through the array getting the pixel values or setting them. It wouldn't be that much more efficient for GD to do it than your PHP.

Re: Why not allow direct access to underlying pixel array?

Posted: Wed Jun 11, 2008 11:03 am
by superdezign
Not all file formats are bitmaps, and do not contain a "pixel array." Thats just the way that file-compression works. GD strives to support multiple file types, and to do such, must contain functions that can apply to all of the the types. You could always use GD to make your pixel array. :P

Re: Why not allow direct access to underlying pixel array?

Posted: Wed Jun 11, 2008 11:05 am
by onion2k
superdezign wrote:Not all file formats are bitmaps, and do not contain a "pixel array." Thats just the way that file-compression works. GD strives to support multiple file types, and to do such, must contain functions that can apply to all of the the types. You could always use GD to make your pixel array. :P
Actually, once you've opened an image with GD it'll be stored in memory the same way regardless of what the format was (with a small difference depending on whether it was 8-bit or 24-bit/32-bit).