Code Monkey home page Code Monkey logo

jpec's Introduction

jpec - a JPEG encoder in C

Overview

jpec is a minimalistic JPEG encoder written in C with a focus on simplicity.

It is both portable (tested on x86 and ARM) and lightweight (around 600 LOC).

The library has no external dependencies.

It is a perfect candidate if you have some embedded C code you need to extend with a JPEG encoder the easy way.

Features

The library allows you to write JPEG compressed images from input image data on memory. No more, no less.

More precisely:

  • it works in grayscale only (monochrome JPEG file): there is no support for color so far,
  • it produces baseline, DCT-based (SOF0), JFIF 1.01 (APP0) JPEG-s,
  • it supports 8x8 blocks only,
  • it includes default quantization and Huffman tables that are not customizable at runtime.

Build

Just type:

make

This produces:

  • libjpec.a: the static library,
  • jpec: a simple command-line tool used to test the library (see main.c)

NOTE the command-line tool depends on OpenCV 2 HighGUI module to easily read any kind of input image. You need to have OpenCV development libraries installed on your machine to use it (e.g. brew install opencv on Mac OS X with Homebrew).

Usage

If you want to embed the library into your own C code you are free to create the static library file, and include jpec.h main header, or to copy-paste the whole code into your project.

Then, encoding a raw image is a matter of a few lines of code:

/* Create a JPEG encoder provided image data */
jpec_enc_t *e = jpec_enc_new(img, w, h);

/* Compress */
int len;
const uint8_t *jpeg = jpec_enc_run(e, &len);

/* Do something with the JPEG blob (e.g. save into a file, etc) */

/* Release the encoder */
jpec_enc_del(e);

Authors

Maxime Brénon & Cédric Deltheil.

Copyright

Copyright (c) 2012-2016 Moodstocks SAS

jpec's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jpec's Issues

jpec_huff_encode_block simplification

in jpec_huff_encode_block:
why not:

  jpec_huff_state_t state;
  state.buffer = h->state.buffer;
  state.nbits = h->state.nbits;
  state.dc = h->state.dc;
  state.buf = buf;
  jpec_huff_encode_block_impl(block, &state);
  h->state.buffer = state.buffer;
  h->state.nbits = state.nbits;
  h->state.dc = state.dc;
  h->state.buf = state.buf;

=>

  h->state.buf = buf;
  jpec_huff_encode_block_impl(block, &h->state);

? am I missing something?

ld fails at make

Hi,

I'm getting ld error on running make on freshly cloned project.

cc -std=c99 `pkg-config --cflags --libs opencv` -Iinclude -L. -ljpec main.c -o jpec
/tmp/cczUcblb.o: In function `main':
main.c:(.text+0x1482): undefined reference to `jpec_enc_new'
main.c:(.text+0x1499): undefined reference to `jpec_enc_run'
main.c:(.text+0x14e3): undefined reference to `jpec_enc_del'
collect2: error: ld returned 1 exit status
Makefile:32: recipe for target 'jpec' failed
make: *** [jpec] Error 1

SEGV caused by a READ memory access

hi, i compile this repo with ASAN to do some test, after compiling I feed test.png in this repo and it crash.
compile command: AFL_USE_ASAN=1 make CC=afl-clang-fast LDFLAGS="-lopencv"

and here is the crash info:

AddressSanitizer:DEADLYSIGNAL

==110236==ERROR: AddressSanitizer: SEGV on unknown address 0x000000001c78 (pc 0x0000004f4d2e bp 0x7ffeb85f5cd0 sp 0x7ffeb85f5bc0 T0)
==110236==The signal is caused by a READ memory access.
    #0 0x4f4d2e in load_image /home/bupt/Desktop/jpec/main.c:69:22
    #1 0x4f49b0 in main /home/bupt/Desktop/jpec/main.c:46:20
    #2 0x7ff2c275bc86 in __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:310
    #3 0x41c759 in _start (/home/bupt/Desktop/jpec/jpec+0x41c759)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/bupt/Desktop/jpec/main.c:69:22 in load_image
==110236==ABORTING

command to reproduce the crash: ./jpec test.png
test.zip

is it some kind of bug?

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.