PackJPG library » History » Version 1
Anonymous, 12/19/2021 04:43 PM
adding original page
| 1 | 1 | h1. packJPG Library Project |
|
|---|---|---|---|
| 2 | |||
| 3 | "packJPG":https://github.com/packjpg/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. |
||
| 4 | |||
| 5 | h2. Initial Steps |
||
| 6 | |||
| 7 | 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. |
||
| 8 | |||
| 9 | # Get the source: |
||
| 10 | <pre> |
||
| 11 | $ git clone https://github.com/packjpg/packJPG.git |
||
| 12 | </pre> |
||
| 13 | # Make a new directory to hold the modified source: |
||
| 14 | <pre> |
||
| 15 | $ cd packJPG |
||
| 16 | $ mkdir lib_src |
||
| 17 | </pre> |
||
| 18 | # Install "unifdef":https://linux.die.net/man/1/unifdef if needed: |
||
| 19 | <pre> |
||
| 20 | $ sudo apt install unifdef |
||
| 21 | </pre> |
||
| 22 | # 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: |
||
| 23 | <pre> |
||
| 24 | $ cd source; for f in *.h; do echo $f; unifdef -DBUILD_LIB $f > ../lib_src/$f; done; cd .. |
||
| 25 | $ cd source; for f in *.cpp; do echo $f; unifdef -DBUILD_LIB $f > ../lib_src/$f; done; cd .. |
||
| 26 | </pre> |
||
| 27 | # Build project, everything should build at this point. |
||
| 28 | ** Create @CMakeLists.txt@ file in @lib_src@: |
||
| 29 | <pre> |
||
| 30 | project("packJPG") |
||
| 31 | cmake_minimum_required(VERSION 3.2) |
||
| 32 | |||
| 33 | include_directories(.) |
||
| 34 | |||
| 35 | set(packjpg_sources |
||
| 36 | ../aricoder.cpp |
||
| 37 | ../bitops.cpp |
||
| 38 | ../packjpg.cpp |
||
| 39 | ) |
||
| 40 | |||
| 41 | add_definitions("-std=c++14 -O3 -Wall -pedantic") |
||
| 42 | add_definitions("-funroll-loops -ffast-math -fomit-frame-pointer") |
||
| 43 | add_definitions("-march=native") |
||
| 44 | |||
| 45 | add_library(packjpg SHARED |
||
| 46 | ${packjpg_sources}) |
||
| 47 | |||
| 48 | </pre> |
||
| 49 | ** Then create build directory and build: |
||
| 50 | <pre> |
||
| 51 | $ mkdir build |
||
| 52 | $ cd build |
||
| 53 | $ cmake .. |
||
| 54 | $ make -j16 |
||
| 55 | </pre> |
||
| 56 | # Remove weird #defines (make sure code still compiles afterwards): |
||
| 57 | <pre> |
||
| 58 | $ sed -i 's/EXPORT //g' *.cpp |
||
| 59 | $ sed -i 's/INTERN //g' *.cpp |
||
| 60 | </pre> |
||
| 61 | # *[optional]* Reformat code for sanity using @astyle@ tool: |
||
| 62 | <pre> |
||
| 63 | $ astyle -A1s4SHUk1jcz2 -n *.cpp *.h |
||
| 64 | </pre> |