@@ -350,48 +350,36 @@ internal static FileInfo GetCacheFileInfo(string filePath)
350350
351351 public static Task ResizeImageStream ( Stream input , Stream output , uint toWidth , uint toHeight )
352352 {
353- TaskCompletionSource tcs = new ( ) ;
354- Task . Factory . StartNew ( Impl ) ;
355-
356- return tcs . Task ;
353+ return Task . Factory . StartNew ( Impl ) ;
357354
358355 void Impl ( )
359356 {
360- try
357+ ProcessImageSettings settings = new ( )
361358 {
362- ProcessImageSettings settings = new ( )
363- {
364- Width = ( int ) toWidth ,
365- Height = ( int ) toHeight ,
366- HybridMode = HybridScaleMode . Off ,
367- Interpolation = InterpolationSettings . CubicSmoother ,
368- Anchor = CropAnchor . Bottom | CropAnchor . Center
369- } ;
370- settings . TrySetEncoderFormat ( ImageMimeTypes . Png ) ;
371-
372- ImageFileInfo imageFileInfo = ImageFileInfo . Load ( input ! ) ;
373- ImageFileInfo . FrameInfo frame = imageFileInfo . Frames [ 0 ] ;
374- input . Position = 0 ;
375-
376- bool isUseWaifu2X = IsWaifu2XEnabled && ( frame . Width < toWidth || frame . Height < toHeight ) ;
377- using ProcessingPipeline pipeline =
378- MagicImageProcessor
379- . BuildPipeline ( input ,
380- isUseWaifu2X
381- ? ProcessImageSettings . Default
382- : settings ) ;
359+ Width = ( int ) toWidth ,
360+ Height = ( int ) toHeight ,
361+ HybridMode = HybridScaleMode . Off ,
362+ Interpolation = InterpolationSettings . CubicSmoother ,
363+ Anchor = CropAnchor . Bottom | CropAnchor . Center
364+ } ;
365+ settings . TrySetEncoderFormat ( ImageMimeTypes . Png ) ;
383366
384- if ( isUseWaifu2X )
385- pipeline . AddTransform ( new Waifu2XTransform ( _waifu2X ) ) ;
367+ ImageFileInfo imageFileInfo = ImageFileInfo . Load ( input ! ) ;
368+ ImageFileInfo . FrameInfo frame = imageFileInfo . Frames [ 0 ] ;
369+ input . Position = 0 ;
386370
387- pipeline . WriteOutput ( output ) ;
371+ bool isUseWaifu2X = IsWaifu2XEnabled && ( frame . Width < toWidth || frame . Height < toHeight ) ;
372+ using ProcessingPipeline pipeline =
373+ MagicImageProcessor
374+ . BuildPipeline ( input ,
375+ isUseWaifu2X
376+ ? ProcessImageSettings . Default
377+ : settings ) ;
388378
389- tcs . SetResult ( ) ;
390- }
391- catch ( Exception e )
392- {
393- tcs . SetException ( e ) ;
394- }
379+ if ( isUseWaifu2X )
380+ pipeline . AddTransform ( new Waifu2XTransform ( _waifu2X ) ) ;
381+
382+ pipeline . WriteOutput ( output ) ;
395383 }
396384 }
397385
0 commit comments