2026-01-07 20:42:28 +01:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
2026-01-07 20:22:49 +01:00
|
|
|
// src/app/document/raster.rs
|
|
|
|
|
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
|
|
use cosmic::iced::widget::image as iced_image;
|
|
|
|
|
use image::{GenericImageView, DynamicImage, ImageReader};
|
|
|
|
|
|
|
|
|
|
/// Represents a raster image document (PNG, JPEG, WebP, ...).
|
|
|
|
|
pub struct RasterDocument {
|
|
|
|
|
pub path: Option<PathBuf>,
|
|
|
|
|
pub image: DynamicImage,
|
|
|
|
|
pub handle: iced_image::Handle,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl RasterDocument {
|
|
|
|
|
/// Load a raster document from disk.
|
|
|
|
|
pub fn open(path: PathBuf) -> image::ImageResult<Self> {
|
|
|
|
|
let img = ImageReader::open(&path)?.decode()?;
|
|
|
|
|
let handle = Self::build_handle(&img);
|
|
|
|
|
|
|
|
|
|
Ok(Self {
|
|
|
|
|
path: Some(path),
|
|
|
|
|
image: img,
|
|
|
|
|
handle,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Construct a handle from a DynamicImage.
|
|
|
|
|
fn build_handle(img: &DynamicImage) -> iced_image::Handle {
|
|
|
|
|
// Get image dimensions.
|
|
|
|
|
let (w, h) = img.dimensions();
|
|
|
|
|
|
|
|
|
|
// Convert to RGBA8 buffer and extract raw bytes.
|
|
|
|
|
let rgba = img.to_rgba8();
|
|
|
|
|
let pixels = rgba.into_raw(); // Vec<u8>
|
|
|
|
|
|
|
|
|
|
// Build an iced image handle from raw RGBA pixels.
|
|
|
|
|
iced_image::Handle::from_rgba(w, h, pixels)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Rebuild the handle after mutating `image`.
|
|
|
|
|
pub fn refresh_handle(&mut self) {
|
|
|
|
|
self.handle = Self::build_handle(&self.image);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Returns the native pixel dimensions (width, height).
|
|
|
|
|
pub fn dimensions(&self) -> (u32, u32) {
|
|
|
|
|
self.image.dimensions()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Save the current image back to disk (overwrite).
|
|
|
|
|
pub fn save(&self) -> image::ImageResult<()> {
|
|
|
|
|
if let Some(path) = &self.path {
|
|
|
|
|
self.image.save(path)
|
|
|
|
|
} else {
|
|
|
|
|
// Cant imagine that it happen but caller should handle missing path case.
|
|
|
|
|
Err(image::ImageError::Parameter(
|
|
|
|
|
image::error::ParameterError::from_kind(image::error::ParameterErrorKind::Generic(
|
|
|
|
|
"RasterDocument does not have a path".into(),
|
|
|
|
|
)),
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
}
|
Implement comprehensive metadata extraction for raster images with
EXIF support and display in the right panel.
New features:
- Extract basic metadata (filename, format, resolution, file size, color type)
- Parse EXIF data (camera, date, exposure, aperture, ISO, focal length, GPS)
- Display metadata in collapsible right panel (toggle with 'i' key)
- Auto-refresh metadata on document navigation
Changes by file:
Cargo.toml, Cargo.lock:
- Add kamadak-exif dependency for EXIF parsing
i18n/en/noctua.ftl:
- Add translation strings for all metadata labels
src/app/document/meta.rs:
- New module for metadata types (BasicMeta, ExifMeta, DocumentMeta)
- Extraction logic with EXIF parsing via kamadak-exif
- Helper methods for formatted display (resolution, file size, camera, GPS)
src/app/document/mod.rs:
- Re-export meta module
src/app/document/{raster,vector,portable}.rs:
- Add extract_metadata() method stubs (full impl for raster)
src/app/document/file.rs:
- Reset metadata on document change
src/app/message.rs:
- Add ToggleRightPanel and RefreshMetadata messages
src/app/model.rs:
- Add metadata: Option<DocumentMeta> field
- Add show_right_panel: bool field
src/app/update.rs:
- Handle panel toggle and metadata refresh
- Auto-refresh metadata on navigation when panel visible
src/app/view/panels.rs:
- Implement right_panel() with metadata display
- Conditional sections for basic info and EXIF data
src/app/view/canvas.rs:
- Integrate right panel into layout"
2026-01-10 11:46:07 +01:00
|
|
|
/// Extract metadata for this raster document.
|
|
|
|
|
pub fn extract_meta(&self) -> super::meta::DocumentMeta {
|
|
|
|
|
let path = self.path.as_deref().unwrap_or(std::path::Path::new(""));
|
|
|
|
|
let (width, height) = self.dimensions();
|
|
|
|
|
|
|
|
|
|
super::meta::build_raster_meta(path, &self.image, width, height)
|
|
|
|
|
}
|
2026-01-07 20:22:49 +01:00
|
|
|
}
|