// Copyright (C) 2026 Elias Wendland // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, version 3 exclusively. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . use crate::plugin::Plugin; use image::ImageFormat; use std::io::Cursor; use std::path::Path; pub struct PluginImpl; impl Plugin for PluginImpl { #[tracing::instrument(skip(self))] fn is_available(&self) -> bool { tracing::trace!("Checking availability for jpeg_to_png plugin (always true)"); true } fn name(&self) -> &'static str { "jpeg_to_png" } fn from_formats(&self) -> Vec<&'static str> { vec!["jpeg"] } fn to_formats(&self) -> Vec<&'static str> { vec!["png"] } fn familiarity(&self, _from: &str, _to: &str) -> u8 { 255 } fn quality(&self, _from: &str, _to: &str) -> u8 { 255 } fn speed(&self, _from: &str, _to: &str) -> u8 { 200 } #[tracing::instrument(skip(self, input, _temp_dir))] fn convert( &self, input: &[u8], _from: &str, _to: &str, _temp_dir: &Path, ) -> Result, String> { tracing::debug!("jpeg_to_png starting conversion"); tracing::trace!("Loading JPEG image from memory ({} bytes)", input.len()); let img = image::load_from_memory_with_format(input, ImageFormat::Jpeg) .map_err(|e| { tracing::error!("Failed to decode JPEG image: {}", e); e.to_string() })?; tracing::trace!("JPEG image loaded successfully. Dimensions: {}x{}", img.width(), img.height()); let mut output = Cursor::new(Vec::new()); tracing::trace!("Encoding image as PNG"); img.write_to(&mut output, ImageFormat::Png) .map_err(|e| { tracing::error!("Failed to encode image as PNG: {}", e); e.to_string() })?; let out_bytes = output.into_inner(); tracing::debug!("jpeg_to_png conversion completed. Output size: {} bytes", out_bytes.len()); Ok(out_bytes) } }