-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
196 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# Pixelating images in terminal | ||
|
||
<p align="center"> | ||
<a href="https://youtu.be/blah"><img src="https://img.youtube.com/vi/blah/0.jpg" alt="Video" align="right" width=40%></a> | ||
</p> | ||
|
||
<!-- Intro --> | ||
|
||
## Formal homework definition | ||
|
||
|
||
### Prerequisites | ||
Please make sure you've done the previous homework and that you're comfortable with all lectures since that homework until this one. The [Readme](../../readme.md) is a convenient way to check this. | ||
|
||
### The expected project structure | ||
The project has to be implemented in the `homework_5` folder in your homework repository (that you can [create from this template](https://github.com/cpp-for-yourself/homeworks)). Otherwise automatic checking won't work. | ||
|
||
The project must follow the template described in the [CMake](../../lectures/cmake.md) and [GoogleTest](../../lectures/googletest.md) lectures. | ||
|
||
Here is how the structure of the project folder will look like: | ||
```bash | ||
homework_5/ | ||
└── tui_pixelator/ | ||
├── CMakeLists.txt | ||
├── external | ||
│ ├── CMakeLists.txt | ||
│ ├── stb/ # Stb library as a submodule | ||
│ ├── ftxui/ # Ftxui library as a submodule | ||
│ └── googletest/ # Googletest library as a submodule | ||
├── examples | ||
│ ├── CMakeLists.txt | ||
│ ├── pixelate.cpp | ||
├── tui_pixelator/ | ||
│ ├── test_data/ | ||
│ │ └── test.png # Test data, see below | ||
│ ├── CMakeLists.txt # Defines all libraries | ||
│ ├── pixelate.hpp | ||
│ ├── pixelate.cpp | ||
│ ├── pixelate_test.cpp | ||
│ └── # rest of your files | ||
├── .clang-format | ||
└── readme.md # Description of your project. Go nuts! | ||
``` | ||
|
||
For your convenience, I am also providing an [empty carcass](tui_pixelator) of the project that you will have to fill in with the following: | ||
- All the `CMakeLists.txt` files are empty, it is part of the task to write them | ||
- There are no header and source files present, it is part of the task to add them | ||
- The needed submodules are missing but the way to build them is present, see below for more details | ||
|
||
### Submodules and the `external` folder | ||
To add all the submodules, navigate to the `homework_5/tui_pixelator/` folder and execute the following: | ||
```bash | ||
git submodule add https://github.com/ArthurSonzogni/FTXUI.git external/ftxui | ||
git submodule add https://github.com/google/googletest.git external/googletest | ||
git submodule add https://github.com/nothings/stb.git external/stb | ||
``` | ||
<!-- TODO: actually provide the folder and link it here --> | ||
For your convenience, I am providing the rest of the `external` folder in the empty [project skeleton](tui_pixelator). | ||
|
||
### Test data | ||
We will require some test data to properly test parts of our code. This test data consists of a single image (that can be found here <!-- TODO -->) which _must_ live under the following path: `homework_5/tui_pixelator/test_data/test.png` | ||
|
||
Note that it is already in the correct place in the provided [project skeleton](tui_pixelator). | ||
|
||
### The libraries | ||
|
||
#### Namespace | ||
All functions in this project must live in the `pixelator` namespace. | ||
|
||
#### CMake targets | ||
There will be 4 libraries (more concretely, library CMake targets): | ||
- `stb_image` - A library that encapsulates the work with the external STB image library and makes using the data loaded from disk nicer | ||
- `drawer` - A library that implements a drawer - a class capable of drawing a pixelated image to the terminal | ||
- `pixelated_image` - A library that encapsulates an image that is created by the `Pixelate` function | ||
- `pixelate_image` - A library that provides the function `Pixelate` that pixelates a provided `StbImage` | ||
|
||
These libraries must all be defined in the `tui_pixelator/CMakeLists.txt` so that the binaries in the `examples` folder and the tests could be linked to those. | ||
|
||
#### Header files | ||
They also should have header files so that they can be included with: | ||
- `#include "tui_pixelator/stb_image.hpp"` | ||
- `#include "tui_pixelator/drawer.hpp"` | ||
- `#include "tui_pixelator/pixelated_image.hpp"` | ||
- `#include "tui_pixelator/pixelate.hpp"` | ||
|
||
> :bulb: Such small libraries are a bit excessive for the real world use, but we are learning how to write libraries here, so it'll do :wink: | ||
#### Expected functionality | ||
|
||
|
||
#### Tests for libraries | ||
All of the libraries must have unit tests using the `googletest` framework available as a submodule in the project's `external` folder, just like it is presented in the [Googletest](../../lectures/googletest.md) lecture. All of the tests must live in the same folder as the file that contains the code that they test and must be registered through `ctest`. | ||
|
||
For validating the right functionality, the homework checking system will inject an additional folder `validation_test` into your project and run the custom-designed tests on your code. This will show up as a separate line in the output from the homework checker in your PR and wiki. | ||
|
||
#### Example binaries | ||
|
||
|
||
## That's it! | ||
Congratulations! You've implemented this relatively complex project in relatively modern C++! On to the next challenge! Do share your thoughts on the whole process in the [discussions page](https://github.com/orgs/cpp-for-yourself/discussions/categories/general) :pray: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
Language: Cpp | ||
BasedOnStyle: Google | ||
AllowShortBlocksOnASingleLine: true | ||
AllowShortCaseLabelsOnASingleLine: true | ||
AllowShortFunctionsOnASingleLine: All | ||
AllowShortLoopsOnASingleLine: true | ||
AllowShortIfStatementsOnASingleLine: true | ||
BinPackArguments: false | ||
BinPackParameters: false | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
cmake_minimum_required(VERSION 3.16..3.24) | ||
project(tui_pixelator VERSION 1 | ||
DESCRIPTION "Pixelate images in terminal" | ||
LANGUAGES CXX) | ||
|
||
if(NOT CMAKE_BUILD_TYPE) | ||
set(CMAKE_BUILD_TYPE Release CACHE STRING "" FORCE) | ||
endif() | ||
|
||
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") | ||
|
||
# Create a pseudo-library to propagate the needed flags. | ||
add_library(cxx_setup INTERFACE) | ||
target_compile_options(cxx_setup INTERFACE -Wall -Wpedantic -Wextra) | ||
target_compile_features(cxx_setup INTERFACE cxx_std_17) | ||
target_include_directories(cxx_setup INTERFACE ${PROJECT_SOURCE_DIR}) | ||
|
||
# Update the submodules here | ||
include(external/UpdateSubmodules.cmake) | ||
|
||
# Enable testing for this project | ||
include(CTest) | ||
|
||
# Add code in subdirectories | ||
add_subdirectory(external) | ||
add_subdirectory(${PROJECT_NAME}) | ||
add_subdirectory(examples) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Add your binaries here | ||
# There must be a binary `pixelate` here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
include(gtest.cmake) | ||
include(ftxui.cmake) | ||
include(stb.cmake) |
27 changes: 27 additions & 0 deletions
27
homeworks/homework_5/tui_pixelator/external/UpdateSubmodules.cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
find_package(Git QUIET) | ||
|
||
if(GIT_FOUND) | ||
option(UPDATE_SUBMODULES "Check submodules during build" ON) | ||
|
||
if(NOT UPDATE_SUBMODULES) | ||
return() | ||
endif() | ||
|
||
execute_process(COMMAND ${GIT_EXECUTABLE} submodule | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
OUTPUT_VARIABLE EXISTING_SUBMODULES | ||
RESULT_VARIABLE RETURN_CODE) | ||
|
||
message(STATUS "Updating git submodules:\n${EXISTING_SUBMODULES}") | ||
|
||
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
RESULT_VARIABLE RETURN_CODE) | ||
|
||
if(NOT RETURN_CODE EQUAL "0") | ||
message(WARNING "Cannot update submodules. Git command failed with ${RETURN_CODE}.") | ||
return() | ||
endif() | ||
|
||
message(STATUS "Git submodules updated successfully.") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
set(CMAKE_CXX_STANDARD 17 CACHE INTERNAL "") | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON CACHE INTERNAL "") | ||
set(CMAKE_CXX_EXTENSIONS OFF CACHE INTERNAL "") | ||
add_subdirectory(ftxui) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
set(CMAKE_CXX_STANDARD 17 CACHE INTERNAL "") | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON CACHE INTERNAL "") | ||
set(CMAKE_CXX_EXTENSIONS OFF CACHE INTERNAL "") | ||
add_subdirectory(googletest) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
add_library(stb INTERFACE) | ||
target_include_directories(stb INTERFACE ${PROJECT_SOURCE_DIR}/external/) | ||
if (NOT TARGET stb::stb) | ||
add_library(stb::stb ALIAS stb) | ||
endif() |
13 changes: 13 additions & 0 deletions
13
homeworks/homework_5/tui_pixelator/tui_pixelator/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Add your libraries here | ||
# You must have the following libraries: | ||
# - stb_image | ||
# - drawer | ||
# - pixelated_image | ||
# - pixelate_image | ||
|
||
if(BUILD_TESTING) | ||
include(GoogleTest) | ||
# Add your tests executable with all your tests here | ||
# Name it tui_pixelator_tests | ||
gtest_discover_tests(tui_pixelator_tests) | ||
endif() |
Binary file added
BIN
+145 Bytes
homeworks/homework_5/tui_pixelator/tui_pixelator/test_data/test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.