Skip to content

fangwei123456/python-jpeg-encoder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

python-jpeg-encoder

A jpeg encoder written in python. It can encode a BMP image file to a JPEG file. A jpeg decoder written in python is not needed because the encoder will create a standardized JPEG file, which can be opened with any picture viewer.

Usage:

python jpegEncoder.py inputBMPFileName outputJPEGFileName quality(from 1 to 100) debugMode(0 or 1)

Example:

python ./jpegEncoder.py ./lena.bmp ./output.jpg 95 0

More information:

If debugMode is 1, you will get more details about encoding process.

For example, run jpegEncoder.py by:

python ./jpegEncoder.py ./8x8.bmp ./output.jpg 95 1

And you will get:

srcImageWidth = 8 srcImageHeight = 8
srcImage info:
<PIL.BmpImagePlugin.BmpImageFile image mode=RGB size=8x8 at 0x7F9E8AD4F908>
added to: 8 8
yImageMatrix:
[[255 255 255 255 255 255 255 255]
[255 255 255 255 255 255 255 255]
[255 255 255 255 255 255 255 255]
[255 255 255 255 255 255 255 255]
[255 255 255 255 255 255 255 255]
[255 255 255 255 255 255 255 255]
[255 255 255 255 255 255 255 255]
[255 255 255 255 255 255 255 255]]
uImageMatrix:
[[128 128 128 128 128 128 128 128]
[128 128 128 128 128 128 128 128]
[128 128 128 128 128 128 128 128]
[128 128 128 128 128 128 128 128]
[128 128 128 128 128 128 128 128]
[128 128 128 128 128 128 128 128]
[128 128 128 128 128 128 128 128]
[128 128 128 128 128 128 128 128]]
vImageMatrix:
[[128 128 128 128 128 128 128 128]
[128 128 128 128 128 128 128 128]
[128 128 128 128 128 128 128 128]
[128 128 128 128 128 128 128 128]
[128 128 128 128 128 128 128 128]
[128 128 128 128 128 128 128 128]
[128 128 128 128 128 128 128 128]
[128 128 128 128 128 128 128 128]]
luminanceQuantTbl:
[[ 2 1 1 2 2 4 5 6]
[ 1 1 1 2 3 6 6 6]
[ 1 1 2 2 4 6 7 6]
[ 1 2 2 3 5 9 8 6]
[ 2 2 4 6 7 11 10 8]
[ 2 4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3 4 code= [1, 0, 1] [1, 0, 0]
encode vAC: [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
EOB [0, 1]

Releases

No releases published

Packages

No packages published

Languages