[nostalgia] Remove NostalgiaTool library

This commit is contained in:
Gary Talent 2019-10-17 17:50:06 -05:00
parent 54ac86fce7
commit 5a0ba33b4c
7 changed files with 1 additions and 221 deletions

View File

@ -13,7 +13,7 @@ add_executable(
target_link_libraries( target_link_libraries(
nostalgia-studio nostalgia-studio
NostalgiaStudio NostalgiaStudio
NostalgiaTool NostalgiaPack
) )
if(APPLE) if(APPLE)

View File

@ -16,5 +16,4 @@ install(
) )
add_subdirectory(lib)
add_subdirectory(pack) add_subdirectory(pack)

View File

@ -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
)

View File

@ -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 <QDebug>
#include <QDir>
#include <ox/fs/fs.hpp>
#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);
}
}

View File

@ -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 <QDir>
#include <ox/fs/fs.hpp>
namespace nostalgia {
ox::Error pack(QDir src, ox::FileSystem *dest);
}

View File

@ -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 <QColor>
#include <QImage>
#include <QMap>
#include <QVector>
#include <ox/clargs/clargs.hpp>
#include <ox/fs/fs.hpp>
#include <nostalgia/core/gba/gba.hpp>
#include <nostalgia/common/point.hpp>
namespace nostalgia {
using namespace nostalgia::core;
using namespace nostalgia::common;
[[nodiscard]] uint16_t toGbaColor(QColor c) {
const auto r = static_cast<uint32_t>(c.red()) >> 3;
const auto g = static_cast<uint32_t>(c.green()) >> 3;
const auto b = static_cast<uint32_t>(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<int> countColors(QString importPath) {
QImage src(importPath);
if (!src.isNull()) {
return {{}, OxError(1)};
}
QMap<QRgb, bool> 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<QVector<uint8_t>> convertImg(QString importPath, int bpp) {
QImage src(importPath);
if (!src.isNull()) {
return {{}, OxError(1)};
}
QMap<QRgb, int> colors;
auto tileCount = (src.width() * src.height()) / 64;
const auto imgDataBuffSize = sizeof(GbaImageData) + 1 + tileCount * 64;
QVector<uint8_t> imgDataBuff(imgDataBuffSize);
memset(imgDataBuff.data(), 0, imgDataBuffSize);
GbaImageData *id = reinterpret_cast<GbaImageData*>(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());
}
}

View File

@ -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 <QString>
#include <ox/fs/fs.hpp>
namespace nostalgia {
[[nodiscard]] ox::ValErr<int> countColors(QString importPath);
ox::Error importTileSet(ox::FileSystem *fs, QString romPath, QString importPath);
}