-
Notifications
You must be signed in to change notification settings - Fork 17
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
Magic pink won't become transparent on macOS (Workaround: Mass-convert to 32-bit PNG, see first post) #431
Comments
@naymapl wrote:
That would fix the pink, and give you correct physics. If you want it really fast, you could, in theory, go through the tiles in Even replacing pink with transparency in the image files would still leave the wrongly-colored symbols on the buttons, but those aren't as important. Lix 0.9.42 should, by itself, replace the pink with transparency and recolor the button symbols, but it doesn't. I've already investigated the source roughly: Allegro 5 and the addons are initialized, and I compute the colors with But this is the first time that somebody is running Lix on macOS ARM64. Anything might be the problem. I'll investigate. |
Ok - now is working - I maybye use wrong file name ;) |
Is it any way to make it bulk ? It so many images to make one by one :D https://graphicdesign.stackexchange.com/questions/16120/batch-replacing-color-with-transparency I found this but no idea how run this with LixD images. |
Lix images are normal PNGs with alpha. Assuming you have ImageMagick 7.x installed, here's a loop:
Still looking for the problem in Lix or Allegro on macOS ARM64. What I do in Lix should work on all systems. Really makes me wonder... |
(Sorry for late reply.) Great to hear that you can play singleplayer well! I'll keep this workaround in mind then -- the shell loop to recolor all graphics. The in-game recoloring still fails for the button icons. But the grey button icons (instead of pale blue) aren't a problem for singleplayer playability. You can still tell what's what. But in multiplayer, you'd have 8 identical-looking player colors instead of 8 different lix colors. This would be more serious, you wouldn't be able to tell apart lix of different players. Thus, I won't close this bug yet. |
Thanks for the report that this bug manifests on the Intel Mac! I haven't investigated since March 2022, but it's getting more important again. Lix is largely unplayable on all Macs until we mass-replace the pink with the shell loop, and even then, the UI elements remain unrecolored. |
My new year's resolution for 2023 is to solve this recoloring bug. I still don't have a Mac, but I have a first theory for you to test:
Do the levels from your earlier screenshots (Beneath the Lab, or the basher tutorial) still show the pink rectangles? |
@cameo69, please post the output of E.g., naymapl on ARM had |
Still happening in Lix 0.10.26 on macOS 10.15.7 Catalina (Intel, 2019 iMac) with Allegro . I may have found some more info that might help with this. Full disclosure: I'm not exactly building Lix the normal way. I'm actually building it under a package manager called (wait for it) Nix. It gives me sandboxed, reproducible builds, and it lets me change out dependencies like Allegro just for Lix without affecting anything else I have installed. However, I did have to do a couple of weird hacks to get it to build and run correctly in that environment, and I can't promise that's not affecting anything… but so far I don't think that's causing what I'm seeing here. 'Performing' line looks like this:
I tried building Lix against various versions of Allegro, going back to 5.2.2.01, but it always got the pink blocks. Looking at them in Digital Color Meter, it's actually being rendered as an even more intense pink/magenta that is out of gamut for sRGB. The native values on my iMac are [0xFB, 0x00, 0xFF], while sRGB shows [0xFF (clipped), 0x00 (clipped), 0xFF (clipped)]. I can also see the difference if I open e.g. mouse.png in Preview or GIMP and compare it against the in-game cursor. I found one reference to a similar problem from way back in 2010: I noticed that some of the images were indexed-color, and wondered if Allegro was somehow interpreting color values in the palette differently than color values in a true-color PNG somehow. I tried converting them all to true-color using this command: find images/ data/images/ -name \*.png -exec magick {} PNG32:{} \; and it seems to work! The sprites, UI, and level terrain all get recolored correctly, and the lix follow the level terrain properly. (I initially messed up and used I'm still not entirely sure what's causing this, or why changing to true-color worked, but from my (admittedly limited) testing, this seems to be a better workaround than the Hope this helps! Footnotes
|
Thanks for your excellent investigation! This helps in several areas: You've seen the bug appear in the current Lix 0.10.26. This confirms that my hand-rolled reimplementation of Originally, I conjectured that Allegro 5's I'll roll back to Allegro 5's implementation and remove my hand-written reimplementation. You've seen pink pixels considerably off-target and you've even proved it in Digital Color Meter. That again suggests that neither Lix's hand-rolled pink conversion nor Allegro 5's Next ideas for my investigation:
You found a better workaround that fixes the GUI recoloring and the multiplayer recoloring. Now the networking mode is playable on Mac Lix. That's great! I'll edit the first post to provide your workaround (with I'll consider adding a shell script for Mac users that runs your line, and explain in the Mac build instructions to run that script. This isn't ideal either: This will produce many changed files in the versioned tree and The obvious next move would be to change all PNGs in the versioned tree to PNG32, commit them, and consider this a bugfix. I'm wary of this for several reasons:
Ideally, I find the source of the bug before I commit everything as PNG32. |
Glad I could help. Yeah, I can definitely see how just changing the upstream images to PNG32 would be a more fragile approach. Normally Allegro uses libpng to read PNG files, but on macOS it usually replaces that with a native loader that goes through Cocoa's NSImage class. If I disable the native loader - by passing I still don't understand where the native loader is breaking, though. Both loaders seem to lock the new bitmap as (Also:
Whoops! Meant to say "[…] with Allegro 5.2.9.1". I stopped to look up the version number, got sidetracked, and never pasted it back in. Of course it's "with Allegro"!) |
Okay, I've been adding various debug prints to Allegro's native macOS bitmap loader trying to figure this out, and have found a little more info. Bear in mind that I have no real experience with Allegro, and while I kinda understand the concepts of color spaces/profiles in theory, I haven't actually worked with them to any significant extent, so I'm mostly guessing my way through this. With that out of the way: I can't find this documented anywhere, but it currently seems like Allegro (at least on macOS?) is working with colors exclusively in native RGB(A) format - not sRGB. That would explain how it's possible for the loader to set an out-of-sRGB-gamut color in the new bitmap - neither the From what I can tell, for most PNGs - at least the ones in Lix's data, which don't specify color profiles - the But when the PNG file is in indexed format, the Meanwhile, the libpng-based loader that Allegro uses on other systems doesn't seem to do any conversion, besides asking libpng to gamma-adjust based on Allegro's best guess as to the correct gamma value for your screen (or a config setting or the I actually don't see much of anything in Allegro's code that does anything color-space-related2. I could be wrong - again, I am very much not an expert on this - but it feels like Allegro is basically assuming "RGB is RGB", shoving whatever values the loader gets from the PNG onto the screen, and hoping for the best. On Linux and Windows, that means the raw pixel/palette values from the file. But on macOS, Cocoa sometimes does its own conversion first, and the combination of those behaviors ends up breaking things. I'm not really sure where to go with this next… Footnotes |
Thanks! That narrows it down to Allegro 5's fundamental image loading. It could still be the Mac libraries, but it's reasonable to assume the Mac libraries themselves to work fine, and to dig deeper into Allegro 5's usage of those Mac libraries.
Yes, this sounds like a good angle of attack: Can/should Allegro 5 ask Cocoa not to convert anything? With all of these findings, it's looking reasonable to file this against Allegro 5 directly. That bug would be: Allegro 5 on Mac loads slightly-off colors from PNG, unless the source was PNG32 or you disable the native image loader (at configuration time). The failing pink-to-transparent conversion is merely a symptom of this bug; after all, my hand-rolled conversion failed in the same way. These days, at the weekend at latest, I'll look through Allegro 5's issues. If I don't see anything similar filed already, I'll file it. Or would you like to spearhead this instead? Feel free to open the bug before I do. I'll watch it closely regardless of who opens it. |
This isn't directly related to this issue, but:
If you do end up trying to make a proper macOS .app bundle for Lix, you're likely to run into SiegeLord/DAllegro5#56. Basically, the game executable works outside the bundle, but as soon as Allegro detects that the game is running from a bundle, it does something that ends up confusing the D Allegro bindings and causing a crash. The proposed fix/workaround in that issue seems to work, but hasn't actually been released or even committed yet. I realize it's unlikely that anyone here besides me will be in exactly the right intersection of niches to find this useful, but if any Mac users are looking to get a working, double-clickable macOS version of Lix and are using the Nix package manager I mentioned earlier, I've added my package for it to the Nix User Repository as nur.repos.Rhys-T.lix-game (source code here). I wouldn't recommend it as the official way of installing Lix on macOS, though - Nix is a rather weird package manager if you're not used to it… Edit 10/7/2024: I suppose I should clarify that the package I did should work on the Linux version of Nix too, if any NixOS users are looking to play the game - but now we're getting even further off topic for this issue… |
If you're on a multi-core Mac and have something like GNU Parallel installed, you can change the command to something like this to let it convert multiple PNGs at once: find images/ data/images/ -name \*.png -print0 | parallel -0 magick {} PNG32:{} \; |
In the Allgero 5 Mac PNG bug, you wrote:
That gives me an idea for a theoretical workaround: Instead of hardcoding the magic pink as The problem with this is: 32-bit PNG will then fail to convert from pink to transparent. I'd have to run every PNG through two rounds of color-to-transparency conversion, once for the color from the 1x1 file (presumably It also relies on the following: Given many different palette-indexed PNGs, Allegro 5 will load all pink pixels across all these PNGs identically, i.e., all these pink pixels load as the same single (wrong) value. Do we know for sure that this is so? |
You'd have to do the same thing to other special colors too. Black would probably be Looking for both possible values regardless of the image also runs the risk of false positives - particularly for the 'gray → UI blue' mapping, where the adjusted value might just happen to line up with another non-adjusted shade of gray.
So far it seems to be that way for me, but I don't have any way to know for sure, and would be hesitant to rely on it. I don't know why those images in particular end up getting pre-converted to native by NSImage, nor how NSImage decides which monitor's native color space to use, if you have more than one. I tried to see if there was any way to disable the native loader at runtime, but I couldn't find any official way to do that. If you needed to, I guess you could temporarily replace the implementation of On a completely unrelated note, I've found a different way of running the PNG32 conversion that's much faster (as in ~3 seconds vs almost a minute): find images/ data/images/ -name \*.png -exec magick mogrify -define png:color-type=6 -depth 8 {} + This batches as many images as possible into a single call to |
Workaround: Mass-convert the PNG files to the 32-bit PNG format (rather than palette-indexed PNG or 24-bit PNG). Lix will then detect pink correctly. To do this:
Lix builds and runs on Mac, but some graphics have problems:
This bug is still in Lix 0.10.26 in 2024.
The first time I heard about this was in naymapl's report in #430 for Lix 0.9.42 in 2022 on a Mac mini m1 with macOS ARM64.
cameo69 reported that this same bug also manifests on an Intel Mac.
In 2024, Rhys-T investigated. Now it looks like it's not a Lix-specific bug, but rather a bug in Allegro 5's Mac-specific image loader.
The text was updated successfully, but these errors were encountered: