MODULE: TruBlu v3.0 - Get true-color blues and magenta in 32-bit games!

Started by monkey0506, Sun 10/07/2011 00:42:38

Previous topic - Next topic

monkey0506

Hi gang,

I was taking a look at some color values when I noticed that even for 32-bit games that RGB(255,255,255) is returning an AGS color value of 65535. That seemed a bit silly to me seeing as that's a 16-bit value. So just on a whim I wanted to see what would happen if I passed in 65536. Turns out that for 32-bit games that matches RGB(0,0,0). So I went up: 65537. That matched RGB(0,0,8). Not the palette replaced 0-31 AGS color value, but actually real RGB(0,0,8).

From there I did some more testing, and I came to the incredible conclusion that for 32-bit AGS games, you can get access to those 0-31 slots, and true-color RGB(255,0,255) magenta by simply offsetting the color value by 65536.

So, with that in mind I bring you the fastest produced module in my entire history, with one amazing function and another one that's simply incredible:

Code: ags
int color = GetColorFromTrueColorRGB(255,0,255);
surface.Clear(color); // clears the surface to magenta, but doesn't match AGS' transparent color! sweet!!
int rgb[] = GetTrueColorRGBFromColor(color); // returns RGB(248,0,248)
rgb = GetTrueColorRGBFromColor(color, true); // returns RGB(255,0,255)


Please note again:

THE "SPECIAL" COLOR VALUES RETURNED ONLY WORK FOR 32-BIT GAMES. If your game is 16-bit then the magenta color returned by this function will match the AGS transparent color!!

Download

Thanks For Downloading!

-monkey

10 July 2011

So the GetTrueColorRGBFromColor was completely broken in that it was returning the 0-31 value instead of the 0-255 value. I fixed that. := I also fixed the G value being completely wrong. := I also added a highBit parameter to the function to control whether the returned values should be the low- or high-end value in the range. The default is false, for which R31 will be converted to R248. If true, R31 will be converted to R255.

09 July 2011

Uploaded v2.0 with a fix for RGB(248,0,248) to RGB(254,0,254) (due to the precision of AGS color values, these are all treated the same as RGB(255,0,255)), and implemented the "reverse" function, to strip out the R, G, and B values from an AGS color value.

Calin Leafshade

the reverse function would be helpful.

Code: ags

int[] colorArray = GetTrueRGB(AGSColor);

monkey0506

Well for that I have a question. In the conversion from RGB to an AGS color value, you're losing 3 bits (anywhere from 0-7 from the maximum 255 value). So, what should the result of (R248-R255)->R31->R??? be? Should it be R248 or R255?

I'll go based on the assumption that the lost bits should just be considered forever lost in the ether and the result should be R248.

Edit: Done. ::)

Snarky

This thread discusses how AGS's mapping to 16-bit color appears to work (I never systematically tested it on any other color than white) and how it should work.

Very cool to have a way to work around those problems! Thanks monkey!

Wyz

Life is like an adventure without the pixel hunts.

monkey0506

Quote from: Snarky on Sun 10/07/2011 09:52:19This thread discusses how AGS's mapping to 16-bit color appears to work (I never systematically tested it on any other color than white) and how it should work.

Very cool to have a way to work around those problems! Thanks monkey!

Your method seems to always convert R31->R255, but what if the original value was R248? I understand that there's not really a way to recover the exact value of the bits that were lost in the initial conversion, but I'm gathering that you would rather that I offset the value to the high-end than returning the low-end value?

Also..I kind of forgot a rather essential step in my reverse conversion function. :=

Snarky

Quote from: monkE3y_05_06 on Sun 10/07/2011 17:09:47
Your method seems to always convert R31->R255, but what if the original value was R248? I understand that there's not really a way to recover the exact value of the bits that were lost in the initial conversion, but I'm gathering that you would rather that I offset the value to the high-end than returning the low-end value?

If I remember the issue correctly, the problem is that by always returning the low-end (i.e. just dropping the least significant bits), the top of the range becomes inaccessible. So instead I proposed making it so that values towards the top of the scale offset towards the high end, values near the bottom of the scale offset towards the low end, and values in the middle offset towards the middle. That way we can access the whole color-space. (Instead of all the values at the top of the scale being inaccessible, inaccessible values are spread out here and there along the whole spectrum, and there are always an accessible value right next to them.) This happens to be the recommended way to convert 16-bit color values to 24-bit values.

I suggested two ways to do this, which both give essentially the same result.

There might be reasons why you would want to stick with the same method of conversion that AGS uses, though. And I didn't know anything about the special mapping of 0-31, which probably adds another complication to the whole thing.

dbuske

Would it be possibly to give an example of how this can be used?
What if your blessings come through raindrops
What if your healing comes through tears...

monkey0506

Uh, yeah, I did. In the first post. You should consider reading it.

Calin Leafshade

This module is for a very specific purpose. If you dont know what it does then you probably dont need it.

dbuske

I will restate my question.
I was asking for a specific example of how module can be used.
Can it be used to make a character look better?
Show an example.
I know you are attacking me and don't help me, but other newbies might want to use this.
What if your blessings come through raindrops
What if your healing comes through tears...

dbuske

Quote from: Calin Leafshade on Tue 19/07/2011 22:50:59
This module is for a very specific purpose. If you dont know what it does then you probably dont need it.

I know you are one of the more helpful, experienced AGS uses.
I am not attacking you here.
But your answer leaves the newbies completely out...  I appreciate your helpful cheerful demeanor.
What if your blessings come through raindrops
What if your healing comes through tears...

ddq

Well Calin's right in that this module doesn't really have use for newbies. It's like a catheter. If you don't have a problem with the specific issue this module addresses, you can pee normally without having to worry about it. I hope that's an appropriate comparison.

monkey0506

Okay, here's a specific example:

If your "game" is a Photoshop clone written in AGS, then this module could be useful to you.

If your game does not require very exact, specific color-values to be drawn onto a DrawingSurface at run-time, then you have absolutely zero need for this module.

And you can drop this charade that everyone is attacking you, because nobody's buying it. You asked a question, and I answered you. Perhaps I was a bit curt, and you didn't understand the example that was given, but if you didn't then I'm reasonably sure that you have zero need for this module.

This module will not make imported sprites look any different. It only applies to the DrawingSurface functions in specific relation to a specific set of color values (RGB(0, 0, 0) to RGB(0, 0, 255) and RGB(255, 0, 255)). If you're not trying to use the DrawingSurface functions with those exact color values, then you have no need of this function.

Oh, and ddq, your comparison is very adequate. :=

Dualnames

Quote from: dbuske on Tue 26/07/2011 13:57:02
I will restate my question.
I was asking for a specific example of how module can be used.
Can it be used to make a character look better?
Show an example.
I know you are attacking me and don't help me, but other newbies might want to use this.

Every sentence and word here, made me LOL so HARD!
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Ryan Timothy B

Does anyone have a copy of this file (or another one)? The link is broken. Thanks!

Dualnames

Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Ryan Timothy B

I knew you would! I was actually thinking of PMing you today but never got around to it.
Thanks!

SMF spam blocked by CleanTalk