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
|
|
|
|
|
|
2026-01-18 20:35:12 +01:00
|
|
|
use std::path::Path;
|
2026-01-07 20:22:49 +01:00
|
|
|
|
2026-01-18 20:35:12 +01:00
|
|
|
use image::{imageops, DynamicImage, GenericImageView, ImageReader};
|
|
|
|
|
|
|
|
|
|
use super::ImageHandle;
|
2026-01-07 20:22:49 +01:00
|
|
|
|
|
|
|
|
/// Represents a raster image document (PNG, JPEG, WebP, ...).
|
|
|
|
|
pub struct RasterDocument {
|
2026-01-18 20:35:12 +01:00
|
|
|
/// The decoded image document.
|
|
|
|
|
document: DynamicImage,
|
|
|
|
|
/// Cached handle for rendering.
|
|
|
|
|
pub handle: ImageHandle,
|
2026-01-07 20:22:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl RasterDocument {
|
|
|
|
|
/// Load a raster document from disk.
|
2026-01-18 20:35:12 +01:00
|
|
|
pub fn open(path: &Path) -> image::ImageResult<Self> {
|
|
|
|
|
let document = ImageReader::open(path)?.decode()?;
|
|
|
|
|
let handle = super::create_image_handle(&document);
|
2026-01-07 20:22:49 +01:00
|
|
|
|
2026-01-18 20:35:12 +01:00
|
|
|
Ok(Self { document, handle })
|
2026-01-07 20:22:49 +01:00
|
|
|
}
|
|
|
|
|
|
2026-01-18 20:35:12 +01:00
|
|
|
/// Rebuild the handle after mutating `document`.
|
2026-01-07 20:22:49 +01:00
|
|
|
pub fn refresh_handle(&mut self) {
|
2026-01-18 20:35:12 +01:00
|
|
|
self.handle = super::create_image_handle(&self.document);
|
2026-01-07 20:22:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Returns the native pixel dimensions (width, height).
|
|
|
|
|
pub fn dimensions(&self) -> (u32, u32) {
|
2026-01-18 20:35:12 +01:00
|
|
|
self.document.dimensions()
|
2026-01-07 20:22:49 +01:00
|
|
|
}
|
|
|
|
|
|
2026-01-18 20:35:12 +01:00
|
|
|
/// Save the current document to disk.
|
|
|
|
|
pub fn save(&self, path: &Path) -> image::ImageResult<()> {
|
|
|
|
|
self.document.save(path)
|
2026-01-07 20:22:49 +01:00
|
|
|
}
|
2026-01-18 20:35:12 +01:00
|
|
|
|
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.
|
2026-01-18 20:35:12 +01:00
|
|
|
pub fn extract_meta(&self, path: &Path) -> super::meta::DocumentMeta {
|
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
|
|
|
let (width, height) = self.dimensions();
|
2026-01-18 20:35:12 +01:00
|
|
|
super::meta::build_raster_meta(path, &self.document, width, height)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Rotate 90 degrees clockwise.
|
|
|
|
|
pub fn rotate_cw(&mut self) {
|
|
|
|
|
self.document = DynamicImage::ImageRgba8(imageops::rotate90(&self.document));
|
|
|
|
|
self.refresh_handle();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Rotate 90 degrees counter-clockwise.
|
|
|
|
|
pub fn rotate_ccw(&mut self) {
|
|
|
|
|
self.document = DynamicImage::ImageRgba8(imageops::rotate270(&self.document));
|
|
|
|
|
self.refresh_handle();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Flip horizontally.
|
|
|
|
|
pub fn flip_horizontal(&mut self) {
|
|
|
|
|
self.document = DynamicImage::ImageRgba8(imageops::flip_horizontal(&self.document));
|
|
|
|
|
self.refresh_handle();
|
|
|
|
|
}
|
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
|
|
|
|
2026-01-18 20:35:12 +01:00
|
|
|
/// Flip vertically.
|
|
|
|
|
pub fn flip_vertical(&mut self) {
|
|
|
|
|
self.document = DynamicImage::ImageRgba8(imageops::flip_vertical(&self.document));
|
|
|
|
|
self.refresh_handle();
|
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
|
|
|
}
|
2026-01-07 20:22:49 +01:00
|
|
|
}
|