@@ -138,12 +138,12 @@ pub enum GrayscaleAlgorithm {
138138
139139}
140140
141- pub static IR4_KEYS : [ & ' static str ; 59 ] = [ "mode" , "anchor" , "flip" , "sflip" , "scale" , "cache" , "process" ,
141+ pub static IR4_KEYS : [ & ' static str ; 60 ] = [ "mode" , "anchor" , "flip" , "sflip" , "scale" , "cache" , "process" ,
142142 "quality" , "zoom" , "crop" , "cropxunits" , "cropyunits" ,
143143 "w" , "h" , "width" , "height" , "maxwidth" , "maxheight" , "format" , "thumbnail" ,
144144 "autorotate" , "srotate" , "rotate" , "ignoreicc" , //really? : "precise_scaling_ratio",
145145 "stretch" ,
146- "frame" , "page" , "subsampling" , "colors" ,
146+ "frame" , "page" , "subsampling" , "colors" , "f.sharpen" ,
147147 "404" , "bgcolor" , "paddingcolor" , "bordercolor" , "preset" , "floatspace" , "jpeg_idct_downscale_linear" , "watermark" ,
148148 "s.invert" , "s.sepia" , "s.grayscale" , "s.alpha" , "s.brightness" , "s.contrast" , "s.saturation" , "trim.threshold" ,
149149 "trim.percentpadding" , "a.blur" , "a.sharpen" , "a.removenoise" , "a.balancewhite" , "dither" ,
@@ -244,9 +244,8 @@ impl Instructions{
244244 add ( & mut m, "s.alpha" , self . s_alpha ) ;
245245 add ( & mut m, "s.brightness" , self . s_brightness ) ;
246246 add ( & mut m, "s.saturation" , self . s_saturation ) ;
247- if self . s_sepia {
248- add ( & mut m, "s.sepia" , Some ( "true" ) ) ;
249- }
247+ add ( & mut m, "s.sepia" , self . s_sepia ) ;
248+
250249
251250 add ( & mut m, "s.grayscale" , self . s_grayscale . map ( |v| format ! ( "{:?}" , v) . to_lowercase ( ) ) ) ;
252251 add ( & mut m, "a.balancewhite" , self . a_balance_white . map ( |v| format ! ( "{:?}" , v) . to_lowercase ( ) ) ) ;
@@ -263,6 +262,8 @@ impl Instructions{
263262 pub fn delete_from_map ( map : & mut HashMap < String , String > , warnings : Option < & mut Vec < ParseWarning > > ) -> Instructions {
264263 let mut p = Parser { m : map, w : warnings, delete_supported : true } ;
265264 let mut i = Instructions :: new ( ) ;
265+ i. f_sharpen = p. parse_f64 ( "f.sharpen" ) ;
266+
266267 i. w = p. parse_i32 ( "width" ) . or ( p. parse_i32 ( "w" ) ) ;
267268 i. h = p. parse_i32 ( "height" ) . or ( p. parse_i32 ( "h" ) ) ;
268269 i. legacy_max_height = p. parse_i32 ( "maxheight" ) ;
@@ -294,7 +295,7 @@ impl Instructions{
294295 i. zoom = p. parse_f64 ( "zoom" ) ;
295296 i. bgcolor_srgb = p. parse_color_srgb ( "bgcolor" ) . or_else ( ||p. parse_color_srgb ( "bgcolor" ) ) ;
296297 i. jpeg_subsampling = p. parse_subsampling ( "subsampling" ) ;
297- i . f_sharpen = p . parse_f64 ( "f.sharpen" ) ;
298+
298299 i. anchor = p. parse_anchor ( "anchor" ) ;
299300
300301 //TODO: warn bounds (-1..1, 0..255)
@@ -306,7 +307,7 @@ impl Instructions{
306307 i. s_alpha = p. parse_f64 ( "s.alpha" ) ;
307308 i. s_saturation = p. parse_f64 ( "s.saturation" ) ;
308309 i. s_brightness = p. parse_f64 ( "s.brightness" ) ;
309-
310+ i . s_sepia = p . parse_bool ( "s.sepia" ) ;
310311 i. a_balance_white = match p. parse_white_balance ( "a.balancewhite" ) {
311312 Some ( HistogramThresholdAlgorithm :: True ) => Some ( HistogramThresholdAlgorithm :: Area ) ,
312313 Some ( HistogramThresholdAlgorithm :: Area ) => Some ( HistogramThresholdAlgorithm :: Area ) ,
@@ -678,7 +679,7 @@ pub struct Instructions{
678679 pub s_contrast : Option < f64 > ,
679680 pub s_saturation : Option < f64 > ,
680681 pub s_brightness : Option < f64 > ,
681- pub s_sepia : bool ,
682+ pub s_sepia : Option < bool > ,
682683 pub s_grayscale : Option < GrayscaleAlgorithm >
683684
684685}
@@ -736,12 +737,14 @@ fn debug_diff<T>(a : &T, b: &T) where T: std::fmt::Debug, T: PartialEq{
736737 }
737738 }
738739}
740+
739741#[ test]
740742fn test_url_parsing ( ) {
741743 fn t ( rel_url : & str , expected : Instructions , expected_warnings : Vec < ParseWarning > ) {
742744 let url = format ! ( "http://localhost/image.jpg?{}" , rel_url) ;
743745 let a = Url :: from_str ( & url) . unwrap ( ) ;
744746 let ( i, warns) = parse_url ( & a) ;
747+ // eprintln!("{} -> {}", &url, i.to_string());
745748 if i. bgcolor_srgb != expected. bgcolor_srgb && i. bgcolor_srgb . is_some ( ) && expected. bgcolor_srgb . is_some ( ) {
746749 let _ = write ! ( :: std:: io:: stderr( ) , "Expected bgcolor={}, actual={}\n " , expected. bgcolor_srgb. unwrap( ) . to_aarrggbb_string( ) , i. bgcolor_srgb. unwrap( ) . to_aarrggbb_string( ) ) ;
747750 }
@@ -780,11 +783,11 @@ fn test_url_parsing() {
780783 t ( "zoom=0.02" , Instructions { zoom : Some ( 0.02f64 ) , ..Default :: default ( ) } , vec ! [ ] ) ;
781784 t ( "trim.threshold=80&trim.percentpadding=0.02" , Instructions { trim_whitespace_threshold : Some ( 80 ) , trim_whitespace_padding_percent : Some ( 0.02f64 ) , ..Default :: default ( ) } , vec ! [ ] ) ;
782785
783- t ( "w=10&f.sharpen=80.5" , Instructions { w : Some ( 1 ) , f_sharpen : Some ( 80.5f64 ) , ..Default :: default ( ) } , vec ! [ ] ) ;
786+ t ( "w=10&f.sharpen=80.5" , Instructions { w : Some ( 10 ) , f_sharpen : Some ( 80.5f64 ) , ..Default :: default ( ) } , vec ! [ ] ) ;
784787
785788 t ( "f.sharpen=80.5" , Instructions { f_sharpen : Some ( 80.5f64 ) , ..Default :: default ( ) } , vec ! [ ] ) ;
786789
787- t ( "s.sepia=true&s.brightness=0.1&s.saturation=-0.1&s.contrast=1&s.alpha=0" , Instructions { s_alpha : Some ( 0f64 ) , s_contrast : Some ( 1f64 ) , s_sepia : true , s_brightness : Some ( 0.1f64 ) , s_saturation : Some ( -0.1f64 ) , ..Default :: default ( ) } , vec ! [ ] ) ;
790+ t ( "s.sepia=true&s.brightness=0.1&s.saturation=-0.1&s.contrast=1&s.alpha=0" , Instructions { s_alpha : Some ( 0f64 ) , s_contrast : Some ( 1f64 ) , s_sepia : Some ( true ) , s_brightness : Some ( 0.1f64 ) , s_saturation : Some ( -0.1f64 ) , ..Default :: default ( ) } , vec ! [ ] ) ;
788791
789792 t ( "s.grayscale=true" , Instructions { s_grayscale : Some ( GrayscaleAlgorithm :: True ) , ..Default :: default ( ) } , vec ! [ ] ) ;
790793 t ( "s.grayscale=flat" , Instructions { s_grayscale : Some ( GrayscaleAlgorithm :: Flat ) , ..Default :: default ( ) } , vec ! [ ] ) ;
@@ -860,6 +863,6 @@ fn test_tostr(){
860863 t ( "a.balancewhite=area" , Instructions { a_balance_white : Some ( HistogramThresholdAlgorithm :: Area ) , ..Default :: default ( ) } ) ;
861864
862865 t ( "s.grayscale=bt709" , Instructions { s_grayscale : Some ( GrayscaleAlgorithm :: Bt709 ) , ..Default :: default ( ) } ) ;
863- t ( "s.alpha=0&s.brightness=0.1&s.contrast=1&s.saturation=-0.1&s.sepia=true" , Instructions { s_alpha : Some ( 0f64 ) , s_contrast : Some ( 1f64 ) , s_sepia : true , s_brightness : Some ( 0.1f64 ) , s_saturation : Some ( -0.1f64 ) , ..Default :: default ( ) } ) ;
866+ t ( "s.alpha=0&s.brightness=0.1&s.contrast=1&s.saturation=-0.1&s.sepia=true" , Instructions { s_alpha : Some ( 0f64 ) , s_contrast : Some ( 1f64 ) , s_sepia : Some ( true ) , s_brightness : Some ( 0.1f64 ) , s_saturation : Some ( -0.1f64 ) , ..Default :: default ( ) } ) ;
864867
865868}
0 commit comments