#28304 [Asn]: ImageFilter, no bounds check processing image per-pixel: creates a black border

From: Date: Thu, 06 May 2004 22:12:56 +0000
Subject: #28304 [Asn]: ImageFilter, no bounds check processing image per-pixel: creates a black border
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-59332@lists.php.net to get a copy of this message
 ID:               28304
 Updated by:       pajoye@php.net
 Reported By:      ken at sonicwizardry dot com
 Status:           Assigned
 Bug Type:         GD related
 Operating System: Linux
 PHP Version:      5.0.0RC2
 Assigned To:      pajoye
 New Comment:

the patch is ok, however I prefer to do the check only once outside the
loops.

Let me check first if it's possible for this filter. Which one are
using?

Pierre


Previous Comments:
------------------------------------------------------------------------

[2004-05-06 18:50:38] ken at sonicwizardry dot com

Description:
------------
Running ImageFilter on an image creates a black border around the edge
because it references non-existing pixels off of the image (beyond
image size).  Bounds check/clamp added to convolution loop.  Code DIFF
is below:

File path: ext/gd/libgd/gd.c

3607,3610c3607,3614 

< pxl = f(srcback, x-(3>>1)+i, y-(3>>1)+j); 
< new_r += (float)gdImageRed(srcback, pxl) * filter[j][i]; 
< new_g += (float)gdImageGreen(srcback, pxl) * filter[j][i]; 
< new_b += (float)gdImageBlue(srcback, pxl) * filter[j][i]; 
 
--- 

> int ix = x-(3>>1)+i; 
> int iy = y-(3>>1)+j; 
> ix = (ix>=src->sx)?src->sx-1 : ((ix<0)?0:ix); 
> iy = (iy>=src->sy)?src->sy-1 : ((iy<0)?0:iy); 
> pxl = f(srcback, ix, iy); 
> new_r += (float)gdImageRed(srcback, pxl) * filter[j][i]; 
> new_g += (float)gdImageGreen(srcback, pxl) * filter[j][i]; 
> new_b += (float)gdImageBlue(srcback, pxl) * filter[j][i];


Hope this helps!
-Ken Post Jr.



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=28304&edit=1


Thread (5 messages)

« previous php.bugs (#59332) next »