mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Remove <filesystem>
Should fix compilation with GCC before 9
This commit is contained in:
@@ -10,9 +10,9 @@
|
|||||||
#define RGBDS_GFX_MAIN_HPP
|
#define RGBDS_GFX_MAIN_HPP
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <filesystem>
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
@@ -27,7 +27,7 @@ struct Options {
|
|||||||
bool beVerbose = false; // -v
|
bool beVerbose = false; // -v
|
||||||
bool columnMajor = false; // -Z, previously -h
|
bool columnMajor = false; // -Z, previously -h
|
||||||
|
|
||||||
std::filesystem::path attrmap{}; // -a, -A
|
std::string attrmap{}; // -a, -A
|
||||||
std::array<uint8_t, 2> baseTileIDs{0, 0}; // -b
|
std::array<uint8_t, 2> baseTileIDs{0, 0}; // -b
|
||||||
enum {
|
enum {
|
||||||
NO_SPEC,
|
NO_SPEC,
|
||||||
@@ -39,14 +39,14 @@ struct Options {
|
|||||||
std::array<uint32_t, 4> inputSlice{0, 0, 0, 0}; // -L
|
std::array<uint32_t, 4> inputSlice{0, 0, 0, 0}; // -L
|
||||||
std::array<uint16_t, 2> maxNbTiles{UINT16_MAX, 0}; // -N
|
std::array<uint16_t, 2> maxNbTiles{UINT16_MAX, 0}; // -N
|
||||||
uint8_t nbPalettes = 8; // -n
|
uint8_t nbPalettes = 8; // -n
|
||||||
std::filesystem::path output{}; // -o
|
std::string output{}; // -o
|
||||||
std::filesystem::path palettes{}; // -p, -P
|
std::string palettes{}; // -p, -P
|
||||||
uint8_t nbColorsPerPal = 0; // -s; 0 means "auto" = 1 << bitDepth;
|
uint8_t nbColorsPerPal = 0; // -s; 0 means "auto" = 1 << bitDepth;
|
||||||
std::filesystem::path tilemap{}; // -t, -T
|
std::string tilemap{}; // -t, -T
|
||||||
std::array<uint16_t, 2> unitSize{1, 1}; // -U (in tiles)
|
std::array<uint16_t, 2> unitSize{1, 1}; // -U (in tiles)
|
||||||
uint64_t trim = 0; // -x
|
uint64_t trim = 0; // -x
|
||||||
|
|
||||||
std::filesystem::path input{}; // positional arg
|
std::string input{}; // positional arg
|
||||||
|
|
||||||
format_(printf, 2, 3) void verbosePrint(char const *fmt, ...) const;
|
format_(printf, 2, 3) void verbosePrint(char const *fmt, ...) const;
|
||||||
uint8_t maxPalSize() const {
|
uint8_t maxPalSize() const {
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
class Png {
|
class Png {
|
||||||
std::filesystem::path const &path;
|
std::string const &path;
|
||||||
std::filebuf file{};
|
std::filebuf file{};
|
||||||
png_structp png = nullptr;
|
png_structp png = nullptr;
|
||||||
png_infop info = nullptr;
|
png_infop info = nullptr;
|
||||||
@@ -156,7 +156,7 @@ public:
|
|||||||
* We also use that occasion to only read the PNG one line at a time, since we store all of
|
* We also use that occasion to only read the PNG one line at a time, since we store all of
|
||||||
* the pixel data in `pixels`, which saves on memory allocations.
|
* the pixel data in `pixels`, which saves on memory allocations.
|
||||||
*/
|
*/
|
||||||
explicit Png(std::filesystem::path const &filePath) : path(filePath), colors() {
|
explicit Png(std::string const &filePath) : path(filePath), colors() {
|
||||||
if (file.open(path, std::ios_base::in | std::ios_base::binary) == nullptr) {
|
if (file.open(path, std::ios_base::in | std::ios_base::binary) == nullptr) {
|
||||||
fatal("Failed to open input image (\"%s\"): %s", path.c_str(), strerror(errno));
|
fatal("Failed to open input image (\"%s\"): %s", path.c_str(), strerror(errno));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <charconv>
|
#include <charconv>
|
||||||
#include <filesystem>
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
@@ -26,6 +25,8 @@
|
|||||||
|
|
||||||
#include "gfx/convert.hpp"
|
#include "gfx/convert.hpp"
|
||||||
|
|
||||||
|
using namespace std::literals::string_view_literals;
|
||||||
|
|
||||||
Options options;
|
Options options;
|
||||||
static uintmax_t nbErrors;
|
static uintmax_t nbErrors;
|
||||||
|
|
||||||
@@ -287,10 +288,25 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
options.input = argv[argc - 1];
|
options.input = argv[argc - 1];
|
||||||
|
|
||||||
auto autoOutPath = [](bool autoOptEnabled, std::filesystem::path &path, char const *extension) {
|
auto autoOutPath = [](bool autoOptEnabled, std::string &path, char const *extension) {
|
||||||
if (autoOptEnabled) {
|
if (autoOptEnabled) {
|
||||||
path = options.input;
|
constexpr std::string_view chars =
|
||||||
path.replace_extension(extension);
|
// Both must start with a dot!
|
||||||
|
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||||
|
"./\\"sv;
|
||||||
|
#else
|
||||||
|
"./"sv;
|
||||||
|
#endif
|
||||||
|
size_t i = options.input.find_last_of(chars);
|
||||||
|
if (i != options.input.npos && options.input[i] == '.') {
|
||||||
|
// We found the last dot, but check if it's part of a stem
|
||||||
|
// (There must be a non-path separator character before it)
|
||||||
|
if (i != 0 && chars.find(options.input[i - 1], 1) == chars.npos) {
|
||||||
|
// We can replace the extension
|
||||||
|
path.resize(i + 1); // Keep the dot, though
|
||||||
|
path.append(extension);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
autoOutPath(autoAttrmap, options.attrmap, ".attrmap");
|
autoOutPath(autoAttrmap, options.attrmap, ".attrmap");
|
||||||
@@ -337,15 +353,9 @@ int main(int argc, char *argv[]) {
|
|||||||
options.baseTileIDs[1]);
|
options.baseTileIDs[1]);
|
||||||
fprintf(stderr, "\tMaximum %" PRIu16 " tiles in bank 0, %" PRIu16 " in bank 1\n",
|
fprintf(stderr, "\tMaximum %" PRIu16 " tiles in bank 0, %" PRIu16 " in bank 1\n",
|
||||||
options.maxNbTiles[0], options.maxNbTiles[1]);
|
options.maxNbTiles[0], options.maxNbTiles[1]);
|
||||||
auto printPath = [](char const *name, std::filesystem::path const &path) {
|
auto printPath = [](char const *name, std::string const &path) {
|
||||||
if (!path.empty()) {
|
if (!path.empty()) {
|
||||||
#ifdef _MSC_VER
|
fprintf(stderr, "\t%s: %s\n", name, path.c_str());
|
||||||
#define PRIpath "ls"
|
|
||||||
#else
|
|
||||||
#define PRIpath "s"
|
|
||||||
#endif
|
|
||||||
fprintf(stderr, "\t%s: %" PRIpath "\n", name, path.c_str());
|
|
||||||
#undef PRIpath
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
printPath("Input image", options.input);
|
printPath("Input image", options.input);
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ void indexed(std::vector<Palette> &palettes, int palSize, png_color const *palRG
|
|||||||
return std::find(colors.begin(), colors.end(), color) != colors.end();
|
return std::find(colors.begin(), colors.end(), color) != colors.end();
|
||||||
})) {
|
})) {
|
||||||
if (palette.size() != options.maxPalSize()) {
|
if (palette.size() != options.maxPalSize()) {
|
||||||
warning("Unused color in PNG embedded palette was re-added; please use `-c embedded` to get this in future versions");
|
warning("Unused color in PNG embedded palette was re-added; please use `-c "
|
||||||
|
"embedded` to get this in future versions");
|
||||||
}
|
}
|
||||||
// Overwrite the palette, and return with that (it's already sorted)
|
// Overwrite the palette, and return with that (it's already sorted)
|
||||||
palette.colors = colors;
|
palette.colors = colors;
|
||||||
|
|||||||
Reference in New Issue
Block a user