diff --git a/0001-Simplify-the-decode-example-s-argument-parsing.patch b/0001-Simplify-the-decode-example-s-argument-parsing.patch new file mode 100644 index 0000000..012d11e --- /dev/null +++ b/0001-Simplify-the-decode-example-s-argument-parsing.patch @@ -0,0 +1,110 @@ +From 19a9e99447b1c7782a7f49bf35f5f756c092fe12 Mon Sep 17 00:00:00 2001 +From: Ulf Nilsson +Date: Sat, 16 Mar 2019 22:01:40 +0100 +Subject: [PATCH] Simplify the decode example's argument parsing + +The first argument is now the input jpeg file and the second argument the output png file. +The output file is no longer optional and must not be specified with the --output option. +--- + examples/decode.rs | 75 +++++++++++++++++----------------------------- + 1 file changed, 28 insertions(+), 47 deletions(-) + +diff --git a/examples/decode.rs b/examples/decode.rs +index d2aa3d7..d74b3ad 100644 +--- a/examples/decode.rs ++++ b/examples/decode.rs +@@ -1,63 +1,44 @@ +-extern crate docopt; + extern crate jpeg_decoder as jpeg; + extern crate png; + +-use docopt::Docopt; + use png::HasParameters; + use std::env; + use std::fs::File; +-use std::io::BufReader; ++use std::io::{self, BufReader, Write}; + use std::process; + +-const USAGE: &'static str = " +-Usage: decode [--output=] +- decode -h | --help +- +-Options: +- -h --help Show this screen. +- -o , --output= Output PNG file. +-"; ++fn usage() -> ! { ++ write!(io::stderr(), "usage: decode image.jpg image.png").unwrap(); ++ process::exit(1) ++} + + fn main() { +- let args = &Docopt::new(USAGE) +- .and_then(|d| d.argv(env::args()).parse()) +- .unwrap_or_else(|e| e.exit()); +- let input = args.get_str(""); +- let output = args.get_str("-o"); +- let file = match File::open(input) { +- Ok(file) => file, +- Err(error) => { +- println!("The specified input could not be opened: {}", error); +- process::exit(1); +- }, +- }; +- let mut decoder = jpeg::Decoder::new(BufReader::new(file)); +- let mut data = match decoder.decode() { +- Ok(data) => data, +- Err(error) => { +- println!("The image could not be decoded: {}", error); +- println!("If other software can decode this image successfully then it's likely that this is a bug."); +- process::exit(1); +- } +- }; ++ let mut args = env::args().skip(1); ++ let input_path = args.next().unwrap_or_else(|| usage()); ++ let output_path = args.next().unwrap_or_else(|| usage()); + +- if !output.is_empty() { +- let output_file = File::create(output).unwrap(); +- let info = decoder.info().unwrap(); +- let mut encoder = png::Encoder::new(output_file, info.width as u32, info.height as u32); +- encoder.set(png::BitDepth::Eight); ++ let input_file = File::open(input_path).expect("The specified input file could not be opened"); ++ let mut decoder = jpeg::Decoder::new(BufReader::new(input_file)); ++ let mut data = decoder.decode().expect("Decoding failed. If other software can successfully decode the specified JPEG image, then it's likely that there is a bug in jpeg-decoder"); ++ let info = decoder.info().unwrap(); + +- match info.pixel_format { +- jpeg::PixelFormat::L8 => encoder.set(png::ColorType::Grayscale), +- jpeg::PixelFormat::RGB24 => encoder.set(png::ColorType::RGB), +- jpeg::PixelFormat::CMYK32 => { +- data = cmyk_to_rgb(&mut data); +- encoder.set(png::ColorType::RGB) +- }, +- }; ++ let output_file = File::create(output_path).unwrap(); ++ let mut encoder = png::Encoder::new(output_file, info.width as u32, info.height as u32); ++ encoder.set(png::BitDepth::Eight); + +- encoder.write_header().expect("writing png header failed").write_image_data(&data).expect("png encoding failed"); +- } ++ match info.pixel_format { ++ jpeg::PixelFormat::L8 => encoder.set(png::ColorType::Grayscale), ++ jpeg::PixelFormat::RGB24 => encoder.set(png::ColorType::RGB), ++ jpeg::PixelFormat::CMYK32 => { ++ data = cmyk_to_rgb(&mut data); ++ encoder.set(png::ColorType::RGB) ++ }, ++ }; ++ ++ encoder.write_header() ++ .expect("writing png header failed") ++ .write_image_data(&data) ++ .expect("png encoding failed"); + } + + fn cmyk_to_rgb(input: &[u8]) -> Vec { +-- +2.22.0 + diff --git a/jpeg-decoder-fix-metadata.diff b/jpeg-decoder-fix-metadata.diff new file mode 100644 index 0000000..195d327 --- /dev/null +++ b/jpeg-decoder-fix-metadata.diff @@ -0,0 +1,19 @@ +--- jpeg-decoder-0.1.15/Cargo.toml 1970-01-01T00:00:00+00:00 ++++ jpeg-decoder-0.1.15/Cargo.toml 2019-06-23T08:56:37.043214+00:00 +@@ -27,14 +27,11 @@ + [dependencies.rayon] + version = "1.0" + optional = true +-[dev-dependencies.docopt] +-version = "0.7" +- + [dev-dependencies.png] +-version = "0.5" ++version = "0.14" + + [dev-dependencies.walkdir] +-version = "1.0" ++version = "2.0" + + [features] + default = ["rayon"] diff --git a/rust-jpeg-decoder.spec b/rust-jpeg-decoder.spec index aca739b..8420fb5 100644 --- a/rust-jpeg-decoder.spec +++ b/rust-jpeg-decoder.spec @@ -1,33 +1,32 @@ -# Generated by rust2rpm -# https://github.com/kaksmet/jpeg-decoder/issues/92 -%bcond_with check +# Generated by rust2rpm 10 +%bcond_without check %global debug_package %{nil} %global crate jpeg-decoder Name: rust-%{crate} Version: 0.1.15 -Release: 1%{?dist} +Release: 2%{?dist} Summary: JPEG decoder # Upstream license specification: MIT / Apache-2.0 License: MIT or ASL 2.0 URL: https://crates.io/crates/jpeg-decoder Source: %{crates_source} +# Initial patched metadata +# * Drop docopt, update other dev-dependencies, https://github.com/kaksmet/jpeg-decoder/pull/93 +Patch0: jpeg-decoder-fix-metadata.diff +Patch0001: 0001-Simplify-the-decode-example-s-argument-parsing.patch ExclusiveArch: %{rust_arches} +%if %{__cargo_skip_build} +BuildArch: noarch +%endif BuildRequires: rust-packaging -BuildRequires: (crate(byteorder/default) >= 1.0.0 with crate(byteorder/default) < 2.0.0) -BuildRequires: (crate(rayon/default) >= 1.0.0 with crate(rayon/default) < 2.0.0) -%if %{with check} -BuildRequires: (crate(docopt/default) >= 0.7.0 with crate(docopt/default) < 0.8.0) -BuildRequires: (crate(png/default) >= 0.5.0 with crate(png/default) < 0.6.0) -BuildRequires: (crate(walkdir/default) >= 1.0.0 with crate(walkdir/default) < 2.0.0) -%endif -%global _description \ -JPEG decoder. +%global _description %{expand: +JPEG decoder.} %description %{_description} @@ -73,6 +72,9 @@ which use "rayon" feature of "%{crate}" crate. %autosetup -n %{crate}-%{version_no_tilde} -p1 %cargo_prep +%generate_buildrequires +%cargo_generate_buildrequires + %build %cargo_build @@ -85,5 +87,8 @@ which use "rayon" feature of "%{crate}" crate. %endif %changelog +* Sun Jun 23 10:56:37 CEST 2019 Igor Gnatenko - 0.1.15-2 +- Regenerate + * Fri Mar 15 2019 Igor Gnatenko - 0.1.15-1 - Initial package