Skip to content

Commit cc7887a

Browse files
authored
Fix compilation failure when "gif" feature not enabled (#893)
* Fix compilation failure when "compress" feature not enabled * Fix compilation failure when "gif" feature not enabled * Match signatures, move compile-time feature checks * Add dummy version of fold_to_gif
1 parent c97fd3d commit cc7887a

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

src/algorithm/media.rs

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use serde::*;
1818
#[allow(unused_imports)]
1919
use crate::{Array, Uiua, UiuaResult, Value};
2020
#[cfg(feature = "gif")]
21-
use crate::{ArrayValue, RealArrayValue, SigNode};
22-
use crate::{Complex, OptionalArg, Shape, SysBackend};
21+
use crate::{ArrayValue, RealArrayValue};
22+
use crate::{Complex, OptionalArg, Shape, SigNode, SysBackend};
2323

2424
use super::monadic::hsv_to_rgb;
2525

@@ -104,7 +104,7 @@ impl SmartOutput {
104104
Self::Normal(value.show())
105105
}
106106
#[cfg(not(feature = "gif"))]
107-
fn try_gif(value: &Value, frame_rate: f64) -> Option<Self> {
107+
fn try_gif(_value: &Value, _frame_rate: f64) -> Option<Self> {
108108
None
109109
}
110110
#[cfg(feature = "gif")]
@@ -127,7 +127,7 @@ impl SmartOutput {
127127
}
128128
}
129129
#[cfg(not(feature = "apng"))]
130-
fn try_apng(value: &Value, frame_rate: f64) -> Option<Self> {
130+
fn try_apng(_value: &Value, _frame_rate: f64) -> Option<Self> {
131131
None
132132
}
133133
#[cfg(feature = "apng")]
@@ -346,6 +346,16 @@ pub fn rgba_image_to_array(image: image::RgbaImage) -> Array<f64> {
346346
)
347347
}
348348

349+
#[doc(hidden)]
350+
#[cfg(not(feature = "image"))]
351+
pub fn image_bytes_to_array(
352+
_bytes: &[u8],
353+
_gray: bool,
354+
_alpha: bool,
355+
) -> Result<Array<f64>, String> {
356+
Err("Decoding images is not supported in this environment".into())
357+
}
358+
349359
#[doc(hidden)]
350360
#[cfg(feature = "image")]
351361
pub fn image_bytes_to_array(bytes: &[u8], gray: bool, alpha: bool) -> Result<Array<f64>, String> {
@@ -626,7 +636,7 @@ pub fn stereo_to_wave_bytes<T: hound::Sample + Copy>(
626636

627637
#[cfg(not(feature = "audio_encode"))]
628638
#[doc(hidden)]
629-
pub fn array_from_wav_bytes(bytes: &[u8]) -> Result<(Array<f64>, u32), String> {
639+
pub fn array_from_wav_bytes(_bytes: &[u8]) -> Result<(Array<f64>, u32), String> {
630640
Err("Audio decoding is not supported in this environment".into())
631641
}
632642

@@ -842,6 +852,11 @@ fn dither(mut img: image::RgbaImage, width: u32, height: u32) -> (Vec<u8>, bool)
842852
(buffer, has_transparent)
843853
}
844854

855+
#[cfg(not(feature = "gif"))]
856+
pub(crate) fn fold_to_gif(_f: SigNode, env: &mut Uiua) -> UiuaResult<Vec<u8>> {
857+
Err(env.error("GIF encoding is not supported in this environment"))
858+
}
859+
845860
#[cfg(feature = "gif")]
846861
pub(crate) fn fold_to_gif(f: SigNode, env: &mut Uiua) -> UiuaResult<Vec<u8>> {
847862
use crate::algorithm::{FixedRowsData, fixed_rows};
@@ -1006,24 +1021,24 @@ where
10061021

10071022
#[doc(hidden)]
10081023
#[cfg(not(feature = "gif"))]
1009-
pub fn gif_bytes_to_value(_bytes: &[u8]) -> Result<(f64, Value), gif::DecodingError> {
1010-
Err(env.error("GIF decoding is not supported in this environment"))
1011-
}
1012-
1013-
#[cfg(not(feature = "gif"))]
1014-
pub(crate) fn gif_bytes_to_value(_bytes: &[u8]) -> Result<(f64, Value), gif::DecodingError> {
1015-
Err(env.error("GIF decoding is not supported in this environment"))
1024+
pub fn gif_bytes_to_value(_bytes: &[u8]) -> Result<(f64, Value), String> {
1025+
Err("GIF decoding is not supported in this environment".into())
10161026
}
10171027

10181028
#[doc(hidden)]
10191029
#[cfg(feature = "gif")]
1020-
pub fn gif_bytes_to_value(bytes: &[u8]) -> Result<(f64, Value), gif::DecodingError> {
1021-
gif_bytes_to_value_impl(bytes, gif::ColorOutput::RGBA)
1030+
pub fn gif_bytes_to_value(bytes: &[u8]) -> Result<(f64, Value), String> {
1031+
gif_bytes_to_value_impl(bytes, gif::ColorOutput::RGBA).map_err(|e| e.to_string())
1032+
}
1033+
1034+
#[cfg(not(feature = "gif"))]
1035+
pub(crate) fn gif_bytes_to_value_gray(_bytes: &[u8]) -> Result<(f64, Value), String> {
1036+
Err("GIF decoding is not supported in this environment".into())
10221037
}
10231038

10241039
#[cfg(feature = "gif")]
1025-
pub(crate) fn gif_bytes_to_value_gray(bytes: &[u8]) -> Result<(f64, Value), gif::DecodingError> {
1026-
gif_bytes_to_value_impl(bytes, gif::ColorOutput::Indexed)
1040+
pub(crate) fn gif_bytes_to_value_gray(bytes: &[u8]) -> Result<(f64, Value), String> {
1041+
gif_bytes_to_value_impl(bytes, gif::ColorOutput::Indexed).map_err(|e| e.to_string())
10271042
}
10281043

10291044
#[doc(hidden)]

src/constant.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ impl ConstantValue {
108108
media::image_bytes_to_array(&bytes, true, false)?.into()
109109
}
110110
BigConstant::BadAppleGif => {
111-
let (_, mut val) = media::gif_bytes_to_value_gray(&bytes)
112-
.map_err(|e| e.to_string())?;
111+
let (_, mut val) = media::gif_bytes_to_value_gray(&bytes)?;
113112
let Value::Byte(_) = &mut val else {
114113
return Err(
115114
"Bad Apple gif data is not properly rounded to 0 or 1"

0 commit comments

Comments
 (0)