Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: true

- name: Install dependencies (Linux)
if: runner.os == 'Linux'
Expand All @@ -31,4 +33,4 @@ jobs:
run: brew install gcc make

- name: Build
run: git clone https://github.com/libjpeg-turbo/libjpeg-turbo.git && ./build.sh build macos
run: ./build.sh build macos
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
!files/apple.jpeg
!files/orange.jpeg
!files/orange.jpeg
files/*
*.jpeg
*.jpg
Expand All @@ -15,4 +15,6 @@ installs/*
tests/test
*.dSYM*
downsampled
test
test
example.c
example
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "libjpeg-turbo"]
path = libjpeg-turbo
url = https://github.com/libjpeg-turbo/libjpeg-turbo.git
[submodule "simde"]
path = simde
url = https://github.com/simd-everywhere/simde.git
37 changes: 29 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,45 @@ cmake_minimum_required(VERSION 2.8.12...3.28)

project(NativeSticher LANGUAGES C)

set(LIBJPEG_TURBO_ROOT "${LIBJPEG_TURBO_ROOT}")
set(LIBJPEG_TURBO_ROOT "${LIBJPEG_TURBO_ROOT}")
set(LIBJPEG_TURBO_INCLUDE_DIR "${LIBJPEG_TURBO_ROOT}/include")
set(LIBJPEG_TURBO_LIB_DIR "${LIBJPEG_TURBO_ROOT}/lib")
set(LIBJPEG_TURBO_LIB_DIR "${LIBJPEG_TURBO_ROOT}/lib")
set(LIBJPEG_LIBS turbojpeg)

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
message(FATAL_ERROR "CMAKE_INSTALL_PREFIX not set. Please provide a prefix using -DCMAKE_INSTALL_PREFIX=<path>")
message(FATAL_ERROR
"CMAKE_INSTALL_PREFIX not set. "
"Please provide a prefix using -DCMAKE_INSTALL_PREFIX=<path>")
endif()


include_directories(${LIBJPEG_TURBO_INCLUDE_DIR})
include_directories(
${LIBJPEG_TURBO_INCLUDE_DIR}
${CMAKE_SOURCE_DIR}/simde
)
link_directories(${LIBJPEG_TURBO_LIB_DIR})

add_library(${PROJECT_NAME} SHARED laplace_blending.c jpeg.c utils.c)
add_library(${PROJECT_NAME} SHARED
image_operations.c
laplace_blending.c
jpeg.c
utils.c
)

target_compile_options(${PROJECT_NAME} PRIVATE -O3 -pthread)
target_link_libraries(${PROJECT_NAME} PRIVATE -pthread)
target_compile_definitions(${PROJECT_NAME} PRIVATE SIMDE_ENABLE_NATIVE_ALIASES)

target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBJPEG_LIBS})

install(TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION lib)

install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION lib)
install(DIRECTORY ${LIBJPEG_TURBO_INCLUDE_DIR}/ DESTINATION include)
install(FILES laplace_blending.h utils.h jpeg.h DESTINATION include)
install(DIRECTORY ${LIBJPEG_TURBO_INCLUDE_DIR}/
DESTINATION include)

install(FILES image_operations.h
laplace_blending.h
utils.h
jpeg.h
DESTINATION include)
28 changes: 13 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
# NativeSticher
**NativeSticher** is a C library for multiband image merging using the Laplacian blending technique.
**NativeSticher** is a C library for multiband image merging using the Laplacian blending technique.
It enables seamless blending of overlapping images, useful for applications such as panorama generation, image stitching, and exposure fusion. Only supports JPEGS for now.

---

## 🚧 Building
A helper script (`build.sh`) is included to streamline the build process for different platforms.
Use this script to build or clean the project easily.
A helper script (`build.sh`) is included to streamline the build process for different platforms.
Use this script to build or clean the project easily.

### 🔨 Build Instructions:
- **Build for macOS:**
- **Build for macOS:**
```bash
./build.sh build macos
```
- **Build for ios:**
- **Build for ios:**
```bash
./build.sh build ios
```

# 🧪 Testing
# 🧪 Testing

To verify the functionality of **NativeSticher**, follow the instructions below based on your setup.
To verify the functionality of **NativeSticher**, follow the instructions below based on your setup.

---

### 1. Testing with libturbojpeg (Direct Compilation)
If you have `libturbojpeg` installed, compile and run the test with the following command:
### 1. Testing with libturbojpeg (Direct Compilation)
If you have `libturbojpeg` installed, compile and run the test with the following command:
```bash
gcc-14 -pthread -fsanitize=address -g -o stitch \
gcc-14 -O3 -mavx2 -mfma -I simde/ -pthread -fsanitize=address -g -o stitch \
-I../ -I/usr/local/include \
-L/usr/local/lib -lturbojpeg \
stitch.c ../laplace_blending.c ../jpeg.c ../utils.c && time ./stitch
stitch.c ../laplace_blending.c ../jpeg.c ../image_operations.c ../utils.c && time ./stitch
```

### 2. Testing with Custom-Built NativeSticher Library
If you have manually built the NativeSticher library, use the following command to test it:
### 2. Testing with Custom-Built NativeSticher Library
If you have manually built the NativeSticher library, use the following command to test it:
```bash
gcc-14 -pthread -fsanitize=address -g -o stitch \
-I../installs/native-stitcher/macos/x86_64/include \
Expand All @@ -43,5 +43,3 @@ gcc-14 -pthread -fsanitize=address -g -o stitch \
-lNativeSticher stitch.c && ./stitch
```
The commands above assume a mac as working machine.


23 changes: 13 additions & 10 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -e
set -e
BUILD_DIR_LIB_TURBOJPEG=$PWD/builds/libturbojpeg
INSTALL_DIR_LIB_TURBOJPEG=$PWD/installs/libturbojpeg
BUILD_DIR_LIB_NATIVE_STITCHER=$PWD/builds/native-stitcher
Expand Down Expand Up @@ -34,6 +34,7 @@ build_macos() {
-DCMAKE_SYSTEM_PROCESSOR=$ARCH \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
-DCMAKE_C_COMPILER=$(xcrun --sdk macosx --find clang) \
-DCMAKE_OSX_SYSROOT=$(xcrun --sdk macosx --show-sdk-path) \
-DCMAKE_C_FLAGS="$TARGET_FLAG"

make -j$(sysctl -n hw.logicalcpu)
Expand All @@ -52,10 +53,12 @@ build_macos() {
-DCMAKE_SYSTEM_PROCESSOR=$ARCH \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
-DCMAKE_C_COMPILER=$(xcrun --sdk macosx --find clang) \
-DCMAKE_OSX_ARCHITECTURES=$ARCH \
-DCMAKE_OSX_SYSROOT=$(xcrun --sdk macosx --show-sdk-path) \
-DCMAKE_C_FLAGS="$TARGET_FLAG"
make -j$(sysctl -n hw.logicalcpu)
make install
popd
popd
done
}

Expand All @@ -65,7 +68,7 @@ build_android() {
BUILD_DIR="$BUILD_DIR_LIB_TURBOJPEG/andriod/$ARCH"
INSTALL_DIR="$INSTALL_DIR_LIB_TURBOJPEG/andriod/$ARCH"
mkdir -p "$BUILD_DIR"


if [ "$ARCH" == "arm64-v8a" ]; then
TARGET_FLAG="-target aarch64-linux-android21"
Expand Down Expand Up @@ -120,7 +123,7 @@ build_android() {
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
-DCMAKE_C_COMPILER=$ANDROID_NDK/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang \
-DCMAKE_C_FLAGS="$TARGET_FLAG" \
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake
make -j$(sysctl -n hw.logicalcpu)
make install
popd
Expand Down Expand Up @@ -148,7 +151,7 @@ build_ios() {
-DCMAKE_OSX_SYSROOT=${IOS_SYSROOT[0]} \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
-DCMAKE_C_COMPILER=$(xcrun --sdk iphoneos --find clang) \
-DCMAKE_C_FLAGS="$TARGET_FLAG"
-DCMAKE_C_FLAGS="$TARGET_FLAG"

make -j$(sysctl -n hw.logicalcpu)
make install
Expand All @@ -167,7 +170,7 @@ build_ios() {
-DCMAKE_OSX_SYSROOT=${IOS_SYSROOT[0]} \
-DCMAKE_C_FLAGS="-target arm64-apple-ios12.0" \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
-DCMAKE_C_COMPILER=$(xcrun --sdk iphoneos --find clang)
-DCMAKE_C_COMPILER=$(xcrun --sdk iphoneos --find clang)
make -j$(sysctl -n hw.logicalcpu)
make install
popd
Expand All @@ -193,7 +196,7 @@ build_ios_sim() {
-DCMAKE_OSX_SYSROOT=${IOS_SYSROOT[0]} \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
-DCMAKE_C_COMPILER=$(xcrun --sdk iphoneos --find clang) \
-DCMAKE_C_FLAGS="$TARGET_FLAG"
-DCMAKE_C_FLAGS="$TARGET_FLAG"

make -j$(sysctl -n hw.logicalcpu)
make install
Expand All @@ -212,7 +215,7 @@ build_ios_sim() {
-DCMAKE_OSX_SYSROOT=${IOS_SYSROOT[0]} \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
-DCMAKE_C_FLAGS="-target $ARCH-apple-ios14.0-simulator" \
-DCMAKE_C_COMPILER=$(xcrun --sdk iphonesimulator --find clang)
-DCMAKE_C_COMPILER=$(xcrun --sdk iphonesimulator --find clang)
make -j$(sysctl -n hw.logicalcpu)
make install
popd
Expand Down Expand Up @@ -269,7 +272,7 @@ case "$1" in
;;
ios-sim)
build_ios_sim
;;
;;
*)
help
;;
Expand All @@ -285,4 +288,4 @@ esac


# gcc-14 -I../ -I/usr/local/include -L/usr/local/lib -lturbojpeg -pthread -fsanitize=address -g -o downsampled ../laplace_blending.c ../jpeg.c ../utils.c downsampling.c && ./downsampled
# gcc-14 -I../ -I/usr/local/include -L/usr/local/lib -lturbojpeg -pthread -fsanitize=address -g -o stitch ../laplace_blending.c ../jpeg.c ../utils.c stitch.c && ./stitch
# gcc-14 -I../ -I/usr/local/include -L/usr/local/lib -lturbojpeg -pthread -fsanitize=address -g -o stitch ../laplace_blending.c ../jpeg.c ../utils.c stitch.c && ./stitch
8 changes: 4 additions & 4 deletions examples/downsampling.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int main()

Image *img = &img_buf1;
char buf[100];

for (int i = 0; i < 3; i++)
{
Image down = downsample(img);
Expand Down Expand Up @@ -53,11 +53,11 @@ int main()
img->width = up.width;
img->height = up.height;
}



destroy_image(&img_buf1);
destroy_image(&down);
destroy_image(&up);
destroy_image(&mask1);
}
}
Loading
Loading