Skip to content

Commit

Permalink
Merge branch 'master' into sync_thread_output
Browse files Browse the repository at this point in the history
  • Loading branch information
rfdzan authored Apr 20, 2024
2 parents eb0ec3b + bff7d9a commit 90b7f73
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 27 deletions.
44 changes: 32 additions & 12 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
34 changes: 25 additions & 9 deletions src/bulk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>> = 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).
///
Expand Down Expand Up @@ -73,6 +88,7 @@ impl ParallelBuilder {
}
}
}

#[derive(Debug)]
pub struct StuffThatNeedsToBeSent {
vec: VecDeque<(usize, Vec<u8>)>,
Expand Down Expand Up @@ -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<dyn std::error::Error>> {
Expand Down
6 changes: 3 additions & 3 deletions src/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self, error::Error> {
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,
};
Expand Down Expand Up @@ -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(),
})
}
Expand Down
6 changes: 3 additions & 3 deletions src/single.rs
Original file line number Diff line number Diff line change
@@ -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<u8>,
Expand Down Expand Up @@ -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};
Expand Down

0 comments on commit 90b7f73

Please sign in to comment.