-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit; Cmd arguments parsing; Palette colors parsing;
Test pictures added;
- Loading branch information
0 parents
commit 8cfc36c
Showing
28 changed files
with
465 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,9 @@ | ||
BasedOnStyle: Mozilla | ||
IndentWidth: 4 | ||
|
||
Language: Cpp | ||
ColumnLimit: 100 | ||
AlwaysBreakAfterDefinitionReturnType: None | ||
AlwaysBreakAfterReturnType: None | ||
AccessModifierOffset: -4 | ||
BreakBeforeBraces: Allman |
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 @@ | ||
############################### | ||
# Core EditorConfig Options # | ||
############################### | ||
# You can learn more about editorconfig here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference | ||
root = true | ||
# All files | ||
[*] | ||
|
||
# Code files | ||
[*.{cpp,h}] | ||
indent_size = 4 | ||
insert_final_newline = true | ||
charset = utf-8-bom |
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,8 @@ | ||
out/ | ||
build/ | ||
.vscode/ | ||
.vs/ | ||
TestResults/ | ||
obj/ | ||
bin/ | ||
.gradle/ |
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 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
project(Dithering VERSION 1.0.0) | ||
set(CMAKE_CXX_STANDARD 20) | ||
set(CMAKE_CXX_STANDARD_REQUIRED True) | ||
|
||
include (utils.cmake) | ||
InstallAndSetupConanPackages() | ||
|
||
add_subdirectory(src) | ||
|
||
enable_testing() |
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 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "x64-Debug", | ||
"generator": "Ninja", | ||
"configurationType": "Debug", | ||
"inheritEnvironments": [ "msvc_x64_x64" ], | ||
"buildRoot": "${projectDir}\\out\\build\\${name}", | ||
"installRoot": "${projectDir}\\out\\install\\${name}", | ||
"cmakeCommandArgs": "", | ||
"buildCommandArgs": "", | ||
"ctestCommandArgs": "" | ||
}, | ||
{ | ||
"name": "x64-Release", | ||
"generator": "Ninja", | ||
"configurationType": "RelWithDebInfo", | ||
"buildRoot": "${projectDir}\\out\\build\\${name}", | ||
"installRoot": "${projectDir}\\out\\install\\${name}", | ||
"cmakeCommandArgs": "", | ||
"buildCommandArgs": "", | ||
"ctestCommandArgs": "", | ||
"inheritEnvironments": [ "msvc_x64_x64" ], | ||
"variables": [] | ||
} | ||
] | ||
} |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Danylo Lebediev | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,20 @@ | ||
# Dithering | ||
|
||
Dithering algorithm implementation. | ||
|
||
## How to use | ||
|
||
This program works as a console utility: | ||
|
||
```cmd | ||
./dithering_app MyColors.json MyPicture.png | ||
``` | ||
|
||
## License | ||
|
||
This program and sources are distributed under the MIT licence. | ||
|
||
Media resources used in this project are distributed under their respective license. | ||
|
||
Unsplash license: | ||
<https://unsplash.com/license> |
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,10 @@ | ||
[requires] | ||
glm/0.9.9.8 | ||
spdlog/1.9.2 | ||
benchmark/1.6.0 | ||
stb/cci.20210713 | ||
gtest/cci.20210126 | ||
rapidjson/cci.20211112 | ||
|
||
[generators] | ||
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,6 @@ | ||
{ | ||
"palette": [ | ||
"000000", | ||
"ffffff" | ||
] | ||
} |
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 @@ | ||
{ | ||
"version": "0.2.1", | ||
"defaults": {}, | ||
"configurations": [ | ||
{ | ||
"type": "default", | ||
"project": "CMakeLists.txt", | ||
"projectTarget": "", | ||
"name": "Make BlackWhite Cat", | ||
"args": [ "../../../../configs/BlackWhite.json", "../../../../pics/1.jpg" ] | ||
} | ||
] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
Unsplash license: | ||
https://unsplash.com/license |
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,16 @@ | ||
add_executable(dithering_app "") | ||
|
||
file (GLOB COLLECTED_SOURCES "*.cpp") | ||
target_sources(dithering_app PRIVATE | ||
${COLLECTED_SOURCES} | ||
) | ||
|
||
target_include_directories(dithering_app PRIVATE | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
) | ||
|
||
#target_link_libraries(dithering_app | ||
# dithering | ||
#) | ||
|
||
CONAN_TARGET_LINK_LIBRARIES(dithering_app) |
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,55 @@ | ||
#include "DitheringConfiguration.h" | ||
|
||
#include <iomanip> | ||
#include <sstream> | ||
|
||
namespace | ||
{ | ||
|
||
const auto PaletteObjName = "palette"; | ||
|
||
inline float toFloat(uint32_t integerColorChannel) | ||
{ | ||
return static_cast<float>(integerColorChannel) / 255.0f; | ||
} | ||
|
||
// Expects 3-component color without alpha-channel | ||
effects::Color toColor(uint32_t v) | ||
{ | ||
const uint32_t rv = (v >> 16) & 0xFF; | ||
const uint32_t gv = (v >> 8) & 0xFF; | ||
const uint32_t bv = v & 0xFF; | ||
|
||
const float r = toFloat(rv); | ||
const float g = toFloat(gv); | ||
const float b = toFloat(bv); | ||
return { r, g, b, 1.0f }; | ||
} | ||
|
||
} // namespace | ||
|
||
namespace effects | ||
{ | ||
DitheringConfiguration::DitheringConfiguration(const rapidjson::Document& configuration) | ||
{ | ||
if (configuration.HasMember(PaletteObjName)) | ||
{ | ||
const auto colors = configuration[PaletteObjName].GetArray(); | ||
m_palette.reserve(colors.Size()); | ||
for (const auto& v : colors) | ||
{ | ||
const auto colorCodeStr = v.GetString(); | ||
const auto length = v.GetStringLength(); | ||
const auto index = | ||
(length > 0 && colorCodeStr[0] == '#') ? colorCodeStr + 1 : colorCodeStr; | ||
|
||
uint32_t colorCode; | ||
std::stringstream ss; | ||
ss << std::hex << colorCodeStr; | ||
ss >> colorCode; | ||
const auto color = toColor(colorCode); | ||
m_palette.push_back(color); | ||
} | ||
} | ||
} | ||
} |
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,20 @@ | ||
#pragma once | ||
|
||
#include <glm/glm.hpp> | ||
#include <rapidjson/document.h> | ||
|
||
#include <vector> | ||
|
||
namespace effects | ||
{ | ||
using Color = glm::vec4; | ||
|
||
class DitheringConfiguration | ||
{ | ||
public: | ||
DitheringConfiguration(const rapidjson::Document& configuration); | ||
|
||
private: | ||
std::vector<Color> m_palette; | ||
}; | ||
} |
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,17 @@ | ||
#include "FloydSteinbergDithering.h" | ||
|
||
#include "Image.h" | ||
|
||
namespace effects | ||
{ | ||
FloydSteinbergDithering::FloydSteinbergDithering(DitheringConfiguration config) | ||
: m_config{ config } | ||
{ | ||
} | ||
|
||
void FloydSteinbergDithering::dither(Image& image) | ||
{ | ||
// | ||
} | ||
|
||
} |
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,18 @@ | ||
#pragma once | ||
|
||
#include "DitheringConfiguration.h" | ||
#include "Image.h" | ||
|
||
namespace effects | ||
{ | ||
class FloydSteinbergDithering | ||
{ | ||
public: | ||
FloydSteinbergDithering(DitheringConfiguration config); | ||
|
||
void dither(Image& image); | ||
|
||
private: | ||
DitheringConfiguration m_config; | ||
}; | ||
} |
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,78 @@ | ||
#include "Image.h" | ||
|
||
#if _WIN32 | ||
#define STBIW_WINDOWS_UTF8 | ||
#endif | ||
|
||
#include <stb_image.h> | ||
#include <stb_image_write.h> | ||
|
||
#include <assert.h> | ||
|
||
namespace effects | ||
{ | ||
constexpr auto TARGET_CHANNELS_COUNT = 4; | ||
|
||
Image::Image(const std::filesystem::path& path) | ||
: m_width{ 0 } | ||
, m_height{ 0 } | ||
, m_channels{ 0 } | ||
, m_data{ nullptr } | ||
{ | ||
const auto buffer = convertPath(path); | ||
if (!std::filesystem::exists(path)) | ||
{ | ||
return; | ||
} | ||
m_data = stbi_load(buffer.get(), &m_width, &m_height, &m_channels, TARGET_CHANNELS_COUNT); | ||
} | ||
|
||
Image::~Image() | ||
{ | ||
if (m_data) | ||
{ | ||
stbi_image_free(m_data); | ||
m_data = nullptr; | ||
} | ||
} | ||
|
||
int Image::width() const | ||
{ | ||
return m_width; | ||
} | ||
|
||
int Image::height() const | ||
{ | ||
return m_height; | ||
} | ||
|
||
ImageData Image::data() | ||
{ | ||
return m_data; | ||
} | ||
|
||
ImageData Image::data() const | ||
{ | ||
return m_data; | ||
} | ||
|
||
void Image::save(const std::filesystem::path& path) const | ||
{ | ||
const auto buffer = convertPath(path); | ||
stbi_write_png(buffer.get(), | ||
m_width, | ||
m_height, | ||
TARGET_CHANNELS_COUNT, | ||
m_data, | ||
m_width * TARGET_CHANNELS_COUNT); | ||
} | ||
|
||
std::shared_ptr<char[]> Image::convertPath(const std::filesystem::path& path) const | ||
{ | ||
constexpr auto BUFFER_SIZE = 4096; | ||
std::shared_ptr<char[]> buffer{ new char[BUFFER_SIZE] }; | ||
stbiw_convert_wchar_to_utf8(buffer.get(), BUFFER_SIZE, path.c_str()); | ||
return buffer; | ||
} | ||
|
||
} |
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,31 @@ | ||
#pragma once | ||
|
||
#include <filesystem> | ||
#include <memory> | ||
|
||
namespace effects | ||
{ | ||
using ImageData = unsigned char*; | ||
|
||
class Image | ||
{ | ||
public: | ||
Image(const std::filesystem::path& path); | ||
~Image(); | ||
|
||
int width() const; | ||
int height() const; | ||
ImageData data(); | ||
ImageData data() const; | ||
|
||
void save(const std::filesystem::path& path) const; | ||
|
||
private: | ||
std::shared_ptr<char[]> convertPath(const std::filesystem::path& path) const; | ||
|
||
int m_width; | ||
int m_height; | ||
int m_channels; | ||
ImageData m_data; | ||
}; | ||
} |
Oops, something went wrong.