diff --git a/.github/workflows/sirc-tiledit.yml b/.github/workflows/sirc-tiledit.yml
index 5338223..072e219 100644
--- a/.github/workflows/sirc-tiledit.yml
+++ b/.github/workflows/sirc-tiledit.yml
@@ -40,7 +40,7 @@ jobs:
ln -s $(which clang-format-18) /usr/local/bin/clang-format
- name: Install ubuntu dependencies
run: |
- sudo apt-get install catch2
+ sudo apt-get install libpng-dev
- name: Set up Python
uses: actions/setup-python@v5
with:
@@ -66,13 +66,16 @@ jobs:
- name: Test Project
run: |
cd build-debug
- meson test
+ meson test --print-errorlogs
ninja coverage-xml
- name: Archive test coverage
uses: actions/upload-artifact@v4
+ if: always()
with:
name: codecov-tiledit
- path: ./sirc-tiledit/build-debug/meson-logs/coverage.xml
+ path: |
+ ./sirc-tiledit/build-debug/meson-logs/coverage.xml
+ ./sirc-tiledit/libs/shared/tests/resources/*actual*.png
if-no-files-found: error
- name: Lint Project
run: |
diff --git a/sirc-tiledit/.clang-format b/sirc-tiledit/.clang-format
index f28c988..003550f 100644
--- a/sirc-tiledit/.clang-format
+++ b/sirc-tiledit/.clang-format
@@ -3,3 +3,7 @@
BasedOnStyle: LLVM
Language: Cpp
Standard: c++20
+
+# Stop the formatter from breaking up clang-tidy nolint comments
+CommentPragmas: '^NOLINTNEXTLINE|^NOLINTBEGIN|^NOLINTEND'
+InsertBraces: true
\ No newline at end of file
diff --git a/sirc-tiledit/.clang-format-ignore b/sirc-tiledit/.clang-format-ignore
new file mode 100644
index 0000000..3c2f9ff
--- /dev/null
+++ b/sirc-tiledit/.clang-format-ignore
@@ -0,0 +1 @@
+libs/shared/tests/catch2/*
\ No newline at end of file
diff --git a/sirc-tiledit/.clang-tidy b/sirc-tiledit/.clang-tidy
index 3ac6343..c4f1a17 100644
--- a/sirc-tiledit/.clang-tidy
+++ b/sirc-tiledit/.clang-tidy
@@ -1,5 +1,5 @@
---
-Checks: "clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,modernize-*,bugprone-*,llvm-*,performance-*,-modernize-use-trailing-return-type,-cppcoreguidelines-owning-memory,-cppcoreguidelines-pro-type-vararg,-bugprone-macro-parentheses,-llvm-header-guard"
+Checks: "clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,modernize-*,bugprone-*,llvm-*,performance-*,-modernize-use-trailing-return-type,-cppcoreguidelines-owning-memory,-cppcoreguidelines-pro-type-vararg,-bugprone-macro-parentheses,-llvm-header-guard,-readability-magic-numbers,-cppcoreguidelines-avoid-magic-numbers"
FormatStyle: llvm
CheckOptions:
cppcoreguidelines-avoid-do-while.IgnoreMacros: "true"
@@ -8,3 +8,4 @@ CheckOptions:
# cppcoreguidelines-pro-type-vararg can be useful sometimes, I'll try to use it sparingly
# bugprone-macro-parentheses because it will cause too many changes right now with all the guards for double header inclusion
# llvm-header-guard because I couldn't get auto fix to work and it is a pretty trivial rule
+# readability-magic-numbers because sometimes magic numbers are more readable, and this isn't really something I need a machine to detect
diff --git a/sirc-tiledit/.clang-tidy-ignore b/sirc-tiledit/.clang-tidy-ignore
new file mode 100644
index 0000000..3c2f9ff
--- /dev/null
+++ b/sirc-tiledit/.clang-tidy-ignore
@@ -0,0 +1 @@
+libs/shared/tests/catch2/*
\ No newline at end of file
diff --git a/sirc-tiledit/.idea/codeStyles/Project.xml b/sirc-tiledit/.idea/codeStyles/Project.xml
index 5316267..966cb05 100644
--- a/sirc-tiledit/.idea/codeStyles/Project.xml
+++ b/sirc-tiledit/.idea/codeStyles/Project.xml
@@ -102,5 +102,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/sirc-tiledit/gcovr.cfg b/sirc-tiledit/gcovr.cfg
new file mode 100644
index 0000000..e95985f
--- /dev/null
+++ b/sirc-tiledit/gcovr.cfg
@@ -0,0 +1 @@
+exclude = .*\/tests\/.*
\ No newline at end of file
diff --git a/sirc-tiledit/libs/gui/src/pixmapadapter.cpp b/sirc-tiledit/libs/gui/src/pixmapadapter.cpp
index d51245f..250d87f 100644
--- a/sirc-tiledit/libs/gui/src/pixmapadapter.cpp
+++ b/sirc-tiledit/libs/gui/src/pixmapadapter.cpp
@@ -2,7 +2,9 @@
#include "pixmapadapter.hpp"
#include "sircimage.hpp"
-u_int16_t sircColorFromQRgb(const QColor qColor) {
+#include
+
+SircColor sircColorFromQRgb(const QColor qColor) {
const unsigned int r = qColor.red() / Q_TO_SIRC_COLOR_RATIO;
const unsigned int g = qColor.green() / Q_TO_SIRC_COLOR_RATIO;
const unsigned int b = qColor.blue() / Q_TO_SIRC_COLOR_RATIO;
@@ -11,7 +13,7 @@ u_int16_t sircColorFromQRgb(const QColor qColor) {
b;
}
-QColor qRgbFromSircColor(const u_int16_t sircColor) {
+QColor qRgbFromSircColor(const SircColor sircColor) {
const unsigned int sircR =
sircColor >> SIRC_COLOR_COMPONENT_BITS * 2 & SIRC_COLOR_RANGE;
const unsigned int sircG =
@@ -29,7 +31,7 @@ QColor qRgbFromSircColor(const u_int16_t sircColor) {
SircImage PixmapAdapter::pixmapToSircImage(const QPixmap &qPixmap) {
const auto image = qPixmap.toImage();
- PackedPixelData pixelData;
+ PackedSircPixelData pixelData;
assert(image.width() >= WIDTH_PIXELS && image.height() >= HEIGHT_PIXELS);
for (int x = 0; x < WIDTH_PIXELS; x++) {
@@ -40,14 +42,14 @@ SircImage PixmapAdapter::pixmapToSircImage(const QPixmap &qPixmap) {
pixelData[x][y] = convertedPixel;
}
}
- auto sircImage = SircImage::fromPixelData(pixelData);
+ auto sircImage = MiscAdapter::packedSircPixelDataToSircImage(pixelData);
return sircImage;
}
QPixmap PixmapAdapter::sircImageToPixmap(const SircImage &sircImage) {
auto image = QImage(WIDTH_PIXELS, HEIGHT_PIXELS, QImage::Format_RGB32);
- auto [palette, pixelData] = sircImage.getImageData();
+ auto [palette, pixelData] = sircImage;
for (int x = 0; x < WIDTH_PIXELS; x++) {
for (int y = 0; y < HEIGHT_PIXELS; y++) {
@@ -65,7 +67,7 @@ QPixmap PixmapAdapter::sircImageToPixmap(const SircImage &sircImage) {
std::vector
PixmapAdapter::getPaletteColors(const SircImage &sircImage) {
auto convertedPalette = std::vector();
- const auto [palette, pixelData] = sircImage.getImageData();
+ const auto [palette, pixelData] = sircImage;
std::vector output;
std::ranges::transform(
diff --git a/sirc-tiledit/libs/shared/include/constants.hpp b/sirc-tiledit/libs/shared/include/constants.hpp
new file mode 100644
index 0000000..127d734
--- /dev/null
+++ b/sirc-tiledit/libs/shared/include/constants.hpp
@@ -0,0 +1,11 @@
+//
+// Created by Sean Dawson on 27/6/2024.
+//
+
+#ifndef CONSTANTS_HPP
+#define CONSTANTS_HPP
+
+constexpr int WIDTH_PIXELS = 256;
+constexpr int HEIGHT_PIXELS = 256;
+
+#endif // CONSTANTS_HPP
diff --git a/sirc-tiledit/libs/shared/include/imageloader.hpp b/sirc-tiledit/libs/shared/include/imageloader.hpp
new file mode 100644
index 0000000..706102e
--- /dev/null
+++ b/sirc-tiledit/libs/shared/include/imageloader.hpp
@@ -0,0 +1,27 @@
+
+#ifndef IMAGELOADER_HPP
+#define IMAGELOADER_HPP
+
+#include "constants.hpp"
+
+#include
+#include
+#include
+
+using RgbaComponent = uint8_t;
+using RgbaPixel = uint32_t;
+using RgbaPixelData =
+ std::array, WIDTH_PIXELS>;
+
+constexpr RgbaComponent RGBA_COMPONENT_MIN =
+ std::numeric_limits::min();
+constexpr RgbaComponent RGBA_COMPONENT_MAX =
+ std::numeric_limits::max();
+
+class ImageLoader {
+public:
+ static RgbaPixelData loadImageFromPng(const char *filename);
+ static void saveImageToPng(const char *filename, const RgbaPixelData &data);
+};
+
+#endif // IMAGELOADER_HPP
diff --git a/sirc-tiledit/libs/shared/include/miscadapter.hpp b/sirc-tiledit/libs/shared/include/miscadapter.hpp
new file mode 100644
index 0000000..5bbc46f
--- /dev/null
+++ b/sirc-tiledit/libs/shared/include/miscadapter.hpp
@@ -0,0 +1,13 @@
+
+#ifndef MISCADAPTER_HPP
+#define MISCADAPTER_HPP
+
+#include "sircimage.hpp"
+
+class MiscAdapter {
+public:
+ static SircImage
+ packedSircPixelDataToSircImage(const PackedSircPixelData &pixelData);
+};
+
+#endif // MISCADAPTER_HPP
diff --git a/sirc-tiledit/libs/shared/include/rgbaadapter.hpp b/sirc-tiledit/libs/shared/include/rgbaadapter.hpp
new file mode 100644
index 0000000..2a688fb
--- /dev/null
+++ b/sirc-tiledit/libs/shared/include/rgbaadapter.hpp
@@ -0,0 +1,19 @@
+#ifndef RGBAADAPTER_H
+#define RGBAADAPTER_H
+
+#include
+#include
+
+// PNGs are loaded with standard 32 bit colour RGBA (8bpp)
+constexpr unsigned int RGBA_COLOR_RANGE = 0xFF;
+constexpr unsigned int RGBA_TO_SIRC_COLOR_RATIO =
+ RGBA_COLOR_RANGE / SIRC_COLOR_RANGE;
+constexpr unsigned int RGBA_BLACK = 0x000000FF;
+
+class RgbaAdapter {
+public:
+ static SircImage rgbaToSircImage(const RgbaPixelData &pixelData);
+ static RgbaPixelData sircImageToRgba(const SircImage &sircImage);
+};
+
+#endif // RGBAADAPTER_H
diff --git a/sirc-tiledit/libs/shared/include/sircimage.hpp b/sirc-tiledit/libs/shared/include/sircimage.hpp
index c055651..99e560c 100644
--- a/sirc-tiledit/libs/shared/include/sircimage.hpp
+++ b/sirc-tiledit/libs/shared/include/sircimage.hpp
@@ -4,11 +4,10 @@
#include
#include
#include
-#include