Project

General

Profile

Actions

packJPG Library Project

packJPG is this awesome piece of compression software that I found a while back. It works very well but its main downside is that it does not support building a proper shared library that can be used to process multiple files concurrently (top level code is not object oriented and contains a ton of global variables). The goal of this project is to modify/wrap the code such that a proper shared library can be built and used in concurrent fashion.

Initial Steps

Below are the initial steps required to prepare the source for wrapping. These steps have been done in the software/packJPG_library directory of the repository so these steps are mainly for reference.

  1. Get the source:
    $ git clone https://github.com/packjpg/packJPG.git
    
  2. Make a new directory to hold the modified source:
    $ cd packJPG
    $ mkdir lib_src
    
  3. Install unifdef if needed:
    $ sudo apt install unifdef
    
  4. Now use unifdef to expand the `BUILD_LIB` define (thereby getting rid of a lot of code) and write the modified files to the `lib_src` directory:
    $ cd source; for f in *.h; do echo $f; unifdef -DBUILD_LIB $f > ../lib_src/$f; done; cd ..
    $ cd source; for f in *.cpp; do echo $f; unifdef -DBUILD_LIB $f > ../lib_src/$f; done; cd ..
    
  5. Build project, everything should build at this point.
    • Create CMakeLists.txt file in lib_src:
      project("packJPG")
      cmake_minimum_required(VERSION 3.2)
      
      include_directories(.)
      
      set(packjpg_sources
          ../aricoder.cpp
          ../bitops.cpp
          ../packjpg.cpp
      )
      
      add_definitions("-std=c++14 -O3 -Wall -pedantic")
      add_definitions("-funroll-loops -ffast-math -fomit-frame-pointer")
      add_definitions("-march=native")
      
      add_library(packjpg SHARED
          ${packjpg_sources})
      
      
    • Then create build directory and build:
      $ mkdir build
      $ cd build
      $ cmake ..
      $ make -j16
      
  6. Remove weird #defines (make sure code still compiles afterwards):
    $ sed -i 's/EXPORT //g' *.cpp
    $ sed -i 's/INTERN //g' *.cpp
    
  7. [optional] Reformat code for sanity using astyle tool:
    $ astyle -A1s4SHUk1jcz2 -n *.cpp *.h
    

Updated by over 4 years ago · 1 revisions