diff --git a/src/nostalgia/studio/CMakeLists.txt b/src/nostalgia/studio/CMakeLists.txt index d05533a5..27234154 100644 --- a/src/nostalgia/studio/CMakeLists.txt +++ b/src/nostalgia/studio/CMakeLists.txt @@ -13,7 +13,7 @@ add_executable( target_link_libraries( nostalgia-studio NostalgiaStudio - NostalgiaTool + NostalgiaPack ) if(APPLE) diff --git a/src/nostalgia/tools/CMakeLists.txt b/src/nostalgia/tools/CMakeLists.txt index 3d1717c5..ac4eddd2 100644 --- a/src/nostalgia/tools/CMakeLists.txt +++ b/src/nostalgia/tools/CMakeLists.txt @@ -16,5 +16,4 @@ install( ) -add_subdirectory(lib) add_subdirectory(pack) diff --git a/src/nostalgia/tools/lib/CMakeLists.txt b/src/nostalgia/tools/lib/CMakeLists.txt deleted file mode 100644 index 221afc7a..00000000 --- a/src/nostalgia/tools/lib/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -set(CMAKE_INCLUDE_CURRENT_DIR ON) -set(CMAKE_AUTOMOC ON) - -add_library( - NostalgiaTool SHARED - pack.cpp - tilesetimport.cpp -) - -target_link_libraries( - NostalgiaTool PUBLIC - Qt5::Widgets - OxClArgs - OxFS - OxStd - NostalgiaCore -) - -install( - FILES - pack.hpp - tilesetimport.hpp - DESTINATION - include/nostalgia/tools/lib -) - -install( - TARGETS - NostalgiaTool - LIBRARY DESTINATION ${NOSTALGIA_DIST_LIB}/nostalgia - ARCHIVE DESTINATION ${NOSTALGIA_DIST_LIB}/nostalgia -) diff --git a/src/nostalgia/tools/lib/pack.cpp b/src/nostalgia/tools/lib/pack.cpp deleted file mode 100644 index 1a9bade2..00000000 --- a/src/nostalgia/tools/lib/pack.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2016 - 2019 gtalent2@gmail.com - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#include -#include - -#include - -#include "tilesetimport.hpp" - -namespace nostalgia { - -ox::Error pack(QDir src, ox::FileSystem *dest) { - for (auto entry : src.entryList()) { - qDebug() << entry; - oxReturnError(importTileSet(dest, entry, entry)); - } - return OxError(0); -} - -} - diff --git a/src/nostalgia/tools/lib/pack.hpp b/src/nostalgia/tools/lib/pack.hpp deleted file mode 100644 index e8b63ad7..00000000 --- a/src/nostalgia/tools/lib/pack.hpp +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2016 - 2019 gtalent2@gmail.com - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#pragma once - -#include - -#include - -namespace nostalgia { - -ox::Error pack(QDir src, ox::FileSystem *dest); - -} - diff --git a/src/nostalgia/tools/lib/tilesetimport.cpp b/src/nostalgia/tools/lib/tilesetimport.cpp deleted file mode 100644 index cab682ba..00000000 --- a/src/nostalgia/tools/lib/tilesetimport.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright 2016 - 2019 gtalent2@gmail.com - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#include -#include -#include -#include - -#include -#include - -#include -#include - -namespace nostalgia { - -using namespace nostalgia::core; -using namespace nostalgia::common; - -[[nodiscard]] uint16_t toGbaColor(QColor c) { - const auto r = static_cast(c.red()) >> 3; - const auto g = static_cast(c.green()) >> 3; - const auto b = static_cast(c.blue()) >> 3; - return (r << 10) | (g << 5) | (b << 0); -} - -[[nodiscard]] constexpr int pointToIdx(int w, int x, int y) noexcept { - constexpr auto colLength = 64; - const auto rowLength = (w / 8) * colLength; - const auto colStart = colLength * (x / 8); - const auto rowStart = rowLength * (y / 8); - const auto colOffset = x % 8; - const auto rowOffset = (y % 8) * 8; - return colStart + colOffset + rowStart + rowOffset; -} - -[[nodiscard]] ox::ValErr countColors(QString importPath) { - QImage src(importPath); - if (!src.isNull()) { - return {{}, OxError(1)}; - } - - QMap colors; - - // copy pixels as color ids - for (int x = 0; x < src.width(); x++) { - for (int y = 0; y < src.height(); y++) { - auto c = src.pixel(x, y); - // assign color a color id for the palette - if (!colors.contains(c)) { - colors[c] = true; - } - } - } - - return colors.size(); -} - -[[nodiscard]] ox::ValErr> convertImg(QString importPath, int bpp) { - QImage src(importPath); - if (!src.isNull()) { - return {{}, OxError(1)}; - } - - QMap colors; - auto tileCount = (src.width() * src.height()) / 64; - const auto imgDataBuffSize = sizeof(GbaImageData) + 1 + tileCount * 64; - QVector imgDataBuff(imgDataBuffSize); - memset(imgDataBuff.data(), 0, imgDataBuffSize); - GbaImageData *id = reinterpret_cast(imgDataBuff.data()); - id->header.bpp = bpp; - id->header.tileCount = tileCount; - int colorId = 0; - - // copy pixels as color ids - for (int x = 0; x < src.width(); x++) { - for (int y = 0; y < src.height(); y++) { - auto destI = pointToIdx(src.width(), x, y); - auto c = src.pixel(x, y); - // assign color a color id for the palette - if (!colors.contains(c)) { - colors[c] = colorId; - colorId++; - } - // set pixel color - if (bpp == 4) { - if (destI % 2) { // is odd number pixel - id->tiles[destI / 2] |= colors[c] << 4; - } else { - id->tiles[destI / 2] |= colors[c]; - } - } else { - id->tiles[destI] = colors[c]; - } - } - } - - // store colors in palette with the corresponding color id - for (auto key : colors.keys()) { - auto colorId = colors[key]; - id->pal[colorId] = toGbaColor(key); - } - - return imgDataBuff; -} - -ox::Error importTileSet(ox::FileSystem *fs, QString romPath, QString importPath) { - int colors = 0; - oxReturnError(countColors(importPath).get(&colors)); - const auto bpp = colors > 16 ? 8 : 4; - auto [imgDataBuff, err] = convertImg(importPath, bpp); - oxReturnError(err); - return fs->write(romPath.toUtf8().data(), imgDataBuff.data(), imgDataBuff.size()); -} - -} diff --git a/src/nostalgia/tools/lib/tilesetimport.hpp b/src/nostalgia/tools/lib/tilesetimport.hpp deleted file mode 100644 index 48d516a4..00000000 --- a/src/nostalgia/tools/lib/tilesetimport.hpp +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2016 - 2019 gtalent2@gmail.com - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#include - -#include - -namespace nostalgia { - -[[nodiscard]] ox::ValErr countColors(QString importPath); - -ox::Error importTileSet(ox::FileSystem *fs, QString romPath, QString importPath); - -}