Skip to content

Commit 6abd091

Browse files
authored
Merge pull request #5 from nerudaj/master
Modernize CMakeLists and add CI pipelines
2 parents 9852d36 + 172db55 commit 6abd091

22 files changed

+1748
-292
lines changed

.github/workflows/CI.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
workflow_dispatch:
9+
10+
env:
11+
BUILD_DIR: ${{ github.workspace}}/vsbuild
12+
13+
jobs:
14+
build:
15+
strategy:
16+
matrix:
17+
os: [ ubuntu-latest, windows-2022 ]
18+
runs-on: ${{ matrix.os }}
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Check CMake version
24+
run: cmake --version
25+
26+
- name: Configure CMake
27+
run: |
28+
mkdir "${{ env.BUILD_DIR }}"
29+
cd "${{ env.BUILD_DIR }}"
30+
cmake ..
31+
32+
- name: Build
33+
working-directory: ${{ env.BUILD_DIR }}
34+
run: |
35+
cmake --build . --config Release
36+
37+
- name: Test
38+
working-directory: ${{ env.BUILD_DIR }}
39+
run: ctest -C Release

.github/workflows/Integration.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: IntegrationTests
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
workflow_dispatch:
9+
10+
env:
11+
IT_DIR: ${{github.workspace}}/integration_tests
12+
13+
jobs:
14+
build:
15+
runs-on: windows-2022
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Get branch names.
21+
id: branch-names
22+
uses: tj-actions/branch-names@v8
23+
24+
- name: Configure
25+
working-directory: ${{env.IT_DIR}}/cpm
26+
run: |
27+
mkdir _build
28+
cd _build
29+
cmake -D GIT_BRANCH=${{ steps.branch-names.outputs.current_branch }} ..
30+
shell: cmd
31+
32+
- name: Build
33+
working-directory: ${{env.IT_DIR}}/cpm/_build
34+
run: |
35+
cmake --build . --config Debug
36+
shell: cmd

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_build

CMakeLists.txt

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
cmake_minimum_required(VERSION 3.10)
2-
project(BitmapPlusPlus VERSION "1.1.0" DESCRIPTION "Simple and Fast header only Bitmap (BMP) C++ library" LANGUAGES CXX)
2+
3+
project(BitmapPlusPlus
4+
VERSION "1.1.0"
5+
DESCRIPTION "Simple and Fast header only Bitmap (BMP) C++ library"
6+
LANGUAGES CXX
7+
)
8+
9+
if (${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR} )
10+
set ( BUILD_EXAMPLES_DEFAULT ON )
11+
else ()
12+
set ( BUILD_EXAMPLES_DEFAULT OFF )
13+
endif ()
14+
15+
option( BPP_BUILD_EXAMPLES "Requires BPP to build all examples inside examples/ folder." ${BUILD_EXAMPLES_DEFAULT} )
16+
317
set(CMAKE_CXX_STANDARD 17)
418

5-
# Examples
6-
option(BPP_BUILD_EXAMPLES "Requires BPP to build all examples inside examples/ folder." ON)
19+
add_subdirectory( "${CMAKE_CURRENT_SOURCE_DIR}/lib" )
20+
721
if(BPP_BUILD_EXAMPLES)
8-
file(GLOB_RECURSE EXAMPLES_FILES ${CMAKE_SOURCE_DIR}/examples/*.cpp)
9-
foreach(example_file ${EXAMPLES_FILES})
10-
message(STATUS "Adding example ${example_file}")
11-
get_filename_component(target_name ${example_file} NAME_WE)
12-
include_directories(${target_name} ${CMAKE_CURRENT_SOURCE_DIR})
13-
add_executable(${target_name} ${example_file})
14-
endforeach()
22+
enable_testing()
23+
add_subdirectory( "${CMAKE_CURRENT_SOURCE_DIR}/examples" )
1524
endif()

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Simple and Fast header only Bitmap (BMP) library
44
## Bitmap Type Supported
55
- 24 Bits Per Pixel (RGB)
66

7+
## Integration
8+
9+
You can either download the header file and use it your project directly, or you can leverage CMake for this. The library can be easily integrated with FetchContent or through CPM. An example of CPM integration can be found [here](integration_tests/cpm).
10+
711
## Examples
812
<strong>Random Pixel Colors</strong>
913
<br>

examples/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
cmake_minimum_required ( VERSION 3.10 )
2+
3+
file( GLOB_RECURSE EXAMPLES_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" )
4+
5+
foreach(example_file ${EXAMPLES_FILES})
6+
message(STATUS "Adding example ${example_file}")
7+
get_filename_component(target_name ${example_file} NAME_WE)
8+
9+
add_executable(${target_name} ${example_file})
10+
target_link_libraries( ${target_name} bmp::BitmapPlusPlus )
11+
target_compile_definitions ( ${target_name} PRIVATE "ROOT_DIR=\"${PROJECT_SOURCE_DIR}\"" )
12+
target_compile_definitions ( ${target_name} PRIVATE "BIN_DIR=\"${PROJECT_BINARY_DIR}\"" )
13+
14+
add_test (
15+
NAME ${target_name}
16+
COMMAND ${target_name}
17+
)
18+
endforeach()

examples/bernoulli_dist.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,25 @@
33
#include <random>
44

55
int main() {
6-
try {
7-
// Generate a bitmap of 10% white and 90% black pixels
8-
bmp::Bitmap image(512, 512);
6+
try {
7+
// Generate a bitmap of 10% white and 90% black pixels
8+
bmp::Bitmap image(512, 512);
99

10-
std::random_device seed{};
11-
std::default_random_engine eng{seed()};
12-
std::bernoulli_distribution dist(0.10); // 10% White, 90% Black
10+
std::random_device seed{};
11+
std::default_random_engine eng{ seed() };
12+
std::bernoulli_distribution dist(0.10); // 10% White, 90% Black
1313

14-
for (bmp::Pixel &pixel: image) {
15-
const bmp::Pixel color = dist(eng) ? bmp::White : bmp::Black;
16-
pixel = color;
17-
}
14+
for (bmp::Pixel& pixel : image) {
15+
const bmp::Pixel color = dist(eng) ? bmp::White : bmp::Black;
16+
pixel = color;
17+
}
1818

19-
image.save("bernoulli.bmp");
19+
image.save(std::string(BIN_DIR) + "/bernoulli.bmp");
2020

21-
return EXIT_SUCCESS;
22-
} catch (const bmp::Exception &e) {
23-
std::cerr << "[BMP ERROR]: " << e.what() << '\n';
24-
return EXIT_FAILURE;
25-
}
21+
return EXIT_SUCCESS;
22+
}
23+
catch (const bmp::Exception& e) {
24+
std::cerr << "[BMP ERROR]: " << e.what() << '\n';
25+
return EXIT_FAILURE;
26+
}
2627
}

examples/chess_board.cpp

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,33 @@
22
#include "BitmapPlusPlus.hpp"
33

44
int main() {
5-
try {
6-
// 8x8 chess board
7-
bmp::Bitmap image(640, 640);
8-
const std::size_t board_dims = 8;
9-
const std::int32_t rect_w = image.width() / board_dims;
10-
const std::int32_t rect_h = image.height() / board_dims;
5+
try {
6+
// 8x8 chess board
7+
bmp::Bitmap image(640, 640);
8+
const std::size_t board_dims = 8;
9+
const std::int32_t rect_w = image.width() / board_dims;
10+
const std::int32_t rect_h = image.height() / board_dims;
1111

12-
// Iterate over rects
13-
bool is_white = true;
14-
for (std::size_t x = 0; x < image.width(); x += rect_w) {
15-
for (std::size_t y = 0; y < image.height(); y += rect_h) {
16-
const bmp::Pixel color = is_white ? bmp::White : bmp::Black;
17-
// Fill rect
18-
image.fill_rect(x, y, rect_w, rect_h, color);
19-
// Next rect in will be the opposite color
20-
is_white = !is_white;
21-
}
22-
is_white = !is_white;
23-
}
12+
// Iterate over rects
13+
bool is_white = true;
14+
for (std::size_t x = 0; x < image.width(); x += rect_w) {
15+
for (std::size_t y = 0; y < image.height(); y += rect_h) {
16+
const bmp::Pixel color = is_white ? bmp::White : bmp::Black;
17+
// Fill rect
18+
image.fill_rect(x, y, rect_w, rect_h, color);
19+
// Next rect in will be the opposite color
20+
is_white = !is_white;
21+
}
22+
is_white = !is_white;
23+
}
2424

25-
// Save bitmap to file
26-
image.save("chess_board.bmp");
25+
// Save bitmap to file
26+
image.save(std::string(BIN_DIR) + "/chess_board.bmp");
2727

28-
return EXIT_SUCCESS;
29-
} catch (const bmp::Exception &e) {
30-
std::cerr << "[BMP ERROR]: " << e.what() << '\n';
31-
return EXIT_FAILURE;
32-
}
28+
return EXIT_SUCCESS;
29+
}
30+
catch (const bmp::Exception& e) {
31+
std::cerr << "[BMP ERROR]: " << e.what() << '\n';
32+
return EXIT_FAILURE;
33+
}
3334
}

examples/draw_primitives.cpp

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,32 @@
44
using namespace bmp;
55

66
int main() {
7-
// Create a 512x240 blank image
8-
Bitmap image(512, 240);
9-
image.clear(Pixel(0x25292e));
10-
11-
/** Line **/
12-
// Draw a yellow line from position (250, 50) to position (500, 50)
13-
image.draw_line(250, 50, 500, 50, Yellow);
14-
15-
/** Rectangle **/
16-
// Draw a red rectangle in position (10, 10) with size 100x100
17-
image.draw_rect(10, 10, 100, 100, Red);
18-
// Draw a white filled rectangle in position (120, 10) with size 100x100
19-
image.fill_rect(120, 10, 100, 100, White);
20-
21-
/** Triangle **/
22-
image.draw_triangle(60, 120, 10, 220, 120, 220, Cyan);
23-
image.fill_triangle(180, 120, 130, 220, 245, 220, Magenta);
24-
25-
/** Circle **/
26-
// Draw a non-filled Gray circle in position (300, 170) with 50 pixels radius
27-
image.draw_circle(300, 170, 50, Gray);
28-
// Draw a filled Lime circle in position (300, 170) with 50 pixels radius
29-
image.fill_circle(420, 170, 50, Lime);
30-
31-
// Save bitmap
32-
image.save("primitives.bmp");
33-
34-
return EXIT_SUCCESS;
7+
// Create a 512x240 blank image
8+
Bitmap image(512, 240);
9+
image.clear(Pixel(0x25292e));
10+
11+
/** Line **/
12+
// Draw a yellow line from position (250, 50) to position (500, 50)
13+
image.draw_line(250, 50, 500, 50, Yellow);
14+
15+
/** Rectangle **/
16+
// Draw a red rectangle in position (10, 10) with size 100x100
17+
image.draw_rect(10, 10, 100, 100, Red);
18+
// Draw a white filled rectangle in position (120, 10) with size 100x100
19+
image.fill_rect(120, 10, 100, 100, White);
20+
21+
/** Triangle **/
22+
image.draw_triangle(60, 120, 10, 220, 120, 220, Cyan);
23+
image.fill_triangle(180, 120, 130, 220, 245, 220, Magenta);
24+
25+
/** Circle **/
26+
// Draw a non-filled Gray circle in position (300, 170) with 50 pixels radius
27+
image.draw_circle(300, 170, 50, Gray);
28+
// Draw a filled Lime circle in position (300, 170) with 50 pixels radius
29+
image.fill_circle(420, 170, 50, Lime);
30+
31+
// Save bitmap
32+
image.save(std::string(BIN_DIR) + "/primitives.bmp");
33+
34+
return EXIT_SUCCESS;
3535
}

examples/fractals/julia.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,37 @@
22
#include "color_maps.inl"
33

44
int main(void) {
5-
bmp::Bitmap image(1280, 960);
5+
bmp::Bitmap image(1280, 960);
66

7-
constexpr const std::uint16_t max_iterations = 300;
7+
constexpr const std::uint16_t max_iterations = 300;
88

9-
constexpr const double cr = -0.70000;
10-
constexpr const double ci = 0.27015;
9+
constexpr const double cr = -0.70000;
10+
constexpr const double ci = 0.27015;
1111

12-
double prevr, previ;
12+
double prevr, previ;
1313

14-
for (std::int32_t y = 0; y < image.height(); ++y) {
15-
for (std::int32_t x = 0; x < image.width(); ++x) {
16-
double nextr = 1.5 * (2.0 * x / image.width() - 1.0);
17-
double nexti = (2.0 * y / image.height() - 1.0);
14+
for (std::int32_t y = 0; y < image.height(); ++y) {
15+
for (std::int32_t x = 0; x < image.width(); ++x) {
16+
double nextr = 1.5 * (2.0 * x / image.width() - 1.0);
17+
double nexti = (2.0 * y / image.height() - 1.0);
1818

19-
for (std::uint16_t i = 0; i < max_iterations; ++i) {
20-
prevr = nextr;
21-
previ = nexti;
19+
for (std::uint16_t i = 0; i < max_iterations; ++i) {
20+
prevr = nextr;
21+
previ = nexti;
2222

23-
nextr = prevr * prevr - previ * previ + cr;
24-
nexti = 2 * prevr * previ + ci;
23+
nextr = prevr * prevr - previ * previ + cr;
24+
nexti = 2 * prevr * previ + ci;
2525

26-
if (((nextr * nextr) + (nexti * nexti)) > 4) {
27-
const bmp::Pixel color = hsv_colormap[static_cast<std::size_t>((1000.0 * i) / max_iterations)];
28-
image.set(x, y, color);
29-
break;
30-
}
31-
}
32-
}
33-
}
26+
if (((nextr * nextr) + (nexti * nexti)) > 4) {
27+
const bmp::Pixel color = hsv_colormap[static_cast<std::size_t>((1000.0 * i) / max_iterations)];
28+
image.set(x, y, color);
29+
break;
30+
}
31+
}
32+
}
33+
}
3434

35-
image.save("julia.bmp");
35+
image.save(std::string(BIN_DIR) + "/julia.bmp");
3636

37-
return EXIT_SUCCESS;
37+
return EXIT_SUCCESS;
3838
}

0 commit comments

Comments
 (0)