Skip to content

Commit

Permalink
CMake: add android build config
Browse files Browse the repository at this point in the history
+ add missing copyright headers
+ fix README.md formatting

Change-Id: Ic01e0c4d16131db287b503c6bab99fa02f1d2e7f
  • Loading branch information
Skal committed Mar 2, 2021
1 parent 44dfae7 commit 7e32e2e
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 38 deletions.
21 changes: 13 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

cmake_minimum_required(VERSION 2.8.7)

project(sjpeg CXX)
project(sjpeg
LANGUAGES C CXX)
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 11)

# Options for coder / decoder executables.
Expand All @@ -36,15 +38,16 @@ set(PROJECT_VERSION 0.1)

################################################################################
# Android only.

if(ANDROID)
include_directories(${ANDROID_NDK}/sources/android/cpufeatures)
add_library(cpufeatures STATIC
${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c
include_directories(${SJPEG_ANDROID_NDK_PATH}/sources/android/cpufeatures)
add_library(cpufeatures
STATIC ${SJPEG_ANDROID_NDK_PATH}/sources/android/cpufeatures/cpu-features.c
)
target_link_libraries(cpufeatures dl)
set(SJPEG_DEP_LIBRARIES ${SJPEG_DEP_LIBRARIES} cpufeatures)
set(SJPEG_DEP_INCLUDE_DIRS ${SJPEG_DEP_INCLUDE_DIRS}
${ANDROID_NDK}/sources/android/cpufeatures
${SJPEG_ANDROID_NDK_PATH}/sources/android/cpufeatures
)
endif()

Expand Down Expand Up @@ -80,7 +83,7 @@ set_target_properties(sjpeg PROPERTIES POSITION_INDEPENDENT_CODE ON)

# Set the version numbers.
set_target_properties(sjpeg PROPERTIES VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION})
SOVERSION ${PROJECT_VERSION})

# Find the standard image libraries.
set(SJPEG_DEP_IMG_LIBRARIES)
Expand Down Expand Up @@ -118,9 +121,11 @@ endif()

# build the utils library
include_directories(${SJPEG_DEP_IMG_INCLUDE_DIRS})
add_library(utils ${CMAKE_CURRENT_SOURCE_DIR}/examples/utils.cc
${CMAKE_CURRENT_SOURCE_DIR}/examples/utils.h
add_library(utils
${CMAKE_CURRENT_SOURCE_DIR}/examples/utils.cc
${CMAKE_CURRENT_SOURCE_DIR}/examples/utils.h
)

if(WIN32)
# quiet warnings related to fopen, sscanf
target_compile_definitions(utils PRIVATE _CRT_SECURE_NO_WARNINGS)
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ DIST_FILES= \
NEWS \
README \
CMakeLists.txt \
cmake/android.cmake \
cmake/cpu.cmake \
cmake/sjpegConfig.cmake.in \
src/libsjpeg.pc.in \
Expand Down
21 changes: 20 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Alternatively, one can use SjpegEstimateQuality() and
sjpeg::EncoderParam::SetQuality() to pass a quality factor instead of using the
matrices.

sjpeg::EncoderParam is also useful for transfering some metadata to the final
sjpeg::EncoderParam is also useful for transferring some metadata to the final
JPEG bitstream.

* 'Riskiness' score:
Expand Down Expand Up @@ -108,6 +108,25 @@ cmake:
. `make -j`, or
. `mkdir build && cd build && cmake ../ && make -j`

* Compiling with Android NDK
****************************

The latest NDK for Android can be retrieved from the
Android download page: https://developer.android.com/ndk/downloads

Assuming the variable NDK_ROOT is positioned correctly to point
to the NDK's directory, the Android binaries can be built with:

. mkdir build && cd build
. cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/android.cmake \
-DSJPEG_ANDROID_NDK_PATH=${NDK_ROOT}
. make -j

Extra configuration option:

ANDROID_ABI: one of armeabi-v7a,armeabi-v7a with NEON,arm64-v8a,
x86,x86_64... (default is arm64-v8a)

* Discussion list
*****************

Expand Down
81 changes: 52 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
```
____ __ __ __ ____ ____ ____
/ __\__) / \ \/ _ \ / / _ \
_\_ \ (/ / __/ /_/ __/
\_____/___/__//_/\__/_/_____/_____/
(__)_/ _ \/ _ \/ .__\
_) \ __/ __/ / \
/____/__/ \_____/_____/v1.0
```

* sjpeg: 's' stands for 'simple'.
* sjpeg: 's' stands for 'simple'.

* sjpeg is a simple encoding library for encoding baseline JPEG files.
It's also a command-line tool that takes PNG or JPEG images as input
to produce JPEG files.
* sjpeg is a simple encoding library for encoding baseline JPEG files. It's
also a command-line tool that takes PNG or JPEG images as input to produce
JPEG files.

* Why 'simple'? Well, the encoder used to be one single source file. And
not a large one, moreover. Over time it grew and was split, for readability,
but the spirit remains the same.
* Why 'simple'? Well, the encoder used to be one single source file. And not a
large one, moreover. Over time it grew and was split, for readability, but
the spirit remains the same.

# The sjpeg library:

The main header is src/sjpeg.h.
This is mainly just one function to call, defined in src/sjpeg.h
The main header is src/sjpeg.h. This is mainly just one function to call,
defined in src/sjpeg.h

```
size_t SjpegCompress(const uint8_t* rgb, int width, int height,
Expand All @@ -43,31 +45,33 @@ as well as functions with a C++ string-based API.
The library comes primarily with a plain-C API, but a C++ version is available
too, that uses `std::string` as interface.

`SjpegFreeBuffer()` can be called release the buffers returned by `SjpegEncode()`
and `SjpegCompress()`.
`SjpegFreeBuffer()` can be called release the buffers returned by
`SjpegEncode()` and `SjpegCompress()`.

Also included in the library: some helper functions to inspect JPEG bitstream.
They are meant to help re-processing a JPEG source:
`SjpegDimensions()`: quickly get the JPEG picture dimensions.
`SjpegFindQuantizer()`: return the quantization matrices
`SjpegEstimateQuality()`: return an estimate of the encoding quality
They are meant to help re-processing a JPEG source: `SjpegDimensions()`: quickly
get the JPEG picture dimensions. `SjpegFindQuantizer()`: return the quantization
matrices `SjpegEstimateQuality()`: return an estimate of the encoding quality

## SjpegEncodeParam interface:

This should be the most fine-tuned use of the library: SjpegEncodeParam gives
access to a lot of fine controls (C++ only). See `src/sjpeg.h` for details.

In particular, using SjpegEncodeParam is the recommended way of re-compressing
a JPEG input. Here is the recipe:
In particular, using SjpegEncodeParam is the recommended way of re-compressing a
JPEG input. Here is the recipe:

* use `SjpegFindQuantizer` to extract the quantization matrices from the source
* use `SjpegEncodeParam::SetQuantMatrix()` to transfer them to the encoding parameters (with a reduction factor if necessary)
* call `sjpeg::SjpegEncode()` with this parameter
* use `SjpegFindQuantizer` to extract the quantization matrices from the
source
* use `SjpegEncodeParam::SetQuantMatrix()` to transfer them to the encoding
parameters (with a reduction factor if necessary)
* call `sjpeg::SjpegEncode()` with this parameter

Alternately, one can use `SjpegEstimateQuality()` and
`SjpegEncodeParam::SetQuality()` to pass a quality factor instead of the matrices.
`SjpegEncodeParam::SetQuality()` to pass a quality factor instead of the
matrices.

`SjpegEncodeParam` is also useful for transfering some metadata to the final
`SjpegEncodeParam` is also useful for transferring some metadata to the final
JPEG bitstream.

## 'Riskiness' score:
Expand All @@ -85,9 +89,9 @@ which returns a recommendation for 'yuv_mode' to use in the above API.

`examples/sjpeg` is a very simple tool to compress a PNG/JPEG file to JPEG.

`sjpeg in.png -o out.jpg -q 70 # compress the PNG source with quality 70`
`sjpeg in.png -o out.jpg -q 70 # compress the PNG source with quality 70`

`sjpeg in.jpg -o out.jpg -r 90 # recompress JPEG input to ~90% `
`sjpeg in.jpg -o out.jpg -r 90 # recompress JPEG input to ~90%`

sjpeg has various options to change the encoding method. Just try `sjpeg -h`.

Expand All @@ -104,14 +108,33 @@ from `SjpegEncodeParam` can be triggered from the keyboard.

Please read the instructions in the INSTALL file.

Basically, you can use the supplied Makefile or generate your build with
cmake:
Basically, you can use the supplied Makefile or generate your build with cmake:

* `make -j`, or
* `mkdir build && cd build && cmake ../ && make -j`

## Compiling with Android NDK

The latest NDK for Android can be retrieved from the Android
[download page](https://developer.android.com/ndk/downloads).

Assuming the variable NDK_ROOT is positioned correctly to point to the NDK's
directory, the Android binaries can be built with:

```shell
$ mkdir build && cd build
$ cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/android.cmake \
-DSJPEG_ANDROID_NDK_PATH=${NDK_ROOT}
$ make -j
```

Extra configuration option:

* `make -j`, or
* `mkdir build && cd build && cmake ../ && make -j`
* `ANDROID_ABI`: one of armeabi-v7a,armeabi-v7a with
NEON,arm64-v8a,x86,x86_64... (default is arm64-v8a)

# Discussion list

The following forum can be used to report bugs or just discuss sjpeg:

[https://groups.google.com/forum/#!forum/sjpeg]([https://groups.google.com/forum/#!forum/sjpeg)
[https://groups.google.com/forum/#!forum/sjpeg](https://groups.google.com/forum/#!forum/sjpeg)
14 changes: 14 additions & 0 deletions cmake/cpu.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2021 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

## Check for SIMD extensions.

function(sjpeg_check_compiler_flag SJPEG_SIMD_DEFINE ENABLE_SIMD)
Expand Down
15 changes: 15 additions & 0 deletions tests/test_cmd.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
#!/bin/sh
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------------

# tests for command lines

SJPEG=../examples/sjpeg
Expand Down
15 changes: 15 additions & 0 deletions tests/test_png_jpg.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
#!/bin/sh
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------------

# tests for JPEG/PNG/PPM -> JPEG -> JPEG chain

SJPEG=../examples/sjpeg
Expand Down

0 comments on commit 7e32e2e

Please sign in to comment.