Skip to content
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

Opacity 255 in Alpha Compositing to Behave as Simple Ink #3047

Closed
KasumiArai opened this issue Nov 10, 2021 · 6 comments
Closed

Opacity 255 in Alpha Compositing to Behave as Simple Ink #3047

KasumiArai opened this issue Nov 10, 2021 · 6 comments

Comments

@KasumiArai
Copy link

Open this file:
ninja_bg_index alternate 2
Eyedrop the black in the top left corner of the image in color+alpha mode. Index 15 is selected.
Click index 0 in the palette to select it as the foreground color.
Fill the black in the top left corner of the image with the foreground color with Alpha Compositing ink and alpha 255.
Eyedrop the black in the top left corner of the image. Index 15 is still selected. The expectation was for it to be filled with the same color index.
GIF of this case:
Aseprite Palette Fill Issue

Aseprite 1.3-beta7-x64 Steam
Windows 10

It works as expected in Aseprite 1.2.30-x64 Steam on Windows 10.
It also works as expected with the other blacks in the palette that are not index 0 in Aseprite 1.3-beta7-x64 Steam
I understand the need to color match after compositing for semi transparent brush colors, but this current behavior confused me

@iamOgunyinka
Copy link
Contributor

@dacap I want to ask you about this behavior. In this screenshot I attached, there is a palette that has seven (7) identical colors at different indexes [0, 4, 8, 12, 13, 14, 15]. When we add these colors to the octree map, using their indexes in the palette as the paletteIndex, new values overwrite the old values, as expected in any typical map.

// color 4278190080 is the color of interest here, so the octree map uses a function to calculate the index of the color.

int index = getHextet(4278190080, level);      // almost always yield `8` for levels in [0,8).

So we now have the following sequence:

a[8] = 0;
a[8] = 4;
a[8] = 8;
a[8] = 12;
a[8] = 13;
a[8] = 14;
a[8] = 15;

Of course, the last value is the only value that'd be retained in the map. So when we try to paint a region on the sprite with the first color in the palette, using the TransparentInkProcessing<IndexedTraits>, what we end up using is the color at index 15. So the Eyedrop's behavior is correct.

image

My question: is this a bug or the expected behavior? I can't tell which it is.

@dacap
Copy link
Member

dacap commented Feb 14, 2022

is this a bug or the expected behavior?

@iamOgunyinka I would say that this is a bug. In transparent layers we could expect to map RGBA=0,0,0,255 to the first match in the palette instead of the last one, e.g. in the original example it's 0 for background layers, and index 4 for transparent layers (but never entry 15 as there are other colors in the palette that matches first).

Anyway the "Alpha Compositing" is a little strange in indexed mode, I think that if there is no alpha composition involved (all opacity is 255), and the active color is index, it should just paint the selected index color (so if we have index 15 selected with "Alpha Compositing", it should paint with index 15, not with 0 or 4, this means that we should use just CopyInkProcesing, maybe something to fix here).

About the generation of the octree here, probably changing the order at which palette indexes are processed might fix part of the problem:

  for (int i=palette->size()-1; i>=0; i--) {
    if (i == maskIndex) {
      m_root.addColor(palette->entry(i), 0, &m_root, maskColorBestFitIndex, 8);
      continue;
    }
    m_root.addColor(palette->entry(i), 0, &m_root, i, 8);
  }

Maybe @Gasparoken can say something about it.


@KasumiArai about this case, you can workaround the issue using the old (v1.2) RGB color mapping instead of octree:

Screen Shot 2022-02-14 at 10 01 14

@Gasparoken
Copy link
Member

Hi @iamOgunyinka and @dacap. Will investigate it.

@Gasparoken Gasparoken added the wip label Feb 14, 2022
@Gasparoken Gasparoken self-assigned this Feb 14, 2022
@Gasparoken
Copy link
Member

Gasparoken commented Feb 15, 2022

Anyway the "Alpha Compositing" is a little strange in indexed mode, I think that if there is no alpha composition involved (all opacity is 255), and the active color is index, it should just paint the selected index color (so if we have index 15 selected with "Alpha Compositing", it should paint with index 15, not with 0 or 4, this means that we should use just CopyInkProcesing, maybe something to fix here).

Alpha Compositing has the feature of compositing the color in the sprite with the current selected fg color, then the resulting color is searched through the palette to find the best fit (this search occurs only in Indexed Color Mode).

For example, assume a sprite in Indexed Color Mode with a Background layer, and it has a palette with white as 'transparent' index, green, dark green and semitransparent black:

153892284-a06dea51-b84d-4249-a5ca-c98762e69790

On ink type = Alpha Compositing, If you pick semitransparent black and try painting over a green pixel, it'll result DARK GREEN (i.e. the better color index which RGB is near to the composition of green + semitransparent black).

On the other hand, on ink type = Simple, If you pick semitransparent black and try painting over any color, it'll result in the composition of TRANSPARENT INDEX (white in this case) + semitransparent black = gray.

153896127-ff86320d-da42-4d47-979f-9ad2ed2a4154

I saw when we painting with the Transparent Index color in Alpha Compositing we turn false 'opaque' variable here and that's why Transparent Processing is selected here and finally, the 'pre-composition' is done here

I'm testing this change (but inks.lua test is failing so, I need to do a little more research on it):

Screen Shot 2022-02-15 at 00 21 45

I'll review octree scheme too (tomorrow).

@Gasparoken
Copy link
Member

Thanks @iamOgunyinka! Yeah, you're right, the octree creation process is from the lower to the higher palette index, and each added color overwrites the previous correspondence INDEX <-> COLOR.

I'll change this behavior as @dacap said.

Finally, thanks @KasumiArai for this report!

Gasparoken added a commit that referenced this issue Feb 15, 2022
… in Alpha Compositing to behave as Simple Ink (fix #3047)
@Gasparoken Gasparoken removed the wip label Feb 17, 2022
@dacap dacap modified the milestones: v1.3, v1.3-beta12 Mar 2, 2022
dacap pushed a commit that referenced this issue Mar 2, 2022
… in Alpha Compositing to behave as Simple Ink (fix #3047)
dacap added a commit to aseprite/tests that referenced this issue Mar 2, 2022
@dacap
Copy link
Member

dacap commented Mar 2, 2022

I'm closing this issue but I think still some work to add colors in the octree in reverse order should be done.

@dacap dacap closed this as completed Mar 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants