Skip to content

Commit

Permalink
Corrected breaking bug with 2bpp or less tile formats; update to newe…
Browse files Browse the repository at this point in the history
…r support headers; lots of housekeeping and modernizations
  • Loading branch information
drojaazu committed Sep 22, 2022
1 parent 365c39e commit f28a82d
Show file tree
Hide file tree
Showing 53 changed files with 1,070 additions and 960 deletions.
30 changes: 28 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,21 +1,47 @@
Language: Cpp
BasedOnStyle: LLVM

AlignAfterOpenBracket: DontAlign
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
BreakBeforeBraces: Custom
AllowShortLoopsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: Never
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BreakConstructorInitializers: AfterColon
BreakBeforeBraces: Allman
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: AfterColon
BinPackArguments: false
BinPackParameters: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ContinuationIndentWidth: 2
Cpp11BracedListStyle: false
Language: Cpp
MaxEmptyLinesToKeep: 1
IndentCaseLabels: true
PackConstructorInitializers: Never
PointerAlignment: Middle
ReferenceAlignment: Pointer
SortIncludes: true
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: true
SpaceAroundPointerQualifiers: Both
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeParens: Never
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 2
UseTab: Always
10 changes: 10 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CompileFlags:
# Treat code as C++, use C++17 standard, enable more warnings.
Add: [-xc++, -std=c++17, -Wall]
Diagnostics:
ClangTidy:
Add: [performance*, modernize*]
Remove: [modernize-use-trailing-return-type,]
CheckOptions:
readability-identifier-naming.VariableCase: SnakeCase

3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
build/
bin/
etc/
docs/
.vscode/
.clang-format
.cache/
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ set(CMAKE_CXX_COMPILER_NAMES clang++ g++ icpc c++ cxx)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")

# chrgfx library
project(chrgfx VERSION 2.0.2 LANGUAGES CXX)
project(chrgfx VERSION 2.1.0 LANGUAGES CXX)
add_subdirectory(chrgfx)

# conversion executables
project(chr2png VERSION 1.2.0 LANGUAGES CXX)
project(chr2png VERSION 1.3.0 LANGUAGES CXX)
add_subdirectory(chr2png)
project(png2chr VERSION 1.2.1 LANGUAGES CXX)
project(png2chr VERSION 1.3.0 LANGUAGES CXX)
add_subdirectory(png2chr)

if(NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)
Expand Down
19 changes: 10 additions & 9 deletions chr2png/src/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
/*
These values should be set within CMakeLists.txt
*/
namespace APP {
static unsigned int const VERSION_MAJOR{1};
static unsigned int const VERSION_MINOR{2};
static unsigned int const VERSION_PATCH{0};
static char const * VERSION{"1.2.0"};
namespace APP
{
static unsigned int const VERSION_MAJOR { 1 };
static unsigned int const VERSION_MINOR { 3 };
static unsigned int const VERSION_PATCH { 0 };
static char const * VERSION { "1.3.0" };

static wchar_t const * NAME{L"chr2png"};
static wchar_t const * CONTACT{L"Damian R ([email protected])"};
static wchar_t const * WEBSITE{L"https://github.com/drojaazu"};
}
static wchar_t const * NAME { L"chr2png" };
static wchar_t const * CONTACT { L"Damian R ([email protected])" };
static wchar_t const * WEBSITE { L"https://github.com/drojaazu" };
} // namespace APP
#endif
19 changes: 10 additions & 9 deletions chr2png/src/app.hpp.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
/*
These values should be set within CMakeLists.txt
*/
namespace APP {
static unsigned int const VERSION_MAJOR{@PROJECT_VERSION_MAJOR@};
static unsigned int const VERSION_MINOR{@PROJECT_VERSION_MINOR@};
static unsigned int const VERSION_PATCH{@PROJECT_VERSION_PATCH@};
static char const * VERSION{"@PROJECT_VERSION@"};
namespace APP
{
static unsigned int const VERSION_MAJOR { @PROJECT_VERSION_MAJOR@ };
static unsigned int const VERSION_MINOR { @PROJECT_VERSION_MINOR@ };
static unsigned int const VERSION_PATCH { @PROJECT_VERSION_PATCH@ };
static char const * VERSION { "@PROJECT_VERSION@" };

static wchar_t const * NAME{L"@PROJECT_NAME@"};
static wchar_t const * CONTACT{L"@PROJECT_CONTACT@"};
static wchar_t const * WEBSITE{L"@PROJECT_WEBSITE@"};
}
static wchar_t const * NAME { L"@PROJECT_NAME@" };
static wchar_t const * CONTACT { L"@PROJECT_CONTACT@" };
static wchar_t const * WEBSITE { L"@PROJECT_WEBSITE@" };
} // namespace APP
#endif
54 changes: 27 additions & 27 deletions chr2png/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "chrgfx.hpp"
#include "filesys.hpp"
#include "fstreams.hpp"
#include "import_defs.hpp"
#include "parsing.hpp"
#include "shared.hpp"
Expand Down Expand Up @@ -32,20 +32,20 @@ int main(int argc, char ** argv)
*******************************************************/
#ifdef DEBUG
chrono::high_resolution_clock::time_point t1 =
chrono::high_resolution_clock::now();
chrono::high_resolution_clock::now();
#endif
process_args(argc, argv);

def_helper defs(cfg);

// see if we have good input before moving on
ifstream chrdata { ifstream_checked(cfg.chrdata_name.c_str()) };
ifstream chrdata { ifstream_checked(cfg.chrdata_name) };

#ifdef DEBUG
chrono::high_resolution_clock::time_point t2 =
chrono::high_resolution_clock::now();
chrono::high_resolution_clock::now();
auto duration =
chrono::duration_cast<chrono::milliseconds>(t2 - t1).count();
chrono::duration_cast<chrono::milliseconds>(t2 - t1).count();

cerr << "SETUP: " << duration << "ms" << endl;
cerr << "\tUsing gfxdefs file: " << cfg.gfxdefs_path << endl;
Expand All @@ -62,14 +62,13 @@ int main(int argc, char ** argv)
#endif

size_t
// byte size of one encoded tile
in_chunksize { defs.chrdef->datasize() / (size_t)8 },
// byte size of one basic (decoded) tile
out_chunksize { (size_t)(defs.chrdef->width() *
defs.chrdef->height()) };
// byte size of one encoded tile
in_chunksize { defs.chrdef->datasize() / (size_t) 8 },
// byte size of one basic (decoded) tile
out_chunksize { (size_t) (defs.chrdef->width() * defs.chrdef->height()) };

// buffer for a single encoded tile, read from the stream
char in_tile[in_chunksize];
byte_t in_tile[in_chunksize];

// basic tiles buffer
buffer<byte_t> out_buffer(0);
Expand All @@ -79,9 +78,9 @@ int main(int argc, char ** argv)
on the buffer repeatedly was a bit faster than creating a large
temporary buffer and resizing
*/
while(1)
while(true)
{
chrdata.read(in_tile, in_chunksize);
chrdata.read((char *) in_tile, in_chunksize);
if(chrdata.eof())
break;

Expand All @@ -103,16 +102,16 @@ int main(int argc, char ** argv)
#endif

palette workpal;
if(!cfg.paldata_name.empty())
if(! cfg.paldata_name.empty())
{
ifstream paldata { ifstream_checked(cfg.paldata_name.c_str()) };
ifstream paldata { ifstream_checked(cfg.paldata_name) };

size_t pal_size = defs.paldef->datasize() / 8;
byte_t palbuffer[pal_size];
paldata.read(palbuffer, pal_size);
paldata.read((char *) palbuffer, pal_size);
if(paldata.gcount() > pal_size)
throw invalid_argument(
"Input palette data too small to form a valid palette");
"Input palette data too small to form a valid palette");

workpal = decode_pal(*defs.paldef, *defs.coldef, palbuffer);
}
Expand All @@ -132,9 +131,11 @@ int main(int argc, char ** argv)
t1 = chrono::high_resolution_clock::now();
#endif

png::image<png::index_pixel> outimg { png_render(
defs.chrdef->width(), defs.chrdef->height(), out_buffer, workpal,
cfg.render_cfg) };
png::image<png::index_pixel> outimg { png_render(defs.chrdef->width(),
defs.chrdef->height(),
out_buffer,
workpal,
cfg.render_cfg) };

#ifdef DEBUG
t2 = chrono::high_resolution_clock::now();
Expand Down Expand Up @@ -182,25 +183,24 @@ void process_args(int argc, char ** argv)
long_opts.push_back({ "border", no_argument, nullptr, 'b' });
long_opts.push_back({ "row-size", required_argument, nullptr, 'r' });
long_opts.push_back({ "output", required_argument, nullptr, 'o' });
long_opts.push_back({ 0, 0, 0, 0 });
long_opts.push_back({ nullptr, 0, nullptr, 0 });

opt_details.push_back({ false, L"Path to input encoded tiles", nullptr });
opt_details.push_back({ false, L"Path to input encoded palette", nullptr });
opt_details.push_back({ false, L"Use palette transparency", nullptr });
opt_details.push_back(
{ false, L"Palette index to use for transparency", nullptr });
opt_details.push_back({ false,
L"Draw a 1 pixel border around tiles in output image",
nullptr });
{ false, L"Palette index to use for transparency", nullptr });
opt_details.push_back(
{ false, L"Number of tiles per row in output image", nullptr });
{ false, L"Draw a 1 pixel border around tiles in output image", nullptr });
opt_details.push_back(
{ false, L"Number of tiles per row in output image", nullptr });
opt_details.push_back({ false, L"Path to output PNG image", nullptr });

// read/parse arguments
while(true)
{
const auto this_opt =
getopt_long(argc, argv, short_opts.data(), long_opts.data(), nullptr);
getopt_long(argc, argv, short_opts.data(), long_opts.data(), nullptr);
if(this_opt == -1)
break;

Expand Down
12 changes: 7 additions & 5 deletions chrgfx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,26 @@ set(HEADERS
set_target_properties(chrgfx PROPERTIES PUBLIC_HEADER "${HEADERS}")

target_include_directories(chrgfx PUBLIC
"${PROJECT_SOURCE_DIR}/chrgfx/inc")
"${PROJECT_SOURCE_DIR}/chrgfx/inc")

find_library(PNG_LIB png)

if(NOT PNG_LIB)
message(FATAL_ERROR "libpng not found")
endif()

check_include_files("png++/png.hpp" PNGPP_H)

if(NOT PNGPP_H)
message(FATAL_ERROR "png++ not found")
endif()

target_compile_features(chrgfx PUBLIC cxx_std_11)
target_compile_features(chrgfx PUBLIC cxx_std_17)
target_link_libraries(chrgfx png)

install(TARGETS chrgfx
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/chrgfx)
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/chrgfx)

install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../gfxdef/gfxdefs
DESTINATION /${CMAKE_INSTALL_SYSCONFDIR}/chrgfx)
DESTINATION /${CMAKE_INSTALL_SYSCONFDIR}/chrgfx)
Loading

0 comments on commit f28a82d

Please sign in to comment.