def draw_grid(self, grid_control, dc, first_row, visible_rows, first_cell, visible_cells): t = grid_control.table t.prepare_for_drawing(first_row, visible_rows, first_cell, visible_cells) last_cell = min(first_cell + visible_cells, self.num_cells) last_row = min(first_row + visible_rows, t.num_rows) log.debug("draw_grid: rows:%d,%d (vis %d, num %d) cols:%d,%d" % (first_row, last_row, visible_rows, t.num_rows, first_cell, last_cell)) ul_rect = self.col_to_rect(first_row, first_cell) lr_rect = self.col_to_rect(last_row - 1, last_cell - 1) frame_rect = wx.Rect(ul_rect.x, ul_rect.y, lr_rect.x - ul_rect.x + lr_rect.width, lr_rect.y - ul_rect.y + lr_rect.height) dc.SetClippingRegion(frame_rect) pixels, style = t.current_rectangle pixels = pixels[:,first_cell:last_cell] style = style[:,first_cell:last_cell] array = px.calc_rgb_from_color_indexes(pixels, style, grid_control.color_list_rgb, grid_control.empty_color_rgb) width = array.shape[1] height = array.shape[0] print(f"array: {array.shape}") if width > 0 and height > 0: array = intscale(array, grid_control.zoom_h, grid_control.zoom_w) #print("bitmap: %d,%d,3 after scaling: %s" % (height, width, str(array.shape))) image = wx.Image(array.shape[1], array.shape[0]) image.SetData(array.tobytes()) bmp = wx.Bitmap(image) dc.DrawBitmap(bmp, frame_rect.x, frame_rect.y)
def draw_grid(self, grid_control, dc, first_row, visible_rows, first_cell, visible_cells): model = grid_control.model first_col = self.cell_to_col(first_row, first_cell) last_cell = min(first_cell + visible_cells, self.num_cells) last_row = min(first_row + visible_rows, model.antic_lines) last_col = self.cell_to_col(last_row, last_cell - 1) + 1 drawlog.debug("draw_grid: rows:%d,%d, cols:%d,%d" % (first_row, last_row, first_col, last_col)) ul_rect = self.col_to_rect(first_row, first_col) lr_rect = self.col_to_rect(last_row - 1, last_col - 1) frame_rect = wx.Rect(ul_rect.x, ul_rect.y, lr_rect.x - ul_rect.x + lr_rect.width, lr_rect.y - ul_rect.y + lr_rect.height) bytes_per_row = model.items_per_row first_index = first_row * bytes_per_row last_index = last_row * bytes_per_row data = model.data[first_index:last_index] style = model.style[first_index:last_index] drawlog.debug("draw_grid: first_index:%d last_index:%d" % (first_index, last_index)) array = grid_control.bitmap_renderer.get_image(grid_control.segment_viewer, bytes_per_row, last_row - first_row, last_index - first_index, data, style) width = array.shape[1] height = array.shape[0] drawlog.debug("Calculated image: %dx%d" % (width, height)) if width > 0 and height > 0: # image returned will have the correct number of rows but will be # 160 pixels wide; need to crop to visible columns cropped = array[:,first_col:last_col,:] array = intscale(cropped, grid_control.zoom_h, grid_control.zoom_w) #print("bitmap: %d,%d,3 after scaling: %s" % (height, width, str(array.shape))) image = wx.Image(array.shape[1], array.shape[0]) image.SetData(array.tobytes()) bmp = wx.Bitmap(image) dc.SetClippingRegion(frame_rect) dc.DrawBitmap(bmp, frame_rect.x, frame_rect.y)
def draw_grid(self, grid_control, dc, first_row, visible_rows, first_cell, visible_cells): t = grid_control.table t.prepare_for_drawing(first_row, visible_rows, first_cell, visible_cells) last_cell = min(first_cell + visible_cells, self.num_cells) last_row = min(first_row + visible_rows, t.num_rows) log.debug("draw_grid: rows:%d,%d (vis %d, num %d) cols:%d,%d" % (first_row, last_row, visible_rows, t.num_rows, first_cell, last_cell)) ul_rect = self.col_to_rect(first_row, first_cell) lr_rect = self.col_to_rect(last_row - 1, last_cell - 1) frame_rect = wx.Rect(ul_rect.x, ul_rect.y, lr_rect.x - ul_rect.x + lr_rect.width, lr_rect.y - ul_rect.y + lr_rect.height) dc.SetClippingRegion(frame_rect) pixels, style = t.current_rectangle pixels = pixels[:, first_cell:last_cell] style = style[:, first_cell:last_cell] array = px.calc_rgb_from_color_indexes(pixels, style, grid_control.color_list_rgb, grid_control.empty_color_rgb) width = array.shape[1] height = array.shape[0] print(f"array: {array.shape}") if width > 0 and height > 0: array = intscale(array, grid_control.zoom_h, grid_control.zoom_w) #print("bitmap: %d,%d,3 after scaling: %s" % (height, width, str(array.shape))) image = wx.Image(array.shape[1], array.shape[0]) image.SetData(array.tobytes()) bmp = wx.Bitmap(image) dc.DrawBitmap(bmp, frame_rect.x, frame_rect.y)
def reshape(self, bitimage, bytes_per_row, nr): # source array 'bitimage' in the shape of (size, w, 3) h, w, colors = bitimage.shape # create a new image with pixels in the correct aspect ratio output = bitimage.reshape((nr, self.pixels_per_byte * bytes_per_row, 3)) output = intscale(output, self.scale_height, self.scale_width) log.debug("bitimage: %d,%d,%d; ppb=%d bpr=%d, output=%s" % (h, w, colors, self.pixels_per_byte * self.scale_width, bytes_per_row, str(output.shape))) return output
def draw_item(self, grid_control, dc, rect, data, style): start = 0 end = len(data) nr = 1 array = grid_control.bitmap_renderer.get_image(grid_control.segment_viewer, end, nr, end, data, style) width = array.shape[1] height = array.shape[0] if width > 0 and height > 0: array = intscale(array, grid_control.zoom_h * grid_control.scale_height, grid_control.zoom_w * grid_control.scale_width) #print("bitmap: %d,%d,3 after scaling: %s" % (height, width, str(array.shape))) image = wx.Image(array.shape[1], array.shape[0]) image.SetData(array.tobytes()) bmp = wx.Bitmap(image) dc.DrawBitmap(bmp, rect.x, rect.y)
def draw_item(self, parent, dc, rect, data, style): start = 0 end = len(data) nr = 1 data = data.reshape((nr, -1)) style = style.reshape((nr, -1)) v = parent.segment_viewer array = parent.font_renderer.get_image(v, v.antic_font, data, style, start, end, end, nr, start, end) width = array.shape[1] height = array.shape[0] if width > 0 and height > 0: array = intscale(array, parent.zoom_h, parent.zoom_w) image = wx.Image(array.shape[1], array.shape[0]) image.SetData(array.tobytes()) bmp = wx.Bitmap(image) dc.DrawBitmap(bmp, rect.x, rect.y)
def draw_item(self, grid_control, dc, rect, data, style): start = 0 end = len(data) nr = 1 array = grid_control.bitmap_renderer.get_image( grid_control.segment_viewer, end, nr, end, data, style) width = array.shape[1] height = array.shape[0] if width > 0 and height > 0: array = intscale(array, grid_control.zoom_h * grid_control.scale_height, grid_control.zoom_w * grid_control.scale_width) #print("bitmap: %d,%d,3 after scaling: %s" % (height, width, str(array.shape))) image = wx.Image(array.shape[1], array.shape[0]) image.SetData(array.tobytes()) bmp = wx.Bitmap(image) dc.DrawBitmap(bmp, rect.x, rect.y)
def draw_grid(self, grid_control, dc, first_row, visible_rows, first_cell, visible_cells): t = grid_control.table log.debug(f"draw_grid: first_row={first_row} visible_rows={visible_rows}; first_cell={first_cell} visible_cells={visible_cells}") first_col = self.cell_to_col(first_row, first_cell) last_cell = min(first_cell + visible_cells, self.num_cells) last_row = min(first_row + visible_rows, t.num_rows) last_col = self.cell_to_col(last_row, last_cell - 1) + 1 log.debug("draw_grid: rows:%d,%d (vis %d, num %d) cols:%d,%d" % (first_row, last_row, visible_rows, t.num_rows, first_col, last_col)) ul_rect = self.col_to_rect(first_row, first_col) lr_rect = self.col_to_rect(last_row - 1, last_col - 1) frame_rect = wx.Rect(ul_rect.x, ul_rect.y, lr_rect.x - ul_rect.x + lr_rect.width, lr_rect.y - ul_rect.y + lr_rect.height) dc.SetClippingRegion(frame_rect) # First and last rows may not span entire width. Process those # separately # # First row may not have bytes at the beginning of the row if the start # offset is not zero if first_row == 0: try: col, index, last_index = self.calc_column_range(grid_control, first_row, first_col, last_col) except IndexError: pass # skip lines with no visible cells else: self.draw_line(grid_control, dc, first_row, col, index, last_index) first_row += 1 if first_row == last_row: return frame_rect.y += ul_rect.height # Last row may not have bytes at the end of the row if last_row == t.num_rows: try: col, index, last_index = self.calc_column_range(grid_control, last_row - 1, first_col, last_col) except IndexError: pass # skip lines with no visible cells else: self.draw_line(grid_control, dc, last_row - 1, col, index, last_index) last_row -= 1 # If there are any more rows to display, they will be full-width rows; # i.e. the data is in a rectangular grid nr = last_row - first_row if nr > 0: bytes_per_row = self.calc_bytes_per_row(t) nc = last_col - first_col offset = t.start_offset % bytes_per_row first_index = (first_row * bytes_per_row) - offset last_index = (last_row * bytes_per_row) - offset log.debug(f"drawing rectangular grid: bpr={bytes_per_row}, first,last={first_index},{last_index}, nr={nr}, start_offset={offset}") data = t.data[first_index:last_index].reshape((nr, bytes_per_row))[0:nr,first_col:last_col].flatten() style = t.style[first_index:last_index].reshape((nr, bytes_per_row))[0:nr,first_col:last_col].flatten() # get_image(cls, machine, antic_font, byte_values, style, start_byte, end_byte, bytes_per_row, nr, start_col, visible_cols): array = grid_control.bitmap_renderer.get_image(grid_control.segment_viewer, nc, nr, nc * nr, data, style) width = array.shape[1] height = array.shape[0] if width > 0 and height > 0: array = intscale(array, grid_control.zoom_h, grid_control.zoom_w) #print("bitmap: %d,%d,3 after scaling: %s" % (height, width, str(array.shape))) image = wx.Image(array.shape[1], array.shape[0]) image.SetData(array.tobytes()) bmp = wx.Bitmap(image) dc.DrawBitmap(bmp, frame_rect.x, frame_rect.y)
def draw_grid(self, grid_control, dc, first_row, visible_rows, first_cell, visible_cells): t = grid_control.table first_col = self.cell_to_col(first_row, first_cell) last_cell = min(first_cell + visible_cells, self.num_cells) last_row = min(first_row + visible_rows, t.num_rows) last_col = self.cell_to_col(last_row, last_cell - 1) + 1 log.debug("draw_grid: rows:%d,%d (vis %d, num %d) cols:%d,%d" % (first_row, last_row, visible_rows, t.num_rows, first_col, last_col)) ul_rect = self.col_to_rect(first_row, first_col) lr_rect = self.col_to_rect(last_row - 1, last_col - 1) frame_rect = wx.Rect(ul_rect.x, ul_rect.y, lr_rect.x - ul_rect.x + lr_rect.width, lr_rect.y - ul_rect.y + lr_rect.height) dc.SetClippingRegion(frame_rect) # First and last rows may not span entire width. Process those # separately # # First row may not have bytes at the beginning of the row if the start # offset is not zero if first_row == 0: try: col, index, last_index = self.calc_column_range( grid_control, first_row, first_col, last_col) except IndexError: pass # skip lines with no visible cells else: self.draw_line(grid_control, dc, first_row, col, index, last_index) first_row += 1 if first_row == last_row: return frame_rect.y += ul_rect.height # Last row may not have bytes at the end of the row if last_row == t.num_rows: try: col, index, last_index = self.calc_column_range( grid_control, last_row - 1, first_col, last_col) except IndexError: pass # skip lines with no visible cells else: self.draw_line(grid_control, dc, last_row - 1, col, index, last_index) last_row -= 1 bytes_per_row = t.items_per_row nr = last_row - first_row nc = last_col - first_col first_index = (first_row * bytes_per_row) - t.start_offset last_index = (last_row * bytes_per_row) - t.start_offset t = t if last_index > len(t.data): last_index = len(t.data) data = np.zeros((nr * bytes_per_row), dtype=np.uint8) data[0:last_index - first_index] = t.data[first_index:last_index] style = np.zeros((nr * bytes_per_row), dtype=np.uint8) style[0:last_index - first_index] = t.style[first_index:last_index] else: data = t.data[first_index:last_index] style = t.style[first_index:last_index] data = data.reshape((nr, -1)) style = style.reshape((nr, -1)) # get_image(cls, machine, antic_font, byte_values, style, start_byte, end_byte, bytes_per_row, nr, start_col, visible_cols): array = grid_control.font_renderer.get_image( grid_control.segment_viewer, grid_control.segment_viewer.antic_font, data, style, first_index, last_index, bytes_per_row, nr, first_col, nc) width = array.shape[1] height = array.shape[0] if width > 0 and height > 0: array = intscale(array, grid_control.zoom_h, grid_control.zoom_w) #print("bitmap: %d,%d,3 after scaling: %s" % (height, width, str(array.shape))) image = wx.Image(array.shape[1], array.shape[0]) image.SetData(array.tobytes()) bmp = wx.Bitmap(image) dc.DrawBitmap(bmp, frame_rect.x, frame_rect.y)
def draw_grid(self, grid_control, dc, first_row, visible_rows, first_cell, visible_cells): t = grid_control.table log.debug( f"draw_grid: first_row={first_row} visible_rows={visible_rows}; first_cell={first_cell} visible_cells={visible_cells}" ) first_col = self.cell_to_col(first_row, first_cell) last_cell = min(first_cell + visible_cells, self.num_cells) last_row = min(first_row + visible_rows, t.num_rows) last_col = self.cell_to_col(last_row, last_cell - 1) + 1 log.debug("draw_grid: rows:%d,%d (vis %d, num %d) cols:%d,%d" % (first_row, last_row, visible_rows, t.num_rows, first_col, last_col)) ul_rect = self.col_to_rect(first_row, first_col) lr_rect = self.col_to_rect(last_row - 1, last_col - 1) frame_rect = wx.Rect(ul_rect.x, ul_rect.y, lr_rect.x - ul_rect.x + lr_rect.width, lr_rect.y - ul_rect.y + lr_rect.height) dc.SetClippingRegion(frame_rect) # First and last rows may not span entire width. Process those # separately # # First row may not have bytes at the beginning of the row if the start # offset is not zero if first_row == 0: try: col, index, last_index = self.calc_column_range( grid_control, first_row, first_col, last_col) except IndexError: pass # skip lines with no visible cells else: self.draw_line(grid_control, dc, first_row, col, index, last_index) first_row += 1 if first_row == last_row: return frame_rect.y += ul_rect.height # Last row may not have bytes at the end of the row if last_row == t.num_rows: try: col, index, last_index = self.calc_column_range( grid_control, last_row - 1, first_col, last_col) except IndexError: pass # skip lines with no visible cells else: self.draw_line(grid_control, dc, last_row - 1, col, index, last_index) last_row -= 1 # If there are any more rows to display, they will be full-width rows; # i.e. the data is in a rectangular grid nr = last_row - first_row if nr > 0: bytes_per_row = self.calc_bytes_per_row(t) nc = last_col - first_col offset = t.start_offset % bytes_per_row first_index = (first_row * bytes_per_row) - offset last_index = (last_row * bytes_per_row) - offset log.debug( f"drawing rectangular grid: bpr={bytes_per_row}, first,last={first_index},{last_index}, nr={nr}, start_offset={offset}" ) data = t.data[first_index:last_index].reshape( (nr, bytes_per_row))[0:nr, first_col:last_col].flatten() style = t.style[first_index:last_index].reshape( (nr, bytes_per_row))[0:nr, first_col:last_col].flatten() # get_image(cls, machine, antic_font, byte_values, style, start_byte, end_byte, bytes_per_row, nr, start_col, visible_cols): array = grid_control.bitmap_renderer.get_image( grid_control.segment_viewer, nc, nr, nc * nr, data, style) width = array.shape[1] height = array.shape[0] if width > 0 and height > 0: array = intscale(array, grid_control.zoom_h, grid_control.zoom_w) #print("bitmap: %d,%d,3 after scaling: %s" % (height, width, str(array.shape))) image = wx.Image(array.shape[1], array.shape[0]) image.SetData(array.tobytes()) bmp = wx.Bitmap(image) dc.DrawBitmap(bmp, frame_rect.x, frame_rect.y)
def draw_grid(self, grid_control, dc, first_row, visible_rows, first_cell, visible_cells): t = grid_control.table first_col = self.cell_to_col(first_row, first_cell) last_cell = min(first_cell + visible_cells, self.num_cells) last_row = min(first_row + visible_rows, t.num_rows) last_col = self.cell_to_col(last_row, last_cell - 1) + 1 log.debug("draw_grid: rows:%d,%d (vis %d, num %d) cols:%d,%d" % (first_row, last_row, visible_rows, t.num_rows, first_col, last_col)) ul_rect = self.col_to_rect(first_row, first_col) lr_rect = self.col_to_rect(last_row - 1, last_col - 1) frame_rect = wx.Rect(ul_rect.x, ul_rect.y, lr_rect.x - ul_rect.x + lr_rect.width, lr_rect.y - ul_rect.y + lr_rect.height) dc.SetClippingRegion(frame_rect) # First and last rows may not span entire width. Process those # separately # # First row may not have bytes at the beginning of the row if the start # offset is not zero if first_row == 0: try: col, index, last_index = self.calc_column_range(grid_control, first_row, first_col, last_col) except IndexError: pass # skip lines with no visible cells else: self.draw_line(grid_control, dc, first_row, col, index, last_index) first_row += 1 if first_row == last_row: return frame_rect.y += ul_rect.height # Last row may not have bytes at the end of the row if last_row == t.num_rows: try: col, index, last_index = self.calc_column_range(grid_control, last_row - 1, first_col, last_col) except IndexError: pass # skip lines with no visible cells else: self.draw_line(grid_control, dc, last_row - 1, col, index, last_index) last_row -= 1 bytes_per_row = t.items_per_row nr = last_row - first_row nc = last_col - first_col first_index = (first_row * bytes_per_row) - t.start_offset last_index = (last_row * bytes_per_row) - t.start_offset t = t if last_index > len(t.data): last_index = len(t.data) data = np.zeros((nr * bytes_per_row), dtype=np.uint8) data[0:last_index - first_index] = t.data[first_index:last_index] style = np.zeros((nr * bytes_per_row), dtype=np.uint8) style[0:last_index - first_index] = t.style[first_index:last_index] else: data = t.data[first_index:last_index] style = t.style[first_index:last_index] data = data.reshape((nr, -1)) style = style.reshape((nr, -1)) # get_image(cls, machine, antic_font, byte_values, style, start_byte, end_byte, bytes_per_row, nr, start_col, visible_cols): array = grid_control.font_renderer.get_image(grid_control.segment_viewer, grid_control.segment_viewer.antic_font, data, style, first_index, last_index, bytes_per_row, nr, first_col, nc) width = array.shape[1] height = array.shape[0] if width > 0 and height > 0: array = intscale(array, grid_control.zoom_h, grid_control.zoom_w) #print("bitmap: %d,%d,3 after scaling: %s" % (height, width, str(array.shape))) image = wx.Image(array.shape[1], array.shape[0]) image.SetData(array.tobytes()) bmp = wx.Bitmap(image) dc.DrawBitmap(bmp, frame_rect.x, frame_rect.y)