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
42 changes: 42 additions & 0 deletions .github/workflows/linux_x64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: linux-x64

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
linux-x64:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y llvm-19 clang-format python3 python3-venv ninja-build
- name: Check installed clang
run: |
which clang++ && clang++ -v
- name: Prepare
run: |
source $GITHUB_WORKSPACE/scripts/prepare_linux_x64.sh
echo PATH=${GITHUB_WORKSPACE}/.venv/bin:$PATH >> $GITHUB_ENV
- name: Check virtual environment
run: |
which clang++ && clang++ -v
which python3 && python3 -V
which conan && conan -v
which cmake && cmake --version
- name: Configure
run: |
cmake --preset 'conan-debug'
- name: Build
run: |
make -j$(nproc) -C $GITHUB_WORKSPACE/build/Debug/
- name: Run tests
run: |
make -j$(nproc) test -C $GITHUB_WORKSPACE/build/Debug/
46 changes: 46 additions & 0 deletions .github/workflows/macos_arm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: macos-arm

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
macos-arm64:
runs-on: macos-15
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Install LLVM
run: |
brew install llvm@19
brew link --force llvm@19
echo 'export PATH="/opt/homebrew/opt/llvm@19/bin:$PATH"' >> /Users/runner/.bash_profile
source /Users/runner/.bash_profile
- name: Check installed clang
run: |
which clang++ && clang++ -v
/opt/homebrew/opt/llvm@19/bin/clang++ -v
- name: Prepare
run: |
source $GITHUB_WORKSPACE/scripts/prepare_macos_arm.sh
echo PATH=${GITHUB_WORKSPACE}/.venv/bin:$PATH >> $GITHUB_ENV
- name: Check virtual environment
run: |
which clang++ && clang++ -v
which /opt/homebrew/opt/llvm@19/bin/clang++ && /opt/homebrew/opt/llvm@19/bin/clang++ -v
which python3 && python3 -V
which conan && conan -v
which cmake && cmake --version
- name: Configure
run: |
cmake --preset 'conan-debug'
- name: Build
run: |
make -j$(sysctl -n hw.ncpu) -C $GITHUB_WORKSPACE/build/Debug/
- name: Run tests
run: |
make -j$(sysctl -n hw.ncpu) test -C $GITHUB_WORKSPACE/build/Debug/
10 changes: 5 additions & 5 deletions .github/workflows/macos.yml → .github/workflows/macos_x64.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: macos
name: macos-x64

on:
push:
Expand Down Expand Up @@ -26,12 +26,12 @@ jobs:
/usr/local/bin/clang++ -v
- name: Prepare
run: |
source $GITHUB_WORKSPACE/scripts/prepare_macos_x64_debug.sh
source $GITHUB_WORKSPACE/scripts/prepare_macos_x64.sh
echo PATH=${GITHUB_WORKSPACE}/.venv/bin:$PATH >> $GITHUB_ENV
- name: Check virtual environment
run: |
which clang++ && clang++ -v
which /usr/local/opt/llvm/bin/clang++ && /usr/local/opt/llvm/bin/clang++ -v
which /usr/local/bin/clang++ && /usr/local/bin/clang++ -v
which python3 && python3 -V
which conan && conan -v
which cmake && cmake --version
Expand All @@ -40,7 +40,7 @@ jobs:
cmake --preset 'conan-debug'
- name: Build
run: |
ninja -j$(sysctl -n hw.ncpu) -C $GITHUB_WORKSPACE/build/Debug/
make -j$(sysctl -n hw.ncpu) -C $GITHUB_WORKSPACE/build/Debug/
- name: Run tests
run: |
ninja -j$(sysctl -n hw.ncpu) test -C $GITHUB_WORKSPACE/build/Debug/
make -j$(sysctl -n hw.ncpu) test -C $GITHUB_WORKSPACE/build/Debug/
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build/
.venv/
CMakeUserPresets.json
.DS_Store
.DS_Store
cmake
22 changes: 1 addition & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.23)

project(liblena)
project(liblena_tests)
project(liblena_JPEG)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down Expand Up @@ -62,23 +61,4 @@ target_link_libraries(liblena_tests
target_compile_definitions(liblena_tests PRIVATE
RESOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}/TestsData"
)
gtest_discover_tests(liblena_tests)

# JPEG
add_executable(liblena_JPEG
${CMAKE_CURRENT_SOURCE_DIR}/Examples/JPEG.cpp
)
target_include_directories(liblena_JPEG PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/
${CMAKE_CURRENT_SOURCE_DIR}/Input
${CMAKE_CURRENT_SOURCE_DIR}/Types
${CMAKE_CURRENT_SOURCE_DIR}/Utils
${CMAKE_CURRENT_SOURCE_DIR}/JPEG
${CMAKE_CURRENT_SOURCE_DIR}/Visualization
)
target_compile_definitions(liblena_JPEG PRIVATE
RESOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}/TestsData"
)
target_link_libraries(liblena_JPEG
liblena
)
gtest_discover_tests(liblena_tests)
File renamed without changes.
41 changes: 21 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ for experiments with data compression techniques
<h3>
</h3>

[![macos](https://github.com/andarut/liblena/actions/workflows/macos.yml/badge.svg?branch=main&event=push)](https://github.com/andarut/liblena/actions/workflows/macos.yml)
[![macos-x64](https://github.com/andarut/liblena/actions/workflows/macos_x64.yml/badge.svg?branch=main&event=push)](https://github.com/andarut/liblena/actions/workflows/macos_x64.yml)
[![macos-arm](https://github.com/andarut/liblena/actions/workflows/macos_arm.yml/badge.svg?branch=main&event=push)](https://github.com/andarut/liblena/actions/workflows/macos_arm.yml)
[![linux-x64](https://github.com/andarut/liblena/actions/workflows/linux_x64.yml/badge.svg?branch=main&event=push)](https://github.com/andarut/liblena/actions/workflows/linux_x64.yml)

</div>

Expand Down Expand Up @@ -124,51 +126,50 @@ Run script for your system to **first time** building `<BUILD_TYPE>` version of
source ./scripts/prepare_<OS>_<ARCH>_<BUILD_TYPE>.sh
```

Example:
ExampleS:
```
source ./scripts/prepare_macos_x64_debug.sh
source ./scripts/prepare_macos_x64.sh
```
```
source ./scripts/prepare_macos_arm.sh
```
```
source ./scripts/prepare_linux_x64.sh
```

This script will install dependencies and link installed `cmake` into `.venv/bin/cmake`.

## Configure
FIRST SEE [Requirements](Requirements) !

From now on you can build with **cmake configs**. `conan-debug` or `conan-release` depending on your build type.
From now on you can build with **cmake configs**. Main is `conan-debug`.

```
cmake --preset 'conan-debug'
```
or
```
cmake --preset 'conan-release'
```

## Build
```
ninja -j$(nproc) -C build/Debug
```
or
```
ninja -j$(nproc) -C build/Release
make -j$(nproc) -C build/Debug
```

On macos you can use `sysctl -n hw.ncpu` instead of `nproc`. `nproc` can be installed with `brew install coreutils`.
```
ninja -j$(sysctl -n hw.ncpu) -C build/Debug
make -j$(sysctl -n hw.ncpu) -C build/Debug
```
or
```
ninja -j$(sysctl -n hw.ncpu) -C build/Release
make -j$(sysctl -n hw.ncpu) -C build/Release
```

## Run tests
Only in **debug** build:
## Run tests (this may a while)
```
ninja test -j$(nproc) -C build/Debug
make test -j$(nproc) -C build/Debug
```

## Goal for v1.0
Working JPEG (encoder and decoder)
## Run test with visualization (this may a while)
```
./build/Debug/liblena_tests
```

## Releases
9 changes: 5 additions & 4 deletions Tests/JPEG.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <gtest/gtest.h>
#include <filesystem>

#include "lena.hpp"

Expand All @@ -23,8 +24,8 @@ BitStream JPEG(const std::vector<ImageChannel<u8>>& RGB_data) {
auto YCbCr_data = RGB2YCbCr(RGB_data);

/* Downsampling */
auto Cb_downsampled = enc::downsampling(YCbCr_data[1], {4, 1, 1});
auto Cr_downsampled = enc::downsampling(YCbCr_data[2], {4, 1, 1});
auto Cb_downsampled = enc::downsampling(YCbCr_data[1], {4, 2, 2});
auto Cr_downsampled = enc::downsampling(YCbCr_data[2], {4, 2, 2});

/* MCUs */
auto Y_MCUs = enc::MCUs(YCbCr_data[0], {8, 8});
Expand Down Expand Up @@ -89,8 +90,8 @@ std::vector<ImageChannel<u8>> JPEG(BitStream& bs) {
auto Cr = dec::MCUs(Cr_IDCT_MCUs, {8, 8}, width, height);

/* Resample */
auto Cb_resampled = dec::downsampling<u8>(Cb, {4, 1, 1}, width, height);
auto Cr_resampled = dec::downsampling<u8>(Cr, {4, 1, 1}, width, height);
auto Cb_resampled = dec::downsampling<u8>(Cb, {4, 2, 2}, width, height);
auto Cr_resampled = dec::downsampling<u8>(Cr, {4, 2, 2}, width, height);

/* Color Transform */
auto RGB_data = YCbCr2RGB({Y, Cb_resampled, Cr_resampled});
Expand Down
60,202 changes: 5,071 additions & 55,131 deletions TestsData/decoded/ppm_image.ppm

Large diffs are not rendered by default.

Binary file modified TestsData/encoded/ppm_image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion TestsData/libjpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Q = 50

def encode(input_path: str, encoded_path: str):
encode_cmd = f"cjpeg -quality {Q} -baseline -dct float -sample 4x1,1x1,1x1 {input_path} > {encoded_path}"
encode_cmd = f"cjpeg -quality {Q} -baseline -dct float -sample 2x1,1x1,1x1 {input_path} > {encoded_path}"
print(f"ENCODE {encode_cmd}")
os.system(encode_cmd)

Expand Down
60,170 changes: 5,198 additions & 54,972 deletions TestsData/ppm_image.ppm

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Utils/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <cstdio>
#include <utility>
#include <cstdarg>

// #define TRUEDEBUG

Expand Down
16 changes: 10 additions & 6 deletions Utils/Timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@

#include "Utils.hpp"

struct Timer {
u64 duration;
std::chrono::steady_clock::time_point time_point;
#include <chrono>
#include <cstdint>
using u64 = std::uint64_t;

Timer() = default;
struct Timer {
u64 duration = 0;
std::chrono::high_resolution_clock::time_point time_point;

void start() {
time_point = std::chrono::high_resolution_clock::now();
}

void end() {
auto now = std::chrono::high_resolution_clock::now();
duration = std::chrono::duration_cast<std::chrono::milliseconds>(now - time_point).count();
duration = std::chrono::duration_cast<std::chrono::milliseconds>(
now - time_point
).count();
}

};


#endif // TIMER_H
2 changes: 1 addition & 1 deletion visualization/Visualization.hpp → Visualization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class Visualization {

int scale = 1;

printf("show %lld x %lld\n", chs[0].width(), chs[0].height());
printf("show %lu x %lu\n", chs[0].width(), chs[0].height());

/* Init window */
GLFWwindow* window = glfwCreateWindow(
Expand Down
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def build_requirements(self):
self.test_requires("stb/cci.20240531")

def generate(self):
tc = CMakeToolchain(self, generator="Ninja")
tc = CMakeToolchain(self, generator="Unix Makefiles")
if self.settings.build_type == "Debug":
tc.variables["CMAKE_C_FLAGS"] = "-fsanitize=address,undefined -fno-omit-frame-pointer"
tc.variables["CMAKE_CXX_FLAGS"] = "-fsanitize=address,undefined -fno-omit-frame-pointer"
Expand Down
Binary file added ppm_image.bs
Binary file not shown.
16 changes: 16 additions & 0 deletions profiles/linux_x64
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[settings]
arch=x86_64
build_type=Debug
compiler=clang
compiler.cppstd=gnu17
compiler.libcxx=libstdc++
compiler.version=16
os=Linux

[buildenv]
CC=/usr/bin/clang
CXX=/usr/bin/clang++

[conf]
tools.system.package_manager:mode = install
tools.system.package_manager:sudo = True
8 changes: 4 additions & 4 deletions profiles/mac_x64_release → profiles/mac_arm
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[settings]
arch=x86_64
build_type=Release
arch=armv8
build_type=Debug
compiler=clang
compiler.cppstd=gnu17
compiler.libcxx=libc++
compiler.version=16
os=Macos

[buildenv]
CC=/usr/local/bin/clang
CXX=/usr/local/bin/clang++
CC=/opt/homebrew/opt/llvm@19/bin/clang
CXX=/opt/homebrew/opt/llvm@19/bin/clang++
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ fi

ROOT_DIR="${SCRIPT_DIR}/.."
PROFILES_DIR="${ROOT_DIR}/profiles"
PROFILE_PATH="${PROFILES_DIR}/mac_x64_debug"
PROFILE_PATH="${PROFILES_DIR}/linux_x64"

VENV_DIR="${ROOT_DIR}/.venv"
VENV_BIN_DIR="${VENV_DIR}/bin"

# Create venv and install conan
source ${SCRIPT_DIR}/macos/install_conan.sh
source ${SCRIPT_DIR}/install_conan.sh

# Activate venv
source ${ROOT_DIR}/.venv/bin/activate
Expand Down
Loading