axx0 / Civ2-clone

An open-source re-implementation of Civilization 2
GNU General Public License v3.0
65 stars 14 forks source link

Transparency #78

Closed axx0 closed 10 months ago

axx0 commented 11 months ago

We've hardcoded transparency colors but this can give bad results. These colors vary in scenarios. For Civ2gold the last 3 colors in image palette define transparency. For TOT the last bit in every 16-bit color seems to set transparency. Anyway based on this we'll have to set alpha in our images.

reubene commented 11 months ago

Yes, there is a lot of work to do in image loading, might need seperate code paths for each version. Some of the TOT bmp files don't even load in the current version, no idea why Raylib just returns a null pointer.

axx0 commented 11 months ago

I'll see what I can do. Basically we could check if the file is gif87a and then use palette data to seek transparent colours or otherwise just interpret the image as 15-bit high color. This could be done independently of mge/tot, which would enable us to use high colours in MGE also. I've also noticed before some bmp files don't load in mge. I'll open an issue in raylib repo if that's the case.

axx0 commented 11 months ago

Bmp reading is not enabled by default in raylib. We'd need to enable a flag and then build raylib manually. So instead I'll try to manually make Image from bmp.

reubene commented 11 months ago

Not a bad idea, might allow us to do the transparency on reading as well which would save doing it later

axx0 commented 10 months ago

BMP files for MGE should work now. But only the 8-bit images, I haven't added support for 16 bit BMPs (for TOT) yet. I moved definition of locations of rectangles (for subimages) to the interface files.

reubene commented 10 months ago

Hey, I've finally had a chance to load up the changes you made, I can't open gif files at all now... is this somthign you're working on or should I look into it?

axx0 commented 10 months ago

Does the error occur with LoadImage method (it returns an empty image)? I'll try to fix that soon. In the meantime just rename the images extensions to lowercase (GIF-->gif). I'll also add support for 16 and 32 bit bmps and I'm also finishing work on reading TOT sav files.

reubene commented 10 months ago

Okay, so the problem was you're using RayLib.LoadImage with fails for uppercase names, which is what created the other LoadImage implementation above to fix by loading the files first and then loading the images from memory. I swapped bak in the fixed load image call and now it's working.

reubene commented 10 months ago

I did note you're only reading the image sizes from the header and assuming 256 colours not there a reason no to read the header value for colour table size etc?

axx0 commented 10 months ago

I forgot LoadImage is sensitive to uppercase. I would rather not use that method in that class, but I need it since otherwise I'd have to write LZW decompression manually.

Unlike BMPs which can be 8, 16 or 32 bpp, all the gif files used by civ2 and scenarios are exclusively 8bpp, so I always assume gifs are 256 colours (at least I haven't stumbled upon high colour gif used in civ2 yet). Anyway we can always make it more flexible to read the number of colours if we want.

axx0 commented 10 months ago

It can now read higher colour bmps. You can replace gifs with bmps from TOT to see if it works. There are some bugs with 24bpp images, I'll have to figure it out.