This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 12 - Pages: 1 - Last Post: 06-Dec-2017 16:47 Last Post By: jGromit
jGromit

Posts: 34,201
Registered: 31-Jan-2006
Convert to new alpha channel standard
Posted: 04-Dec-2017 15:42
 
  Click to reply to this thread Reply
I've emailed David about this, but thought it deserved to be memorialized in a thread.

All current browsers support alpha channel colors (semi-transparencies) using this notation:
background-color: rgba (r-value, g-value, b-value, a-value);
And jAlbum provides a utility method, JAlphaColorSelector.toRGBAString(color), to convert hex representations to that form.

Internally, in project files and when displaying alpha channel color values in a user interface, jAlbum displays them as #AARRGGBB, with the alpha channel value in the highest-order bits.

Happily, Chrome, Firefox, and Safari now support using hex colors directly, without having to convert them to the rgba() format. The bad news is that they've settled on a standard, #RRGGBBAA, with the alpha channel value in the lowest-order bits. No word about Edge yet.

jAlbum needs to convert to the new standard. The tricky part of it is that merely looking at a saved color value, there's no way to tell whether it's #RRGGBBAA or #AARRGGBB. It's probably going to need a hidden boolean variable in the project file that says, "Yes, I've converted these values to the new standard."
davidekholm

Posts: 21,874
Registered: 18-Oct-2002
Re: Convert to new alpha channel standard
Posted: 04-Dec-2017 16:00   in response to: jGromit in response to: jGromit
 
  Click to reply to this thread Reply
I guess we shouldn't change jAlbum's internal representation but instead introduce a new utility method to get the color formatted according to the new standard.
jGromit

Posts: 34,201
Registered: 31-Jan-2006
Re: Convert to new alpha channel standard
Posted: 04-Dec-2017 16:18   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
I think that's a prescription for ongoing confusion. I think it needs a one-time fix so that alpha channel colors are shown as #RRGGBBAA in the UI and in the project file.

In jAlbum 15.x, alphas are shown in the new format, and JAlphaColorSelector.toRGBAString() is expecting the hex strings in the new format. When you open a project in jAlbum 15.x, look for alphaConverted. Don't find it? Hunt down all 8-digit hex codes in the project file and switch them. Add alphaConverted=true.

(And remember that JAlphaColorSelector.toRGBAString() will still be needed until Edge comes around, and IE11 is dead - I suspect that IE11 won't ever get the update, even if Edge does.)
davidekholm

Posts: 21,874
Registered: 18-Oct-2002
Re: Convert to new alpha channel standard
Posted: 06-Dec-2017 14:50   in response to: jGromit in response to: jGromit
 
  Click to reply to this thread Reply
Can't one simply stick to the CSS style rgba(rr,gg,bb,aa) format?
jGromit

Posts: 34,201
Registered: 31-Jan-2006
Re: Convert to new alpha channel standard
Posted: 06-Dec-2017 15:02   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
Can't one simply stick to the CSS style rgba(rr,gg,bb,aa) format?

For now, sure. But once all browsers support the hex notation, skin developers are going to want to write:
body {background-color: ${bodyColor};}
Maintaining all that JAlphaColorSelector.toRGBAString() code is a pain.

Beyond that, having jAlbum displaying the hex code for alpha channel colors in a different way than the rest of the tech world doesn't strike me as being a good idea. Confusing, and might lead to some interesting copy-and-paste errors.
davidekholm

Posts: 21,874
Registered: 18-Oct-2002
Re: Convert to new alpha channel standard
Posted: 06-Dec-2017 15:10   in response to: jGromit in response to: jGromit
 
  Click to reply to this thread Reply
Perhaps a less error-prone solution would be to use the CaSING of the hex code to determine if an existing code is in the old aarrggbb format or the new RRGGBBAA format when reading project files? That way, the transition could be fully smooth.
jGromit

Posts: 34,201
Registered: 31-Jan-2006
Re: Convert to new alpha channel standard
Posted: 06-Dec-2017 15:17   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Less error-prone? You're kidding, right? I'd be hard-pressed to come up with a solution that was more likely to produce mistakes. There is no casing standard for hex colors. Do you really want to invent one?
davidekholm

Posts: 21,874
Registered: 18-Oct-2002
Re: Convert to new alpha channel standard
Posted: 06-Dec-2017 15:53   in response to: jGromit in response to: jGromit
 
  Click to reply to this thread Reply
jGromit wrote:
Less error-prone? You're kidding, right? I'd be hard-pressed to come up with a solution that was more likely to produce mistakes. There is no casing standard for hex colors. Do you really want to invent one?

But jAlbum property files are machine generated so I don't see the problem. The only difference we need to do is to start using UPPER CASE color values in project files. Special state variables always run the risk of getting into the wrong state. I've checked that even if the user explicitly writes upper case hex colors to the text field of color controls, jAlbum writes those as small case, when writing to the project file.
jGromit

Posts: 34,201
Registered: 31-Jan-2006
Re: Convert to new alpha channel standard
Posted: 06-Dec-2017 16:19   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
So if jAlbum 16 opens a project file and sees lower case hex values, it knows they haven't been converted. So it hunts down any 8-digit hex, swaps the low- and high-order bits, then writes out all of the hex values in upper case.

But is the UI display still lower case? Or does the UI display start using upper case for all hex values? Not unreasonable - I've encountered a number of applications that always use upper case for them.

BTW, just in case this isn't enough fun already, the standard also recognizes #RGBA, with the same digit-doubling as non-alpha 3-digits hex codes like #RGB.
davidekholm

Posts: 21,874
Registered: 18-Oct-2002
Re: Convert to new alpha channel standard
Posted: 06-Dec-2017 16:28   in response to: jGromit in response to: jGromit
 
  Click to reply to this thread Reply
jGromit wrote:
So if jAlbum 16 opens a project file and sees lower case hex values, it knows they haven't been converted. So it hunts down any 8-digit hex, swaps the low- and high-order bits, then writes out all of the hex values in upper case.

Yes, upon project save. The only downside I see is that if you later open such projects in older jAlbum versions, then such colors will be distorted.

But is the UI display still lower case? Or does the UI display start using upper case for all hex values? Not unreasonable - I've encountered a number of applications that always use upper case for them.

Doesn't really matter, capital letters seems to be more of the norm, but takes a bit more visual space sometimes.

BTW, just in case this isn't enough fun already, the standard also recognizes #RGBA, with the same digit-doubling as non-alpha 3-digits hex codes like #RGB.

Ok. We could naturally detect if it's possible to express the resulting color in that format and then use it. It would make generated code sliiightly more compact :-)
jGromit

Posts: 34,201
Registered: 31-Jan-2006
Re: Convert to new alpha channel standard
Posted: 06-Dec-2017 16:40   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
The only downside I see is that if you later open such projects in older jAlbum versions, then such colors will be distorted.

Yeah, I thought about that one, but it wouldn't be the first time that some change made re-opening in an older version problematic. In fact, given some the theme image changes in my skins, trying to open in an older version of jAlbum crashes completely. It's not because of what jAlbum is doing - it's because the skin's UI is looking for something in the jAlbum core that didn't exist in that version.

Doesn't really matter, capital letters seems to be more of the norm...

Yes, I think I've seen that more often than lower case.

Ok. We could naturally detect if it's possible to express the resulting color in that format and then use it. It would make generated code sliiightly more compact :-)

I was thinking more of the opposite, where someone enters just 3 or 4 digits. Currently jAlbum handles it correctly for the six-digit colors - if you enter #fff, save and re-open, it's #ffffff, as it should be. But it makes a mess of 4-digit alpha colors. If you enter #8000, you end up with #ff008000.

What gets written out to the CSS should always be 6 or 8 digits, I think.
davidekholm

Posts: 21,874
Registered: 18-Oct-2002
Re: Convert to new alpha channel standard
Posted: 06-Dec-2017 16:44   in response to: jGromit in response to: jGromit
 
  Click to reply to this thread Reply
jGromit wrote:

I was thinking more of the opposite, where someone enters just 3 or 4 digits. Currently jAlbum handles it correctly for the six-digit colors - if you enter #fff, save and re-open, it's #ffffff, as it should be. But it makes a mess of 4-digit alpha colors. If you enter #8000, you end up with #ff008000.

Ok, that should be easy to fix.

What gets written out to the CSS should always be 6 or 8 digits, I think.

I agree
jGromit

Posts: 34,201
Registered: 31-Jan-2006
Re: Convert to new alpha channel standard
Posted: 06-Dec-2017 16:47   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
There's no big rush on any of this, of course. As long as Edge doesn't recognize the 8-digit hex format, skins have to stick to the conversion to rgba. IE11 is a bigger problem - it's still in wide use, and will probably never recognize 8-digit hex. But maybe the Gnomes of RedmondĀ® will surprise me.
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums