← Back to team overview

phatch-dev team mailing list archive

[Bug 384420] Re: Inaccurate opacity floating point calculations

 

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

-- 
Inaccurate opacity floating point calculations
https://bugs.launchpad.net/bugs/384420
You received this bug notification because you are a member of Phatch
Developers, which is subscribed to Phatch.

Status in Phatch = Photo & Batch!: Fix Committed

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



References