Skip to content

Commit

Permalink
Fix issue with updating image canvas display efficiently.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmeyer committed May 28, 2024
1 parent 19eec7e commit fd07bd9
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions nion/swift/ImageCanvasItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,10 +916,10 @@ def __display_info_changed(self) -> None:
color_map_rgba = color_map_rgba.view(numpy.uint32).reshape(color_map_rgba.shape[:-1])
else:
color_map_rgba = None
self.__bitmap_canvas_item.set_data(display_data.data, display_range, color_map_rgba, trigger_update=False)
self.__bitmap_canvas_item.set_data(display_data.data, display_range, color_map_rgba)
else:
data_rgba = display_values.display_rgba
self.__bitmap_canvas_item.set_rgba_bitmap_data(data_rgba, trigger_update=False)
self.__bitmap_canvas_item.set_rgba_bitmap_data(data_rgba)
self.__timestamp_canvas_item.timestamp = display_values.display_rgba_timestamp if self.__display_latency else None

def __update_display_properties_and_layers(self, display_calibration_info: DisplayItem.DisplayCalibrationInfo, display_properties: Persistence.PersistentDictType, display_layers: typing.Sequence[Persistence.PersistentDictType]) -> None:
Expand Down Expand Up @@ -983,12 +983,13 @@ def __update_display_properties_and_layers(self, display_calibration_info: Displ
self.update_layout(self.canvas_origin, self.canvas_size)
# trigger updates
self.__composite_canvas_item.update()
self.__bitmap_canvas_item.update()
else:
# trigger updates
self.__bitmap_canvas_item.update()

# update bitmaps
# note: bitmap canvas item will be updated in the display_info_changed method.
# doing it in display_info_changed ensures that the repaint (on a thread) does not occur
# before setting the data. if the update were done above, as it used to be, the repaint
# could occur before the new data was sent to the bitmap canvas item.

# update bitmaps. this will update the bitmap canvas item, too.
self.__display_info_changed()

# setting the bitmap on the bitmap_canvas_item is delayed until paint, so that it happens on a thread, since it may be time consuming
Expand Down

0 comments on commit fd07bd9

Please sign in to comment.