mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-27 21:42:06 +00:00
Implement more features and fix bugs
This commit is contained in:
@@ -44,7 +44,8 @@ public:
|
||||
if (!slot.has_value()) {
|
||||
slot.emplace(rgba);
|
||||
} else if (*slot != rgba) {
|
||||
warning("Different colors melded together"); // TODO: indicate position
|
||||
warning("Different colors melded together (#%08x into #%08x as %04x)", rgba.toCSS(),
|
||||
slot->toCSS(), rgba.cgbColor()); // TODO: indicate position
|
||||
}
|
||||
}
|
||||
|
||||
@@ -363,7 +364,7 @@ public:
|
||||
public:
|
||||
iterator begin() const { return {*this, _width, 0, 0}; }
|
||||
iterator end() const {
|
||||
iterator it{*this, _width, _width - 8, _height - 8}; // Last valid one
|
||||
iterator it{*this, _limit, _width - 8, _height - 8}; // Last valid one
|
||||
return ++it; // Now one-past-last
|
||||
}
|
||||
};
|
||||
@@ -443,7 +444,9 @@ static void outputTileData(Png const &png, DefaultInitVec<AttrmapEntry> const &a
|
||||
}
|
||||
}
|
||||
output.sputc(row & 0xFF);
|
||||
output.sputc(row >> 8);
|
||||
if (options.bitDepth == 2) {
|
||||
output.sputc(row >> 8);
|
||||
}
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
@@ -505,6 +508,7 @@ public:
|
||||
mutable size_t tileID;
|
||||
|
||||
TileData(Png::TilesVisitor::Tile const &tile, Palette const &palette) : _hash(0) {
|
||||
size_t writeIndex = 0;
|
||||
for (uint32_t y = 0; y < 8; ++y) {
|
||||
uint16_t bitplanes = 0;
|
||||
for (uint32_t x = 0; x < 8; ++x) {
|
||||
@@ -517,8 +521,10 @@ public:
|
||||
bitplanes |= 0x100;
|
||||
}
|
||||
}
|
||||
_data[y * 2] = bitplanes & 0xFF;
|
||||
_data[y * 2 + 1] = bitplanes >> 8;
|
||||
_data[writeIndex++] = bitplanes & 0xFF;
|
||||
if (options.bitDepth == 2) {
|
||||
_data[writeIndex++] = bitplanes >> 8;
|
||||
}
|
||||
|
||||
// Update the hash
|
||||
_hash ^= bitplanes;
|
||||
@@ -632,7 +638,7 @@ static void outputTileData(UniqueTiles const &tiles) {
|
||||
for (TileData const *tile : tiles) {
|
||||
assert(tile->tileID == tileID);
|
||||
++tileID;
|
||||
output.sputn(reinterpret_cast<char const *>(tile->data().data()), tile->data().size());
|
||||
output.sputn(reinterpret_cast<char const *>(tile->data().data()), options.bitDepth * 8);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -203,10 +203,8 @@ public:
|
||||
size_t volume() const { return uniqueColors().size(); }
|
||||
bool canFit(ProtoPalette const &protoPal) const {
|
||||
auto &colors = uniqueColors();
|
||||
for (uint16_t color : protoPal) {
|
||||
colors.insert(color);
|
||||
}
|
||||
return colors.size() <= 4;
|
||||
colors.insert(protoPal.begin(), protoPal.end());
|
||||
return colors.size() <= options.maxPalSize();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -274,9 +272,9 @@ std::tuple<DefaultInitVec<size_t>, size_t>
|
||||
bestPal.assign(std::move(attrs));
|
||||
|
||||
// If this overloads the palette, get it back to normal (if possible)
|
||||
while (bestPal.volume() > 4) {
|
||||
options.verbosePrint("Palette %zu is overloaded! (%zu > 4)\n", bestPalIndex,
|
||||
bestPal.volume());
|
||||
while (bestPal.volume() > options.maxPalSize()) {
|
||||
options.verbosePrint("Palette %zu is overloaded! (%zu > %" PRIu8 ")\n",
|
||||
bestPalIndex, bestPal.volume(), options.maxPalSize());
|
||||
|
||||
// Look for a proto-pal minimizing "efficiency" (size / rel_size)
|
||||
auto efficiency = [&bestPal](ProtoPalette const &pal) {
|
||||
@@ -309,7 +307,7 @@ std::tuple<DefaultInitVec<size_t>, size_t>
|
||||
|
||||
// Deal with palettes still overloaded, by emptying them
|
||||
for (AssignedProtos &pal : assignments) {
|
||||
if (pal.volume() > 4) {
|
||||
if (pal.volume() > options.maxPalSize()) {
|
||||
for (ProtoPalAttrs &attrs : pal) {
|
||||
queue.emplace(std::move(attrs));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user