Re: Manipulating binary data
- From: brainflakes.org@xxxxxxxxxxxxxx
- Date: 30 Apr 2007 02:39:06 -0700
I doubt that's the optimal solution. Function calls are relatively
expensive in PHP. The difference in speed you observed between the
different methods can probably be attributed to the number of calls
made per element.
Explain exactly what you're trying to do. There probably is a better
approach.
I'm creating some custom image processing filters on 8bit greyscale
images
for($x=0; $x<$width; $x++){
for($y=0; $x<$height; $y++){
check value of pixels (0-255) in a 10x10 area around given pixel
calculate new value
plot value at x,y (0-255)
}
}
I figured the best way to do it would be to just "allocate" a memory
space of $width * $height bytes and copy the image into that, which I
guess is done by creating a string of that length. However even just
plotting to $string[$n++]=chr($val) (no co-ord calculations) is slower
then imagesetpixel() on an 8-bit image.
For some reason tho I can't actually render directly from the 8-bit
image (I use imagesetcolor() to set colours in a greyscale gradient
but imagepng complains there's the wrong number of colours) so I have
to copy the image in and out of a truecolour image anyway.
I have done some further optimisations on the actual processing code
and improved the speed about 10-fold, but if there's a faster way to
read/write 8bit data I'm still interested as every little helps when
you're doing batch processing. (tho I guess I should probably be doing
it in C or .net anyway ;)
Andrew
.
- Follow-Ups:
- Re: Manipulating binary data
- From: Chung Leong
- Re: Manipulating binary data
- References:
- Manipulating binary data
- From: brainflakes . org
- Re: Manipulating binary data
- From: Chung Leong
- Manipulating binary data
- Prev by Date: Re: Delete temporary images after loading website
- Next by Date: Re: help on integrating RSS in site done in php
- Previous by thread: Re: Manipulating binary data
- Next by thread: Re: Manipulating binary data
- Index(es):