Start moving nost-pack into library
This commit is contained in:
parent
9a920c5a99
commit
0ec41de34e
@ -21,6 +21,7 @@ target_link_libraries(
|
|||||||
NostalgiaCommon
|
NostalgiaCommon
|
||||||
NostalgiaCore
|
NostalgiaCore
|
||||||
NostalgiaStudio
|
NostalgiaStudio
|
||||||
|
NostalgiaTool
|
||||||
)
|
)
|
||||||
|
|
||||||
install(
|
install(
|
||||||
|
@ -101,7 +101,6 @@ Qt::ItemFlags OxFSModel::flags(const QModelIndex &index) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QVariant OxFSModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
QVariant OxFSModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
||||||
return QVariant();
|
|
||||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
|
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
|
||||||
return m_rootItem->data(section);
|
return m_rootItem->data(section);
|
||||||
} else {
|
} else {
|
||||||
|
@ -23,3 +23,5 @@ install(
|
|||||||
RUNTIME DESTINATION
|
RUNTIME DESTINATION
|
||||||
bin
|
bin
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_subdirectory(lib)
|
||||||
|
33
src/nostalgia/tools/lib/CMakeLists.txt
Normal file
33
src/nostalgia/tools/lib/CMakeLists.txt
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
cmake_minimum_required(VERSION 2.8.11)
|
||||||
|
|
||||||
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
|
||||||
|
add_library(
|
||||||
|
NostalgiaTool
|
||||||
|
tilesetimport.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(
|
||||||
|
NostalgiaTool
|
||||||
|
Qt5::Widgets
|
||||||
|
OxClArgs
|
||||||
|
OxFS
|
||||||
|
OxStd
|
||||||
|
NostalgiaCommon
|
||||||
|
NostalgiaCore
|
||||||
|
)
|
||||||
|
|
||||||
|
install(
|
||||||
|
FILES
|
||||||
|
tilesetimport.hpp
|
||||||
|
DESTINATION
|
||||||
|
include/nostalgia/tools/lib
|
||||||
|
)
|
||||||
|
|
||||||
|
install(
|
||||||
|
TARGETS
|
||||||
|
NostalgiaTool
|
||||||
|
LIBRARY DESTINATION lib/ox
|
||||||
|
ARCHIVE DESTINATION lib/ox
|
||||||
|
)
|
96
src/nostalgia/tools/lib/tilesetimport.cpp
Normal file
96
src/nostalgia/tools/lib/tilesetimport.cpp
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016-2017 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 <ox/clargs/clargs.hpp>
|
||||||
|
#include <ox/fs/filesystem.hpp>
|
||||||
|
|
||||||
|
#include <nostalgia/core/gba/gba.hpp>
|
||||||
|
#include <nostalgia/common/point.hpp>
|
||||||
|
|
||||||
|
namespace nostalgia {
|
||||||
|
|
||||||
|
using namespace ox;
|
||||||
|
using namespace nostalgia::core;
|
||||||
|
using namespace nostalgia::common;
|
||||||
|
|
||||||
|
uint16_t toGbaColor(QColor c) {
|
||||||
|
auto r = ((uint32_t) c.red()) >> 3;
|
||||||
|
auto g = ((uint32_t) c.green()) >> 3;
|
||||||
|
auto b = ((uint32_t) c.blue()) >> 3;
|
||||||
|
return (r << 10) | (g << 5) | (b << 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int pointToIdx(int w, int x, int y) {
|
||||||
|
const 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
Error importTileSet(FileSystem *fs, QString romPath, QString importPath, int bpp) {
|
||||||
|
Error err = 0;
|
||||||
|
|
||||||
|
QImage src(importPath);
|
||||||
|
if (!src.isNull()) {
|
||||||
|
QMap<QRgb, int> colors;
|
||||||
|
auto tileCount = (src.width() * src.height()) / 64;
|
||||||
|
const auto imgDataBuffSize = sizeof(GbaImageData) + 1 + tileCount * 64;
|
||||||
|
uint8_t imgDataBuff[imgDataBuffSize];
|
||||||
|
memset(&imgDataBuff, 0, imgDataBuffSize);
|
||||||
|
GbaImageData *id = (GbaImageData*) imgDataBuff;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!err) {
|
||||||
|
err |= fs->write(romPath.toUtf8().data(), imgDataBuff, imgDataBuffSize);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
17
src/nostalgia/tools/lib/tilesetimport.hpp
Normal file
17
src/nostalgia/tools/lib/tilesetimport.hpp
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016-2017 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/std/types.hpp>
|
||||||
|
|
||||||
|
namespace nostalgia {
|
||||||
|
|
||||||
|
ox::Error importTileSet(FileSystem *fs, QString romPath, QString importPath, int bpp);
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user