📜 ⬆️ ⬇️

“Hue” in the flash works incorrectly - intrigue, investigation

All hands did not reach to share with the community a rather critical bug found in flash (at least in CS5 - for sure).

It turns out that the Adjust Color → Hue filter does not work correctly.

I'll tell you in order ...

Preamble or "how we found a rake."


It all started with the fact that in our project (mentioned in the previous habratopic ) we allowed the user to create all kinds of animal creatures (a la Spore) from pre-drawn parts. Plus - the creature has a torso / legs / arms that are dynamically generated. The artist was given the task to paint parts of the body in "pure green" colors. Those. using colors like # 008800, # 00FF00, # 002200. The body color of the creature was also generated pure green.
')
Everything was ok, until we decided to introduce different coloring. Those. from the green being it was necessary to get another color.



It would seem - everything is simple. We change the hue and everything is fine. We do this:

public static function getHueFilter(hue: Number): ColorMatrixFilter {

var a: AdjustColor = new AdjustColor();
a.hue = hue;
a.saturation = 0;
a.brightness = 0;
a.contrast = 0;
return new ColorMatrixFilter(a.CalculateFinalFlatArray());
}


* This source code was highlighted with Source Code Highlighter .


And then the problems started. The color shifted by exactly 120 degrees instead of pure blue turned into a “dirty” blue. And since our torso and limbs were colored with the expected “clear” blue, then there was a clear discrepancy of colors.

Of course, we quickly overcame the problem by refusing to generate different colored bodies. Now just the same Hue filter is hung on the green body.

But the problem remained incomprehensible.

Experiment


In an effort to get to the bottom of the truth, I conducted a simple experiment. No longer touching ActionScript, but purely within Flash itself.
  1. created a square with a fill. # 008800
  2. converted to a movie clip
  3. made a copy
  4. I added the filter “Adjust Color” to the copy, where zeros are everywhere except Hue = 120
  5. got what is on the screen shot below - blue color nifiga not blue



I checked several times ... Logic prompted that this could not be. The facts contradicted this ...

But the result is obvious.

Having conducted such an experiment for pure bright red / blue / green - # FF0000, # 0000FF, # 00FF00 - I received another proof of incorrect operation of the filter in the flash. In addition, as you can see - on bright colors, filter errors are even more obvious.

At the same time on the screen I gave the result of the work of the same filter in PhotoShop. Which, as expected, by turning the green at 120 degrees, got exactly the same pure blue. Without any impurities.


The “dirtyness” of the resulting flowers is visible to the naked eye. More precisely, the resulting blue from turning green. Obtained from turning red and blue, despite their color “purity”, for some reason lost their brightness. Rotation at an angle of -120 ° also gives incorrect results.

Explanation.


As it turned out (thanks for the tip to the lsdima habrauser ), the effect is explainable.

The fact is that FLASH's ColorMatrixFilter works exclusively with the RGB color space, trying to apply one single matrix to all pixels. To solve the hue shift problem, it is necessary to translate all pixels from RGB to HSL, perform the conversion in HSL-space, and then translate back. Using matrix transformations in the RGB space is impracticable.

At the same time, for some reason, there are no tools for matrix transformations in HSL space in flash.

This explains why hue on ColorMatrixFilter does not work correctly.

And since when applying the “Adjust Color → Hue” effect in the flash itself, essentially the same thing is done - then in the flash itself we get the same result.

However, I personally believe that this is fundamentally wrong. After all, absolutely all graphic editors showed us exactly how the hue shift effect should work. And when in flash you take and apply the usual hue-effect, you expect to see what you see at all. Confusion arises because Flash uses the conventional term “hue” to denote an effect, which essentially does something different.

But the fact is a fact. Keep in mind.

Findings.


1. The “hue” effect in the flash is essentially some sort of “pseudo-hue”, trying to emulate the effect of the tint shift with not quite applicable tools.
2. For the full (correct) shift effect hue, pixel-by-pixel conversion of the image into the HSL space is necessary. For some reason, there are no similar tools in the flash. Strange, because other pixel pixel image effects exist (for example, the same blur).

Therefore, the correct hue effect in a flash is possible only in two cases:
1. Manually transforming the movie into a bitmap and processing each pixel separately, spending a lot of processor resources on it.
2. When Adobe will add classes of matrix transformations in HSL-space. Something like HSLColorMatrixFilter.

P.S


Habrayuzer GeneralSpecific advises to pay attention to the technology of Pixel Bender , available including and in flash, to solve this problem. Honestly, I did not come across it, so I can’t say anything.

Source: https://habr.com/ru/post/105742/


All Articles