Jump to content

Palettes


Bomb Bloke

Recommended Posts

I sat down and decoded the palettes files the other night. They're simple enough, but just for the record:

 

Each main palette is made up of 768 bytes, that is 3 bytes per color, for a total of 256 colors per palette. Each RGB value has a maximum intensity of 63 (3F:h), as opposed to 255 (FF:h).

 

Pal1: Geoscape view.

Pal2: *Unknown*

Pal3: Graph views.

Pal4: Research view.

Pal5: Battlescape view.

 

Each palette has a six byte 'buffer' following it. I dunno what these buffers mean, but here they are:

 

Pal1: B7 13 FF 76 FE 50
Pal2: A1 E8 13 0B 06 E6
Pal3: 01 00 8B 46 FA 0B
Pal4: FF 76 10 FF 76 0E
Pal5: C8 1E 00 00 1E B8

 

These values are much larger then the others, and no, they don't translate well into ascii. ;) I'm guessing that there was an earlier version of this palette file, which used values out of 255; when the new version was made, it was written over the old, leaving these bytes behind... Much like the trash you get in the save files, really. The palette files are the same for both the dos version and the CE version of the game.

 

Five palettes of 768 bytes each, plus five buffers of 6 bytes each, makes 3870 bytes - the size of the palettes.dat file.

 

The second palette I can't identify. Diashiva's viewers (which use palettes made by BladeFireLight, I think) don't use it. It bears more then a passing resembalence to the battlescape palette, but if you check it closely, it's not a match. I'm thinking it's used for the base view screens.

 

There is another palette file, the back palette. The game swaps color information around in memory, and uses this file to get the extra colors. It contains only 128 colors, and part (or maybe all) of it is temporarily loaded to display certain screens. Examples are the background of the load game screen, or the background of the terror site announcement window.

 

This here image displays the five main palettes, one after the other. Underneath that, it shows the four palettes Diashiva uses. Underneath THAT is the contents of the backpals.dat file. Sorry, I used Microsoft Paint to save the original, so the RGB values are not 100% correct... :) But, if you enlarge it to full screen, you'll still get a pretty good idea of what each palette looks like. (Yep, even at 24bit, MSPaint doesn't save images correctly. Not as bad as what it does to gif files, though! :blink: ).

 

https://img.photobucket.com/albums/v213/BombBloke/pals.png

 

As you can see, each of the default palettes end in the same few colors, which I'm guessing are used for the cursor. You can also see that the end of the battlescape palette doesn't match Diashiva's too well - his has grey, the default has greys and blues.

 

So, I rewrote my map viewer to use the original palettes. Guess which one works? Well, it's not the default:

 

https://img.photobucket.com/albums/v213/BombBloke/arctic.png

 

While that would look very cool and all in the mountain maps, it's doesn't look good the rest of the time. I'm guessing a palette swap method (such as used with the backpals.dat file) is used, but I don't know where the correct colors are stored. :) Any one else have any ideas? :eh:

Link to comment
Share on other sites

  • 2 weeks later...

Hmm. I've got some experience with palettes during my attepts to write a X-Com style DOS GUI for the abandoned batch multiplayer project.

 

I can add that game uses so called BIOS formatted palette where all colour components are 6-bit length and this fact limits maximal value to 0x63. Old videocards had such a limit. But if you want to get an effective 8-bit component value, it should be calculated this way:

actualColour = paletteColour<<2; In the terms of C language of course.

 

Buffers, you mentioned, are most probably a palette specific indexes for the colour cycling. Lifts at the Alien base and ships make intensive use of this video effect. Palette register values are beeing changed instead of the pixel itself and we see neat wavy glow. This is an unapprooved guess which must bee checked. Other possibility is that these values define replaced portions of the master palette.

 

Concerning detection of the partialy replaced palette portions at the battle screens like the one shown above, I believe the most simple way is a screen capture. It should be made on differnt screen of DOS X-Com via Game Wizard or similar DOS4G(W) aware utility. Palettes of the resulting pictures could be easily compared.

 

I hope this will help you a little. :(

Link to comment
Share on other sites

actualColour = paletteColour

 

I can't even remember the name for that operation... But actualColour = paletteColour*4; does exactly the same thing. I hope. :(

 

Concerning the glowing effect, that is, beieve it or not, not palette swapping. Each part of those glowing animations is a seperate sprite. Each tile on the map has an animatoin property, allowing it to display four (or perhaps even eight) different sprites in a sequence. This animation is sometimes temporaraly disabled, for instance, doors.

 

So old video cards maxed out at six bit palette entries... That'd be interesting to program for...

Link to comment
Share on other sites

Well, some palette entries use the palette shift to change colours. The Geoscape for example uses this a lot, such as the intercept screen's scanner image and all the background images.

 

In the battlescape though, yeah, most of the animations would be done through sprites. But how about the UFO grav-lift's red beams? And the disco room walls in the battleship (the orange and cyan walls)?

 

The > shifts bits to the right. If you had::

 

0001000

 

And You bit shifted to the left by 2 you'd end up with

 

0100000

 

A single left shift is technically a * 2, or a single right shift divides by 2. Eh, actually I've become a bit rusty about the bit operators myself.

 

- NKF

Link to comment
Share on other sites

I reached the same conclusion you did about the palette structure. When i noticed that their palettes didnt match mine at all, i stopped looking at the files. Couldnt find a good mapping/equation to make the original colors somewhat close to mine either. Its possible I overlooked something extremely obvious though, so if you figure it out, i would love to know =)
Link to comment
Share on other sites

Once you work out that each entry has to be multiplied by 4 (which is equal to the double bit shift operation... knew the concept, forgot the term!), you can see how the two relate to each other. It's only the very end of the battlescape palette that seems different.

 

I think perhaps the colors I'm looking for are in the backpals file after all. The color blocks are the same size, now that I take another look, but I'm not sure if any of the colors come up as a match. But then, perhaps the palette you use is simply incorrect - how was it made? Was I right when I said BladeFireLight produced it?

Link to comment
Share on other sites

Once you work out that each entry has to be multiplied by 4 (which is equal to the double bit shift operation... knew the concept, forgot the term!), you can see how the two relate to each other. It's only the very end of the battlescape palette that seems different.

 

I think perhaps the colors I'm looking for are in the backpals file after all. The color blocks are the same size, now that I take another look, but I'm not sure if any of the colors come up as a match. But then, perhaps the palette you use is simply incorrect - how was it made? Was I right when I said BladeFireLight produced it?

 

I made a background image containing every color and in such a way i could determine the color->index mapping. After loading it into the game, i took a screenshot (printscreen), wrote a program to look at the pixel colors and put them into a format i wanted, and poof, i had my palette =)

Link to comment
Share on other sites

Once you work out that each entry has to be multiplied by 4 (which is equal to the double bit shift operation... knew the concept, forgot the term!), you can see how the two relate to each other. It's only the very end of the battlescape palette that seems different.

 

I think perhaps the colors I'm looking for are in the backpals file after all. The color blocks are the same size, now that I take another look, but I'm not sure if any of the colors come up as a match. But then, perhaps the palette you use is simply incorrect - how was it made? Was I right when I said BladeFireLight produced it?

 

Multiplying the backpals colors by a constant number does show that every 16 colors is a color gradient. I'm *fairly* sure that the background images only use a 'row' of 16 colors as this would allow you to simply offset each index by 16 and you have a completely recolored image that still looks good.

 

Getting the exact colors seems to be more hit and miss though, as each monitor will display them just a tad different.

Link to comment
Share on other sites

I just checked out the palette.dat file, the colors line up almost exactly between the hand-made and the originals. Thanks for the <<2 tip =)

 

The battlescape palette for tftd is not in the palette.dat file it would seem

 

Now we just have to figure out what that 6-byte block is for

Link to comment
Share on other sites

You mean the final yellowy colors at the end of each palette?

 

My guess is that that's the mouse cursor palette. Note that it seems that block doesn't get used in the battlescape view... I think.

 

Concerning bumping around the color indexes for the background images, you're guess is spot on. In fact, my map viewer currently already does that. Use your viewers to check the files back00.scr (or whatever it's called), then check the in game "load" screen.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...