[Image-SIG] PSDraw: Floating Point Typo

Eric Etheridge etherson at yahoo.com
Tue Apr 12 02:11:44 CEST 2005


I have finally tracked down the cause of images
sometimes not showing up when using PSDraw's
im.image() method.  The problem is the following
lines, 101 and 102 in PSDraw.ph:

            sx = x / im.size[0]
            sy = y / im.size[1]

These lines can occasionally perform integer division
rather than floating point division.  This is
partially prevented by the use of float() on lines
87-88, but then lines 90-95 cause problems again:

        xmax = box[2] - box[0]
        ymax = box[3] - box[1]
        if x > xmax:
            y = y * xmax / x; x = xmax
        if y > ymax:
            x = x * ymax / y; y = ymax

x or y may hold an integer value after these lines,
depending on the size and shape of the box versus the
image.  The fix is to add a pair of float() in one of
three places, either around xmax and ymax's creation,
their assignment to x and y, or in lines 101-102:

        xmax = float(box[2] - box[0])
        ymax = float(box[3] - box[1])
or
        if x > xmax:
            y = y * xmax / x; x = float(xmax)
        if y > ymax:
            x = x * ymax / y; y = float(ymax)
or
            sx = float(x) / im.size[0]
            sy = float(y) / im.size[1]

Any of those ways works.  This is an extremely
frustrating bug and its existance can render the
PSDraw module relatively useless, so please include
the fix in the distribution as soon as possible.  I
think it has been in existance for several years.

- Eric Etheridge



		
__________________________________ 
Do you Yahoo!? 
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/


More information about the Image-SIG mailing list