Skip to content

Commit

Permalink
Merge pull request #1093 from fintelia/simplify-cargo-toml
Browse files Browse the repository at this point in the history
Simplify cargo toml
  • Loading branch information
fintelia committed Dec 8, 2019
2 parents f23f53a + bf8e26b commit 3a7eb68
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 75 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -20,9 +20,9 @@ env:
matrix:
- DEFAULT_FEATURES='yes'
- FEATURES=''
- FEATURES='gif_codec'
- FEATURES='gif'
- FEATURES='jpeg'
- FEATURES='png_codec'
- FEATURES='png'
- FEATURES='pnm'
- FEATURES='tga'
- FEATURES='tiff'
Expand Down
48 changes: 10 additions & 38 deletions Cargo.toml
Expand Up @@ -3,19 +3,10 @@ name = "image"
version = "0.23.0-preview.0"
license = "MIT"
description = "Imaging library written in Rust. Provides basic filters and decoders for the most common image formats."
authors = [
"ccgn",
"bvssvni <bvssvni@gmail.com>",
"nwin",
"TyOverby <ty@pre-alpha.com>",
"HeroicKatora",
"Calum",
"CensoredUsername <cens.username@gmail.com>",
"fintelia <fintelia@gmail.com>"
]
authors = ["The image-rs Developers"]
readme = "README.md"
documentation = "https://docs.rs/image"
repository = "https://github.com/image-rs/image.git"
repository = "https://github.com/image-rs/image"
homepage = "https://github.com/image-rs/image"
categories = ["multimedia::images", "multimedia::encoding"]
exclude = [
Expand All @@ -33,27 +24,11 @@ byteorder = "1.2.1"
num-iter = "0.1.32"
num-rational = { version = "0.2.1", default-features = false }
num-traits = "0.2.0"

[dependencies.gif]
version = "0.10.0"
optional = true

[dependencies.jpeg-decoder]
version = "0.1"
default-features = false
optional = true

[dependencies.png]
version = "0.15"
optional = true

[dependencies.scoped_threadpool]
version = "0.1"
optional = true

[dependencies.tiff]
version = "0.4.0"
optional = true
gif = { version = "0.10.0", optional = true }
jpeg = { package = "jpeg-decoder", version = "0.1", default-features = false, optional = true }
png = { version = "0.15", optional = true }
scoped_threadpool = { version = "0.1", optional = true }
tiff = { version = "0.4.0", optional = true }

[dev-dependencies]
crc32fast = "1.2.0"
Expand All @@ -62,18 +37,15 @@ glob = "0.3"
quickcheck = "0.6.2"

[features]
default = ["gif_codec", "jpeg", "ico", "png_codec", "pnm", "tga", "tiff", "webp", "bmp", "hdr", "dxt", "jpeg_rayon"]
default = ["gif", "jpeg", "ico", "png", "pnm", "tga", "tiff", "webp", "bmp", "hdr", "dxt", "jpeg_rayon"]

gif_codec = ["gif"]
ico = ["bmp", "png_codec"]
jpeg = ["jpeg-decoder"]
png_codec = ["png"]
ico = ["bmp", "png"]
pnm = []
tga = []
webp = []
bmp = []
hdr = ["scoped_threadpool"]
dxt = []
jpeg_rayon = ["jpeg-decoder/rayon"]
jpeg_rayon = ["jpeg/rayon"]

benchmarks = []
8 changes: 4 additions & 4 deletions src/dynimage.rs
Expand Up @@ -5,13 +5,13 @@ use std::u32;

#[cfg(feature = "bmp")]
use bmp;
#[cfg(feature = "gif_codec")]
#[cfg(feature = "gif")]
use gif;
#[cfg(feature = "ico")]
use ico;
#[cfg(feature = "jpeg")]
use jpeg;
#[cfg(feature = "png_codec")]
#[cfg(feature = "png")]
use png;
#[cfg(feature = "pnm")]
use pnm;
Expand Down Expand Up @@ -477,7 +477,7 @@ impl DynamicImage {

#[allow(deprecated)]
match format {
#[cfg(feature = "png_codec")]
#[cfg(feature = "png")]
image::ImageOutputFormat::Png => {
let p = png::PNGEncoder::new(w);
match *self {
Expand Down Expand Up @@ -519,7 +519,7 @@ impl DynamicImage {
Ok(())
}

#[cfg(feature = "gif_codec")]
#[cfg(feature = "gif")]
image::ImageOutputFormat::Gif => {
let mut g = gif::Encoder::new(w);

Expand Down
8 changes: 4 additions & 4 deletions src/image.rs
Expand Up @@ -156,7 +156,7 @@ impl ImageFormat {
/// An enumeration of supported image formats for encoding.
#[derive(Clone, PartialEq, Eq, Debug)]
pub enum ImageOutputFormat {
#[cfg(feature = "png_codec")]
#[cfg(feature = "png")]
/// An Image in PNG Format
Png,

Expand All @@ -168,7 +168,7 @@ pub enum ImageOutputFormat {
/// An Image in one of the PNM Formats
Pnm(PNMSubtype),

#[cfg(feature = "gif_codec")]
#[cfg(feature = "gif")]
/// An Image in GIF Format
Gif,

Expand All @@ -189,13 +189,13 @@ pub enum ImageOutputFormat {
impl From<ImageFormat> for ImageOutputFormat {
fn from(fmt: ImageFormat) -> Self {
match fmt {
#[cfg(feature = "png_codec")]
#[cfg(feature = "png")]
ImageFormat::Png => ImageOutputFormat::Png,
#[cfg(feature = "jpeg")]
ImageFormat::Jpeg => ImageOutputFormat::Jpeg(75),
#[cfg(feature = "pnm")]
ImageFormat::Pnm => ImageOutputFormat::Pnm(PNMSubtype::ArbitraryMap),
#[cfg(feature = "gif_codec")]
#[cfg(feature = "gif")]
ImageFormat::Gif => ImageOutputFormat::Gif,
#[cfg(feature = "ico")]
ImageFormat::Ico => ImageOutputFormat::Ico,
Expand Down
2 changes: 1 addition & 1 deletion src/imageops/sample.rs
Expand Up @@ -757,7 +757,7 @@ mod tests {
use test;

#[bench]
#[cfg(all(feature = "benchmarks", feature = "png_codec"))]
#[cfg(all(feature = "benchmarks", feature = "png"))]
fn bench_resize(b: &mut test::Bencher) {
use std::path::Path;
let img = ::open(&Path::new("./examples/fractal.png")).unwrap();
Expand Down
16 changes: 8 additions & 8 deletions src/io/free_functions.rs
Expand Up @@ -6,15 +6,15 @@ use std::u32;

#[cfg(feature = "bmp")]
use bmp;
#[cfg(feature = "gif_codec")]
#[cfg(feature = "gif")]
use gif;
#[cfg(feature = "hdr")]
use hdr;
#[cfg(feature = "ico")]
use ico;
#[cfg(feature = "jpeg")]
use jpeg;
#[cfg(feature = "png_codec")]
#[cfg(feature = "png")]
use png;
#[cfg(feature = "pnm")]
use pnm;
Expand Down Expand Up @@ -57,9 +57,9 @@ pub fn load<R: BufRead + Seek>(r: R, format: ImageFormat) -> ImageResult<Dynamic
#[allow(deprecated, unreachable_patterns)]
// Default is unreachable if all features are supported.
match format {
#[cfg(feature = "png_codec")]
#[cfg(feature = "png")]
image::ImageFormat::Png => DynamicImage::from_decoder(png::PngDecoder::new(r)?),
#[cfg(feature = "gif_codec")]
#[cfg(feature = "gif")]
image::ImageFormat::Gif => DynamicImage::from_decoder(gif::GifDecoder::new(r)?),
#[cfg(feature = "jpeg")]
image::ImageFormat::Jpeg => DynamicImage::from_decoder(jpeg::JpegDecoder::new(r)?),
Expand Down Expand Up @@ -101,9 +101,9 @@ pub(crate) fn image_dimensions_with_format_impl<R: BufRead + Seek>(fin: R, forma
Ok(match format {
#[cfg(feature = "jpeg")]
image::ImageFormat::Jpeg => jpeg::JpegDecoder::new(fin)?.dimensions(),
#[cfg(feature = "png_codec")]
#[cfg(feature = "png")]
image::ImageFormat::Png => png::PngDecoder::new(fin)?.dimensions(),
#[cfg(feature = "gif_codec")]
#[cfg(feature = "gif")]
image::ImageFormat::Gif => gif::GifDecoder::new(fin)?.dimensions(),
#[cfg(feature = "webp")]
image::ImageFormat::WebP => webp::WebPDecoder::new(fin)?.dimensions(),
Expand Down Expand Up @@ -145,7 +145,7 @@ pub(crate) fn save_buffer_impl(
"ico" => ico::ICOEncoder::new(fout).encode(buf, width, height, color),
#[cfg(feature = "jpeg")]
"jpg" | "jpeg" => jpeg::JPEGEncoder::new(fout).encode(buf, width, height, color),
#[cfg(feature = "png_codec")]
#[cfg(feature = "png")]
"png" => png::PNGEncoder::new(fout).encode(buf, width, height, color),
#[cfg(feature = "pnm")]
"pbm" => pnm::PNMEncoder::new(fout)
Expand Down Expand Up @@ -185,7 +185,7 @@ pub(crate) fn save_buffer_with_format_impl(
image::ImageFormat::Ico => ico::ICOEncoder::new(fout).encode(buf, width, height, color),
#[cfg(feature = "jpeg")]
image::ImageFormat::Jpeg => jpeg::JPEGEncoder::new(fout).encode(buf, width, height, color),
#[cfg(feature = "png_codec")]
#[cfg(feature = "png")]
image::ImageFormat::Png => png::PNGEncoder::new(fout).encode(buf, width, height, color),
#[cfg(feature = "bmp")]
image::ImageFormat::Bmp => bmp::BMPEncoder::new(fout).encode(buf, width, height, color),
Expand Down
28 changes: 14 additions & 14 deletions src/jpeg/decoder.rs
@@ -1,4 +1,4 @@
extern crate jpeg_decoder;
extern crate jpeg;

use std::convert::TryFrom;
use std::io::{self, Cursor, Read};
Expand All @@ -10,21 +10,21 @@ use image::{ImageDecoder, ImageError, ImageResult};

/// JPEG decoder
pub struct JpegDecoder<R> {
decoder: jpeg_decoder::Decoder<R>,
metadata: jpeg_decoder::ImageInfo,
decoder: jpeg::Decoder<R>,
metadata: jpeg::ImageInfo,
}

impl<R: Read> JpegDecoder<R> {
/// Create a new decoder that decodes from the stream ```r```
pub fn new(r: R) -> ImageResult<JpegDecoder<R>> {
let mut decoder = jpeg_decoder::Decoder::new(r);
let mut decoder = jpeg::Decoder::new(r);

decoder.read_info()?;
let mut metadata = decoder.info().unwrap();

// We convert CMYK data to RGB before returning it to the user.
if metadata.pixel_format == jpeg_decoder::PixelFormat::CMYK32 {
metadata.pixel_format = jpeg_decoder::PixelFormat::RGB24;
if metadata.pixel_format == jpeg::PixelFormat::CMYK32 {
metadata.pixel_format = jpeg::PixelFormat::RGB24;
}

Ok(JpegDecoder {
Expand Down Expand Up @@ -64,7 +64,7 @@ impl<'a, R: 'a + Read> ImageDecoder<'a> for JpegDecoder<R> {
fn into_reader(mut self) -> ImageResult<Self::Reader> {
let mut data = self.decoder.decode()?;
data = match self.decoder.info().unwrap().pixel_format {
jpeg_decoder::PixelFormat::CMYK32 => cmyk_to_rgb(&data),
jpeg::PixelFormat::CMYK32 => cmyk_to_rgb(&data),
_ => data,
};

Expand All @@ -76,7 +76,7 @@ impl<'a, R: 'a + Read> ImageDecoder<'a> for JpegDecoder<R> {

let mut data = self.decoder.decode()?;
data = match self.decoder.info().unwrap().pixel_format {
jpeg_decoder::PixelFormat::CMYK32 => cmyk_to_rgb(&data),
jpeg::PixelFormat::CMYK32 => cmyk_to_rgb(&data),
_ => data,
};

Expand Down Expand Up @@ -113,9 +113,9 @@ fn cmyk_to_rgb(input: &[u8]) -> Vec<u8> {
output
}

impl From<jpeg_decoder::PixelFormat> for ColorType {
fn from(pixel_format: jpeg_decoder::PixelFormat) -> ColorType {
use self::jpeg_decoder::PixelFormat::*;
impl From<jpeg::PixelFormat> for ColorType {
fn from(pixel_format: jpeg::PixelFormat) -> ColorType {
use self::jpeg::PixelFormat::*;
match pixel_format {
L8 => ColorType::L8,
RGB24 => ColorType::Rgb8,
Expand All @@ -124,9 +124,9 @@ impl From<jpeg_decoder::PixelFormat> for ColorType {
}
}

impl From<jpeg_decoder::Error> for ImageError {
fn from(err: jpeg_decoder::Error) -> ImageError {
use self::jpeg_decoder::Error::*;
impl From<jpeg::Error> for ImageError {
fn from(err: jpeg::Error) -> ImageError {
use self::jpeg::Error::*;
match err {
Format(desc) => ImageError::FormatError(desc),
Unsupported(desc) => ImageError::UnsupportedError(format!("{:?}", desc)),
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Expand Up @@ -84,15 +84,15 @@ pub mod flat;
pub mod bmp;
#[cfg(feature = "dxt")]
pub mod dxt;
#[cfg(feature = "gif_codec")]
#[cfg(feature = "gif")]
pub mod gif;
#[cfg(feature = "hdr")]
pub mod hdr;
#[cfg(feature = "ico")]
pub mod ico;
#[cfg(feature = "jpeg")]
pub mod jpeg;
#[cfg(feature = "png_codec")]
#[cfg(feature = "png")]
pub mod png;
#[cfg(feature = "pnm")]
pub mod pnm;
Expand Down
4 changes: 2 additions & 2 deletions tests/reference_images.rs
Expand Up @@ -185,7 +185,7 @@ fn check_references() {

match case.kind {
ReferenceTestKind::AnimatedGifFrame { frame: frame_num } => {
#[cfg(feature = "gif_codec")]
#[cfg(feature = "gif")]
{
// Interpret the input file as an animation file
use image::AnimationDecoder;
Expand Down Expand Up @@ -214,7 +214,7 @@ fn check_references() {
test_img = frame.into_buffer();
}

#[cfg(not(feature = "gif_codec"))]
#[cfg(not(feature = "gif"))]
{
println!("Skipping - GIF codec is not enabled");
return;
Expand Down

0 comments on commit 3a7eb68

Please sign in to comment.