Giter Club home page Giter Club logo

jpeg.c's Introduction

jpeg.c

JPEG specs

Only JPEG Baseline is implemented. Basic support for restart markers.

Some test images: https://www.w3.org/MarkUp/Test/xhtml-print/20050519/tests/A_2_1-BF-01.htm

  • In general, to ensure safe decoding, we need to do quite a lot of checks i.e. make sure resources, like Huffman tables, are initialized before use, the values are within expected range (otherwise we might index out of bounds).
  • JPEG/JFIF does not limit the range of values for component identifier. It is 1 byte, so theoretically the possible values are [0, 255]. Most proper JPEGs use 1, 2, 3 for RGB, but a few, like https://www.w3.org/MarkUp/Test/xhtml-print/20050519/tests/jpeg444.jpg, use 0, 1, 2 instead. Note that the standard says decoders only need to support up to 4 components in a scan (Adobe standard with APP13 or APP14 markers may interpret 4 components as CMYK).
  • The standard does not specify how to reverse chroma-subsampling i.e. upsample subsampled components. A reasonable choice would be a bilinear filter. In this repo, I just repeat the data i.e. nearest neighbor upsampling. Also note on the alignment (JFIF page 4) i.e. point sampling.
  • Many silent bugs in C are due to out of bounds access i.e. buffer overflow. Simply add -fsanitize=address to the compiler to check for those bugs.

Build

Linux and MacOS

make test_all

Windows

cl test.c jpeg.c && ./test sample.jpg

Decode flow

Check Figure E6-E10 of ITU-T.81

Most basic: Baseline JPEG, no restart.

graph LR
  SOI-->Metadata
  Metadata-->Tables
  Tables-->SOF
  SOF-->SOS
  SOS-->EOI

  Metadata["Metadata\n(e.g. APP0 - JFIF, Exif)"]
  Tables["Tables\n(Huffman and Quantization)"]
Loading

jpeg.c's People

Contributors

gau-nernst avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.