Inaccurate opacity floating point calculations

Bug #384420 reported by Nadia Alramli
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Phatch
Fix Released
Critical
Nadia Alramli

Bug Description

when calculating the opacity, in the reflection and background actions (and possible others) we are using this method:
opacity = int(2.55 * opacity)
if opacity is 100 the result is:
int(2.55 * 100)= int(249.99999999999999) = 244

Which is generating inaccurate results. The correct way of calculating is:
opacity = (255 * opacity) / 100

Nadia Alramli (nadiana)
Changed in phatch:
assignee: nobody → Nadia Alramli (nadiana)
importance: Undecided → Critical
Revision history for this message
Stani (stani) wrote :

Only the reflection action needs to be fixed. I've looked for 2[.]55 with regexxer.

Changed in phatch:
status: New → In Progress
Revision history for this message
Stani (stani) wrote :

Thanks for the fix!

$ bzr diff
=== modified file 'phatch/actions/reflection.py'
--- phatch/actions/reflection.py 2009-06-08 12:17:51 +0000
+++ phatch/actions/reflection.py 2009-06-09 22:52:15 +0000
@@ -58,8 +58,8 @@
         resample_shadow,gap=0,scale=False,cache=None):
     if cache is None:
         cache = {}
- opacity = int(2.55*opacity)
- background_opacity = int(2.55*background_opacity)
+ opacity = (255 * opacity) / 100
+ background_opacity = (255 * background_opacity) / 100
     resample_shadow = getattr(Image,resample_shadow)
     if background_opacity == 255:
         mode = 'RGB'

$ bzr commit -m "fix reflection"
Committing to: /home/stani/sync/python/phatch/trunk/
modified phatch/actions/reflection.py
Committed revision 715.

Changed in phatch:
status: In Progress → Fix Committed
Stani (stani)
Changed in phatch:
milestone: none → 0.2.1
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.