From: Trevor B. <tl...@an...> - 2004-03-09 20:24:12
|
In backend_gtk.py, it does some antialiased rendering by direct manipulation of pixel values which is only correct for 24-bit TrueColor X11 visuals. I'm running a 16-bit (5 red, 6 green, 5 blue) visual, so this produces visual junk. I think the right way to do it is with a Pixbuf, which handles alpha rendering. The code is much simpler and faster too. Here is a patch: (This is from matplotlib-0.51.) --- backends/backend_gtk.py~ Wed Mar 3 09:31:39 2004 +++ backends/backend_gtk.py Tue Mar 9 12:00:37 2004 @@ -350,47 +351,20 @@ xox = int(x+ox) yoy = int(y+oy) - - imw = min(imw, self.width-xox) imh = min(imh, yoy) - #print imw, imh, xox, yoy, self.width, self.height - image = self.gdkDrawable.get_image(xox, self.height-yoy, imw, imh) - #return - - - tr = int(rgb[0]*255) # text red - tg = int(rgb[1]*255) # text green - tb = int(rgb[2]*255) # text blue - - ind = indices(Xs.shape) - numRows, numCols = Xs.shape - ind.shape = 2, numRows*numCols - Xs.shape = numRows*numCols, - visible = nonzero(Xs>0) - Xs.shape = numRows,numCols - for thisInd in visible: - j,i = ind[:,thisInd] - if i >= imw: continue - if j >= imh: continue - pixel = image.get_pixel(i, j) - br = (pixel >> 16) & 0xff # background red - bg = (pixel >> 8 ) & 0xff - bb = (pixel >> 0) & 0xff - #print br, bg, bb, Xs[j,i] - - alpha = int((255-Xs[j,i])*255) - - nr = (((br - tr) * alpha) + (tr << 16)) >> 16 - ng = (((bg - tg) * alpha) + (tg << 16)) >> 16 - nb = (((bb - tb) * alpha) + (tb << 16)) >> 16 - newpixel = (nr<<16) + (ng<<8) + (nb) - - image.put_pixel(i, j, newpixel) - self.gdkDrawable.draw_image(gc.gdkGC, image, 0, 0, - xox, self.height-yoy, imw, imh) + pb=gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, + has_alpha=1, bits_per_sample=8, width=imw, height=imh) + pbpix=pb.pixel_array + pbpix[:,:,3]=Xs + pbpix[:,:,0]=int(rgb[0]*255) + pbpix[:,:,1]=int(rgb[1]*255) + pbpix[:,:,2]=int(rgb[2]*255) + pb.render_to_drawable(self.gdkDrawable, gc.gdkGC, 0, 0, xox, self.height-yoy, imw, imh, + gdk.RGB_DITHER_NONE, 0, 0) + if 0: self.gdkDrawable.draw_rectangle( gc.gdkGC, 0, xox, -- Trevor Blackwell tl...@an... (650) 210-9272 |