diff --git a/CHANGELOG.md b/CHANGELOG.md index d57c430..6e4c06c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,14 +1,34 @@ -# 15 April 2024: 1.0.0 -- **This crate now only process JPEG bytes. All other filesystem processes is handed over to the user of the crate.** -- Renamed primary public API to `Single::from_bytes` and `Parallel::from_vec` which reflect their input types. -- `Parallel` now produces an iterator via `into_iter()` to iterate over compression results sent by spawned threads. +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] +## [1.0.0] - 2024-04-15 +### Added +- Added public methods `Single::from_bytes` and `Parallel::from_vec`. - Added crate error enumerations. +- Added documentations & tests. +- Added dependency `thiserror` +### Changed +- **This crate now only process JPEG bytes.** It no longer interacts with your filesystem. Meaning it doesn't read and/or write files, nor does it read and/or create directories. +- `Parallel` now produces an iterator via `into_iter()` to iterate over compression results sent by spawned threads. +- `compress` method in `Single` is now fallible. +### Removed - Removed mandatory method `output_dir()`. -- Removed dependency: `clap`, `anyhow`, `colored`. -# 04 April 2024: 0.4.0 -- now stands as its own crate, called 'jippigy' (previously a cli tool [smoljpg](https://github.com/rfdzan/smoljpg)). -- defining public API, added tests and documentations. -# 22 March 2024: 0.3.0 -- cli: Output directory is now optional. Previously, specifying custom quality requires specifying an output directory as well. -# 17 March 2024: 0.2.0 -- feature: allow single image compression. +- Removed dependencies: `clap`, `anyhow`, `colored`. +### Fixed +- Updated README. + +## [0.4.0] - 2024-04-04 +- **Now stands as its own crate**, called 'jippigy' (previously a cli tool [smoljpg](https://github.com/rfdzan/smoljpg)). +### Added +- Added `Single` and `Parallel` for processing JPEG images. +- Added required methods `output_dir`. +- Added optional methods prefixed by `with_`. +### Changed +- Renamed project to "jippigy". +- Renamed compression-invoking methods to `compress`. +### Fixed +- Updated README. diff --git a/src/bulk.rs b/src/bulk.rs index bca7199..7ac4442 100644 --- a/src/bulk.rs +++ b/src/bulk.rs @@ -12,16 +12,31 @@ pub struct ParallelBuilder { quality: u8, device_num: u8, } -impl Default for ParallelBuilder { - fn default() -> Self { - Self { - vec: Default::default(), - quality: QUALITY, - device_num: DEVICE, +impl ParallelBuilder { + /// Builds a new [`Parallel`] with default or specified configuration. + /// # Example + /// This is the minimal requirements for using this method: + /// ``` + /// # fn main() { + /// # use jippigy::Parallel; + /// let mut vector_of_bytes: Vec> = Vec::new(); + /// let _build = Parallel::from_vec(vector_of_bytes).build(); + /// # } + /// ``` + pub fn build(self) -> Parallel { + let (tx, rx) = channel::unbounded(); + Parallel { + main_worker: Worker::new_fifo(), + vec: self.vec, + to_thread: StuffThatNeedsToBeSent { + device_num: self.device_num, + quality: self.quality, + stealers: Vec::with_capacity(usize::from(self.device_num)), + }, + transmitter: tx, + receiver: rx, } } -} -impl ParallelBuilder { /// Specifies the quality of compressed images. /// Defaults to 95 (95% of the original quality). /// @@ -73,6 +88,7 @@ impl ParallelBuilder { } } } + #[derive(Debug)] pub struct StuffThatNeedsToBeSent { vec: VecDeque<(usize, Vec)>, @@ -156,7 +172,7 @@ impl Parallel { /// let _parallel = Parallel::from_vec(vector_of_bytes); /// } /// ``` - /// In order to start the compression, it has to be built and made into an iterator with `into_iter`: + /// In order to start the compression, it has to be made into an iterator with `into_iter`: /// ``` /// use jippigy::Parallel; /// fn main() -> Result<(), Box> { diff --git a/src/compress.rs b/src/compress.rs index 6604d55..87ad393 100644 --- a/src/compress.rs +++ b/src/compress.rs @@ -55,7 +55,7 @@ impl PreserveExif { /// Parse EXIF information from the original bytes and write it /// into the compressed bytes. fn preserve_exif(self) -> Result { - let original_img_parts = match Jpeg::from_bytes(self.original_bytes.clone().into()) { + let original_img_parts = match Jpeg::from_bytes(self.original_bytes.into()) { Err(e) => return Err(error::Error::ImgPartError(e.to_string())), Ok(res) => res, }; @@ -86,8 +86,8 @@ impl PreserveExif { compressed_img_part.set_exif(exif.into()); compressed_img_part.set_icc_profile(icc_profile.into()); Ok(Self { - original_bytes: self.original_bytes, - compressed_bytes: Vec::with_capacity(0), // raw compressed bytes is no longer needed + original_bytes: Vec::with_capacity(0), // no longer needed + compressed_bytes: Vec::with_capacity(0), // no longer needed with_exif_preserved: compressed_img_part.encoder().bytes().to_vec(), }) } diff --git a/src/single.rs b/src/single.rs index 193d7de..f09ec14 100644 --- a/src/single.rs +++ b/src/single.rs @@ -1,6 +1,7 @@ - use crate::{error, Compress, QUALITY}; -/// Creates a new Single struct for compressing single images. +/// Custom configuration for building a [`Single`]. +/// This struct is not meant to be used directly. +/// Use [`Single::from_bytes`] instead. #[derive(Debug, Clone)] pub struct SingleBuilder { bytes_slice: Vec, @@ -63,7 +64,6 @@ impl Single { } /// Compress a single image. /// # Example - /// In order to start the compression, it has to be built first: /// ``` /// use jippigy::Single; /// use image::{RgbImage, ImageFormat::Jpeg};