Skip to content

Commit

Permalink
Merge pull request #590 from foresterre/foresterre/feat/av1
Browse files Browse the repository at this point in the history
  • Loading branch information
foresterre authored Oct 4, 2020
2 parents 8fda427 + e652b45 commit 33acebf
Show file tree
Hide file tree
Showing 8 changed files with 272 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
# pinned rust version :: ubuntu
- build: pinned
os: ubuntu-18.04
rust: 1.42.0
rust: 1.43.0

# latest rust stable :: ubuntu
- build: stable
Expand Down
233 changes: 233 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ Pre build binary: see [releases](https://github.com/foresterre/sic/releases).

From the source:
- Setup rust and cargo (for example using [rustup](https://rustup.rs/)) <br>
Current [MSRV](https://github.com/foresterre/cargo-msrv): 1.35 (edition 2018 is required);
we aim to always develop against the latest stable release.
- Clone this repo: `git clone https://github.com/foresterre/sic.git`
- Switch to this repo: `cd sic`
- Build a release: `cargo build --release`

**MSRV when building from source:**

Expects development against the latest Rust stable version, but may work on older versions.

### Usage

Expand Down
2 changes: 1 addition & 1 deletion components/sic_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ license = "MIT"
repository = "https://github.com/foresterre/sic"

[dependencies]
image = "0.23.10"
image = { version = "0.23.10", features = ["avif"] }
20 changes: 19 additions & 1 deletion components/sic_io/src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::errors::SicIoError;
use image::buffer::ConvertBuffer;
use image::DynamicImage;
use sic_core::image;
use sic_core::image::GenericImageView;
use std::io::Write;

#[derive(Clone, Copy, Debug)]
Expand Down Expand Up @@ -44,7 +45,24 @@ impl<'a> ConversionWriter<'a> {
None => &self.image,
};

ConversionWriter::save_to(writer, &export_buffer, output_format)
// FIXME remove: https://github.com/foresterre/sic/issues/597
if std::env::var("SIC_AVIF_HACK").is_ok() {
let avif_encoder = image::avif::AvifEncoder::new(writer);
avif_encoder
.write_image(
&export_buffer.to_bytes(),
export_buffer.width(),
export_buffer.height(),
export_buffer.color(),
)
.map_err(SicIoError::ImageError)?;

std::env::remove_var("SIC_AVIF_HACK");

Ok(())
} else {
ConversionWriter::save_to(writer, &export_buffer, output_format)
}
}

/// Some image output format types require color type pre-processing.
Expand Down
8 changes: 8 additions & 0 deletions components/sic_io/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ impl EncodingFormatByIdentifier for DetermineEncodingFormat {
/// Identifiers are based on common output file extensions.
fn by_identifier(&self, identifier: &str) -> Result<image::ImageOutputFormat, SicIoError> {
match identifier.to_ascii_lowercase().as_str() {
"avif" => {
// FIXME: Dirty hack
// - https://github.com/foresterre/sic/issues/597
std::env::set_var("SIC_AVIF_HACK", "1");
Ok(image::ImageOutputFormat::Farbfeld)
}
"bmp" => Ok(image::ImageOutputFormat::Bmp),
"farbfeld" => Ok(image::ImageOutputFormat::Farbfeld),
"gif" => Ok(image::ImageOutputFormat::Gif),
Expand Down Expand Up @@ -142,10 +148,12 @@ mod tests {
use super::*;

const INPUT_FORMATS: &[&str] = &[
//"avif",
"bmp", "farbfeld", "gif", "ico", "jpg", "jpeg", "png", "pbm", "pgm", "ppm", "pam",
];

const EXPECTED_VALUES: &[image::ImageOutputFormat] = &[
// image::ImageOutputFormat::Avif,
image::ImageOutputFormat::Bmp,
image::ImageOutputFormat::Farbfeld,
image::ImageOutputFormat::Gif,
Expand Down
Binary file added resources/wh1616.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 7 additions & 9 deletions src/cli/pipeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ fn create_format_decider(
io_device: &PathVariant,
config: &Config,
) -> anyhow::Result<image::ImageOutputFormat> {
let encoding_format_determiner = DetermineEncodingFormat {
let format_resolver = DetermineEncodingFormat {
pnm_sample_encoding: if config.encoding_settings.pnm_use_ascii_format {
Some(image::pnm::SampleEncoding::Ascii)
} else {
Expand All @@ -163,15 +163,13 @@ fn create_format_decider(
};

let format = match &config.forced_output_format {
Some(format) => encoding_format_determiner
.by_identifier(format)
.fallback_if(
config.encoding_settings.image_output_format_fallback,
guess_output_by_identifier,
format,
)?,
Some(format) => format_resolver.by_identifier(format).fallback_if(
config.encoding_settings.image_output_format_fallback,
guess_output_by_identifier,
format,
)?,
None => match io_device {
PathVariant::Path(out) => encoding_format_determiner.by_extension(out).fallback_if(
PathVariant::Path(out) => format_resolver.by_extension(out).fallback_if(
config.encoding_settings.image_output_format_fallback,
guess_output_by_path,
out,
Expand Down

0 comments on commit 33acebf

Please sign in to comment.