X-Git-Url: https://git.gag.com/?p=debian%2Fgnuradio;a=blobdiff_plain;f=gr-wxgui%2Fsrc%2Fpython%2Fplotter%2Fwaterfall_plotter.py;fp=gr-wxgui%2Fsrc%2Fpython%2Fplotter%2Fwaterfall_plotter.py;h=0af64b826121badeca5745b27aaf7181b7c3d408;hp=2e0669961badf81da5e6494186746600bc47145a;hb=fd9980f919b6f05e2fbea404fea322825ce438f0;hpb=2415ccdbf9d97878a0888bbdff30d699ae2326dd diff --git a/gr-wxgui/src/python/plotter/waterfall_plotter.py b/gr-wxgui/src/python/plotter/waterfall_plotter.py index 2e066996..0af64b82 100644 --- a/gr-wxgui/src/python/plotter/waterfall_plotter.py +++ b/gr-wxgui/src/python/plotter/waterfall_plotter.py @@ -1,5 +1,5 @@ # -# Copyright 2008, 2009 Free Software Foundation, Inc. +# Copyright 2008, 2009, 2010 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -26,6 +26,7 @@ import common import numpy import gltext import math +import struct LEGEND_LEFT_PAD = 7 LEGEND_NUM_BLOCKS = 256 @@ -37,6 +38,9 @@ MIN_PADDING = 0, 60, 0, 0 #top, right, bottom, left ceil_log2 = lambda x: 2**int(math.ceil(math.log(x)/math.log(2))) +pack_color = lambda x: struct.unpack('I', struct.pack('BBBB', *x))[0] +unpack_color = lambda x: struct.unpack('BBBB', struct.pack('I', int(x))) + def _get_rbga(red_pts, green_pts, blue_pts, alpha_pts=[(0, 0), (1, 0)]): """ Get an array of 256 rgba values where each index maps to a color. @@ -53,11 +57,10 @@ def _get_rbga(red_pts, green_pts, blue_pts, alpha_pts=[(0, 0), (1, 0)]): #linear interpolation if x <= x2: return float(y1 - y2)/(x1 - x2)*(x - x1) + y1 raise Exception - return [numpy.array(map( - lambda pw: int(255*_fcn(i/255.0, pw)), - (red_pts, green_pts, blue_pts, alpha_pts), - ), numpy.uint8).tostring() for i in range(0, 256) - ] + return numpy.array([pack_color(map( + lambda pw: int(255*_fcn(i/255.0, pw)), + (red_pts, green_pts, blue_pts, alpha_pts), + )) for i in range(0, 256)], numpy.uint32) COLORS = { 'rgb1': _get_rbga( #http://www.ks.uiuc.edu/Research/vmd/vmd-1.7.1/ug/img47.gif @@ -179,8 +182,8 @@ class waterfall_plotter(grid_plotter_base): block_height = float(legend_height)/LEGEND_NUM_BLOCKS x = self.width - self.padding_right + LEGEND_LEFT_PAD for i in range(LEGEND_NUM_BLOCKS): - color = COLORS[self._color_mode][int(255*i/float(LEGEND_NUM_BLOCKS-1))] - GL.glColor4f(*map(lambda c: ord(c)/255.0, color)) + color = unpack_color(COLORS[self._color_mode][int(255*i/float(LEGEND_NUM_BLOCKS-1))]) + GL.glColor4f(*numpy.array(color)/255.0) y = self.height - (i+1)*block_height - self.padding_bottom self._draw_rect(x, y, LEGEND_WIDTH, block_height) #draw rectangle around color scale border @@ -209,7 +212,7 @@ class waterfall_plotter(grid_plotter_base): self._pointer = 0 if self._num_lines and self._fft_size: GL.glBindTexture(GL.GL_TEXTURE_2D, self._waterfall_texture) - data = numpy.zeros(self._num_lines*self._fft_size*4, numpy.uint8).tostring() + data = numpy.zeros(self._num_lines*ceil_log2(self._fft_size)*4, numpy.uint8).tostring() GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, ceil_log2(self._fft_size), self._num_lines, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, data) self._resize_texture_flag = False @@ -261,7 +264,7 @@ class waterfall_plotter(grid_plotter_base): samples = numpy.clip(samples, 0, 255) #clip samples = numpy.array(samples, numpy.uint8) #convert the samples to RGBA data - data = numpy.choose(samples, COLORS[self._color_mode]).tostring() + data = COLORS[self._color_mode][samples].tostring() self._buffer.append(data) self._waterfall_cache.changed(True) self.unlock()