Skip to main content

Module image_diff

Module image_diff 

Source
Expand description

Image diff support for displaying image files in the TUI.

This module handles:

  • Detection of image files by extension (dynamic via image crate)
  • SVG rasterization via resvg
  • Image loading, downscaling, and caching
  • LRU cache eviction

Structs§

CachedImage
A loaded and cached image ready for display
ImageCache
LRU cache for loaded images
ImageDiffState
Image diff state for a single file (before and after versions)

Constants§

FONT_HEIGHT_PX
Terminal font height in pixels (used for image sizing calculations). Most monospace terminal fonts are 16 pixels tall per character cell.
FONT_WIDTH_PX
Terminal font width in pixels (used for image sizing calculations). Most monospace terminal fonts are 8 pixels wide per character cell.
IMAGE_BOTTOM_MARGIN
Margin between image and metadata (rows)
IMAGE_PANEL_OVERHEAD
Total overhead for an image panel: borders (2) + margins (2) + metadata (1) This is subtracted from the panel height to get the available image height.
IMAGE_TOP_MARGIN
Margin above the image within the panel (rows)
MAX_CACHED_IMAGES
Maximum number of images to keep in cache
MAX_CACHE_DIMENSION
Maximum dimension for cached images (larger images are downscaled)
MAX_IMAGE_HEIGHT_ROWS
Maximum height in terminal rows for an image diff panel. Prevents very tall images from consuming excessive vertical space.
METADATA_HEIGHT
Height of the metadata line below each image panel (rows)

Functions§

center_in_area
Center a smaller rectangle within a larger area
fit_dimensions
Calculate display dimensions maintaining aspect ratio. Converts image pixel dimensions to terminal cell dimensions using font metrics, then scales to fit the available space without upscaling.
format_file_size
Format file size for human-readable display
format_name_from_path
Get format name from file path extension
is_image_file
Check if a file is a supported image format. Uses the image crate’s format detection - no hardcoded extension list.
is_lfs_pointer
Check if content is a Git LFS pointer (not actual file content)
is_svg
Check if a file is an SVG (handled via resvg, not image crate)
load_and_cache
Load image bytes and create a cached image with optional downscaling
load_image_diff
Load image diff state for a file (before and after versions).
rasterize_svg
Rasterize SVG bytes to a DynamicImage