-
Notifications
You must be signed in to change notification settings - Fork 642
Improve RGB channel detection heuristics for the HT256 encoder #2029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: htj2k-beta
Are you sure you want to change the base?
Improve RGB channel detection heuristics for the HT256 encoder #2029
Conversation
c5bdab3
to
710e606
Compare
|
||
if (c_name == "r" || c_name.compare(0, 3, "red") == 0) { r_index = i; } | ||
else if (c_name == "g" || c_name.compare(0, 5, "green") == 0) { g_index = i; } | ||
else if (c_name == "b" || c_name.compare(0, 4, "blue")== 0) { b_index = i; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will consider R
as a red channel, but not a channel which has a layer name with a R
suffix e.g.diffuse.R
?
Also, if the image happens to have both a R
and a r
channel, it'll pick the r
channel as the red channel not R
, which is a little unfortunate, since the standard name is R
Ideally it should look for R
as the channel name, and only fall back to using a channel with a non-standard name, or whose name starts with a layer name, if no R
channel is found.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proposed algorithm:
- look for R, G and B (case sensitive)
- if not found, look for:
- r, g and b
- .r, .g and .b suffixes (case insensitive)
- red, green, blue (case insensitive)
Anything else, like:
-red
,-green
and-blue
suffixes (case insensitive)red*
,green*
andblue*
(case insensitive)-r
,-g
and-b
suffixes (case insensitive)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first two points seem sensible. The standard says that a red channel must be R
, or a *.R
. It's quite common to see .red
as a suffix, and it would be worth checking for that too, as well as the full channel name
Being too generous with names may cause problems, such as redrawn.G
being treated as a red channel, or blueberry.R
as a blue channel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the RGBA interface? It looks like it simply appends R, G and B to a common prefix. If so, should the encoder look for R, G and B at the end of the channel name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NVM, it looks like the prefix in the RGBA interface is computed with prefixFromLayerName()
, which ensures a .
is present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See revised algorithm.
The algorithm below captures two years of use and feedback from many contributors and is believed to be good for this purpose.
|
The rgba detection is much more robust now! However, there is one more fly in the ointment. The algorithm I posted takes a layer name. The point there is that if an exr image contains layers named say albedo.{rgba} one should take care to group albedo.{rgba} together, and beauty.{rgba} together. A fault that can arise if you don't also aggregate layer names is this: albedo.{rgb} beauty.{rgba} will yield rgba = {albedo.r, albedo.g, albedo.b, beauty.a } or this scenario: odd.{rb} yielding rgba={odd.r, even.g, odd.b, even.a} |
Also, I was wondering about the red, grn, blu, suffixes. In the code I posted we only allow red, green, blue, and r, g, b. I've never seen grn, blu arise, and was curious if you use tools that produce them? |
This came from the DWA code. |
To summarize: the prefix, if it exists, should match across the R, G and B channels, right? |
@meshula I have added RGB detection heuristics tests at |
Signed-off-by: Pierre-Anthony Lemieux <[email protected]>
Signed-off-by: Pierre-Anthony Lemieux <[email protected]>
Signed-off-by: Pierre-Anthony Lemieux <[email protected]>
Add unit tests Signed-off-by: Pierre-Anthony Lemieux <[email protected]>
49e4855
to
4c98d80
Compare
RGBChannelParams params[] = { | ||
{"r", "g", "b", -1, -1, -1, NULL, 0}, | ||
{"red", "green", "blue", -1, -1, -1, NULL, 0}, | ||
{"red", "grn", "blu", -1, -1, -1, NULL, 0}}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still wonder if there's a tool that produces red, gin, blu, in other words, what's the motivation or including them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am happy to remove them... your call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My opinion is that it suggests to the reader of the code that those abbreviations are expected as legal, but we don't do that anywhere else so I prefer to elide them without something to ground them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This version seems robust against the combinations I can think of, thanks!
Signed-off-by: Pierre-Anthony Lemieux <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks
Updated algorithm: