[][src]Crate show_image

show-image is a library for quickly displaying images. It is intended as a debugging aid for writing image processing code. The library is not intended for making full-featured GUIs, but you can process keyboard events from the created windows.

Supported image types.

The library aims to support as many different data types used to represent images. To keep the dependency graph as small as possible, support for third party libraries must be enabled explicitly with feature flags.

Currently, the following types are supported:

  • Tuples of binary data and ImageInfo.
  • [image::DynamicImage] and [image::ImageBuffer] with the image feature.
  • tch::Tensor with the tch feature.

If you think support for a some data type is missing, feel free to send a PR or create an issue on GitHub.

Event handling.

You can receive events using Window::events. This is a general channel on which all events for that window are sent. Alternatively you can use Window::add_event_handler to register an asynchronous event handler. This event handler will run in the context thread, so shouldn't block for too long.

You can also handle keyboard events for windows using Window::wait_key or Window::wait_key_deadline. These functions will wait for key press events while discarding key up events.

Saving displayed images.

If the save feature is enabled, windows allow the displayed image to be saved using Ctrl+S. This will open a file dialog to save the currently displayed image.

Note that images are saved in a background thread. To ensure that no data loss occurs, call stop to gracefully stop and join the background thread.

Example 1: Showing an image.

This example uses a tuple of (&[u8], ImageInfo) as image, but any type that implements ImageData will do.

use show_image::{ImageInfo, make_window};

let image = (pixel_data, ImageInfo::rgb8(1920, 1080));

// Create a window and display the image.
let window = make_window("image")?;
window.set_image(image, "image-001")?;

Example 2: Handling keyboard events.

use show_image::{KeyCode, make_window};

// Create a window and display the image.
let window = make_window("image")?;
window.set_image(&image, "image-001")?;

// Print keyboard events until Escape is pressed, then exit.
// If the user closes the window, wait_key() will return an error and the loop also exits.
while let Ok(event) = window.wait_key(Duration::from_millis(100)) {
    if let Some(event) = event {
        println!("{:#?}", event);
        if event.key == KeyCode::Escape {
            break;
        }
    }
}

// Make sure all background tasks are stopped cleanly.
show_image::stop()?;

Modules

tch

Support for [tch::Tensor].

Structs

EventHandlerContext

The context for a registered event handler.

Image

An image currently being shown by a window.

ImageInfo

Information describing the binary data of an image.

KeyModifiers

Pressed modifier keys.

KeyboardEvent

Keyboard events are issued for all pressed and released keys.

MouseButtonEvent

Information describing a mouse button event.

MouseButtonState

Information describing a mouse state.

MouseMoveEvent

Information describing a mouse move event.

Rectangle

A rectangle.

Window

A window capable of displaying images.

WindowInner

Inner window doing the real work in the background thread.

WindowOptions

Options for creating a window.

Enums

Event

Enum describing any of the possible events.

KeyCode

Key represents the meaning of a keypress.

KeyLocation

The location attribute contains an indication of the logical location of the key on the device.

KeyState

Describes the state the key is in.

MouseButton

Enum describing the mouse buttons.

MouseState

Enum describing the mouse buttons.

PixelFormat

Supported pixel formats.

ScanCode

Code is the physical position of a key.

WaitKeyError

Error that can occur while waiting for a key press.

Traits

ImageData

Allows a type to be displayed as an image.

Functions

make_window

Make a window with default options using the global context.

make_window_full

Make a window with the given options using the global context.

prompt_save_image

Prompt the user to save an image.

save_image

Save an image to the given path.

stop

Close all windows, stop the global context and join the background thread.

Type Definitions

EventHandler

A event handler.