Change UseTab to ForIndentation

This fixes many whitespace issues
This commit is contained in:
ISSOtm
2022-03-09 21:43:36 +01:00
committed by Eldred Habert
parent c4361b965c
commit 5efc49cb12
8 changed files with 64 additions and 64 deletions

View File

@@ -96,4 +96,4 @@ SpacesInSquareBrackets: false
Standard: c++17 Standard: c++17
TabWidth: 4 TabWidth: 4
UseCRLF: false UseCRLF: false
UseTab: AlignWithSpaces UseTab: ForIndentation

View File

@@ -25,7 +25,7 @@ namespace packing {
* Returns which palette each proto-palette maps to, and how many palettes are necessary * Returns which palette each proto-palette maps to, and how many palettes are necessary
*/ */
std::tuple<DefaultInitVec<size_t>, size_t> std::tuple<DefaultInitVec<size_t>, size_t>
overloadAndRemove(std::vector<ProtoPalette> const &protoPalettes); overloadAndRemove(std::vector<ProtoPalette> const &protoPalettes);
} }

View File

@@ -22,7 +22,7 @@ struct Rgba {
* Constructs the color from a "packed" RGBA representation (0xRRGGBBAA) * Constructs the color from a "packed" RGBA representation (0xRRGGBBAA)
*/ */
explicit Rgba(uint32_t rgba = 0) explicit Rgba(uint32_t rgba = 0)
: red(rgba >> 24), green(rgba >> 16), blue(rgba >> 8), alpha(rgba) {} : red(rgba >> 24), green(rgba >> 16), blue(rgba >> 8), alpha(rgba) {}
/** /**
* Returns this RGBA as a 32-bit number that can be printed in hex (`%08x`) to yield its CSS * Returns this RGBA as a 32-bit number that can be printed in hex (`%08x`) to yield its CSS

View File

@@ -52,8 +52,8 @@ public:
size_t size() const { size_t size() const {
return std::count_if(_colors.begin(), _colors.end(), return std::count_if(_colors.begin(), _colors.end(),
[](decltype(_colors)::value_type const &slot) { [](decltype(_colors)::value_type const &slot) {
return slot.has_value() && !slot->isTransparent(); return slot.has_value() && !slot->isTransparent();
}); });
} }
decltype(_colors) const &raw() const { return _colors; } decltype(_colors) const &raw() const { return _colors; }
@@ -138,8 +138,8 @@ public:
uint8_t mask = 1 << color->grayIndex(); uint8_t mask = 1 << color->grayIndex();
if (bins & mask) { // Two in the same bin! if (bins & mask) { // Two in the same bin!
options.verbosePrint( options.verbosePrint(
"Color #%08x conflicts with another one, not using grayscale sorting\n", "Color #%08x conflicts with another one, not using grayscale sorting\n",
color->toCSS()); color->toCSS());
return false; return false;
} }
bins |= mask; bins |= mask;
@@ -348,7 +348,7 @@ public:
public: public:
TilesVisitor(Png const &png, bool columnMajor, uint32_t width, uint32_t height) TilesVisitor(Png const &png, bool columnMajor, uint32_t width, uint32_t height)
: _png(png), _columnMajor(columnMajor), _width(width), _height(height) {} : _png(png), _columnMajor(columnMajor), _width(width), _height(height) {}
class Tile { class Tile {
Png const &_png; Png const &_png;
@@ -435,7 +435,7 @@ struct AttrmapEntry {
}; };
static std::tuple<DefaultInitVec<size_t>, std::vector<Palette>> static std::tuple<DefaultInitVec<size_t>, std::vector<Palette>>
generatePalettes(std::vector<ProtoPalette> const &protoPalettes, Png const &png) { generatePalettes(std::vector<ProtoPalette> const &protoPalettes, Png const &png) {
// Run a "pagination" problem solver // Run a "pagination" problem solver
// TODO: allow picking one of several solvers? // TODO: allow picking one of several solvers?
auto [mappings, nbPalettes] = packing::overloadAndRemove(protoPalettes); auto [mappings, nbPalettes] = packing::overloadAndRemove(protoPalettes);
@@ -471,7 +471,7 @@ static std::tuple<DefaultInitVec<size_t>, std::vector<Palette>>
} }
static std::tuple<DefaultInitVec<size_t>, std::vector<Palette>> static std::tuple<DefaultInitVec<size_t>, std::vector<Palette>>
makePalsAsSpecified(std::vector<ProtoPalette> const &protoPalettes, Png const &png) { makePalsAsSpecified(std::vector<ProtoPalette> const &protoPalettes, Png const &png) {
if (options.palSpecType == Options::EMBEDDED) { if (options.palSpecType == Options::EMBEDDED) {
// Generate a palette spec from the first few colors in the embedded palette // Generate a palette spec from the first few colors in the embedded palette
auto [embPalSize, embPalRGB, embPalAlpha] = png.getEmbeddedPal(); auto [embPalSize, embPalRGB, embPalAlpha] = png.getEmbeddedPal();
@@ -876,8 +876,8 @@ contained:;
// Sort the proto-palettes by size, which improves the packing algorithm's efficiency // Sort the proto-palettes by size, which improves the packing algorithm's efficiency
// We sort after all insertions to avoid moving items: https://stackoverflow.com/a/2710332 // We sort after all insertions to avoid moving items: https://stackoverflow.com/a/2710332
std::sort( std::sort(
protoPalettes.begin(), protoPalettes.end(), protoPalettes.begin(), protoPalettes.end(),
[](ProtoPalette const &lhs, ProtoPalette const &rhs) { return lhs.size() < rhs.size(); }); [](ProtoPalette const &lhs, ProtoPalette const &rhs) { return lhs.size() < rhs.size(); });
auto [mappings, palettes] = options.palSpecType == Options::NO_SPEC auto [mappings, palettes] = options.palSpecType == Options::NO_SPEC
? generatePalettes(protoPalettes, png) ? generatePalettes(protoPalettes, png)

View File

@@ -93,31 +93,31 @@ static char const *optstring = "Aa:b:Cc:Dd:FfhL:mN:n:o:Pp:s:Tt:U:uVvx:Z";
* over short opt matching * over short opt matching
*/ */
static struct option const longopts[] = { static struct option const longopts[] = {
{"output-attr-map", no_argument, NULL, 'A'}, {"output-attr-map", no_argument, NULL, 'A'},
{"attr-map", required_argument, NULL, 'a'}, {"attr-map", required_argument, NULL, 'a'},
{"base-tiles", required_argument, NULL, 'b'}, {"base-tiles", required_argument, NULL, 'b'},
{"color-curve", no_argument, NULL, 'C'}, {"color-curve", no_argument, NULL, 'C'},
{"colors", required_argument, NULL, 'c'}, {"colors", required_argument, NULL, 'c'},
{"debug", no_argument, NULL, 'D'}, // Ignored {"debug", no_argument, NULL, 'D'}, // Ignored
{"depth", required_argument, NULL, 'd'}, {"depth", required_argument, NULL, 'd'},
{"fix", no_argument, NULL, 'f'}, {"fix", no_argument, NULL, 'f'},
{"fix-and-save", no_argument, NULL, 'F'}, // Deprecated {"fix-and-save", no_argument, NULL, 'F'}, // Deprecated
{"horizontal", no_argument, NULL, 'h'}, // Deprecated {"horizontal", no_argument, NULL, 'h'}, // Deprecated
{"slice", required_argument, NULL, 'L'}, {"slice", required_argument, NULL, 'L'},
{"mirror-tiles", no_argument, NULL, 'm'}, {"mirror-tiles", no_argument, NULL, 'm'},
{"nb-tiles", required_argument, NULL, 'N'}, {"nb-tiles", required_argument, NULL, 'N'},
{"nb-palettes", required_argument, NULL, 'n'}, {"nb-palettes", required_argument, NULL, 'n'},
{"output", required_argument, NULL, 'o'}, {"output", required_argument, NULL, 'o'},
{"output-palette", no_argument, NULL, 'P'}, {"output-palette", no_argument, NULL, 'P'},
{"palette", required_argument, NULL, 'p'}, {"palette", required_argument, NULL, 'p'},
{"output-tilemap", no_argument, NULL, 'T'}, {"output-tilemap", no_argument, NULL, 'T'},
{"tilemap", required_argument, NULL, 't'}, {"tilemap", required_argument, NULL, 't'},
{"unit-size", required_argument, NULL, 'U'}, {"unit-size", required_argument, NULL, 'U'},
{"unique-tiles", no_argument, NULL, 'u'}, {"unique-tiles", no_argument, NULL, 'u'},
{"version", no_argument, NULL, 'V'}, {"version", no_argument, NULL, 'V'},
{"verbose", no_argument, NULL, 'v'}, {"verbose", no_argument, NULL, 'v'},
{"trim-end", required_argument, NULL, 'x'}, {"trim-end", required_argument, NULL, 'x'},
{"columns", no_argument, NULL, 'Z'}, {"columns", no_argument, NULL, 'Z'},
{NULL, no_argument, NULL, 0 } {NULL, no_argument, NULL, 0 }
}; };
@@ -293,9 +293,9 @@ int main(int argc, char *argv[]) {
constexpr std::string_view chars = constexpr std::string_view chars =
// Both must start with a dot! // Both must start with a dot!
#if defined(_MSC_VER) || defined(__MINGW32__) #if defined(_MSC_VER) || defined(__MINGW32__)
"./\\"sv; "./\\"sv;
#else #else
"./"sv; "./"sv;
#endif #endif
size_t i = options.input.find_last_of(chars); size_t i = options.input.find_last_of(chars);
if (i != options.input.npos && options.input[i] == '.') { if (i != options.input.npos && options.input[i] == '.') {

View File

@@ -71,7 +71,7 @@ class AssignedProtos {
public: public:
template<typename... Ts> template<typename... Ts>
AssignedProtos(std::vector<ProtoPalette> const &protoPals, Ts &&...elems) AssignedProtos(std::vector<ProtoPalette> const &protoPals, Ts &&...elems)
: _assigned{std::forward<Ts>(elems)...}, _protoPals{&protoPals} {} : _assigned{std::forward<Ts>(elems)...}, _protoPals{&protoPals} {}
private: private:
template<typename Inner, template<typename> typename Constness> template<typename Inner, template<typename> typename Constness>
@@ -142,8 +142,8 @@ public:
template<typename... Ts> template<typename... Ts>
void assign(Ts &&...args) { void assign(Ts &&...args) {
auto freeSlot = std::find_if_not( auto freeSlot = std::find_if_not(
_assigned.begin(), _assigned.end(), _assigned.begin(), _assigned.end(),
[](std::optional<ProtoPalAttrs> const &slot) { return slot.has_value(); }); [](std::optional<ProtoPalAttrs> const &slot) { return slot.has_value(); });
if (freeSlot == _assigned.end()) { // We are full, use a new slot if (freeSlot == _assigned.end()) { // We are full, use a new slot
_assigned.emplace_back(std::forward<Ts>(args)...); _assigned.emplace_back(std::forward<Ts>(args)...);
@@ -158,8 +158,8 @@ public:
bool empty() const { bool empty() const {
return std::find_if_not( return std::find_if_not(
_assigned.begin(), _assigned.end(), _assigned.begin(), _assigned.end(),
[](std::optional<ProtoPalAttrs> const &slot) { return slot.has_value(); }) [](std::optional<ProtoPalAttrs> const &slot) { return slot.has_value(); })
== _assigned.end(); == _assigned.end();
} }
size_t nbProtoPals() const { return std::distance(begin(), end()); } size_t nbProtoPals() const { return std::distance(begin(), end()); }
@@ -210,18 +210,18 @@ public:
double relSizeOf(ProtoPalette const &protoPal) const { double relSizeOf(ProtoPalette const &protoPal) const {
// NOTE: this function must not call `uniqueColors`, or one of its callers will break // NOTE: this function must not call `uniqueColors`, or one of its callers will break
return std::transform_reduce( return std::transform_reduce(
protoPal.begin(), protoPal.end(), 0.0, std::plus<>(), [this](uint16_t color) { protoPal.begin(), protoPal.end(), 0.0, std::plus<>(), [this](uint16_t color) {
// NOTE: The paper and the associated code disagree on this: the code has // NOTE: The paper and the associated code disagree on this: the code has
// this `1 +`, whereas the paper does not; its lack causes a division by 0 // this `1 +`, whereas the paper does not; its lack causes a division by 0
// if the symbol is not found anywhere, so I'm assuming the paper is wrong. // if the symbol is not found anywhere, so I'm assuming the paper is wrong.
return 1. return 1.
/ (1 / (1
+ std::count_if( + std::count_if(
begin(), end(), [this, &color](ProtoPalAttrs const &attrs) { begin(), end(), [this, &color](ProtoPalAttrs const &attrs) {
ProtoPalette const &pal = (*_protoPals)[attrs.palIndex]; ProtoPalette const &pal = (*_protoPals)[attrs.palIndex];
return std::find(pal.begin(), pal.end(), color) != pal.end(); return std::find(pal.begin(), pal.end(), color) != pal.end();
})); }));
}); });
} }
/** /**
@@ -342,7 +342,7 @@ static void decant(std::vector<AssignedProtos> &assignments,
} }
std::tuple<DefaultInitVec<size_t>, size_t> std::tuple<DefaultInitVec<size_t>, size_t>
overloadAndRemove(std::vector<ProtoPalette> const &protoPalettes) { overloadAndRemove(std::vector<ProtoPalette> const &protoPalettes) {
options.verbosePrint("Paginating palettes using \"overload-and-remove\" strategy...\n"); options.verbosePrint("Paginating palettes using \"overload-and-remove\" strategy...\n");
struct Iota { struct Iota {
@@ -414,12 +414,12 @@ std::tuple<DefaultInitVec<size_t>, size_t>
return pal.size() / bestPal.relSizeOf(pal); return pal.size() / bestPal.relSizeOf(pal);
}; };
auto [minEfficiencyIter, maxEfficiencyIter] = auto [minEfficiencyIter, maxEfficiencyIter] =
std::minmax_element(bestPal.begin(), bestPal.end(), std::minmax_element(bestPal.begin(), bestPal.end(),
[&efficiency, &protoPalettes](ProtoPalAttrs const &lhs, [&efficiency, &protoPalettes](ProtoPalAttrs const &lhs,
ProtoPalAttrs const &rhs) { ProtoPalAttrs const &rhs) {
return efficiency(protoPalettes[lhs.palIndex]) return efficiency(protoPalettes[lhs.palIndex])
< efficiency(protoPalettes[rhs.palIndex]); < efficiency(protoPalettes[rhs.palIndex]);
}); });
// All efficiencies are identical iff min equals max // All efficiencies are identical iff min equals max
// TODO: maybe not ideal to re-compute these two? // TODO: maybe not ideal to re-compute these two?
@@ -452,7 +452,7 @@ std::tuple<DefaultInitVec<size_t>, size_t>
ProtoPalAttrs const &attrs = queue.front(); ProtoPalAttrs const &attrs = queue.front();
ProtoPalette const &protoPal = protoPalettes[attrs.palIndex]; ProtoPalette const &protoPal = protoPalettes[attrs.palIndex];
auto iter = auto iter =
std::find_if(assignments.begin(), assignments.end(), std::find_if(assignments.begin(), assignments.end(),
[&protoPal](AssignedProtos const &pal) { return pal.canFit(protoPal); }); [&protoPal](AssignedProtos const &pal) { return pal.canFit(protoPal); });
if (iter == assignments.end()) { // No such page, create a new one if (iter == assignments.end()) { // No such page, create a new one
options.verbosePrint("Adding new palette for overflow\n"); options.verbosePrint("Adding new palette for overflow\n");

View File

@@ -36,8 +36,8 @@ void indexed(std::vector<Palette> &palettes, int palSize, png_color const *palRG
// Check that the palette only uses those colors // Check that the palette only uses those colors
if (std::all_of(palette.begin(), palette.end(), [&colors](uint16_t color) { if (std::all_of(palette.begin(), palette.end(), [&colors](uint16_t color) {
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 " warning("Unused color in PNG embedded palette was re-added; please use `-c "
"embedded` to get this in future versions"); "embedded` to get this in future versions");

View File

@@ -12,22 +12,22 @@
* with ties resolved by comparing the difference of the squares. * with ties resolved by comparing the difference of the squares.
*/ */
static std::array<uint8_t, 256> reverse_curve{ static std::array<uint8_t, 256> reverse_curve{
0, 0, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, // These 0, 0, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, // These
5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, // comments 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, // comments
7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, // prevent 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, // prevent
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, // clang-format 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, // clang-format
10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, // from 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, // from
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, // reflowing 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, // reflowing
13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, // these 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, // these
14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, // 16 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, // 16
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, // 16-iterm 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, // 16-iterm
17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, // lines, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, // lines,
18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, // which, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, // which,
19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, // in 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, // in
21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, // my 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, // my
22, 23, 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, // opinion, 22, 23, 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, // opinion,
24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, // help 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, // help
26, 27, 27, 27, 27, 27, 28, 28, 28, 28, 29, 29, 29, 30, 30, 31, // visualization! 26, 27, 27, 27, 27, 27, 28, 28, 28, 28, 29, 29, 29, 30, 30, 31, // visualization!
}; };
uint16_t Rgba::cgbColor() const { uint16_t Rgba::cgbColor() const {