def _render_offscreen(self, drawable, data, dst_x, dst_y, width, height): # NOTE [A] daht, dawd, depth = data.shape self.logger.debug("data shape is %dx%dx%d" % (dawd, daht, depth)) # Get qimage for copying pixel data qimage = self._get_qimage(data) painter = QPainter(drawable) painter.setWorldMatrixEnabled(True) # fill pixmap with background color imgwin_wd, imgwin_ht = self.get_window_size() bgclr = self._get_color(*self.img_bg) painter.fillRect(QtCore.QRect(0, 0, imgwin_wd, imgwin_ht), bgclr) # draw image data from buffer to offscreen pixmap painter.drawImage(QtCore.QRect(dst_x, dst_y, width, height), qimage, QtCore.QRect(0, 0, width, height)) # Draw a cross in the center of the window in debug mode if self.t_['show_pan_position']: clr = QColor() clr.setRgbF(1.0, 0.0, 0.0) painter.setPen(clr) ctr_x, ctr_y = self.get_center() painter.drawLine(ctr_x - 10, ctr_y, ctr_x + 10, ctr_y) painter.drawLine(ctr_x, ctr_y - 10, ctr_x, ctr_y + 10) # render self.message if self.message: self._draw_message(painter, imgwin_wd, imgwin_ht, self.message)
def __get_color(self, color, alpha): clr = QColor() if isinstance(color, tuple): clr.setRgbF(color[0], color[1], color[2], alpha) else: r, g, b = colors.lookup_color(color) clr.setRgbF(r, g, b, alpha) return clr
def _get_color(self, r, g, b): n = 255.0 clr = QColor(int(r * n), int(g * n), int(b * n)) return clr
def _get_color(self, r, g, b): # TODO: combine with the method from the RenderContext? n = 255.0 clr = QColor(int(r * n), int(g * n), int(b * n)) return clr
def _draw(self, cr): width, height = self.get_size() #print "window size is %d,%d" % (width, height) x1 = 0; x2 = width clr_wd = width // 256 rem_px = x2 - (clr_wd * 256) if rem_px > 0: ival = 256 // rem_px else: ival = 0 clr_ht = height #print "clr is %dx%d width=%d rem=%d ival=%d" % ( # width, height, clr_wd, rem_px, ival) dist = self.rgbmap.get_dist() j = ival; off = 0 range_pts = [] for i in range(256): wd = clr_wd if rem_px > 0: j -= 1 if j == 0: rem_px -= 1 j = ival wd += 1 x = off (r, g, b) = self.rgbmap.get_rgbval(i) color = QColor(r, g, b) cr.fillRect(QtCore.QRect(x, 0, wd, clr_ht), color) # Draw range scale if we are supposed to if self.t_showrange and i in self._interval: cb_pct = float(i) / 256.0 # get inverse of distribution function and calculate value # at this position rng_pct = dist.get_dist_pct(cb_pct) val = int(self.loval + (rng_pct * (self.hival - self.loval))) text = "%d" % (val) rect = cr.boundingRect(0, 0, 1000, 1000, 0, text) x1, y1, x2, y2 = rect.getCoords() _wd = x2 - x1 _ht = y2 - y1 _ht = 14 rx = x ry = _ht - 2 range_pts.append((rx, ry, text)) off += wd # draw range pen = cr.pen() cr.setFont(QFont(self.t_font, pointSize=self.t_fontsize)) color = QColor() color.setRgbF(0.0, 0.0, 0.0) pen.setColor(color) cr.setPen(pen) for (x, y, text) in range_pts: # tick cr.drawLine(x, 0, x, 2) # number cr.drawText(x, y, text)
def _draw(self, cr): width, height = self.get_size() #print "window size is %d,%d" % (width, height) x1 = 0 x2 = width clr_wd = width // 256 rem_px = x2 - (clr_wd * 256) if rem_px > 0: ival = 256 // rem_px else: ival = 0 clr_ht = height #print "clr is %dx%d width=%d rem=%d ival=%d" % ( # width, height, clr_wd, rem_px, ival) dist = self.rgbmap.get_dist() j = ival off = 0 range_pts = [] for i in range(256): wd = clr_wd if rem_px > 0: j -= 1 if j == 0: rem_px -= 1 j = ival wd += 1 x = off (r, g, b) = self.rgbmap.get_rgbval(i) color = QColor(r, g, b) cr.fillRect(QtCore.QRect(x, 0, wd, clr_ht), color) # Draw range scale if we are supposed to if self.t_showrange and i in self._interval: cb_pct = float(i) / 256.0 # get inverse of distribution function and calculate value # at this position rng_pct = dist.get_dist_pct(cb_pct) val = int(self.loval + (rng_pct * (self.hival - self.loval))) text = "%d" % (val) rect = cr.boundingRect(0, 0, 1000, 1000, 0, text) x1, y1, x2, y2 = rect.getCoords() _wd = x2 - x1 _ht = y2 - y1 _ht = 14 rx = x ry = _ht - 2 range_pts.append((rx, ry, text)) off += wd # draw range pen = cr.pen() cr.setFont(QFont(self.t_font, pointSize=self.t_fontsize)) color = QColor() color.setRgbF(0.0, 0.0, 0.0) pen.setColor(color) cr.setPen(pen) for (x, y, text) in range_pts: # tick cr.drawLine(x, 0, x, 2) # number cr.drawText(x, y, text)