How xbambinox/imageeditor works
1. Application type and architectural style
- This is a WPF desktop image editor built on .NET 8+ using MVVM.
- The UI is split into XAML views/windows, ViewModels for state and actions, and services for image manipulation and editor behavior.
2. Shell and top-level composition
- App.xaml bootstraps the application, and Views/MainWindow.xaml is the main shell.
- The main workspace is tab-based, matching the README’s multi-document editing model.
- MainViewModel is the central coordinator for editor state, active tab, tool selection, commands, and file operations.
3. Document/tab model
- Models/ImageTab represents an open image tab and likely carries the image source plus editor-specific state.
- Models/ImageDocument appears to be the underlying document/data model for the loaded image and file metadata.
- Models/ImageInfoModel and Services/ImageInfoService support image metadata display in the info window/status surfaces.
4. Undo/redo and snapshot strategy
- Models/ImageSnapshot and Models/LimitedStack implement the undo/redo history.
- The README’s “dirty-region snapshots” indicate the editor avoids full-frame copies and instead stores partial pixel regions for efficient history management.
- This is a key architectural boundary: editing actions capture state through snapshot services rather than mutating UI directly.
5. Drawing and selection subsystem
- Services/Toolbar/DrawingService handles canvas editing actions such as brush strokes, lines, text placement, and likely the raster updates behind them.
- Services/Toolbar/SelectionService handles rectangular selection, copy/cut/paste, and floating paste behavior.
- These services sit between tool-specific UI input and the image bitmap data, making them core to interaction logic.
6. Image processing subsystem
- Services/ImageProcessing/*Helper.cs contains individual filter/transform operations: brightness, gamma, grayscale, invert, blur, sharpen, Sobel, pixelate.
- Each helper is a focused processing unit rather than a single monolithic filter engine.
- The filter-specific ViewModels (BlurViewModel, BrightnessViewModel, etc.) likely gather parameters from dialogs and invoke the corresponding helper.
7. Editing modes and tool-oriented UI
- The application supports multiple tools: brush, selection, line, text, eyedropper, plus color picking.
- Tool settings are exposed via dedicated windows such as BrushSettingsWindow, LineSettingsWindow, TextSettingsWindow, and ColorPickerWindow.
- Models/Tooltype and Models/ShortcutItem suggest a structured tool/shortcut system feeding the command layer and toolbar.
8. File and image lifecycle
- Open/save workflows are handled in the main editor flow, with Services/ImageStatus/SaveImageHelper likely centralizing persistence and format-specific handling.
- The README notes PNG and JPEG support, and the presence of Unsavedchangesdialog indicates document dirty-state tracking before close or overwrite.
- New image creation and canvas resizing are handled by dedicated dialogs (NewImageDialog, ExpandCanvasdialog).
9. UI structure and dialog boundaries
- The repository uses many self-contained modal/dialog windows for secondary interactions: filters, keyboard shortcuts, image info, brush/line/text settings, unsaved changes, etc.
- Views/ToolbarView.xaml separates the editor’s tool palette from the main canvas area.
- Views/BindingProxy.cs suggests some WPF binding bridge to share ViewModel state across disconnected visual tree elements.
10. Command and interaction layer
- Commands/RelayCommand.cs is the main command abstraction for MVVM actions.
- Keyboard shortcuts in the README map directly to commands in the ViewModel layer, not to code-behind logic.
- This keeps input handling routed through the command system, which is important for drawing a clean architecture diagram.
11. Cross-cutting utilities
- Services/Math/Tools.cs holds shared geometric or pixel math used by tools and processing operations.
- Services/Logger.cs is a cross-cutting diagnostic utility rather than a core editor subsystem.
- Models/ShortcutItem and Properties/Resources* support UI metadata, icons, text, and localization-style resource usage.
12. Primary data flow
- User input enters through WPF views/windows.
- Commands and bindings route that input to MainViewModel or tool/filter ViewModels.
- Those ViewModels call into drawing, selection, image processing, or save services.
- Services mutate the current image/tab state and push snapshots for undo/redo.
- The updated bitmap is then reflected back into the active tab and canvas via WPF bindings.
13. Key architectural boundary to diagram
- The most important separation is between:
- presentation layer: Views/ + XAML dialogs
- state/orchestration layer: ViewModels/
- editor mechanics: Services/
- data/history layer: Models/
- That boundary keeps UI concerns, command logic, and pixel manipulation distinct, which is the central structure of the repo.
Main entry points: MainViewModel.cs Main view-model · DrawingService.cs Drawing service · SelectionService.cs Selection service · MainWindow.xaml Main window
Components 22
Presentation
WPF shells, views, and dialog surfaces
- App shell · Starts the desktop app and loads the main window
App.xaml - Main window · Top-level workspace and tabbed editor frame
Views/MainWindow.xaml - Toolbar · Editor tool and mode surface
Views/ToolbarView.xaml - Binding proxy · Shares view-model state across WPF visual tree boundaries
Views/BindingProxy.cs - Tool dialogs · Brush, line, text, color, and canvas dialogs
- Filter dialogs · Parameter entry windows for image filters and effects
Orchestration
MVVM coordination and command entry points
- Main view-model · Owns tabs, commands, active tool, and file workflow
ViewModels/MainViewModel.cs - Base VM · Shared view-model behavior
ViewModels/BaseViewModel.cs - Filter VMs · Brightness, gamma, blur, grayscale, pixelate, sharpen, and Sobel parameter models
- Relay command · Command abstraction for view-model actions
Commands/RelayCommand.cs
Editor mechanics
Drawing, selection, image processing, and persistence
- Drawing service · Brush, line, text, and canvas paint operations
Services/Toolbar/DrawingService.cs - Selection service · Rectangular selection, copy/cut/paste, and floating paste behavior
Services/Toolbar/SelectionService.cs - Image filters · Brightness, gamma, blur, grayscale, invert, sharpen, Sobel, and pixelate helpers
Services/ImageProcessing - Save helper · Centralized image save workflow and format handling
Services/ImageStatus/SaveImageHelper.cs - Info service · Builds image information for info surfaces
Services/ImageInfoService.cs - Math tools · Shared pixel and geometry utilities
Services/Math/Tools.cs
Data and history
Document state, snapshots, and shared models
- Image tab · Open image workspace and tab-local editor state
Models/ImageTab.cs - Image document · Loaded image data and file metadata
Models/ImageDocument.cs - History stack · Limited undo/redo history with image snapshots
Models/LimitedStack.cs - Snapshot · Dirty-region snapshot used for efficient history management
Models/ImageSnapshot.cs - Image info · Image metadata displayed in info surfaces
Models/ImageInfoModel.cs - Tool models · Tool and shortcut metadata used by the shell and command layer
Models/Tooltype.cs
Connections 27
- App shell → Main window: loads · Bootstraps the main editor shell
- Main window → Main view-model: binds to · Shell state and commands are driven by the main view-model
- Main window → Toolbar: hosts · Places the toolbar alongside the canvas workspace
- Toolbar → Main view-model: commands · Tool selections and actions route into the central coordinator
- Binding proxy → Main view-model: shares state · Exposes view-model data across disconnected visual trees
- Main view-model → Relay command: uses · Executes UI actions through MVVM commands
- Main view-model → Image tab: manages · Tracks the active document tabs
- Main view-model → Image document: opens/saves · Coordinates document lifecycle and file workflow
- Main view-model → Drawing service: routes tools · Sends paint and annotation actions to editing mechanics
- Main view-model → Selection service: routes tools · Sends selection and clipboard actions to editing mechanics
- Main view-model → Filter VMs: opens dialogs · Creates parameter view-models for image effects
- Filter dialogs → Filter VMs: hosts · Modal windows collect filter parameters
- Filter VMs → Image filters: invokes · Runs the selected filter helper
- Drawing service → Snapshot: captures · Stores partial bitmap history for undo/redo
- Drawing service → History stack: pushes · Adds edits to the history stack
- Selection service → Snapshot: captures · Preserves pre-edit pixel regions for selection workflows
- Selection service → History stack: pushes · Records selection edits in history
- Drawing service → Math tools: uses · Relies on shared geometry and pixel math
- Selection service → Math tools: uses · Relies on shared geometry and pixel math
- Save helper → Image document: persists · Writes the current document back to disk
- Main view-model → Save helper: delegates save · Centralizes save and export behavior
- Info service → Image info: builds · Produces metadata for info views and status surfaces
- Main view-model → Info service: queries · Requests image metadata for the UI
- Image tab → Image document: wraps · A tab represents one open image document
- Image tab → History stack: tracks history · Each open tab maintains its own undo/redo state
- Main view-model → Tool models: uses · Tool and shortcut metadata inform editor behavior
- Tool dialogs → Main view-model: drives settings · Brush, line, text, and canvas dialogs feed editor configuration