Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
epel9
Igor Gnatenko 6 years ago
parent 501fb3bd4d
commit dd0101443e
No known key found for this signature in database
GPG Key ID: 695714BD1BBC5F4C

@ -0,0 +1,110 @@
From 19a9e99447b1c7782a7f49bf35f5f756c092fe12 Mon Sep 17 00:00:00 2001
From: Ulf Nilsson <kaksmet@gmail.com>
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 <input> [--output=<file>]
- decode -h | --help
-
-Options:
- -h --help Show this screen.
- -o <file>, --output=<file> 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("<input>");
- 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<u8> {
--
2.22.0

@ -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"]

@ -1,33 +1,32 @@
# Generated by rust2rpm # Generated by rust2rpm 10
# https://github.com/kaksmet/jpeg-decoder/issues/92 %bcond_without check
%bcond_with check
%global debug_package %{nil} %global debug_package %{nil}
%global crate jpeg-decoder %global crate jpeg-decoder
Name: rust-%{crate} Name: rust-%{crate}
Version: 0.1.15 Version: 0.1.15
Release: 1%{?dist} Release: 2%{?dist}
Summary: JPEG decoder Summary: JPEG decoder
# Upstream license specification: MIT / Apache-2.0 # Upstream license specification: MIT / Apache-2.0
License: MIT or ASL 2.0 License: MIT or ASL 2.0
URL: https://crates.io/crates/jpeg-decoder URL: https://crates.io/crates/jpeg-decoder
Source: %{crates_source} 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} ExclusiveArch: %{rust_arches}
%if %{__cargo_skip_build}
BuildArch: noarch
%endif
BuildRequires: rust-packaging 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 \ %global _description %{expand:
JPEG decoder. JPEG decoder.}
%description %{_description} %description %{_description}
@ -73,6 +72,9 @@ which use "rayon" feature of "%{crate}" crate.
%autosetup -n %{crate}-%{version_no_tilde} -p1 %autosetup -n %{crate}-%{version_no_tilde} -p1
%cargo_prep %cargo_prep
%generate_buildrequires
%cargo_generate_buildrequires
%build %build
%cargo_build %cargo_build
@ -85,5 +87,8 @@ which use "rayon" feature of "%{crate}" crate.
%endif %endif
%changelog %changelog
* Sun Jun 23 10:56:37 CEST 2019 Igor Gnatenko <ignatenkobrain@fedoraproject.org> - 0.1.15-2
- Regenerate
* Fri Mar 15 2019 Igor Gnatenko <ignatenkobrain@fedoraproject.org> - 0.1.15-1 * Fri Mar 15 2019 Igor Gnatenko <ignatenkobrain@fedoraproject.org> - 0.1.15-1
- Initial package - Initial package

Loading…
Cancel
Save