-
Notifications
You must be signed in to change notification settings - Fork 162
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
AGS4: Extend Allegro palette to 0-255 #2356
Conversation
I am curious about this being rebased after the recent changes. |
628232d
to
31cc90a
Compare
Alright, I rebased and revised this PR. Should work fine both for antialiased sprites on and off. |
I will try to finally review this in the following days.
Idk if useful, but a while ago I added "test--4.0.0" branch to the old demo repository: |
Editor/AGS.Editor/ImportExport.cs
Outdated
writer.Write((byte)(game.Palette[i].Colour.B / 4)); | ||
writer.Write((byte)(game.Palette[i].Colour.R)); | ||
writer.Write((byte)(game.Palette[i].Colour.G)); | ||
writer.Write((byte)(game.Palette[i].Colour.B)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ExportCharacter272 must not be adjusted, because this exports to a old data format; and by changing palette range you are changing data specs. Better keep this as-is (maybe with some commentary).
OTOH, Export/ImportCharacter272 functions should be removed as obsolete.
Engine/ac/room.cpp
Outdated
if (palette[ff].g > 255) | ||
palette[ff].g = 255; | ||
if (palette[ff].b > 255) | ||
palette[ff].b = 255; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code chunk may be removed completely, because palette components are declared as unsigned char
and can never be > 255.
libsrc/allegro/src/allegro.c
Outdated
{ 255, 255, 255, 0 },{ 255, 0, 0, 0 },{ 0, 255, 0, 0 },{ 255, 255, 0, 0 }, | ||
{ 0, 0, 255, 0 },{ 255, 0, 255, 0 },{ 0, 255, 255, 0 },{ 65, 65, 65, 0 }, | ||
{ 125, 125, 125, 0 },{ 255, 125, 125, 0 },{ 125, 255, 125, 0 },{ 255, 255, 125, 0 }, | ||
{ 125, 125, 255, 0 },{ 255, 125, 255, 0 },{ 125, 255, 255, 0 },{ 0, 0, 0, 0 } | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently, desktop_palette
may also be removed, as it's not used anywhere in our stripped allegro sources.
Besides the in-code comments above,
Is this still true, or has been fixed? BTW, I got confused by |
Good news. Thanks to divine inspiration I managed to fix the bestfit algorithms for real. Now sprites can finally match the 252-gray that used to become full white. The rgb_table is still being wrapped to a 6bit palette. I don't have time for figuring that one. I duped the bestfit_init, so it can still generate the weights it needs.
Seems a waste of time, since the format is essentially unchanged and we only need a full rebuild to get everything on track.
Sounds good, but in my opinion supporting 8bit mode in the way it's implemented is a waste of time, because shaders could do all these transformations in more convenient ways. I suppose that's what the rgb_table is supposed to optimize. In fact there are several sections where the table overtakes the individual bestfit, if initialized.
I'm bothered by all the 8bit code. I hope to never have to touch it again.
I managed to fix both to full 0-255 color matching.
Fixed |
Format is changed, because you switch the palette units from 64-based to 256-based, this changes the meaning of data. Without fixups this will make loading older data incorrect. EDIT: Fine, I will raise it myself after merging this. |
@@ -233,20 +232,20 @@ private static void RemapPixels(byte[] pixels, Color[] oldPal, Color[] newPal, b | |||
} | |||
|
|||
// 1.5k lookup table for color matching | |||
private static uint[] ColDiffTable = new uint[3 * 128]; | |||
private static uint[] ColDiffTable = new uint[3 * 512]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a comment about "1.5k table", now it does not reflect the table size. Should be either fixed, or removed.
@@ -261,7 +261,7 @@ int geta(int c) | |||
|
|||
|
|||
/* 1.5k lookup table for color matching */ | |||
static unsigned int col_diff[3*128]; | |||
static unsigned int col_diff[3*512]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also comment about 1.5k table, same as above.
Tested the palette remap, it seems to work fine (results are equal or close to the existing version). |
Somehow I completely missed this, but this PR did 2 changes that were not related to the palette in any way, and instead changed regular color property calculation from 16-bit R5G6B5 to 32-bit R8G8B8, which refers rather to task #1980. But since these changes are not complemented by others, on their own they break some things in both Editor and Engine. Noteably these are changes to ColorMapper and For example, same "Color" property numbers now produce a different RGB, so loading existing project suddenly makes colored things look different. And because I've already reverted the |
Uhm, is this also related to #2352 somehow? |
This may be the related place in code, but the change itself is not related, because it was done in ags4, while the mistake is found in 3.* branch. |
This is a WIP attempt to increase Allegro's internal palette from 0-63 to 0-255.
EDIT2: I managed to fix the bestfit algorithm, but I'm still converting to 6bit for the rbg_map
I upgraded some pieces from the ancient demo quest, which can be used as a test project.
DemoQuest_ags4.zip
You can also import other 256 games, but they will need a full rebuild to update the palettes in game data, and manual palette manipulation that were previously restricted to 0-63 will obviously work differently.