[Commits] (alecf) round brush bitmaps to the nearest power of 2, so that they draw correctly on the mac. Be sure to fill in the rest of the bitmap with the right gradient.

commits at osafoundation.org commits at osafoundation.org
Wed Apr 27 11:55:45 PDT 2005


Commit by: alecf
Modified files:
chandler/parcels/osaf/framework/blocks/calendar/CalendarCanvas.py 1.85 1.86

Log message:
round brush bitmaps to the nearest power of 2, so that they draw correctly on the mac. Be sure to fill in the rest of the bitmap with the right gradient.


ViewCVS links:
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/framework/blocks/calendar/CalendarCanvas.py.diff?r1=text&tr1=1.85&r2=text&tr2=1.86

Index: chandler/parcels/osaf/framework/blocks/calendar/CalendarCanvas.py
diff -u chandler/parcels/osaf/framework/blocks/calendar/CalendarCanvas.py:1.85 chandler/parcels/osaf/framework/blocks/calendar/CalendarCanvas.py:1.86
--- chandler/parcels/osaf/framework/blocks/calendar/CalendarCanvas.py:1.85	Wed Apr 27 10:51:35 2005
+++ chandler/parcels/osaf/framework/blocks/calendar/CalendarCanvas.py	Wed Apr 27 11:55:44 2005
@@ -1,8 +1,8 @@
 """ Canvas for calendaring blocks
 """
 
-__version__ = "$Revision: 1.85 $"
-__date__ = "$Date: 2005/04/27 17:51:35 $"
+__version__ = "$Revision: 1.86 $"
+__date__ = "$Date: 2005/04/27 18:55:44 $"
 __copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
 __license__ = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -21,6 +21,7 @@
 
 from colorsys import *
 import copy
+import math
 
 # 'color' is 0..255 based
 # 'rgb' is 0..1.0 based
@@ -923,11 +924,14 @@
         rightColor. This means that the Hue and Value should be the same, 
         or the resulting color on the right won't match rightColor
         """
-        
+        # mac requires bitmaps to have a height and width that are powers of 2
+        # use frexp to round up to the nearest power of 2
+        # (frexp(x) returns (m,e) where x = m * 2**e, and we just want e)
+        bitmapWidth = 2**math.frexp(width-1)[1]
         # There is probably a nicer way to do this, without:
         # - going through wxImage
         # - individually setting each RGB pixel
-        image = wx.EmptyImage(width, 1)
+        image = wx.EmptyImage(bitmapWidth, 1)
         leftHSV = rgb_to_hsv(*color2rgb(*leftColor))
         rightHSV = rgb_to_hsv(*color2rgb(*rightColor))
         
@@ -945,11 +949,12 @@
         
         # assign a sliding scale of floating point values from left to right
         # in the bitmap
-        for x in xrange(width):
-            sat = satStart + satStep*x
+        bits = ""
+        for x in xrange(bitmapWidth):
+            pixel = x % width
+            sat = satStart + satStep*pixel
             newColor = rgb2color(*hsv_to_rgb(hue, sat, value))
             image.SetRGB(x,0,*newColor)
-        
         # and now we have to go from Image -> Bitmap. Yuck.
         return wx.BitmapFromImage(image)
         



More information about the Commits mailing list