@@ -365,6 +365,44 @@ test.describe('ImageAddon', () => {
365365 const qoiScrape = await getImageAtBufferCell ( 0 , 11 ) ;
366366 deepStrictEqual ( qoiScrape , pngScrape ) ;
367367 } ) ;
368+ test . describe . only ( 'IIP resizing - QOI format' , ( ) => {
369+ /**
370+ * Same as the tests above, but with QOI format.
371+ * This is needed, as QOI uses a slightly different parse path.
372+ */
373+ test ( 'palette.qoi: N --> width=20 height=5 preserveAspectRatio=0' , async ( ) => {
374+ // cell based resize
375+ const header = `size=${ qoiData . length } ;width=20;height=5;preserveAspectRatio=0` ;
376+ await ctx . proxy . write ( `\x1b]1337;File=inline=1;${ header } :${ PALETTE_QOI_BASE64 } \x07` ) ;
377+ const dim = await getDimensions ( ) ;
378+ deepStrictEqual ( await getOrigSize ( 1 ) , [ dim . cellWidth * 20 , dim . cellHeight * 5 ] ) ;
379+ } ) ;
380+ test ( 'palette.qoi: Npx --> width=320px height=160px preserveAspectRatio=0' , async ( ) => {
381+ // pixel based resize
382+ const header = `size=${ qoiData . length } ;width=320px;height=160px;preserveAspectRatio=0` ;
383+ await ctx . proxy . write ( `\x1b]1337;File=inline=1;${ header } :${ PALETTE_QOI_BASE64 } \x07` ) ;
384+ deepStrictEqual ( await getOrigSize ( 1 ) , [ 320 , 160 ] ) ;
385+ } ) ;
386+ test ( 'palette.qoi: N% --> width=50% height=30% preserveAspectRatio=0' , async ( ) => {
387+ // % of viewport resize
388+ const header = `size=${ qoiData . length } ;width=50%;height=30%;preserveAspectRatio=0` ;
389+ await ctx . proxy . write ( `\x1b]1337;File=inline=1;${ header } :${ PALETTE_QOI_BASE64 } \x07` ) ;
390+ const dim = await getDimensions ( ) ;
391+ deepStrictEqual ( await getOrigSize ( 1 ) , [ Math . floor ( dim . width * 0.5 ) , Math . floor ( dim . height * 0.3 ) ] ) ;
392+ } ) ;
393+ test ( 'palette.qoi: ommitted dimension assumes preserveAspectRatio=1' , async ( ) => {
394+ // width provided in percent
395+ const header = `size=${ qoiData . length } ;width=50%` ;
396+ await ctx . proxy . write ( `\x1b]1337;File=inline=1;${ header } :${ PALETTE_QOI_BASE64 } \x07` ) ;
397+ const dim = await getDimensions ( ) ;
398+ const width = Math . floor ( dim . width * 0.5 ) ;
399+ deepStrictEqual ( await getOrigSize ( 1 ) , [ width , Math . floor ( width * 80 / 640 ) ] ) ;
400+ // height provided in pixel
401+ const header2 = `size=${ qoiData . length } ;height=200px` ;
402+ await ctx . proxy . write ( `\x1b]1337;File=inline=1;${ header2 } :${ PALETTE_QOI_BASE64 } \x07` ) ;
403+ deepStrictEqual ( await getOrigSize ( 2 ) , [ Math . floor ( 200 * 640 / 80 ) , 200 ] ) ;
404+ } ) ;
405+ } ) ;
368406 } ) ;
369407} ) ;
370408
0 commit comments