Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Berid of most (all?) warnings #1206

Merged
merged 3 commits into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,49 @@ impl ColorType {
/// decoding from and encoding to such an image format.
#[derive(Copy, PartialEq, Eq, Debug, Clone, Hash)]
pub enum ExtendedColorType {
/// Pixel is 1-bit luminance
L1,
/// Pixel is 1-bit luminance with an alpha channel
La1,
/// Pixel contains 1-bit R, G and B channels
Rgb1,
/// Pixel is 1-bit RGB with an alpha channel
Rgba1,
/// Pixel is 2-bit luminance
L2,
/// Pixel is 2-bit luminance with an alpha channel
La2,
/// Pixel contains 2-bit R, G and B channels
Rgb2,
/// Pixel is 2-bit RGB with an alpha channel
Rgba2,
/// Pixel is 4-bit luminance
L4,
/// Pixel is 4-bit luminance with an alpha channel
La4,
/// Pixel contains 4-bit R, G and B channels
Rgb4,
/// Pixel is 4-bit RGB with an alpha channel
Rgba4,
/// Pixel is 8-bit luminance
L8,
/// Pixel is 8-bit luminance with an alpha channel
La8,
/// Pixel contains 8-bit R, G and B channels
Rgb8,
/// Pixel is 8-bit RGB with an alpha channel
Rgba8,
/// Pixel is 16-bit luminance
L16,
/// Pixel is 16-bit luminance with an alpha channel
La16,
/// Pixel contains 16-bit R, G and B channels
Rgb16,
/// Pixel is 16-bit RGB with an alpha channel
Rgba16,
/// Pixel contains 8-bit B, G and R channels
Bgr8,
/// Pixel is 8-bit BGR with an alpha channel
Bgra8,

/// Pixel is of unknown color type with the specified bits per pixel. This can apply to pixels
Expand Down
6 changes: 6 additions & 0 deletions src/dynimage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,8 +689,14 @@ impl DynamicImage {
w: &mut W,
format: F,
) -> ImageResult<()> {
#[allow(unused_variables)]
// When no features are supported
let w = w;
#[allow(unused_variables,unused_mut)]
let mut bytes = self.to_bytes();
#[allow(unused_variables)]
let (width, height) = self.dimensions();
#[allow(unused_variables,unused_mut)]
let mut color = self.color();
let format = format.into();

Expand Down
8 changes: 8 additions & 0 deletions src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ impl From<ImageFormat> for ImageOutputFormat {

// This struct manages buffering associated with implementing `Read` and `Seek` on decoders that can
// must decode ranges of bytes at a time.
#[allow(dead_code)]
// When no image formats that use it are enabled
pub(crate) struct ImageReadBuffer {
scanline_bytes: usize,
buffer: Vec<u8>,
Expand All @@ -149,6 +151,8 @@ impl ImageReadBuffer {
/// Panics if scanline_bytes doesn't fit into a usize, because that would mean reading anything
/// from the image would take more RAM than the entire virtual address space. In other words,
/// actually using this struct would instantly OOM so just get it out of the way now.
#[allow(dead_code)]
// When no image formats that use it are enabled
pub(crate) fn new(scanline_bytes: u64, total_bytes: u64) -> Self {
Self {
scanline_bytes: usize::try_from(scanline_bytes).unwrap(),
Expand All @@ -159,6 +163,8 @@ impl ImageReadBuffer {
}
}

#[allow(dead_code)]
// When no image formats that use it are enabled
pub(crate) fn read<F>(&mut self, buf: &mut [u8], mut read_scanline: F) -> io::Result<usize>
where
F: FnMut(&mut [u8]) -> io::Result<usize>,
Expand Down Expand Up @@ -204,6 +210,8 @@ impl ImageReadBuffer {

/// Decodes a specific region of the image, represented by the rectangle
/// starting from ```x``` and ```y``` and having ```length``` and ```width```
#[allow(dead_code)]
// When no image formats that use it are enabled
pub(crate) fn load_rect<'a, D, F, F1, F2, E>(x: u32, y: u32, width: u32, height: u32, buf: &mut [u8],
progress_callback: F,
decoder: &mut D,
Expand Down
17 changes: 14 additions & 3 deletions src/io/free_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ use crate::color;
use crate::image;
use crate::dynimage::DynamicImage;
use crate::error::{ImageError, ImageFormatHint, ImageResult};
use crate::image::{ImageDecoder, ImageEncoder, ImageFormat};
use crate::image::ImageFormat;
#[allow(unused_imports)] // When no features are supported
use crate::image::{ImageDecoder, ImageEncoder};

/// Internal error type for guessing format from path.
pub(crate) enum PathError {
Expand All @@ -58,8 +60,10 @@ pub(crate) fn open_impl(path: &Path) -> ImageResult<DynamicImage> {
/// Try [`io::Reader`] for more advanced uses.
///
/// [`io::Reader`]: io/struct.Reader.html
#[allow(unused_variables)]
// r is unused if no features are supported.
pub fn load<R: BufRead + Seek>(r: R, format: ImageFormat) -> ImageResult<DynamicImage> {
#[allow(deprecated, unreachable_patterns)]
#[allow(unreachable_patterns)]
// Default is unreachable if all features are supported.
match format {
#[cfg(feature = "png")]
Expand Down Expand Up @@ -99,11 +103,14 @@ pub(crate) fn image_dimensions_impl(path: &Path) -> ImageResult<(u32, u32)> {
image_dimensions_with_format_impl(fin, format)
}

#[allow(unused_variables)]
// fin is unused if no features are supported.
pub(crate) fn image_dimensions_with_format_impl<R: BufRead + Seek>(fin: R, format: ImageFormat)
-> ImageResult<(u32, u32)>
{
#[allow(unreachable_patterns)]
#[allow(unreachable_patterns,unreachable_code)]
// Default is unreachable if all features are supported.
// Code after the match is unreachable if none are.
Ok(match format {
#[cfg(feature = "jpeg")]
image::ImageFormat::Jpeg => jpeg::JpegDecoder::new(fin)?.dimensions(),
Expand Down Expand Up @@ -133,6 +140,8 @@ pub(crate) fn image_dimensions_with_format_impl<R: BufRead + Seek>(fin: R, forma
})
}

#[allow(unused_variables)]
// Most variables when no features are supported
pub(crate) fn save_buffer_impl(
path: &Path,
buf: &[u8],
Expand Down Expand Up @@ -177,6 +186,8 @@ pub(crate) fn save_buffer_impl(
}
}

#[allow(unused_variables)]
// Most variables when no features are supported
pub(crate) fn save_buffer_with_format_impl(
path: &Path,
buf: &[u8],
Expand Down
2 changes: 2 additions & 0 deletions src/jpeg/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ mod tests {
#[cfg(feature = "benchmarks")]
use test::Bencher;

#[cfg(feature = "benchmarks")]
const W: usize = 256;
#[cfg(feature = "benchmarks")]
const H: usize = 256;

#[test]
Expand Down
6 changes: 6 additions & 0 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ where

/// Expand a buffer of packed 1, 2, or 4 bits integers into u8's. Assumes that
/// every `row_size` entries there are padding bits up to the next byte boundry.
#[allow(dead_code)]
// When no image formats that use it are enabled
pub(crate) fn expand_bits(bit_depth: u8, row_size: u32, buf: &[u8]) -> Vec<u8> {
// Note: this conversion assumes that the scanlines begin on byte boundaries
let mask = (1u8 << bit_depth as usize) - 1;
Expand Down Expand Up @@ -63,11 +65,15 @@ pub(crate) fn expand_bits(bit_depth: u8, row_size: u32, buf: &[u8]) -> Vec<u8> {
p
}

#[allow(dead_code)]
// When no image formats that use it are enabled
pub(crate) fn vec_u16_into_u8(vec: Vec<u16>) -> Vec<u8> {
// Do this way until we find a way to not alloc/dealloc but get llvm to realloc instead.
vec_u16_copy_u8(&vec)
}

#[allow(dead_code)]
// When no image formats that use it are enabled
pub(crate) fn vec_u16_copy_u8(vec: &[u16]) -> Vec<u8> {
let mut new = vec![0; vec.len() * mem::size_of::<u16>()];
NativeEndian::write_u16_into(&vec[..], &mut new[..]);
Expand Down