{picLeft, picRight, picTop, picBottom} = If( 1, picURL = "
https://upload.wikimedia.org/wikipedia/commons/1/1e/Rooster_-_Public_Domain.jpg"; // Lisafern, CC0, tramite Wikimedia Commons --
https://commons.wikimedia.org/wiki/Special:ListFiles/lisafern {600000, 6000000, 35, 5};// , // picURL = "
https://upload.wikimedia.org/wikipedia/commons/3/3a/Foster_graph_hamiltonian.png"; // pubblico dominio:
https://commons.wikimedia.org/wiki/File:Foster_graph_hamiltonian.png {450000, 10000000, 32, 8};// ); gTempFiles = Converti percorso file( "$temp\pil_webp\", "windows" ); Elimina directory( gTempFiles ); // attenzione! Crea directory( gTempFiles ); // la directory esiste ed è vuota // carica python e assicurati che PIL sia disponibile... rc = Python Execute( {}, {}, "\[from PIL import Image, ImageSequence import numpy as np import os import time def rmse(imageA, imageB): if imageA.size != imageB.size: raise ValueError("Le immagini devono avere le stesse dimensioni per calcolare RMSE") imgA_np = np.asarray(imageA).astype("float") imgB_np = np.asarray(imageB).astype("float") err = np.sum((imgA_np - imgB_np) ** 2) err /= float(imageA.size[0] * imageA.size[1]) return np.sqrt(err) ]\", echo( 0 ) ); If( rc != 0, Throw( "python init error rc=" || Char( rc ) ), "ok" ); // aggiungi un'immagine JSL a un elenco di file per un .webp e .jpg e .gif addNewFrame = Function( {filename, img}, img << saveimage( gTempFiles || filename || ".png", "png" ); // il formato png è lossless e rmse lo usa per il confronto File Size( gTempFiles || filename || ".png" ); ); // le funzioni saveFrameTo... e saveFramesTo... // riflettono il modo in cui i formati vengono solitamente utilizzati; // normalmente non creeresti un GIF con un singolo fotogramma // e non puoi creare un JPG con più fotogrammi. saveFrameToWebP = Function( {outputfilename, qual}, {filelist, webpname, rc}, // filelist = Transform Each( {f}, Files In Directory( gTempFiles ), // Convert File Path( gTempFiles || f, "windows" );// ); If( N Items( filelist ) != 1, // Throw( "saveFrameToWebP nitems=" || Char( N Items( filelist ) ) );// ); webpname = Convert File Path( outputfilename, "windows" ); rc = Python Execute( {filelist, webpname, qual}, // input {_rmse, _ossize, _timew, _timer}, // output "\[#
https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#webp imgs = [] for f in elenco file: imgs.append(Image.open(f).convert('RGB')) img=imgs[0] _timew = time.perf_counter() img.save(webpname,save_all=True,format="WEBP", minimize_size=True, lossless=False,quality=int(qual)) _timew = time.perf_counter() - _timew _timer = time.perf_counter() ir = Image.open(webpname).convert('RGB') _timer = time.perf_counter() - _timer _rmse = rmse(img,ir) _ossize = os.path.getsize(webpname) imgs = None ]\", echo( 0 ) ); If( rc != 0, // Throw( "errore saveFrameToWebP rc=" || Char( rc ) );// , // Elenco di valutazione ({_rmse, _ossize, _timew, _timer}); // valore restituito ); ); saveFrameToPng = Function( {outputfilename, qual}, {filelist, pngname, rc}, // filelist = Transform Each( {f}, Files In Directory( gTempFiles ), // Convert File Path( gTempFiles || f, "windows" );// ); If( N Items( filelist ) != 1, // Throw( "saveFrameToPng nitems=" || Char( N Items( filelist ) ) );// ); pngname = Convert File Path( outputfilename, "windows" ); rc = Python Execute( {filelist, pngname, qual}, // input {_rmse, _ossize, _timew, _timer}, // output "\[# imgs = [] for f in filelist: imgs.append(Image.open(f).convert('RGB')) img=imgs[0] _timew = time.perf_counter() img.save(pngname,save_all=True,format="PNG", optimize=True, quality=int(qual)) _timew = time.perf_counter() - _timew _timer = time.perf_counter() ir = Image.open(pngname).convert('RGB') _timer = time.perf_counter() - _timer _rmse = rmse(img,ir) _ossize = os.path.getsize(pngname) imgs = None ]\", echo( 0 ) ); If( rc != 0, // Throw( "saveFrameToWebP error rc=" || Char( rc ) );// , // Eval List( {_rmse, _ossize, _timew, _timer} );// valore restituito ); ); saveFrameToJPG = Function( {outputfilename, qual}, {filelist, jpgname, rc}, // filelist = Transform Each( {f}, Files In Directory( gTempFiles ), // Convert File Path( gTempFiles || f, "windows" );// ); If( N Items( filelist ) != 1, // Throw( "saveFrameToJPG nitems=" || Char( N Items( filelist ) ) );// ); jpgname = Convert File Path( outputfilename, "windows" ); rc = Python Execute( {filelist, jpgname, qual}, // input {_rmse, _ossize, _timew, _timer}, // output "\[#
https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#webp imgs = [] for f in filelist: imgs.append(Image.open(f).convert('RGB')) img=imgs[0] _timew = time.perf_counter() img.save(jpgname,format="JPEG", optimize=True, quality=int(qual)) _timew = time.perf_counter() - _timew _timer = time.perf_counter() ir = Image.open(jpgname).convert('RGB') _timer = time.perf_counter() - _timer _rmse = rmse(img,ir) _ossize = os.path.getsize(jpgname) imgs = None ]\", echo( 0 ) ); If( rc != 0, // Throw( "errore saveFrameToJPG rc=" || Char( rc ) );// , // Eval List( {_rmse, _ossize, _timew, _timer} );// valore restituito ); ); // Lisafern, CC0, tramite Wikimedia Commons --
https://commons.wikimedia.org/wiki/Special:ListFiles/lisafern img = New Image( picURL ); start = HP Time(); pngSize1 = addNewFrame( "1jsl.png", img ); JSLpngTime = (HP Time() - start) / 1e6; dt = New Table( // New Column( "extension", "character" ), New Column( "size" ), New Column( "timewrite" ), New Column( "timeread" ), New Column( "rmse" ) ); dt << addrows( 1 ); extension = "JSLPng"; size = pngSize1; rmse = 0; timewrite = JSLpngTime; dt << addrows( 1 ); extension = "PILPng"; {rmse, dimensione, scrittura, lettura} = saveFrameToPng( "$temp/1.png", 95 ); Per( i = 0, i <= 100, i += 1, dt << addrows( 1 ); estensione = "WebP"; {rmse, dimensione, scrittura, lettura} = saveFrameToWebP( "$temp/1.webp", i ); Attendi( .01 ); dt << addrows( 1 ); estensione = "Jpg"; {rmse, dimensione, scrittura, lettura} = saveFrameToJpg( "$temp/1.jpg", i ); Attendi( .01 ); ); dt << Generatore di grafici (Dimensione (996, 713), Mostra pannello di controllo (0), Posizione legenda ("All'interno di Floating"), Variabili (X (:dimensione), Y (:rmse), Sovrapposizione (:estensione), Dimensione (:timewrite) ), Elementi (Punti (X, Y, Legenda (47) ) ), Invia a report (Invia ({}, "dimensione", ScaleBox, {Scala ("Log"), Formato ("SI ingegneristico", 12), Min (1e4), Max (6.1e6), Tick minori (1), Riga etichetta ({Mostra griglia principale (1), Mostra griglia secondaria (1), Mostra etichette secondarie (1)} )} ), Invio ({}, "rmse", ScaleBox, {Min (-0.5), Max (32), Inc (5), Tick minori (0)} ), Dispatch( {}, "400", ScaleBox, {Legend Model( 47, Type Properties( 0, "Marker", {Marker( "FilledCircle" )} ), Properties( 1, {Line Color( 3 ), Marker( "FilledCircle" )}, Item ID( "Jpg", 1 ) ), Properties( 2, {Line Color( 5 ), Marker( "FilledCircle" )}, Item ID( "JSLPng", 1 ) ), Properties( 3, {Line Color( 6 ), Marker( "FilledCircle" )}, Item ID( "PILPng", 1 ) ), Properties( 4, {Line Color( 8 ), Marker( "FilledCircle" )}, Item ID( "WebP", 1 ) ), Properties( -1, {Marker( "FilledSquare" )}, Item ID( "Png", 1 ) ) )} ), Dispatch( {}, "titolo grafico", TextEditBox, {Imposta testo( "WebP vs Jpg vs Png" )} ), Dispatch( {}, "dimensione", TextEditBox, {Imposta testo( "Dimensione su disco, byte" )} ), Dispatch( {}, "rmse", TextEditBox, {Imposta testo( "RMSE su 255" )} ), Dispatch( {}, "Generatore grafico", FrameBox, {Modalità di disegno del marcatore( "Normale" ), Ordine delle linee di riferimento( 6 ), Aggiungi immagine( 2, // livello 2 sopra le linee della griglia immagine( Nuova immagine( picURL ) ), Limiti( Sinistra( picLeft ), Destra( picRight ), In alto( picTop ), In basso( picBottom ) ) ), Aggiungi script grafico( 7, Descrizione( "" ), Vuoto() )} ), Dispatch( {}, "400", LegendBox, {Posizione legenda( {47, [4, 0, 3, 2, 1]} )} ) ) ); dt << Generatore di grafici (Dimensione (638, 370), Mostra pannello di controllo (0), Variabili (X (:dimensione), Y (:timeread), Sovrapposizione (:estensione)), Elementi (Punti (X, Y, Legenda (9) ) ), Invia a report (Invia ({}, "400", ScaleBox, {Modello legenda (9, Proprietà (0, {Colore linea (3)}, ID elemento ("Jpg", 1) ), Proprietà (1, {Colore linea (5)}, ID elemento ("JSLPng", 1) ), Proprietà (2, {Colore linea (6)}, ID elemento ("PILPng", 1) ), Proprietà (3, {Colore linea (8)}, ID elemento ("WebP", 1) ) )} ), Invia ({}, "400", LegendBox, {Posizione legenda( {9, [0, 3, 2, 1]} )} ) ) );