Christopher Barker wrote:
Christopher Barker wrote:
Are you saying I'll be able to follow the code and figure out how to enable HitTest for a color depth of 16?

I think the solution is for the color generator to actually draw the color to a small bitmap, then check the pixel color, and see what it comes back as -- then store that color as the index for the hot-test. Or maybe it would be easier to test if the color comes back the same, and reject it if it doesn't, then no other code would have to change.

Paul,

Enclosed is a test file that may help. It should be in FloatCnvas SVN, in the Tests dir, but just in case, here it is.

Attached is my patch to this test, which runs on Linux and Mac. Interesting that Mac can seemingly handle any depth from 2 to 32, with all output pixels matching all input pixels. I don't understand how that could be, unless the bitmap is automatically created with maximum depth regardless of the depth argument...

I now know how to fix my patch to FloatCanvas to work on Mac, and will work on that next.

Paul
Index: TestBitmapColors.py
===================================================================
--- TestBitmapColors.py	(revision 57217)
+++ TestBitmapColors.py	(working copy)
@@ -5,35 +5,46 @@
 
 """
 
-
+import sys
 import wx
 
-Size = (200, 200)
+# Mac requires special handling
+mac = sys.platform.startswith("darwin")
+lin = sys.platform.startswith("linux")
 
+def test():
+        if len(sys.argv) > 1:
+            # depth arg passed
+            Depth = int(sys.argv[1])
+            if lin:
+                print "Warning: Gtk can't handle setting a depth less than the display depth."
+        else:
+            # use current display depth
+            Depth = wx.GetDisplayDepth()
+        print "display depth:", Depth
+        Size = (200,200)
+        Start, Stop, Step = (0, 255, 10)
 
-class DemoApp(wx.App):
-    def OnInit(self):
-        #frame = TestFrame()
-        #frame.Show(True)
+        B = wx.EmptyBitmap(Size[0], Size[1], depth=Depth)
+        print "Bitmap depth:", B.GetDepth()
 
-        #Start, Stop, Step = (0, 200, 10)
-        Start, Stop, Step = (0, 200, 20)
-        Depth = 24
+        print "Bitmap Size:", Size
+        print "(Start, Stop, Step)", (Start, Stop, Step)
 
-        B = wx.EmptyBitmap(Size[0], Size[1], depth=24)
-        #B = wx.EmptyBitmap(Size[0], Size[1])
-        print "Bitmap depth is:", B.GetDepth()
-        #raise Exception("stopping")
         dc = wx.MemoryDC()
         dc.SelectObject(B)
-
         dc.SetBackground(wx.BLACK_BRUSH)
         dc.Clear()
-        del dc
+        if mac:
+        	del dc
 
         i = 0
         j = 0
+        good = []
+        bad = []
         for r in range(Start, Stop, Step):
+            print ".",
+            sys.stdout.flush()
             for g in range(Start, Stop, Step):
                 for b in range(Start, Stop, Step):
                     i+=1
@@ -43,47 +54,35 @@
                     if j >= Size[1]:
                         raise Exception("Too many color tests for bitmap size") 
                     inColor = (r,g,b)
-                    print "Drawing:", inColor, "To pixel:", (i,j)
+                    #print "Drawing:", inColor, "To pixel:", (i,j)
 
-                    dc = wx.MemoryDC(B)
+                    if mac:
+                        dc = wx.MemoryDC(B)
                     dc.SetPen(wx.Pen(wx.Color(*inColor), 4))
                     dc.DrawPoint(i,j)
-                    del dc
-                    
-                    print "Bitmap depth is:", B.GetDepth()
-                    pdata = wx.AlphaPixelData(B)
-                    pacc = pdata.GetPixels()
-                    pacc.MoveTo(pdata, i,j)
-                    outColor = pacc.Get()[:3]
-                    
-                    #print "Got", outColor
-                    if inColor != outColor:
-                        print "Error!!, inColor = %s, outColor = %s at pixel: %s"%(inColor, outColor, (i,j) )
+                    if mac:
+                        del dc
 
-        B.SaveFile("junk.png", wx.BITMAP_TYPE_PNG )
+                        pdata = wx.AlphaPixelData(B)
+                        pacc = pdata.GetPixels()
+                        pacc.MoveTo(pdata, i, j)
+                        outColor = pacc.Get()[:3]
+                    else:
+                        outColor = dc.GetPixel(i,j)
+                    if inColor != outColor:
+                        bad.append((inColor, outColor))
+                    else:
+                        good.append((inColor, outColor))
+        print
+        print "good, bad:", len(good), len(bad)
+        #for g in good:
+        #  print g
+        #B.SaveFile("junk.png", wx.BITMAP_TYPE_PNG )
         
         return True
 
 if __name__ == "__main__":
-    app = DemoApp(False)
-    app.MainLoop()
+    app = wx.App(False)
+    test()
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
_______________________________________________
FloatCanvas mailing list
[email protected]
http://mail.mithis.com/cgi-bin/mailman/listinfo/floatcanvas

Reply via email to