开发者

How to write a JPEG file decoder from scratch

开发者 https://www.devze.com 2023-03-23 23:07 出处:网络
I know there are many tools for this already. My goal is to learn. So I can read a JPEG file with fopen(), I know this is a binary file.

I know there are many tools for this already. My goal is to learn. So I can read a JPEG file with fopen(), I know this is a binary file. Then what? I know that i can learn the JPEG specifications. But it doesn't seem to tell what is the structure of the binary jpeg file.

This file contains zeros and ones How can i transform this or how can i know which chain of bits means what ?

I've come across this example: nano jpeg decoder But it's pretty hard to read the code

Thanks in advance

PS: This princeton guy h开发者_运维知识库as done a project on this which provides a good reference


This page has a lot of info on how to process a jpeg file. Also, you can take a look at my own attempt at writing a jpeg decoder in Python.

The short variable names in the program often correspond directly to variables in the standard. So if you have the standard ready, it'll help a lot. It's called ITU-1150 and is freely available on the Internet.


Jpegs are tricky if you're just starting. You need to work with huffmann tables, have some sort of fast inverse discrete cosine transform function, and the ability to interpret quantization tables.

http://en.wikipedia.org/wiki/JPEG is rather helpful.

If you want to start with something simpler, look at PNGs. The format is basically a header, followed by a bunch of variable length, chunks, and then a zlib stream. Decompressing that leaves you with almost-raw pixels, but they've been filtered. Unfiltering is easy.

0

精彩评论

暂无评论...
验证码 换一张
取 消