| Author |
Message |
Matt H Dark Trooper Phase 1
Joined: 24 Sep 2003
|
Posted: Nov 17, 2004 23:41 Post subject: Rounding for PALette files |
|
|
If you were going to convert a .PLT to a .PAL file, how would you do the rounding?*
A .PLT file has RGB values from 0 to 255. A .PAL file, on the other hand, goes from 0 to 63. Converting to .PLT is easy, you just multiply each value by 4 (giving you a range of 0 to 252). The inverse would be to divide by 4. But since the .PLT numbers aren't always multiples of 4, some rounding needs to be done.
There are two ways to round - a normal round and a 'floor' round, where you return the next lowest integer value by rounding down. For example, if a .PLT color was 47 89 6, dividing the numbers by 4 would be 11.75 22.25 1.5. A simple round for the .PAL it would be 12 22 2. A floor round would be 11 22 1.
For the most part, the first way seems better, more instinctive. The problem happens with numbers over 253. 254/4 = 63.5 and 255/4 = 63.75. The rules of normal rounding would put them at 64, which is out of range. So they would need to be knocked down to 63. That puts a weird balance on things - only 2 numbers round to 0 (0 and 1), where 6 numbers round to 63 (250, 251, 252, 253, 254, 255). The palette might be a little bright-heavy.
So where a straight round would have the colors more accurate to the original, a floor round would keep the palette more proportional. Which do you think is more important? Which would you do?
*Please don't say anything like "I would just use WDFuse to convert it." - That doesn't address my question in the slightest.
|
|
japh Gamorrean
Joined: 30 Sep 2003
|
Posted: Nov 18, 2004 03:30 Post subject: |
|
|
I'd do a straight round. It seems to keep the contrast better.
Or run it percentage-wise: going from 255 to 248 is what percent change (97.25)? Going from 63 to 62 (98.41)? Doesn't seem like much, right?
Normalizing the numbers might help :)
|
|
Matt H Dark Trooper Phase 1
Joined: 24 Sep 2003
|
Posted: Nov 18, 2004 04:11 Post subject: |
|
|
Hmmmm... maybe something like that. Take any number from the .PLT, and multiply it by 252/255 (0.988) which brings the range from 0-255 to 0-252. Then divide the number by 4 and round it. In my example, 47 89 6 becomes 46.447 87.953 5.929, dividing by 4 to be 11.611 21.988 1.482, and rounded to be 12 22 1.
Yes... that may be the answer. Thanks japh.
|
|
Matt H Dark Trooper Phase 1
Joined: 24 Sep 2003
|
Posted: Nov 18, 2004 21:08 Post subject: |
|
|
Well, I think I need to go back to using the 'floor' round. The problem is this: if I convert the .PAL to .PLT and then back to .PAL, I should get the same thing. But I don't. A value of 63 will go up to 252. 252 * 252/255 = 249.035. Divide that by 4 and it's 62.259, which will round down to 62. If I ran it back and forth again, it would go down to 61. (It will probably keep doing this until around 42.) So that method isn't working so well. There were also little things - three numbers rounded down to 0, three rounded down to 63, but five numbers rounded down to 21 and 42 each (and the rest have four numbers.) At least with the floor round, it's set - four numbers round down to each number in the 0-63 range.
Thanks to anyone who gave this a thought.
|
|
The MAZZTer Death Star

Joined: 25 Sep 2003
|
Posted: Nov 19, 2004 12:27 Post subject: |
|
|
PLT to PAL I would do value * 63 / 255 and then do a round (not a floor or ceiling, but a "normal" round).
For the inverse I would do value * 255 / 63 and then round that.
That would get the most accurate translation.
_________________ http://www.mzzt.net/ | I am a respectable admin with a respectable sig. |
|
Matt H Dark Trooper Phase 1
Joined: 24 Sep 2003
|
Posted: Nov 23, 2004 08:58 Post subject: |
|
|
That's a good idea - one I hadn't thought of. But I both like it and don't like it. It all depends on if you think color 63 should go up to 252 or up to 255. If you look at it as 63 being the highest number, so it should go up to the highest number, 255, it makes sense. But my instincts don't agree - they say that it's not 63 going to 255, but 64 going to 256, which would be just times four ( * 4) Also, the 255/252 * 4 method often has a lack of nice even round numbers that a simple *4 gives, which is kind of appealing.
It makes it a tough call.
|
|
japh Gamorrean
Joined: 30 Sep 2003
|
Posted: Nov 29, 2004 23:11 Post subject: |
|
|
Your instincts might be wrong. Instincts often are, in such cases.
|
|
Nottheking Kell Dragon
Joined: 29 Sep 2003
|
Posted: Nov 30, 2004 16:09 Post subject: |
|
|
Matt H wrote:
That's a good idea - one I hadn't thought of. But I both like it and don't like it. It all depends on if you think color 63 should go up to 252 or up to 255. If you look at it as 63 being the highest number, so it should go up to the highest number, 255, it makes sense. But my instincts don't agree - they say that it's not 63 going to 255, but 64 going to 256, which would be just times four ( * 4) Also, the 255/252 * 4 method often has a lack of nice even round numbers that a simple *4 gives, which is kind of appealing.
It makes it a tough call.
No, I think that it could only make sense if color 63 translated into color 255. After all, when you have a value of zero, that value of 63 is a value of 64, the maximum, and that 255 really is 256, so 64x4 should be 256. I think that it might be more accurate that, when translating your PLT and PAL files, that you should add 1 to each color value before multiplying/dividing them, and then subtract one thereafter. I haven't spent too much time with this, but it seems like it would improve the accuracy of the translation, at least for higher-level numbers.
_________________ Wake up, George Lucas... The Matrix has you.. |
|
|