Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
Image Compression
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nathaniel Callens
Image Compression
Commits
a7135ce7
Commit
a7135ce7
authored
Mar 08, 2022
by
Nathaniel Callens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete adaptive_arithmetic_compress.py
parent
328d8ed8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
57 deletions
+0
-57
adaptive_arithmetic_compress.py
adaptive_arithmetic_compress.py
+0
-57
No files found.
adaptive_arithmetic_compress.py
deleted
100644 → 0
View file @
328d8ed8
#
# Compression application using adaptive arithmetic coding
#
# Usage: python adaptive-arithmetic-compress.py InputFile OutputFile
# Then use the corresponding adaptive-arithmetic-decompress.py application to recreate the original input file.
# Note that the application starts with a flat frequency table of 257 symbols (all set to a frequency of 1),
# and updates it after each byte encoded. The corresponding decompressor program also starts with a flat
# frequency table and updates it after each byte decoded. It is by design that the compressor and
# decompressor have synchronized states, so that the data can be decompressed properly.
#
# Copyright (c) Project Nayuki
#
# https://www.nayuki.io/page/reference-arithmetic-coding
# https://github.com/nayuki/Reference-arithmetic-coding
#
import
sys
import
arithmeticcoding
python3
=
sys
.
version_info
.
major
>=
3
# Command line main application function.
def
main
(
args
):
# Handle command line arguments
if
len
(
args
)
!=
2
:
sys
.
exit
(
"Usage: python adaptive-arithmetic-compress.py InputFile OutputFile"
)
inputfile
=
args
[
0
]
outputfile
=
args
[
1
]
# Perform file compression
with
open
(
inputfile
,
"rb"
)
as
inp
:
bitout
=
arithmeticcoding
.
BitOutputStream
(
open
(
outputfile
,
"wb"
))
try
:
compress
(
inp
,
bitout
)
finally
:
bitout
.
close
()
def
compress
(
inp
,
bitout
):
initfreqs
=
arithmeticcoding
.
FlatFrequencyTable
(
257
)
freqs
=
arithmeticcoding
.
SimpleFrequencyTable
(
initfreqs
)
enc
=
arithmeticcoding
.
ArithmeticEncoder
(
bitout
)
while
True
:
# Read and encode one byte
symbol
=
inp
.
read
(
1
)
if
len
(
symbol
)
==
0
:
break
symbol
=
symbol
[
0
]
if
python3
else
ord
(
symbol
)
enc
.
write
(
freqs
,
symbol
)
freqs
.
increment
(
symbol
)
enc
.
write
(
freqs
,
256
)
# EOF
enc
.
finish
()
# Flush remaining code bits
# Main launcher
if
__name__
==
"__main__"
:
main
(
sys
.
argv
[
1
:
])
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment