diff --git a/src/nostalgia/core/studio/imgconv.cpp b/src/nostalgia/core/studio/imgconv.cpp deleted file mode 100644 index 3cf53b3e..00000000 --- a/src/nostalgia/core/studio/imgconv.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. - */ - -#include -#include -#include - -#include - -#include "imgconv.hpp" - -namespace nostalgia::core { - -[[nodiscard]] -static 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; - const auto a = static_cast(c.alpha() > 128 ? 1 : 0); - return (a << 15) | (r << 10) | (g << 5) | (b << 0); -} - -[[nodiscard]] -static int countColors(const QImage &img, int argTiles) { - QMap colors; - // copy pixels as color ids - for (int x = 0; x < img.width(); x++) { - for (int y = 0; y < img.height(); y++) { - auto destI = pointToIdx(img.width(), x, y); - if (destI <= argTiles * PixelsPerTile) { - auto c = img.pixel(x, y); - // assign color a color id for the palette - if (!colors.contains(c)) { - colors[c] = true; - } - } - } - } - return colors.size(); -} - -[[nodiscard]] -ox::UniquePtr imgToNg(QString argSrc, int argBpp) { - QImage src(argSrc); - - if (src.isNull()) { - return {}; - } - - const auto Pixels = src.width() * src.height(); - const auto Tiles = Pixels / PixelsPerTile; - const auto Colors = countColors(src, Tiles); - if (argBpp != 4 && argBpp != 8) { - argBpp = Colors > 16 ? 8 : 4; - } - - QMap colors; - auto ng = std::make_unique(); - ng->pal.colors.resize(static_cast(countColors(src, Tiles))); - if (argBpp == 4) { - ng->pixels.resize(static_cast(Pixels / 2)); - } else { - ng->pixels.resize(static_cast(Pixels)); - } - ng->bpp = argBpp; - ng->columns = src.width() / TileWidth; - ng->rows = src.height() / TileHeight; - - int colorIdx = 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); - if (destI < Tiles * PixelsPerTile) { - const auto c = src.pixel(x, y); - // assign color a color id for the palette - if (!colors.contains(c)) { - colors[c] = colorIdx; - colorIdx++; - } - // set pixel color - if (argBpp == 4) { - if (destI % 2) { // is odd number pixel - ng->pixels[static_cast(destI / 2)] |= colors[c] << 4; - } else { - ng->pixels[static_cast(destI / 2)] |= colors[c]; - } - } else { - ng->pixels[static_cast(destI)] = static_cast(colors[c]); - } - } - } - } - - // store colors in palette with the corresponding color id - for (auto key : colors.keys()) { - auto colorId = static_cast(colors[key]); - ng->pal.colors[colorId] = toGbaColor(key); - } - - return ng; -} - -} diff --git a/src/nostalgia/core/studio/imgconv.hpp b/src/nostalgia/core/studio/imgconv.hpp deleted file mode 100644 index a04e8366..00000000 --- a/src/nostalgia/core/studio/imgconv.hpp +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. - */ - -#pragma once - -#include -#include - -#include - -#include - -namespace nostalgia::core { - -[[nodiscard]] -ox::UniquePtr imgToNg(ox::String argInPath, int argBpp = -1); - -} diff --git a/src/nostalgia/core/studio/import_tilesheet_wizard.cpp b/src/nostalgia/core/studio/import_tilesheet_wizard.cpp deleted file mode 100644 index a044e62d..00000000 --- a/src/nostalgia/core/studio/import_tilesheet_wizard.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. - */ - -#include -#include -#include - -#include - -#include "imgconv.hpp" -#include "import_tilesheet_wizard.hpp" - -namespace nostalgia::core { - -ImportTilesheetWizardMainPage::ImportTilesheetWizardMainPage(const studio::Context *ctx) { - m_ctx = ctx; - addLineEdit(tr("&Tile Sheet Name:"), QString(TileSheetName) + "*", "", [this](QString) { - auto importPath = field(ImportPath).toString(); - if (QFile(importPath).exists()) { - return 0; - } else { - this->showValidationError(tr("Invalid image file: %1").arg(importPath)); - return 1; - } - } - ); - auto fileTypes = "(*.png);;(*.bmp);;(*.jpg);;(*.jpeg)"; - addPathBrowse(tr("Tile Sheet &Path:"), QString(ImportPath) + "*", "", - QFileDialog::ExistingFile, fileTypes); -} - -ImportTilesheetWizardPalettePage::ImportTilesheetWizardPalettePage(const studio::Context *ctx) { - m_ctx = ctx; - addLineEdit(tr("Palette &Name:"), PaletteName); -} - -int ImportTilesheetWizardPalettePage::accept() { - const auto tilesheetName = field(TileSheetName).toString(); - const auto importPath = field(ImportPath).toString(); - const auto paletteName = field(PaletteName).toString(); - const auto outPath = TileSheetDir + tilesheetName + FileExt_ng; - if (!QFile(importPath).exists()) { - return OxError(1); - } - auto ng = imgToNg(importPath, 0); - if (!ng) { - return OxError(1); - } - const auto paletteOutPath = PaletteDir + paletteName + FileExt_npal; - core::NostalgiaPalette pal; - pal = std::move(ng->pal); - m_ctx->project->writeObj(paletteOutPath, &pal); - auto defaultPalette = paletteOutPath.toUtf8(); - ng->defaultPalette = defaultPalette.data(); - m_ctx->project->writeObj(outPath, ng.get()); - return 0; -} - -} diff --git a/src/nostalgia/core/studio/import_tilesheet_wizard.hpp b/src/nostalgia/core/studio/import_tilesheet_wizard.hpp deleted file mode 100644 index c2fdee4f..00000000 --- a/src/nostalgia/core/studio/import_tilesheet_wizard.hpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. - */ - -#pragma once - -#include - -#include "consts.hpp" - -namespace nostalgia::core { - -constexpr auto TileSheetName = "tilesheetName"; -constexpr auto ImportPath = "importPath"; -constexpr auto Palette = "palette"; -constexpr auto PaletteName = "paletteName"; - -class ImportTilesheetWizardMainPage: public studio::WizardFormPage { - private: - //static constexpr auto BPP = "bpp"; - const studio::Context *m_ctx = nullptr; - - public: - ImportTilesheetWizardMainPage(const studio::Context *args); -}; - -class ImportTilesheetWizardPalettePage: public studio::WizardFormPage { - private: - //static constexpr auto BPP = "bpp"; - const studio::Context *m_ctx = nullptr; - - public: - ImportTilesheetWizardPalettePage(const studio::Context *args); - - int accept(); -}; - -} diff --git a/src/nostalgia/core/studio/new_tilesheet_wizard.cpp b/src/nostalgia/core/studio/new_tilesheet_wizard.cpp deleted file mode 100644 index 9b3e474a..00000000 --- a/src/nostalgia/core/studio/new_tilesheet_wizard.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. - */ - -#include -#include - -#include -#include - -#include "consts.hpp" -#include "new_tilesheet_wizard.hpp" - -namespace nostalgia::core { - -NewTilesheetWizardPage::NewTilesheetWizardPage(const studio::Context *ctx) { - m_ctx = ctx; - addLineEdit(tr("&Tile Sheet Name:"), QString(TileSheetName) + "*", "", [](QString) { - return 0; - }); - m_palettePicker = addComboBox(tr("&Palette:"), QString(Palette) + "*", {""}); - m_ctx->project->subscribe(studio::ProjectEvent::FileRecognized, m_palettePicker, [this](QString path) { - if (path.startsWith(PaletteDir) && path.endsWith(FileExt_npal)) { - m_palettePicker->addItem(studio::filePathToName(path, PaletteDir, FileExt_npal), path); - } - }); -} - -int NewTilesheetWizardPage::accept() { - const auto tilesheetName = field(TileSheetName).toString(); - const auto palette = m_palettePicker->itemData(field(Palette).toInt()).toString(); - const auto outPath = QString(TileSheetDir) + tilesheetName + FileExt_ng; - auto err = m_ctx->project->exists(outPath); - if (err) { - showValidationError(tr("A tile sheet with this name already exists.")); - return err; - } - NostalgiaGraphic ng; - ng.columns = 1; - ng.rows = 1; - ng.defaultPalette = palette.toUtf8().data(); - m_ctx->project->writeObj(outPath, &ng); - return 0; -} - -} diff --git a/src/nostalgia/core/studio/new_tilesheet_wizard.hpp b/src/nostalgia/core/studio/new_tilesheet_wizard.hpp deleted file mode 100644 index 3b3fe6c9..00000000 --- a/src/nostalgia/core/studio/new_tilesheet_wizard.hpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. - */ - -#pragma once - -#include - -namespace nostalgia::core { - -class NewTilesheetWizardPage: public studio::WizardFormPage { - private: - static constexpr auto TileSheetName = "projectName"; - static constexpr auto Palette = "palette"; - class QComboBox *m_palettePicker = nullptr; - const studio::Context *m_ctx = nullptr; - - public: - NewTilesheetWizardPage(const studio::Context *args); - - int accept(); - - private: -}; - -} diff --git a/src/nostalgia/core/studio/newpalettewizard.cpp b/src/nostalgia/core/studio/newpalettewizard.cpp deleted file mode 100644 index 71d8b0e3..00000000 --- a/src/nostalgia/core/studio/newpalettewizard.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. - */ - -#include -#include - -#include -#include - -#include "consts.hpp" -#include "newpalettewizard.hpp" - -namespace nostalgia::core { - -NewPaletteWizardPage::NewPaletteWizardPage(const studio::Context *ctx) { - m_ctx = ctx; - addLineEdit(tr("&Palette Name:"), QString(PaletteName) + "*", "", [](QString) { - return 0; - }); -} - -int NewPaletteWizardPage::accept() { - const auto paletteName = field(PaletteName).toString(); - const auto path = PaletteDir + paletteName + FileExt_npal; - if (m_ctx->project->exists(path)) { - showValidationError(tr("A palette with this name already exists.")); - return 1; - } - NostalgiaPalette pal; - m_ctx->project->writeObj(path, &pal); - return 0; -} - -} diff --git a/src/nostalgia/core/studio/newpalettewizard.hpp b/src/nostalgia/core/studio/newpalettewizard.hpp deleted file mode 100644 index e675d98a..00000000 --- a/src/nostalgia/core/studio/newpalettewizard.hpp +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved. - */ - -#pragma once - -#include - -namespace nostalgia::core { - -class NewPaletteWizardPage: public studio::WizardFormPage { - private: - static constexpr auto PaletteName = "paletteName"; - const studio::Context *m_ctx = nullptr; - - public: - NewPaletteWizardPage(const studio::Context *args); - - int accept(); - - private: -}; - -}