Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite RGBGFX in C++ #981

Merged
merged 118 commits into from
Jul 2, 2022
Merged

Rewrite RGBGFX in C++ #981

merged 118 commits into from
Jul 2, 2022

Conversation

ISSOtm
Copy link
Member

@ISSOtm ISSOtm commented Feb 28, 2022

Currently missing from the old version:

  • -f ("fixing" the input image to be indexed)
  • -m (the code for detecting mirrored tiles is missing, but all of the "plumbing" is otherwise there)
  • -C
  • -d (removed)
  • -x (though I need to check the exact functionality the old one has)
  • Also the man page is still a draft and needs to be fleshed out It only needs proofreading now (and -U's description when that is implemented)
  • Once everything is done, the shell completion scripts must also be updated

More planned features are not implemented yet either:

  • Explicit palette spec (fixes Allow RGBGFX to take an external palette specification #487)
  • Better error messages, also error "images"
  • Better 8x16 support, as well as other "dedup unit" sizes
  • Support for arbitrary number of palettes & colors per palette
  • Other output formats (for example, a "full" palette map for "streaming" use cases like gb-open-world)
  • Quantization?

Some things may also be bugged:

...and performance remains to be checked.
We need to set up some tests, honestly.

@ISSOtm ISSOtm added enhancement Typically new features; lesser priority than bugs refactoring This PR is intended to clean up code more than change functionality rgbgfx This affects RGBGFX tests This affects the test suite labels Feb 28, 2022
@ISSOtm
Copy link
Member Author

ISSOtm commented Feb 28, 2022

Oh yeah; it also currently doesn't build due to a lot of issues with the mixed C/C++ builds. This'll obviously need fixing, but it does compile on at least my machine. It also compiles on at least one CI configuration, but the disasms fail since it's currently incomplete.

src/gfx/pal_sorting.cpp Outdated Show resolved Hide resolved
src/gfx/pal_packing.cpp Outdated Show resolved Hide resolved
Makefile Show resolved Hide resolved
Makefile Show resolved Hide resolved
src/gfx/convert.cpp Outdated Show resolved Hide resolved

class ImagePalette {
// Use as many slots as there are CGB colors (plus transparency)
std::array<std::optional<Rgba>, 0x8001> _colors;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::array<std::optional<Rgba>, 0x8001> _colors;
std::array<std::optional<Rgba>, 1 << (5 * 3) + 1> _colors;

Copy link
Member Author

@ISSOtm ISSOtm Feb 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree on the usefulness of this change, but as-is, the calculation seems arbitrary at first glance, and has confused me at first. Constants would help, but I will hold off until some of them are (potentially) introduced by further modifications.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this appears in a couple other files, I still think it's worth a constant; or is it still too early to bother?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what to name that constant, tbh.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bump?

src/gfx/convert.cpp Outdated Show resolved Hide resolved
src/gfx/convert.cpp Outdated Show resolved Hide resolved

// All efficiencies are identical iff min equals max
// TODO: maybe not ideal to re-compute these two?
// TODO: yikes for float comparison! I *think* this threshold is OK?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say protoPalettes[maxEfficiencyIter->palIndex] is A and protoPalettes[minEfficiencyIter->palIndex] is B. This compares efficiency(A) and efficiency(B) with a threshold. But efficiency(x) = x.size() / bestPal.relSizeOf(x); so instead, how about finding the LCM of bestPal.relSizeOf(A) and bestPal.relSizeOf(B) and comparing A.size() and B.size() based on that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain that a bit more?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A := protoPalettes[maxEfficiencyIter->protoPalIndex]
B := protoPalettes[minEfficiencyIter->protoPalIndex]
condition := efficiency(A) ==~ efficiency(B)
condition := A.size() / bestPal.relSizeOf(A) ==~ B.size() / bestPal.relSizeOf(B) // float threshold
condition := A.size() * bestPal.relSizeOf(B) == B.size() * bestPal.relSizeOf(A) // exact comparison

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I meant regarding how the two algorithms are equivalent, sorry

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just multiplied both sides by the denominators.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto efficiency = [&bestPal](ProtoPalette const &pal) {
	return pal.size() / bestPal.relSizeOf(pal);
};

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right. Forgive me for lacking in confidence, but I'd like to implement this change after we've set up a test corpus, so we can ensure that this does not accidentally changes generation output.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this doesn't work because relSizeOf is floating-point as well. Any other ideas?

src/gfx/pal_packing.cpp Outdated Show resolved Hide resolved
@ISSOtm ISSOtm force-pushed the rgbgfx-cxx branch 2 times, most recently from 2ddac3b to 75d54f4 Compare March 1, 2022 18:05
include/gfx/convert.hpp Outdated Show resolved Hide resolved
src/gfx/pal_packing.cpp Outdated Show resolved Hide resolved
src/gfx/pal_packing.cpp Outdated Show resolved Hide resolved
src/gfx/convert.cpp Outdated Show resolved Hide resolved
src/gfx/convert.cpp Outdated Show resolved Hide resolved
src/gfx/convert.cpp Outdated Show resolved Hide resolved
src/gfx/convert.cpp Outdated Show resolved Hide resolved
src/gfx/convert.cpp Outdated Show resolved Hide resolved
src/gfx/convert.cpp Outdated Show resolved Hide resolved
As it turns out, it is really difficult to implement, and can be dealt with later.
Also correct minor blunders in the man page
@ISSOtm
Copy link
Member Author

ISSOtm commented Jul 2, 2022

As it turns out, -U is really difficult to implement, and I don't want this PR to stay unmerged.

@ISSOtm ISSOtm marked this pull request as ready for review July 2, 2022 14:58
@ISSOtm ISSOtm merged commit 2b83a81 into gbdev:master Jul 2, 2022
@Rangi42 Rangi42 added this to the 0.6.0 milestone Aug 27, 2022
@ISSOtm ISSOtm deleted the rgbgfx-cxx branch November 5, 2023 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Typically new features; lesser priority than bugs refactoring This PR is intended to clean up code more than change functionality rgbgfx This affects RGBGFX tests This affects the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Weird behaviour with transparent pixels in rgbgfx Allow RGBGFX to take an external palette specification
4 participants