rayrobdod / png-inflate Goto Github PK
View Code? Open in Web Editor NEWA clean filter for git that decompresses png images
License: Apache License 2.0
A clean filter for git that decompresses png images
License: Apache License 2.0
For two purposes: first to avoid data loss when given an invalid PNG file (the file is already corrupt so what data is there to loose, but still), and because IEND is not the last chunk of an MNG file.
This probably involves detecting where an EOF is in ::png::Chunk::read and telling the difference between "there is no chunk to read" and "read an incomplete chunk"
MNG has a very similar format to PNG - just with additional chunks and a different magic number.
If the program output is to a file, a file already exists at that location, and the program output is smaller than the existing file contents, then the output file is not shrunk, and the file contains garbage data at the end.
Options:
File::set_len
. Would have to be done at the end of the program, and need to be a special case when closing a file (whereas all current special casing is when opening the file)(using a deconstructor, maybe?)APNG is an extension to PNG adding several non-standard chunks (although the current w3c editor's draft of the PNG spec mentions the APNG chunks)
Although encoders and decoders should treat the length as unsigned, its value shall not exceed 231-1 bytes.
-- the PNG spec (Second Edition)
IDAT
(or fdAT
- but this would require renumbering all the APNG chunks, which is the same problem as merging adjacent fdATs
) can be split;
Chunk
struct could hold data that is illegal to write - which can already happen through the ConcatinateIdats
step, or theoretically since Chunk
doesn't currently encapsulate its typ
field. Being idiomatic would probably require forcing Chunk
to always be a valid-to-write chunk. (have separate png-legal Chunk and a not-neccessarily-legal Chunk types? seems overengineered). And this would require adding a SplitIdats
step.zTXT
, iCCP
or iTXT
would be unrecoverable. Those chunks can't be split with a preserved meaning, and an algorithm to inflate as much as possible without going over 2MB is not worth the time or effort.Also, might want to be able to integration-test this without having to commit a 2MB file into the source repository. Which would mean having to let the derive crate generate files in addition to listing existing paths.
I mean, that is the only practical use of this I've thought of so far.
Remember to disable the computer's sleep mode before trying this again.
Maybe also compare against a tree-filter that recompresses with pngout, or one that uses both pngout and this.
https://github.com/eliatlarge/FEMultiPlayer-V2 and https://github.com/thatswhatyouget/tpp-progress are probably two repositories with a lot of images (even if the images are dwarfed by the music files and generated js files respectively), but their images are all poorly compressed anyway. Maybe one of the pret ones.
#! powershell -File
$CACHE=$env:TMP + '\.hash_inflate\'
$FILTER='C:\Users\Raymond\AppData\Local\Temp\rust\release\png_inflate.exe'
ForEach ($file in $args) {
$hash = $(Get-FileHash -LiteralPath $file).Hash
$hashpath = $($CACHE + $hash)
if ($(Test-Path -LiteralPath $hashpath)) {
Copy-Item -LiteralPath $hashpath -Destination $file -Force
} else {
&"$PNG_FILTER" $file $hashpath
Copy-Item -LiteralPath $hashpath -Destination $file -Force
}
}
Set-ExecutionPolicy Unrestricted -Scope Process
cd $env:TMP
git clone https://github.com/thatswhatyouget/tpp-progress.git tpp-progress6
cd tpp-progress6
&git filter-branch --tree-filter "find -name '*.png' -exec C:/Users/Raymond/AppData/Local/Temp/filter.ps1 {} +"
cd ..
git clone file://C:/Users/Raymond/AppData/Local/Temp/tpp-progress6 tpp-progress7
# Then check the sizes of the `.git` drectories of a fresh clone of the original repository with the newly produced one
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.